RHEL 7/centos 7 NIC名をeth 0に変更


RHEL 7では新しいNIC名の命名方法が採用されているため、NIC名の理解と記憶が困難になるが、本稿では、NIC名を従来のeth 0に変更する命名方法を紹介し、任意のNICをeth 0と定義ことができる.
私のブログにはもう一つのネットカードの名前を変更する方法があります.参考にしてください.linux/RHEL 7/centos 7ネットカードの名前をeth 0に変更します.

NICの名前変更手順の説明


NIC名を変更するには、まずlinux NICデバイスの名前を変更する手順を理解します.赤い帽子の公式ドキュメントによると、デバイスの名前を変更する手順は以下の通りです.
  • A rule in/usr/lib/udev/rules.d/60-net.rules instructs the udev helper utility,/lib/udev/rename_device,to look into all/etc/sysconfig/networkscripts/ifcfg-suffix files.If it finds an ifcfg file with a HWADDR entry matching the MAC address of an interface it renames the interface to the name given in the ifcfg file by the DEVICE directive.
  • A rule in/usr/lib/udev/rules.d/71-biosdevname. rules instructs biosdevname to rename the interface according to its naming policy, provided that it was not renamed in a previous step, biosdevname is installed, and biosdevname=0 was not given as a kernel command on the boot command line.
  • A rule in/lib/udev/rules.d/75-net-description.rules instructs udev to fill in the internal udev device property values ID_NET_NAME_ONBOARD, ID_NET_NAME_SLOT, ID_NET_NAME_PATH, ID_NET_NAME_MAC by examining the network interface device.Note,that some device properties might be undefined.
  • A rule in/usr/lib/udev/rules.d/80-net-name-slot.rules instructs udev to rename the interface, provided that it was not renamed in step 1 or 2, and the kernel parameter net.ifnames=0 was not given, according to the following priority: ID_NET_NAME_ONBOARD,ID_NET_NAME_SLOT,ID _NET_NAME_PATH. It falls through to the next in the list, if one is unset. If none of these are set, then the interface will not be renamed.

  • 簡単な翻訳は以下の通りです.
  • /usr/lib/udev/rules.d/60-net.rulesファイルのルールでは、udevヘルプツール/lib/udev/renamedeviceがすべての/etc/sysconfig/networkscripts/ifcfg-suffixファイルを表示します.HWADDRエントリを含むifcfgファイルがあるインタフェースのMACアドレスと一致していることが判明した場合、そのインタフェースはifcfgファイルのDEVICE命令によって与えられた名前に名前を変更します.
  • /usr/lib/udev/rules.d/71-biosdevname.rulesのルールでは、biosdevnameがそのネーミングポリシーに従ってインタフェースの名前を変更されます.このネーミングメソッドは、前のステップでインタフェースの名前を変更しなかったが、biosdevnameがインストールされ、bootコマンドラインでbiosdevname=0がカーネルコマンドとして与えられることを前提として実行されます.
  • /lib/udev/rules.d/75-net-description.rulesのルールはudevにネットワークインタフェースデバイスをチェックさせ、内部udevデバイス属性値ID_を記入させる.NET_NAME_ONBOARD、ID_NET_NAME_SLOT、ID_NET_NAME_PATH.注意:一部のデバイスのプロパティは未定義の場合があります.
  • /usr/lib/udev/rules.d/80-net-name-slot.rulesのルールはudevにインタフェースの名前を変更させ、優先順位は以下の通りです:ID_NET_NAME_ONBOARD、ID_NET_NAME_SLOT、ID_NET_NAME_PATH.すなわち、ステップ1または2でインタフェースの名前を変更する、カーネルパラメータnetが与えられない.ifnames=0の場合、このルールに従って名前が変更されます.このルールに従って名前を変更すると、パラメータが設定されていない場合は、リストの順序で次のパラメータが設定されます.パラメータが設定されていない場合は、インタフェースの名前は変更されません.

  • NICの名前変更方法


    以上の説明に従って、ここでは手順1の説明に従ってNICの名前を変更できます.
  • ifconfigコマンド各NIC MACアドレス
  • を表示
    [root@test01 ~]# ifconfig 
    enp0s3: flags=4163  mtu 1500
            ether 08:00:27:43:c1:1d  txqueuelen 1000  (Ethernet)
            RX packets 233  bytes 43354 (42.3 KiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 0  bytes 0 (0.0 B)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    enp0s8: flags=4163  mtu 1500
            inet 192.168.56.102  netmask 255.255.255.0  broadcast 192.168.56.255
            inet6 fe80::a00:27ff:fe56:9530  prefixlen 64  scopeid 0x20
            ether 08:00:27:56:95:30  txqueuelen 1000  (Ethernet)
            RX packets 259  bytes 48117 (46.9 KiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 50  bytes 8735 (8.5 KiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    enp0s9: flags=4163  mtu 1500
            inet 192.168.56.101  netmask 255.255.255.0  broadcast 192.168.56.255
            inet6 fe80::a00:27ff:fea5:4fd  prefixlen 64  scopeid 0x20
            ether 08:00:27:a5:04:fd  txqueuelen 1000  (Ethernet)
            RX packets 1213  bytes 131145 (128.0 KiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 771  bytes 86683 (84.6 KiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    lo: flags=73  mtu 65536
            inet 127.0.0.1  netmask 255.0.0.0
            inet6 ::1  prefixlen 128  scopeid 0x10
            loop  txqueuelen 0  (Local Loopback)
            RX packets 1220  bytes 105112 (102.6 KiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 1220  bytes 105112 (102.6 KiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

    このことから、NIC MACアドレスは、それぞれ、
    enp0s3: 08:00:27:43:c1:1d
    enp0s8: 08:00:27:56:95:30
    enp0s9: 08:00:27:a5:04:fd

    ここで、NIC名の対応関係を変更するには、次のようにします.
    enp0s3: 08:00:27:43:c1:1d --eth0
    enp0s8: 08:00:27:56:95:30 --eth1
    enp0s9: 08:00:27:a5:04:fd --eth2
    #   :               ,  enp0s8   eth2,enp0s9   eth2.
  • NICプロファイルの名前変更
  • [root@test01 ~]# cd /etc/sysconfig/network-scripts/
    [root@test01 network-scripts]# ls ifcfg-*
    ifcfg-enp0s3 ifcfg-lo      
    [root@test01 network-scripts]# 
    #           ,                 
    [root@test01 network-scripts]# nmcli connection add type ethernet ifname enp0s8 con-name enp0s8 autoconnect yes 
            'enp0s8'(71306055-0869-4125-955a-4b7959cc9226)。
    [root@test01 network-scripts]# nmcli connection add type ethernet ifname enp0s9 con-name enp0s9 autoconnect yes 
            'enp0s9'(9d5a3033-b478-4076-95b0-83e62aa62cbe)。
    [root@test01 network-scripts]# ls ifcfg-*
    ifcfg-enp0s3  ifcfg-enp0s8  ifcfg-enp0s9  ifcfg-lo
    
    [root@test01 network-scripts]# mv ifcfg-enp0s3 ifcfg-eth0
    [root@test01 network-scripts]# mv ifcfg-enp0s8 ifcfg-eth1
    [root@test01 network-scripts]# mv ifcfg-enp0s9 ifcfg-eth2
    [root@test01 network-scripts]# 
    [root@test01 network-scripts]# ls ifcfg-*
    ifcfg-eth0  ifcfg-eth1  ifcfg-eth2  ifcfg-lo
  • NICプロファイル
  • を変更
    プロファイル名を変更した後、HWADDR、DEVICE、NAMEパラメータを変更またはプロファイルに追加します.
    [root@test01 network-scripts]# cat ifcfg-eth0 
    TYPE=Ethernet
    BOOTPROTO=none
    DEFROUTE=yes
    IPV4_FAILURE_FATAL=no
    IPV6INIT=no
    IPV6_AUTOCONF=yes
    IPV6_DEFROUTE=yes
    IPV6_PEERDNS=yes
    IPV6_PEERROUTES=yes
    IPV6_FAILURE_FATAL=no
    NAME=eth0          --    NAME=eth0
    UUID=77c7f1b8-ddef-4d96-bf74-68ecedc99a1a
    DEVICE=eth0 --    DEVICE=eth0
    ONBOOT=yes
    IPADDR=192.168.56.10
    PREFIX=24
    HWADDR=08:00:27:43:c1:1d  --    HWADDR

    以上の方法で、すべてのNICプロファイルを変更します.
  • コピープロファイル60-net.rules
  • [root@test01 network-scripts]# cp /usr/lib/udev/rules.d/60-net.rules /etc/udev/rules.d/
  • システムを再起動してNIC名を表示する
  • shutdown -r 0

    以上のように変更することで、異なるMACアドレスのNICに対応するNIC名を自由に定義することができる、プロファイルにHWADDRを追加した上で、プロファイル名ifcfg-ethxとその中のDEVICE=ethx、NAME=ethxを変更するだけでよい.
    [root@test01 ~]# ifconfig 
    eth0: flags=4163  mtu 1500
            ether 08:00:27:43:c1:1d  txqueuelen 1000  (Ethernet)
            RX packets 9  bytes 3788 (3.6 KiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 0  bytes 0 (0.0 B)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    eth1: flags=4163  mtu 1500
            inet 192.168.56.102  netmask 255.255.255.0  broadcast 192.168.56.255
            inet6 fe80::a00:27ff:fe56:9530  prefixlen 64  scopeid 0x20
            ether 08:00:27:56:95:30  txqueuelen 1000  (Ethernet)
            RX packets 16  bytes 5825 (5.6 KiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 21  bytes 4149 (4.0 KiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    eth2: flags=4163  mtu 1500
            inet 192.168.56.101  netmask 255.255.255.0  broadcast 192.168.56.255
            inet6 fe80::a00:27ff:fea5:4fd  prefixlen 64  scopeid 0x20
            ether 08:00:27:a5:04:fd  txqueuelen 1000  (Ethernet)
            RX packets 66  bytes 11712 (11.4 KiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 63  bytes 10460 (10.2 KiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0