在测试或生产环境中,经常会遇到克隆的服务器(虚拟机),网卡配置经常也会克隆为eth1,下面讲如何将网卡配置修改为eth0(eth1网卡也可以正常使用,但是有些强逼症的同学看不习惯);
配置环境:RHEL6
目录
步骤一:更改服务器的网卡名,将克隆的服务器网卡配置修改为eth0;
步骤二:修改网卡名(ifcfg-eth1修改为ifcfg-eth0)
步骤三:修改网卡配置(DEVICE=eth1修改为DEVICE=eth0)
步骤四:重启,重新加载网卡信息
[root@localhost ~]# ip a
1: lo: mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth1: mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:bc:7a:aa brd ff:ff:ff:ff:ff:ff
inet 192.168.50.44/27 brd 192.168.50.63 scope global eth1
inet6 fe80::20c:29ff:febc:7aaa/64 scope link
valid_lft forever preferred_lft forever
3: pan0: mtu 1500 qdisc noop state DOWN
link/ether 9e:62:69:38:2f:f0 brd ff:ff:ff:ff:ff:ff
网卡MAC地址记录(唯一):00:0c:29:bc:7a:aa,稍后修改;
[root@localhost ~]# cat /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:7d:e0:e9", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
# PCI device 0x8086:0x100f (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:bc:7a:aa", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
找到对应MAC地址的网卡配置,修改为eth0,其他网卡配置注释掉,如下:
[root@localhost ~]# 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:7d:e0:e9", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
# PCI device 0x8086:0x100f (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:bc:7a:aa", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
mv /etc/sysconfig/network-scripts/ifcfg-eth1 /etc/sysconfig/network-scripts/ifcfg-eth0
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=dhcp
#IPADDR=192.168.2.30
#NETMAST=255.255.255.0
#GATEWAY=192.168.2.254
[root@localhost ~]# /etc/init.d/network restart
关闭环回接口: [确定]
弹出环回接口: [确定]
弹出界面 eth0: 活跃连接状态:激活中
活跃连接路径:/org/freedesktop/NetworkManager/ActiveConnection/3
状态:激活中
状态:激活的
连接被激活
[确定]
[root@localhost ~]# reboot
重启完成后观察已经修改为eth0,恭喜完成修改-z-
[root@localhost ~]# ip a
1: lo: mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:bc:7a:aa brd ff:ff:ff:ff:ff:ff
inet 192.168.50.44/27 brd 192.168.50.63 scope global eth0
inet6 fe80::20c:29ff:febc:7aaa/64 scope link
valid_lft forever preferred_lft forever
3: pan0: mtu 1500 qdisc noop state DOWN
link/ether 32:ac:93:52:29:2f brd ff:ff:ff:ff:ff:ff