ubuntu:
#!/bin/bash PS3="Select your network:" echo "auto eth0" > /etc/network/interfaces select choice in "home(dhcp)" "company(static)" do case "$REPLY" in 1) echo "iface eth0 inet dhcp" >> /etc/network/interfaces break;; 2) echo "iface eth0 inet static" >> /etc/network/interfaces echo "address 192.168.10.160" >> /etc/network/interfaces echo "netmask 255.255.255.0" >> /etc/network/interfaces echo "gateway 192.168.10.2" >> /etc/network/interfaces break;; *) echo -e "$REPLY is not a valid choice.Try again\n" 1>&2 REPLY= ;; esac done echo "auto lo" >> /etc/network/interfaces echo "iface lo inet loopback" >> /etc/network/interfaces /etc/init.d/networking restart
redhat,fedora,centos的:
#!/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.10.160' >> /etc/sysconfig/network-scripts/ifcfg-eth0 echo 'NETMASK=255.255.255.0' >> /etc/sysconfig/network-scripts/ifcfg-eth0 echo 'GATEWAY=192.168.10.2' >> /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
|