
关于Linux的shell脚本,希望高手帮忙写一下这个shell脚本,不胜感激~运行脚本大致如下:
关于Linux的shell脚本,希望高手帮忙写一下这个shell脚本,不胜感激~运行脚本大致如下:首先查看所有eth*的网卡状态,然后请用户输入1,2,3,4来选择修改网...
关于Linux的shell脚本,希望高手帮忙写一下这个shell脚本,不胜感激~运行脚本大致如下:
首先查看所有eth*的网卡状态,然后请用户输入1,2,3,4来选择修改网卡地址:例如用户输入1代表eth0用户输入2代表eth2用户输入3代表要修改eth3用户输入4代表要修改eth4等等,然后用户输入1,2,3或者4以后就请用户输入要修改的网卡ip地址和netmask;然后自动重启网络。就是这么一个脚本,不算太难吧..谢谢了``` 展开
首先查看所有eth*的网卡状态,然后请用户输入1,2,3,4来选择修改网卡地址:例如用户输入1代表eth0用户输入2代表eth2用户输入3代表要修改eth3用户输入4代表要修改eth4等等,然后用户输入1,2,3或者4以后就请用户输入要修改的网卡ip地址和netmask;然后自动重启网络。就是这么一个脚本,不算太难吧..谢谢了``` 展开
1个回答
展开全部
#vi config.sh
ifconfig
echo "Please input:0/1/2"
read dir
case $dir in
0)
echo -n "Please enter new ip for eth0:"
read ip0
echo -n "Please enter netmask for eth0:"
read mask0
ifconfig eth0 $ip0 netmask $mask0
service network restart;;
1)
echo -n "Please enter new ip for eth1:"
read ip1
echo -n "Please enter netmask for eth1:"
read mask1
ifconfig eth1 $ip1 netmask $mask1
service network restart;;
2)
echo -n "Please enter new ip for eth2:"
read ip2
echo -n "Please enter netmask for eth2:"
read mask2
ifconfig eth2 $ip2 netmask $mask2
service network restart;;
*)
echo "you can only input 0,1,2";;
esac
# chmod +x config.sh
# ./config.sh
Please input:0/1/2
0
Please enter new ip for eth0:10.254.197.10
Please enter netmask for eth0:255.255.252.0
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0:
Determining IP information for eth0... done.
[ OK ]
================================================
以上是我运行的结果,但我只有一个网卡,所以只是测了eth0. 还没有做错误处理,所以ip和netmask一定要输入对了才好用。
ifconfig
echo "Please input:0/1/2"
read dir
case $dir in
0)
echo -n "Please enter new ip for eth0:"
read ip0
echo -n "Please enter netmask for eth0:"
read mask0
ifconfig eth0 $ip0 netmask $mask0
service network restart;;
1)
echo -n "Please enter new ip for eth1:"
read ip1
echo -n "Please enter netmask for eth1:"
read mask1
ifconfig eth1 $ip1 netmask $mask1
service network restart;;
2)
echo -n "Please enter new ip for eth2:"
read ip2
echo -n "Please enter netmask for eth2:"
read mask2
ifconfig eth2 $ip2 netmask $mask2
service network restart;;
*)
echo "you can only input 0,1,2";;
esac
# chmod +x config.sh
# ./config.sh
Please input:0/1/2
0
Please enter new ip for eth0:10.254.197.10
Please enter netmask for eth0:255.255.252.0
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0:
Determining IP information for eth0... done.
[ OK ]
================================================
以上是我运行的结果,但我只有一个网卡,所以只是测了eth0. 还没有做错误处理,所以ip和netmask一定要输入对了才好用。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询