Linux下在静态与动态IP之间切换的脚本脚本代码如下: #!/bin/bash#Switch of static IP and DHCPif [ $1 = "home" ] ; then echo 'BOOTPROTO=static' >/etc/sysconfig/network-scripts/ifcfg-eth0 echo "DEVICE=eth0" >> /etc/sysconfig/network-scripts/ifcfg-eth0 echo 'IPADDR=192.168.1.109' >> /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-eth0else echo 'BOOTPROTO=dhcp' >/etc/sysconfig/network-scripts/ifcfg-eth0fiservice network restart 复制代码 执行脚本sh /changeIP.sh [home | office] 静态时是home,动态随便输一下什么参数即可