首页 > 所有文章 > 行业 >文章详情

静态ip 变成自动获取(家用宽带ip是静态还是动态)

时间:2023-10-27 21:21:11 浏览量:17

怎么将linux的动态IP设置成静态IP?

例如我的eth0网卡信息如下

eth0 Link encap:Ethernet HWaddr 00:0C:29:AA:B2:CA

inet addr:192.168.79.135 Bcast:192.168.79.255 Mask:255.255.254.0

inet6 addr: fe80::20c:29ff:feaa:b2ca/64 Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

RX packets:208685 errors:0 dropped:0 overruns:0 frame:0

TX packets:53443 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:42393010 (40.4 MiB) TX bytes:18010745 (17.1 MiB)


现在我想把我的本地IP固定成192.168.79.133(用虚拟机的童鞋都知道, IP老是变化好麻烦)

1.查看网关地址, 我的是192.168.79.2

> # route -n

Kernel IP routing table

Destination Gateway Genmask Flags Metric Ref Use Iface

192.168.78.0 0.0.0.0 255.255.254.0 U 1 0 0 eth0

0.0.0.0 192.168.79.2 0.0.0.0 UG 0 0 0 eth0

此时的网关: 192.168.199.2

掩码: 255.255.255.0

2.查看DNS,我的是192.168.79.2

> # cat /etc/resolv.conf

# Generated by NetworkManager

search 7

nameserver 192.168.79.2

3.配置网卡信息, 我的是 vim /etc/sysconfig/network-scripts/ifcfg-eth0

配置信息如下

DEVICE="eth0"

IPV6INIT="yes"

NM_CONTROLLED="yes"

ONBOOT="yes"

TYPE="Ethernet"BOOTPROTO=static

DNS1=192.168.79.2

IPADDR=192.168.79.133

NETMASK=255.255.254.0

GATEWAY=192.168.79.2

通用需要修改的参数

BOOTPROTO="static"

DNS1=192.168.79.2

IPADDR=192.168.79.133

NETMASK=255.255.254.0

GATEWAY=192.168.79.2

重启网络

systemctl restart network

来源:https://www.cnblogs.com/xiaozong/p/7070015.html

Linux系统\Centos没有网卡eth0配置文件怎么办?

一般来说如果没有网卡eth0配置文件, 你到网卡配置目/etc/sysconfig/network-scripts/下面都会有一个 ifcfg-lo 回环接口配置文件(可以复制其他的配置文件), 拷贝一份

> # cd /etc/sysconfig/network-scripts

> # pwd

/etc/sysconfig/network-scripts

> # cp cp ifcfg-ziroom502 ifcfg-eth0

拷贝了一个lo配置文件之后, 把文件IP地址和参数改一下改成eth0保存即可

[root@localhost ~]# ifconfig

enp2s0: flags=4099 mtu 1500

ether ec:aa:a0:26:df:11 txqueuelen 1000 (Ethernet)

RX packets 0 bytes 0 (0.0 B)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 0 bytes 0 (0.0 B)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73 mtu 65536

inet 127.0.0.1 netmask 255.0.0.0

inet6 ::1 prefixlen 128 scopeid 0x10

loop txqueuelen 1000 (Local Loopback)

RX packets 68 bytes 5912 (5.7 KiB)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 68 bytes 5912 (5.7 KiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

virbr0: flags=4099 mtu 1500

inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255

ether 52:54:00:5e:7f:0a txqueuelen 1000 (Ethernet)

RX packets 0 bytes 0 (0.0 B)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 0 bytes 0 (0.0 B)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

wlp1s0: flags=4163 mtu 1500

inet 192.168.8.236 netmask 255.255.255.0 broadcast 192.168.8.255

inet6 fe80::21f6:8823:b668:701b prefixlen 64 scopeid 0x20

ether 2c:6e:85:60:cb:c4 txqueuelen 1000 (Ethernet)

RX packets 121494 bytes 173704591 (165.6 MiB)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 46497 bytes 4666787 (4.4 MiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Last login: Fri May 1 09:53:12 2020 from desktop-gmsei0s.lan

[root@localhost ~]# ifconfig

enp2s0: flags=4099 mtu 1500

ether ec:aa:a0:26:df:11 txqueuelen 1000 (Ethernet)

RX packets 0 bytes 0 (0.0 B)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 0 bytes 0 (0.0 B)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73 mtu 65536

inet 127.0.0.1 netmask 255.0.0.0

inet6 ::1 prefixlen 128 scopeid 0x10

loop txqueuelen 1000 (Local Loopback)

RX packets 72 bytes 6256 (6.1 KiB)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 72 bytes 6256 (6.1 KiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

virbr0: flags=4099 mtu 1500

inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255

ether 52:54:00:5e:7f:0a txqueuelen 1000 (Ethernet)

RX packets 0 bytes 0 (0.0 B)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 0 bytes 0 (0.0 B)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

wlp1s0: flags=4163 mtu 1500

inet 192.168.8.236 netmask 255.255.255.0 broadcast 192.168.8.255

inet6 fe80::21f6:8823:b668:701b prefixlen 64 scopeid 0x20

ether 2c:6e:85:60:cb:c4 txqueuelen 1000 (Ethernet)

RX packets 128179 bytes 182388737 (173.9 MiB)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 50886 bytes 5188221 (4.9 MiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0