LInux下网络参数切换的脚本
等下次再贴出linux下完整设置IP的脚本
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=192.168.1.2' >> /etc/sysconfig/network-scripts/ifcfg-eth0
echo 'NETMASK=255.255.255.0' >> /etc/sysconfig/network-scripts/ifcfg-eth0
echo 'GATEWAY=192.168.1.1' >> /etc/sysconfig/network-scripts/ifcfg-eth0
echo 'nameserver 202.96.69.38' > /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.100' > /etc/resolv.conf
fi;
service network restart
4、执行脚本
#./chip.scr [home | office]
等下次再贴出linux下完整设置IP的脚本
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=192.168.1.2' >> /etc/sysconfig/network-scripts/ifcfg-eth0
echo 'NETMASK=255.255.255.0' >> /etc/sysconfig/network-scripts/ifcfg-eth0
echo 'GATEWAY=192.168.1.1' >> /etc/sysconfig/network-scripts/ifcfg-eth0
echo 'nameserver 202.96.69.38' > /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.100' > /etc/resolv.conf
fi;
service network restart
4、执行脚本
#./chip.scr [home | office]