当前位置: 首页 > Linux > 正文

CentOS 7 修改网卡名称为eth0

1、编辑网卡配置文件
# vim /etc/sysconfig/network-scripts/ifcfg-ens160
把参数 DEVICE 改为 eth0
把参数 NAME 改为 eth0

2、重命名 ifcfg-ens160
mv ifcfg-ens160 ifcfg-eth0

3、禁用内核默认的全名规则
编辑配置文件 /etc/default/grub
修改参数 GRUB_CMDLINE_LINUX 加入 net.ifnames=0 devname=0

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="crashkernel=auto rd.lvm.lv=ol/root rd.lvm.lv=ol/swap rd.lvm.lv=ol/swap00 rhgb quiet numa=off transparent_hugepag
e=neveri  net.ifnames=0 devname=0"
GRUB_DISABLE_RECOVERY="true"

4、执行 grub2-mkconfig -o /boot/grub2/grub.cfg

# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.1.12-94.3.9.el7uek.x86_64
Found initrd image: /boot/initramfs-4.1.12-94.3.9.el7uek.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-693.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-693.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-d2b9f2dff7e04f9f955b7e6f1cc15906
Found initrd image: /boot/initramfs-0-rescue-d2b9f2dff7e04f9f955b7e6f1cc15906.img
done

5、reboot重启系统

6、修改系统名称
hostnamectl set-hostname hisdb01

更改前:

# ifconfig 
ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 100.1.2.42  netmask 255.255.255.0  broadcast 100.1.2.255
        inet6 fe80::250:56ff:fea1:3458  prefixlen 64  scopeid 0x20<link>
        ether 00:50:56:a1:34:58  txqueuelen 1000  (Ethernet)
        RX packets 193391  bytes 213596167 (203.7 MiB)
        RX errors 0  dropped 106  overruns 0  frame 0
        TX packets 71669  bytes 6432303 (6.1 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens192: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:50:56:a1:7c:b9  txqueuelen 1000  (Ethernet)
        RX packets 15473  bytes 1432670 (1.3 MiB)
        RX errors 0  dropped 105  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens224: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:50:56:a1:12:cc  txqueuelen 1000  (Ethernet)
        RX packets 71514  bytes 5328879 (5.0 MiB)
        RX errors 0  dropped 106  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens256: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:50:56:a1:4a:e9  txqueuelen 1000  (Ethernet)
        RX packets 71513  bytes 5328819 (5.0 MiB)
        RX errors 0  dropped 105  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<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 644  bytes 54460 (53.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 644  bytes 54460 (53.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

更改后:

# ifconfig 
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 100.1.2.41  netmask 255.255.255.0  broadcast 100.1.2.255
        inet6 fe80::250:56ff:fea1:4f3b  prefixlen 64  scopeid 0x20<link>
        ether 00:50:56:a1:4f:3b  txqueuelen 1000  (Ethernet)
        RX packets 146  bytes 12382 (12.0 KiB)
        RX errors 0  dropped 10  overruns 0  frame 0
        TX packets 79  bytes 11603 (11.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:50:56:a1:18:b8  txqueuelen 1000  (Ethernet)
        RX packets 111  bytes 8391 (8.1 KiB)
        RX errors 0  dropped 9  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:50:56:a1:3c:35  txqueuelen 1000  (Ethernet)
        RX packets 183  bytes 12796 (12.4 KiB)
        RX errors 0  dropped 10  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:50:56:a1:67:55  txqueuelen 1000  (Ethernet)
        RX packets 181  bytes 12676 (12.3 KiB)
        RX errors 0  dropped 8  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<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 280  bytes 25348 (24.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 280  bytes 25348 (24.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

本文固定链接: http://t.yjsec.com/index.php/2018/03/02/418/ | 下一站

该日志由 admin 于2018年03月02日发表在 Linux 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: CentOS 7 修改网卡名称为eth0 | 下一站

CentOS 7 修改网卡名称为eth0:等您坐沙发呢!

发表评论

快捷键:Ctrl+Enter