0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【CentOS】MACアドレス/デバイス名変更【RHEL】

Last updated at Posted at 2022-12-12

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

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?