CentOS 7 更改网卡名到以前的eth0
最近安装了CentOS7,内核总算升级到3.10,支持Linux容器,network namespace·······
但是安装完之后,发现ifconfig没看到熟悉的eth0,却是enp0s3,虽然只是一个网卡代号,但明显会影响一些脚本,带来诸多不方便,也不知道CentOS为何设置成这样。于是想把他改回来。
[root@localhost fbw]# ifconfig
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.2.5 netmask 255.255.255.0 broadcast 10.0.2.255
inet6 fe80::a00:27ff:fe80:4d3c prefixlen 64 scopeid 0x20<link>
ether 08:00:27:80:4d:3c txqueuelen 1000 (Ethernet)
RX packets 2134 bytes 176901 (172.7 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1504 bytes 206316 (201.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 538 bytes 46716 (45.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 538 bytes 46716 (45.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
|
于是参考之前的一篇日志 Centos 配置eth0 提示Device does not seem to be present ,先去将ifcfg-enp0s3重命名为ifcfg-eth0,然后去查看/etc/udev/rules.d/70-persistent-net.rules文件,居然发现CentOS7里面没有这个文件,看来之前删除这个重启的方法不奏效了。
先百度一下,找到了一篇《 Centos Linux系统安装后网卡em改回eth的两种方法》,看了其中的第二个方法,改了一下grub的引导文件,重启一下,发现还是没有改名。
后google了一下,找到了一篇《Change default network name to old “eth0″ on RHEL 7 / Fedora 19 above》,也是改了一下grub文件,重启之后成功解决!!!
具体步骤如下:
1、 vim /etc/default/grub
GRUB_TIMEOUT=5 GRUB_DISTRIBUTOR=”$(sed ‘s, release .*$,,g’ /etc/system-release)” GRUB_DEFAULT=saved GRUB_DISABLE_SUBMENU=true GRUB_TERMINAL_OUTPUT=”console” GRUB_CMDLINE_LINUX=”rd.lvm.lv=rootvg/usrlv rd.lvm.lv=rootvg/swaplv crashkernel=auto vconsole.keymap=us rd.lvm.lv=rootvg/rootlv vconsole.font=latarcyrheb-sun16 rhgb quiet” GRUB_DISABLE_RECOVERY=”true”
在GRUB_CMDLINE_LINUX的最后,加上 net.ifnames=0 biosdevname=0 的参数
GRUB_CMDLINE_LINUX=”rd.lvm.lv=rootvg/usrlv rd.lvm.lv=rootvg/swaplv crashkernel=auto vconsole.keymap=us rd.lvm.lv=rootvg/rootlv vconsole.font=latarcyrheb-sun16 rhgb quiet net.ifnames=0 biosdevname=0”
2、 grub2-mkconfig -o /boot/grub2/grub.cfg
3、 mv /etc/sysconfig/network-scripts/ifcfg-enp0s3 /etc/sysconfig/network-scripts/ifcfg-eth0
4、 reboot
最后成功将网卡重名为eth0,嗯~~,还是那个味道,还是那么亲切~~~
[fbw@localhost ~]$ ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 10.0.2.5 netmask 255.255.255.0 broadcast 10.0.2.255 inet6 fe80::a00:27ff:fe80:4d3c prefixlen 64 scopeid 0x20<link> ether 08:00:27:80:4d:3c txqueuelen 1000 (Ethernet) RX packets 56 bytes 7959 (7.7 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 70 bytes 10796 (10.5 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 0 (Local Loopback) RX packets 5 bytes 580 (580.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 5 bytes 580 (580.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 |