#!/bin/bash
#auto to exchange network mode in home and office
Work_mode=`grep "BOOTPROTO" /etc/sysconfig/network-scripts/ifcfg-eth1|awk -F = '{print $2}'`
function Office()
{
if [ "$Work_mode" == "static" ]
then
echo "It's working in the mode of Office.!!"
exit
else
sed '4s/dhcp/static/' < /etc/sysconfig/network-scripts/ifcfg-eth1|
sed '5s/#IPADDR/IPADDR/'| //需要对网卡的配置文件事先做些调整。。
sed '6s/#NETMASK/NETMASK/'|
sed '7s/#GATEWAY/GATEWAY/' > /etc/sysconfig/network-scripts/ifcfg-eth2
rm -rf /etc/sysconfig/network-scripts/ifcfg-eth1 &&
mv /etc/sysconfig/network-scripts/ifcfg-eth2 /etc/sysconfig/network-scripts/ifcfg-eth1
service network restart
fi
}
function Home()
{
if [ "$Work_mode" == "dhcp" ]
then
echo "It's working the mode of Home.!!"
exit
else
sed '4s/static/dhcp/' < /etc/sysconfig/network-scripts/ifcfg-eth1|
sed '5s/IPADDR/#IPADDR/'|
sed '6s/NETMASK/#NETMASK/'|
sed '7s/GATEWAY/#GATEWAY/' > /etc/sysconfig/network-scripts/ifcfg-eth2
rm -rf /etc/sysconfig/network-scripts/ifcfg-eth1 &&
mv /etc/sysconfig/network-scripts/ifcfg-eth2 /etc/sysconfig/network-scripts/ifcfg-eth1
service network restart
fi
}
case $1 in
home)Home;;
office)Office;;
*)echo $? {home|office}
esac
IP地址设置在dhcp与static模式之间快速切换
原创
©著作权归作者所有:来自51CTO博客作者xiongyaofu的原创作品,如需转载,请与作者联系,否则将追究法律责任
上一篇:通过shell将*.txt文本内容批量录入mysql
下一篇:linux内核升级
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
中兴2928static/dhcp配置
by--dianzi_hys@163.com
交换机 密码 用户名 create 性价比