1、dmesg |grep -i eth

ethtool -i eth1

[root@centos6 ~]# dmesg |grep -i eth
e1000 0000:02:01.0: eth0: (PCI:66MHz:32-bit) 00:50:56:3f:3f:87
e1000 0000:02:01.0: eth0: Intel(R) PRO/1000 Network Connection
e1000 0000:02:05.0: eth1: (PCI:66MHz:32-bit) 00:50:56:25:24:c8
e1000 0000:02:05.0: eth1: Intel(R) PRO/1000 Network Connection

卸载网卡驱动:modprobe -r e1000

装载网卡驱动:modprobe e1000 

2、编辑 /etc/udev/rules.d/70-persistent-net.rules #注意mac 地址

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:50:56:25:24:c8", ATTR{type}=

="1", KERNEL=="eth*", NAME="eth1"



# PCI device 0x8086:0x100f (e1000)

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:50:56:3f:3f:87", ATTR{type}=

="1", KERNEL=="eth*", NAME="eth0"


blob.png


3、编辑静态网卡:/etc/sysconfig/network-scripts

[root@centos6 network-scripts]# vim ifcfg-eth0
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=192.168.30.104
GATEWAY=192.168.30.1
DNS1=192.168.30.1

4、编辑动态网卡:/etc/sysconfig/network-scripts

[root@centos6 network-scripts]# vim ifcfg-eth1
TYPE=Ethernet
#BOOTPROTO=static
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eth1
DEVICE=eth1
ONBOOT=yes

5、reboot/init 6 


6、验证结果:

centos 6 修改网卡名_第1张图片


7、脚本转载:

[root@centos6 network-scripts]# cat f1.sh 
VERSION=`egrep -o "[0-9]+" /etc/centos-release | head -1`
 
dev_list() {
    echo -e "\033[31mthe device list as following:\033[0m\n==========="
    ip a | grep mtu | awk -F "[ :]+" '{print $2}' | grep -v lo
    echo "==========="
}
 
change_name() {
    if [ ${VERSION} != "6" ];then
        echo "only support centos6";exit 
    fi
    
    dev_list
    
    read -p "please select a device:" OLD_NAME
    read -p "please input a new device name:" NEW_NAME
    
    /sbin/ifconfig ${OLD_NAME} &> /dev/null
    if [ $? -ne 0 ];then
        echo -e "\033[31mdevice [${OLD_NAME}] do not found\033[0m";exit
    fi
    
    DRIVER=`ethtool -i ${OLD_NAME} | awk -F "[: ]+" '/driver/{print $2}'`
    cd /etc/sysconfig/network-scripts/ && \
    sed -i "/DEVICE=/s/${OLD_NAME}/${NEW_NAME}/" ifcfg-${OLD_NAME}
    sed -i "/NAME=/s/${OLD_NAME}/${NEW_NAME}/" ifcfg-${OLD_NAME}
    sed -i "/${OLD_NAME}/s/${OLD_NAME}/${NEW_NAME}/" /etc/udev/rules.d/70-persistent-net.rules
    mv ifcfg-${OLD_NAME} ifcfg-${NEW_NAME}
    modprobe -r $DRIVER
    modprobe $DRIVER
    /etc/init.d/network restart
}
 
change_name