VMコピーなどでMACアドレスを変更したい場合とか、ethXXのデバイス名がおかしくなった場合の対応。
dmesg | grep eth
udev: renamed network interface eth0 to eth7
udev: renamed network interface eth1 to eth8
名前が変わってしまっている...
[root@host01 ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 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: eth7: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
link/ether 52:54:00:c6:XX:XX brd ff:ff:ff:ff:ff:ff
3: eth8: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
link/ether 52:54:00:c6:XX:XX brd ff:ff:ff:ff:ff:ff
こりゃ気持ち悪い。
まずIPアドレス設定と同じファイルに新しいMACアドレスを指定します。
/etc/sysconfig/network-scripts/ifcfg-ethX
HWADDR=52:54:00:c6:XX:XX #ここに変更後のMACアドレスを記載
その後/etc/udev/rules.d
フォルダ配下にある70-presistent-net.rules
ファイルの各NICのデバイス名とMACアドレスの記載を書き換えましょう。
/etc/udev/rules.d/70-persistent-net.rules
[root@host01 ~]# vi /etc/udev/rules.d/70-persistent-net.rules
"70-persistent-net.rules" 56L, 3153C# 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 0x1af4:0x1000 (virtio-pci)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:c6:XX:X1", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
# PCI device 0x1af4:0x1000 (virtio-pci)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:c6:XX:X2", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
# PCI device 0x1af4:0x1000 (virtio-pci)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:c6:XX:X3", ATTR{type}=="1", KERNEL=="eth*", NAME="eth2"
# PCI device 0x1af4:0x1000 (virtio-pci)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:c6:XX:X4", ATTR{type}=="1", KERNEL=="eth*", NAME="eth3"
ATTR{address}==
とNAME=
を変更。ethX以外の名前にしたい場合もここ。
で、ネットワーク再起動
systemctl restart network
以上。