CentOS7修改网卡名称eth0
我在VMWare workstation里面安装的centos7虚拟机设置了2张网卡,网卡名称默认为eno16777736、eno33554984:
[root@controller ~]# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:50:56:3a:78:ee brd ff:ff:ff:ff:ff:ff inet 192.168.128.85/24 brd 192.168.128.255 scope global eno16777736 valid_lft forever preferred_lft forever inet6 fe80::250:56ff:fe3a:78ee/64 scope link valid_lft forever preferred_lft forever 3: eno33554984: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:72:41:10 brd ff:ff:ff:ff:ff:ff inet 10.10.10.10/24 brd 10.10.10.255 scope global eno33554984 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fe72:4110/64 scope link valid_lft forever preferred_lft forever
如果改为eth0、eth1,该如何操作呢?
1.修改配置
[root@controller ~]# vi /etc/default/grub
GRUB_CMDLINE_LINUX 加上 net.ifnames=0 biosdevname=0 GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0 crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet"
2.重新加载配置
grub2-mkconfig -o /boot/grub2/grub.cfg
[root@controller ~]# grub2-mkconfig -o /boot/grub2/grub.cfg Generating grub configuration file ... Found linux image: /boot/vmlinuz-3.10.0-693.5.2.el7.x86_64 Found initrd image: /boot/initramfs-3.10.0-693.5.2.el7.x86_64.img Found linux image: /boot/vmlinuz-3.10.0-327.28.3.el7.x86_64 Found initrd image: /boot/initramfs-3.10.0-327.28.3.el7.x86_64.img Found linux image: /boot/vmlinuz-3.10.0-327.el7.x86_64 Found initrd image: /boot/initramfs-3.10.0-327.el7.x86_64.img Found linux image: /boot/vmlinuz-0-rescue-0ff0e879cd2f443cb90ec9afa4d66dfb Found initrd image: /boot/initramfs-0-rescue-0ff0e879cd2f443cb90ec9afa4d66dfb.img done
3.修改网卡名称
[root@controller ~]# cd /etc/sysconfig/network-scripts/ [root@controller network-scripts]# vi ifcfg-eno16777736 修改为 NAME=eth0 DEVICE=eth0 [root@controller network-scripts]# mv ifcfg-eno16777736 ifcfg-eth0 同样另外一张网卡改为eth1
4.重启机器
发现通过ssh连接不到 192.168.128.85
进入vmware控制台查看,还是显示原网卡名称,再查看网络服务状态,显示failed
如何解决?
进入目录 /etc/udev/rules.d/ [root@controller ~]# cd /etc/udev/rules.d/ 查看 90-eno-pix.rules # This file was automatically generated on systemd update SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:50:56:3a:78:ee", NAME="eno16777736" SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:72:41:10", NAME="eno33554984"
看到还是之前的网卡名称
删掉此文件,或者改为正确的网卡名称,注意和mac对应,然后重启机器
这次成功了
[root@controller ~]# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:50:56:3a:78:ee brd ff:ff:ff:ff:ff:ff inet 192.168.128.85/24 brd 192.168.128.255 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::250:56ff:fe3a:78ee/64 scope link valid_lft forever preferred_lft forever 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:72:41:10 brd ff:ff:ff:ff:ff:ff inet 10.10.10.10/24 brd 10.10.10.255 scope global eth1 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fe72:4110/64 scope link valid_lft forever preferred_lft forever
Centos 7 网卡配置无错:
[root@h ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=static DEFROUTE=yes IPV4_FAILURE_FATAL=no NAME=eth0 DEVICE=eth0 ONBOOT=yes DNS1=223.5.5.5 DNS2=223.6.6.6 IPV6INIT=no IPADDR=10.0.0.129 NETMASK=255.255.255.0 GATEWAY=10.0.0.2 PREFIX=24