1\> 创建文件chip.scr
#touch chip.scr
2\> 修改权限为700
#chmod 700 chip.scr
3\> 编辑文件内容如下
#!/bin/bash
echo 'DEVICE=eth0' > /etc/sysconfig/network-scripts/ifcfg-eth0
echo 'ONBOOT=yes' >> /etc/sysconfig/network-scripts/ifcfg-eth0
echo 'TYPE=Ethernet' >> /etc/sysconfig/network-scripts/ifcfg-eth0
echo 'BOOTPROTO=static' >> /etc/sysconfig/network-scripts/ifcfg-eth0
if [ $1 = "home" ] ; then
echo 'IPADDR=10.10.10.2' >> /etc/sysconfig/network-scripts/ifcfg-eth0
echo 'NETMASK=255.255.255.0' >> /etc/sysconfig/network-scripts/ifcfg-eth0
echo 'GATEWAY=10.10.10.1' >> /etc/sysconfig/network-scripts/ifcfg-eth0
echo 'nameserver 10.10.10.3' > /etc/resolv.conf
else
echo 'IPADDR=10.0.0.2' >> /etc/sysconfig/network-scripts/ifcfg-eth0
echo 'NETMASK=255.0.0.0' >> /etc/sysconfig/network-scripts/ifcfg-eth0
echo 'GATEWAY=10.0.0.1' >> /etc/sysconfig/network-scripts/ifcfg-eth0
echo 'nameserver 10.0.0.3' > /etc/resolv.conf
fi;
service network restart
4\> 执行脚本
#./chip.scr [home | office]
阅读(629) | 评论(0) | 转发(0) |