联系:QQ(5163721)
标题:Linux7(CentOS,RHEL,OEL)和Oracle RAC环境系列-7-网络管理之修改网络接口名
作者:Lunar©版权所有[文章允许转载,但必须以链接方式注明源地址,否则追究法律责任.]
由于Linux7中采用了固定的网络接口名的方式,目的是如果网卡损坏可以方便的使用类似新增网卡的方法进行替换,非常简便
但是如果由于某种原因,需要修改网络接口名就很麻烦,例如想修改为以前的eth0的名称。
Linux7中,使用nmtui修改网络连接和IP地址后,可以使用重建加载配置文件的方式使新的配置生效。
需要注意的是,网络接口名称不能通过nmtui来修改(可以修改,但是修改是无效的,会被自动还原为缺省的网络接口名)。
.
下面是通过修改网络配置文件的方法来修改网络设备接口名称的过程(注意,结论是不能用此方法修改):
[root@lunar1 ~]# cp /etc/sysconfig/network-scripts/ifcfg-enp0s9 /tmp/ifcfg-enp0s3 [root@lunar1 ~]# mv /etc/sysconfig/network-scripts/ifcfg-enp0s9 /etc/sysconfig/network-scripts/ifcfg-eth1 [root@lunar1 ~]#
修改/etc/sysconfig/network-scripts/ifcfg-eth1中的两个地方:
DEVICE=eth1 ———-设备名称(device)
NAME=eth1 ———-连接名称(connect)
修改后:
[root@lunar1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1 DEVICE=enp0s9 HWADDR=08:00:27:A8:83:CF TYPE=Ethernet BOOTPROTO=none DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=no IPV6_FAILURE_FATAL=no NAME=eth1 UUID=5e43be5e-5a8c-4f33-bdd1-dfdce55cec0d ONBOOT=yes IPADDR=192.168.209.15 PREFIX=24 GATEWAY=192.168.209.1 IPV6_PEERDNS=yes IPV6_PEERROUTES=yes [root@lunar1 ~]# [root@lunar1 ~]# ll /etc/sysconfig/network-scripts/ifcfg* -rw-r--r--. 1 root root 319 1月 16 03:08 /etc/sysconfig/network-scripts/ifcfg-enp0s3 -rw-r--r--. 1 root root 319 1月 16 03:08 /etc/sysconfig/network-scripts/ifcfg-enp0s8 -rw-r--r--. 1 root root 325 1月 16 08:28 /etc/sysconfig/network-scripts/ifcfg-eth1 -rw-r--r--. 1 root root 254 9月 16 19:51 /etc/sysconfig/network-scripts/ifcfg-lo [root@lunar1 ~]#
修改后重新加载配置文件:
[root@lunar1 ~]# nmcli con load /etc/sysconfig/network-scripts/ifcfg-eth1 [root@lunar1 ~]#
这样只能修改连接的名称,但是不能修改设备名称:
[root@lunar1 ~]# nmcli dev show eth1
错误:没有找到设备 ‘eth1’。
[root@lunar1 ~]# nmcli dev show enp0s9 GENERAL.设备: enp0s9 GENERAL.类型: ethernet GENERAL.硬盘: 08:00:27:A8:83:CF GENERAL.MTU: 1500 GENERAL.状态: 100 (连接的) GENERAL.CONNECTION: eth1 GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/2 WIRED-PROPERTIES.容器: 开 IP4.地址[1]: 192.168.209.15/24 IP4.网关: 192.168.209.1 IP6.地址[1]: fe80::a00:27ff:fea8:83cf/64 IP6.网关: [root@lunar1 ~]# nmcli conn show 名称 UUID 类型 设备 enp0s8 ba5021c5-727b-4b19-b6eb-c77892fb40b6 802-3-ethernet enp0s8 eth1 5e43be5e-5a8c-4f33-bdd1-dfdce55cec0d 802-3-ethernet enp0s9 enp0s3 3e33deb2-5f53-4850-a424-76042c27b419 802-3-ethernet enp0s3 [root@lunar1 ~]#
在Linux7中修改设备名称只能禁用一致和可预测的网络设备命名规则,即,修改grub,还原到Linux6的设备命名方法:
[root@lunar1 ~]# cat /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="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet" GRUB_DISABLE_RECOVERY="true" [root@lunar1 ~]#
至此,我们看到,不能通过修改配置文件的方法来改变网络接口设备名称。
那么如果一定要在Linux7中将网络设备接口名修改回以前很土的eth0有方法么?
答案是:yes。
.
我们可以通过禁用可命名规则,编辑/etc/default/grub文件来实现。
在该文件的GRUB_CMDLINE_linux=”rhgb quiet”改为GRUB_CMDLINE_LINUX=”net.ifnames=0 biosdevname=0 rhgb quiet”
[root@lunar1 ~]# cp /etc/default/grub /etc/default/grub.orig [root@lunar1 ~]# ls -lrt /etc/default/grub* -rw-r--r--. 1 root root 279 1月 16 08:57 /etc/default/grub.orig -rw-r--r--. 1 root root 307 1月 16 08:58 /etc/default/grub [root@lunar1 ~]# [root@lunar1 ~]# cat /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="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap net.ifnames=0 biosdevname=0 rhgb quiet" GRUB_DISABLE_RECOVERY="true" [root@lunar1 ~]#
运行命令grub2-mkconfig -o /boot/grub2/grub.cfg来重新生成grub配置并更新内核参数:
[root@lunar1 ~]# grub2-mkconfig -o /boot/grub2/grub.cfg Generating grub configuration file ... 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-11f3b15bbc73453287d186e6aa5dda16 Found initrd image: /boot/initramfs-0-rescue-11f3b15bbc73453287d186e6aa5dda16.img done [root@lunar1 ~]# [root@lunar1 ~]# ll /etc/udev/rules.d/70-persistent-ipoib.rules -rw-r--r--. 1 root root 709 11月 20 23:59 /etc/udev/rules.d/70-persistent-ipoib.rules [root@lunar1 ~]# [root@lunar1 ~]# ll /etc/udev/rules.d/70-persistent-ipoib.rules -rw-r--r--. 1 root root 709 11月 20 23:59 /etc/udev/rules.d/70-persistent-ipoib.rules [root@lunar1 ~]# cat /etc/udev/rules.d/70-persistent-ipoib.rules # This is a sample udev rules file that demonstrates how to get udev to # set the name of IPoIB interfaces to whatever you wish. There is a # 16 character limit on network device names though, so don't go too nuts # # Important items to note: ATTR{type}=="32" is IPoIB interfaces, and the # ATTR{address} match must start with ?* and only reference the last 8 # bytes of the address or else the address might not match on any given # start of the IPoIB stack # # Note: as of rhel7, udev is case sensitive on the address field match # and all addresses need to be in lower case. # # ACTION=="add", SUBSYSTEM=="net", DRIVERS=="?*", ATTR{type}=="32", ATTR{address}=="?*00:02:c9:03:00:31:78:f2", NAME="mlx4_ib3" [root@lunar1 ~]#
这里我们看到了熟悉的类似Linux6中的UDEV绑定网络设备的方式。
然后,我们reboot后,可以看到,网络接口名已经还原到了以前的样子:
[root@lunar1 ~]# ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.56.101 netmask 255.255.255.0 broadcast 192.168.56.255 inet6 fe80::a00:27ff:feee:cd8d prefixlen 64 scopeid 0x20<link> ether 08:00:27:ee:cd:8d txqueuelen 1000 (Ethernet) RX packets 56 bytes 6161 (6.0 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 59 bytes 11596 (11.3 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 ether 08:00:27:42:0f:b8 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 50 bytes 8652 (8.4 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eth2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.209.15 netmask 255.255.255.0 broadcast 192.168.209.255 inet6 fe80::a00:27ff:fea8:83cf prefixlen 64 scopeid 0x20<link> ether 08:00:27:a8:83:cf txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 27 bytes 3995 (3.9 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 328 bytes 26600 (25.9 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 328 bytes 26600 (25.9 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@lunar1 ~]# [root@lunar1 ~]# ll /etc/sysconfig/network-scripts/ifcfg* -rw-r--r--. 1 root root 319 1月 16 03:08 /etc/sysconfig/network-scripts/ifcfg-enp0s3 -rw-r--r--. 1 root root 319 1月 16 03:08 /etc/sysconfig/network-scripts/ifcfg-enp0s8 -rw-r--r--. 1 root root 313 1月 16 08:55 /etc/sysconfig/network-scripts/ifcfg-eth1 -rw-r--r--. 1 root root 254 9月 16 19:51 /etc/sysconfig/network-scripts/ifcfg-lo [root@lunar1 ~]# [root@lunar1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1 HWADDR=08:00:27:A8:83:CF TYPE=Ethernet BOOTPROTO=none DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=no IPV6_FAILURE_FATAL=no NAME=eth1 UUID=5e43be5e-5a8c-4f33-bdd1-dfdce55cec0d ONBOOT=yes IPADDR=192.168.209.15 PREFIX=24 GATEWAY=192.168.209.1 IPV6_PEERDNS=yes IPV6_PEERROUTES=yes [root@lunar1 ~]#
现在,我们再还原回到可预测的网络设备命名网络接口的方法:
[root@lunar1 ~]# cp /etc/default/grub.orig /etc/default/grub cp:是否覆盖"/etc/default/grub"? y [root@lunar1 ~]# cat /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="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet" GRUB_DISABLE_RECOVERY="true" [root@lunar1 ~]# [root@lunar1 ~]# grub2-mkconfig -o /boot/grub2/grub.cfg Generating grub configuration file ... 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-11f3b15bbc73453287d186e6aa5dda16 Found initrd image: /boot/initramfs-0-rescue-11f3b15bbc73453287d186e6aa5dda16.img done [root@lunar1 ~]# ll /etc/udev/rules.d/70-persistent-ipoib.rules -rw-r--r--. 1 root root 709 11月 20 23:59 /etc/udev/rules.d/70-persistent-ipoib.rules [root@lunar1 ~]# cat /etc/udev/rules.d/70-persistent-ipoib.rules # This is a sample udev rules file that demonstrates how to get udev to # set the name of IPoIB interfaces to whatever you wish. There is a # 16 character limit on network device names though, so don't go too nuts # # Important items to note: ATTR{type}=="32" is IPoIB interfaces, and the # ATTR{address} match must start with ?* and only reference the last 8 # bytes of the address or else the address might not match on any given # start of the IPoIB stack # # Note: as of rhel7, udev is case sensitive on the address field match # and all addresses need to be in lower case. # # ACTION=="add", SUBSYSTEM=="net", DRIVERS=="?*", ATTR{type}=="32", ATTR{address}=="?*00:02:c9:03:00:31:78:f2", NAME="mlx4_ib3" [root@lunar1 ~]# reboot [root@lunar1 ~]# ifconfig enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.56.11 netmask 255.255.255.0 broadcast 192.168.56.255 inet6 fe80::a00:27ff:feee:cd8d prefixlen 64 scopeid 0x20<link> ether 08:00:27:ee:cd:8d txqueuelen 1000 (Ethernet) RX packets 51 bytes 4801 (4.6 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 59 bytes 10958 (10.7 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.60.11 netmask 255.255.255.0 broadcast 192.168.60.255 inet6 fe80::a00:27ff:fe42:fb8 prefixlen 64 scopeid 0x20<link> ether 08:00:27:42:0f:b8 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 27 bytes 3933 (3.8 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 enp0s9: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.209.15 netmask 255.255.255.0 broadcast 192.168.209.255 inet6 fe80::a00:27ff:fea8:83cf prefixlen 64 scopeid 0x20<link> ether 08:00:27:a8:83:cf txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 27 bytes 3939 (3.8 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 336 bytes 27280 (26.6 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 336 bytes 27280 (26.6 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@lunar1 ~]#
Linux7(CentOS,RHEL,OEL)和Oracle RAC环境系列–1-简介
Linux7(CentOS,RHEL,OEL)和Oracle RAC环境系列-2-修改主机名和hostnamectl工具的使用
Linux7(CentOS,RHEL,OEL)和Oracle RAC环境系列–3-systemd(d.bin和ohasd守护进程)
Linux7(CentOS,RHEL,OEL)和Oracle RAC环境系列–4-target(图形界面和字符界面)
Linux7(CentOS,RHEL,OEL)和Oracle RAC环境系列–5-防火墙
Linux7(CentOS,RHEL,OEL)和Oracle RAC环境系列–6-开机自动启动或者禁用服务
Linux7(CentOS,RHEL,OEL)和Oracle RAC环境系列-7-网络管理之添加网
Linux7(CentOS,RHEL,OEL)和Oracle RAC环境系列-7-网络管理之修改IP地址
Linux7(CentOS,RHEL,OEL)和Oracle RAC环境系列-7-网络管理之修改网络接口名
Linux7(CentOS,RHEL,OEL)和Oracle RAC环境系列-8-在Linux7上安装11.2 RAC和12.1 RAC需要禁用哪些服务
Linux7(CentOS,RHEL,OEL)和Oracle RAC环境系列-9-Linux 7.2上的virbr0设备
Linux7(CentOS,RHEL,OEL)和Oracle RAC环境系列-10-ABRT-系统启动后自动检查和报告错误
Linux7(CentOS,RHEL,OEL)和Oracle RAC环境系列-11-配置VNC和常见问题处理