天天看点

centos7实战之网卡名从eth1改为eth0,设置固定IPcentos网卡名从eth1改为eth0,设置固定IP

centos网卡名从eth1改为eth0,设置固定IP

网卡名默认是eth0,那为什么会变成eth1呢?

是因为我们在开启linux镜像的时候,点了复制该虚拟机导致的。

centos7实战之网卡名从eth1改为eth0,设置固定IPcentos网卡名从eth1改为eth0,设置固定IP

修改eth0

vim  /etc/udev/rules.d/70-persistent-net.rules 

# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.


# PCI device 0x8086:0x100f (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:d3:d1:35", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

# PCI device 0x8086:0x100f (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0C:29:B5:B2:69", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
           

此时如果你去修改/etc/sysconfig/network-scripts/ifcfg-eth0文件,改IP是没有用的,因为现在系统起作用的是eth1网卡,而这个文件只对eth0有效(我试的是这样,如果错了请告我)。

所以我们需要把/etc/udev/rules.d/70-persistent-net.rules 中的eth0删除,然后把eth1改成eth0。改完之后我们还需修改/etc/sysconfig/network-scripts/ifcfg-eth0文件

设置固定IP

vim /etc/udev/rules.d/70-persistent-net.rules 

# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.


# PCI device 0x8086:0x100f (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:51:62:2d", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
           

此时只有我们设置好的eth0网卡了,我们需要把eth0的网卡地址在/etc/sysconfig/network-scripts/ifcfg-eth0配置一下即可

vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0 #网卡名称
HWADDR=00:0c:29:51:62:2d #MAC地址改成eth0的地址就行
TYPE=Ethernet
UUID=ea47e492-95cc-4d39-b186-ba1bc3b189e2
ONBOOT=yes #相当于启动这个网卡的开关,你要用eth0这个一定要yes,表示开
NM_CONTROLLED=yes 
BOOTPROTO=static #获取ip的方式(static/dhcp(动态获取)/bootp/none) 
IPADDR=192.168.211.130 #IP地址 我们需要设的(注意要和自己电脑同一网段呀!不然ping不通)
NETMASK=255.255.255.0 #子网掩码
NETWORK=192.168.211.0 #网络地址
BROADCAST=192.168.0.255 #广播地址
NBROOT=yes  #  系统启动时是否设置此网络接口,设置为yes时,系统启动时激活此设备。
           

修改完成后,把虚拟机镜像重启即可了,如果不重启,则当前的虚拟机还是使用的eth1。

继续阅读