#!/bin/bash
MAC=`ifconfig eth0|grep eth0|awk '{print $5}'` #这个得到当前的MAC地址。
if [ $# == 0 ] ;then echo "The MAC have not changed !" ;echo "Now the MAC is $MAC "#如果没有参数,只输入脚本名就选择这里。
elif [ $# == 2 ] ;then #这里在命令有跟着两个参数,这里是你指定的MAC最后两个域。如这个脚本叫做up, 那么输入up a8 d9 ,注意MAC是以十六进制表示的,字母不要输入比F大的。
echo "The old MAC is $MAC"
ifconfig eth0 down #使网卡注销出系统。
ifconfig eth0 hw ether 00:**:**:**:"$1":"$2" #设置MAC,这里的$1表示第一个参数,$2表示第二个参数。
ifconfig eth0 up #重新激活网卡。
NEWMAC=`ifconfig eth0|grep eth0|awk '{print $5}'`
echo "The new MAC is $NEWMAC"
else echo "command error " ;exit 0 #结束这个进程。
fi ;echo "lease wait......"
adsl-start ;sync;NEWIP=`ifconfig ppp0|grep addr|awk '{print $2}'|cut -f2 -d ":"` #这里的sync是刷新缓冲区。不要也行。#连网,后打印出IP地址。
echo "Now the IP is $NEWIP "
fi
直接输入adsl-start没问题。这是下网再连上的情况。
# up d8 a9
The old MAC : 00:E0:**:**:**:A0
/root/bin/up: line 13: 00:**:**:**:d8:a9: command not found
The new MAC :
/root/bin/up: line 15: *.*.*.*: command not found
now IP is