RHEL6.4下用udev做网卡名称绑定

无论你是系统工程师,还是运维工程师,亦或是数据库工程师等等,均有可能会遇到需要网卡特殊命名的时候,本文基于RHEL6.4系统为例介绍如何做网卡名称绑定,仅供参考!


环境:rhel6.4操作系统

要求:将网卡eth0 改名为 public0


步骤介绍:

    1. 查看当前eth0网卡的信息

    2. 写Udev规则指定网卡名称

    3. 网卡文件修改以及网卡信息查看

    4. 重启验证

    5. 网卡跳号解决方案


查看当前eth0网卡的信息

    # udevadm  info  --query=path  --path=/sys/class/net/eth0  --attribute

        .......................

        looking at device '/devices/pci0000:00/0000:00:11.0/0000:02:02.0/net/eth0':

        KERNEL=="eth0"

        SUBSYSTEM=="net"

        DRIVER==""

        ATTR{addr_assign_type}=="0"

        ATTR{addr_len}=="6"

        ATTR{dev_id}=="0x0"

        ATTR{ifalias}==""

        ATTR{iflink}=="3"

        ATTR{ifindex}=="3"

        ATTR{features}=="0x10b89"

        ATTR{type}=="1"

        ATTR{link_mode}=="0"

        ATTR{address}=="00:0c:29:20:34:b9"

        ATTR{broadcast}=="ff:ff:ff:ff:ff:ff"

        ATTR{carrier}=="1"

        ATTR{speed}=="1000"

        ATTR{duplex}=="full"

        ATTR{dormant}=="0"

        ATTR{operstate}=="up"

        ATTR{mtu}=="1500"

        ATTR{flags}=="0x1003"

        ATTR{tx_queue_len}=="1000"

        ..............................


参考上面的输出,截取能够唯一标识eth0网卡的信息,开始写udev规则

    # vim /etc/udev/rules.d/99-nic.rules

        SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:20:34:b9", ATTR{type}=="1", KERNEL=="eth*", NAME="public"


查看现在网卡的名称

    # ifconfig

    

        eth0   Link encap:Ethernet  HWaddr 00:0C:29:20:34:B9  

                  inet addr:192.168.1.121  Bcast:192.168.1.255  Mask:255.255.255.0

                  inet6 addr: fe80::20c:29ff:fe20:34b9/64 Scope:Link

                  UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

                  RX packets:361 errors:0 dropped:0 overruns:0 frame:0

                  TX packets:14 errors:0 dropped:0 overruns:0 carrier:0

                  collisions:0 txqueuelen:1000 

                  RX bytes:45981 (44.9 KiB)  TX bytes:1622 (1.5 KiB)


        eth1    Link encap:Ethernet  HWaddr 00:0C:29:20:34:AF  

                  inet addr:192.168.1.120  Bcast:192.168.1.255  Mask:255.255.255.0

                  inet6 addr: fe80::20c:29ff:fe20:34af/64 Scope:Link

                  UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

                  RX packets:1364 errors:0 dropped:0 overruns:0 frame:0

                  TX packets:840 errors:0 dropped:0 overruns:0 carrier:0

                  collisions:0 txqueuelen:1000 

                  RX bytes:137901 (134.6 KiB)  TX bytes:112227 (109.5 KiB)


            .......................


修改网卡的配置文件

    # cd /etc/sysconfig/network-scripts/

    # mv ifcfg-eth0  ifcfg-public0

    # vim ifcfg-public0 

        DEVICE="eth0"  --->  DEVICE="public0"


重启机器看是否生效

    # reboot

    # ifconfig

        eth0      Link encap:Ethernet  HWaddr 00:0C:29:20:34:AF  

                  inet addr:192.168.1.120  Bcast:192.168.1.255  Mask:255.255.255.0

                  inet6 addr: fe80::20c:29ff:fe20:34af/64 Scope:Link

                  UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

                  RX packets:140 errors:0 dropped:0 overruns:0 frame:0

                  TX packets:108 errors:0 dropped:0 overruns:0 carrier:0

                  collisions:0 txqueuelen:1000 

                  RX bytes:16902 (16.5 KiB)  TX bytes:14153 (13.8 KiB)


        public0   Link encap:Ethernet  HWaddr 00:0C:29:20:34:B9  

                  inet addr:192.168.1.121  Bcast:192.168.1.255  Mask:255.255.255.0

                  inet6 addr: fe80::20c:29ff:fe20:34b9/64 Scope:Link

                  UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

                  RX packets:30 errors:0 dropped:0 overruns:0 frame:0

                  TX packets:11 errors:0 dropped:0 overruns:0 carrier:0

                  collisions:0 txqueuelen:1000 

                  RX bytes:5875 (5.7 KiB)  TX bytes:1365 (1.3 KiB)

        ...........................................


如果出现网卡跳号的情况,解决方法如下:

    删除默认网卡命名的文件,并重启即可

        # rm -rf /etc/udev/rules.d/70-persistent-net.rules

        # reboot















你可能感兴趣的:(网卡udev命名)