Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2039141
  • 博文数量: 369
  • 博客积分: 10093
  • 博客等级: 上将
  • 技术积分: 4271
  • 用 户 组: 普通用户
  • 注册时间: 2005-03-21 00:59
文章分类

全部博文(369)

文章存档

2013年(1)

2011年(2)

2010年(10)

2009年(16)

2008年(33)

2007年(146)

2006年(160)

2005年(1)

分类: LINUX

2006-05-15 12:34:42

#!/bin/sh
#
# Author xiaosuo
# Licence GPL2 or above
# Check if the network card is mapped correctly
#

CONFFILE=/etc/conf.d/ifmap.conf
if [ ! -e $CONFFILE  ]; then
        echo "config file:$CONFFILE isn't found"
        exit
fi

while read line; do
        eth_name="";
        eth_addr="";
        # skip the comment
        if echo $line | grep -q -e "^#.*$" ; then
                continue;
        fi
        eth_name=`echo $line | awk '{print $1}'`
        eth_addr=`echo $line | awk '{print $2}' | tr "[:upper:]" "[:lower:]"`
        if ip link show dev $eth_name &>/dev/null; then
                real_addr=`ip link show dev $eth_name | grep 'link/ether' | awk '{print $2}'`
                if [ $real_addr = $eth_addr ]; then
                        continue;
                fi
        fi

        # search for the correct link address
        echo "$eth_name($eth_addr) is changed"
        got="NO"
        for (( i=0; i < 256 ; i ++ )) ; do
                search_name="eth$i"
                if ip link show dev $search_name &>/dev/null; then
                        search_addr=`ip link show dev $search_name | grep 'link/ether' | awk '{print $2}'`
                        if [ $search_addr = $eth_addr ]; then
                                got="YES"
                                break;
                        fi
                fi
        done
        if [ $got = "NO" ]; then
                echo "Cann't config $eth_name"
                continue;
        fi

        # swap the dev name
        echo substitute $eth_name for $search_name
        ip link set dev $eth_name down &>/dev/null
        ip link set dev $search_name down &>/dev/null
        ip link set dev $eth_name name eth_tmp &>/dev/null
        ip link set dev $search_name name $eth_name &>/dev/null
        ip link set dev eth_tmp name $search_name &>/dev/null
        ip link set dev $eth_name up &>/dev/null
        ip link set dev $search_name up &>/dev/null
        /etc/init.d/net.$eth_name restart
        /etc/init.d/net.$search_name restart
done < $CONFFILE
参考资料:

阅读(1645) | 评论(0) | 转发(0) |
0

上一篇:用kexec快速重启操作系统

下一篇:无题

给主人留下些什么吧!~~