centos6 修改网卡名脚本

centos6 修改网卡名脚本

#!/bin/bash
#
#********************************************************************
#Author         : shchangming
#QQ             : 414945814
#Date           : 2016-12-27
#FileName       : change_ifname.sh
#URL            : https://www.cnblogs.com/shichangming
#Description    : This script is to change Ethernet name on centos6
#Copyright (C)  : 2018 All rights reserved
#********************************************************************

VERSION=`grep -Eo "[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 "/${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

本文链接:https://www.cnblogs.com/shichangming/p/10198063.html

转载于:https://www.cnblogs.com/shichangming/p/10198063.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值