I am trying to write a set of scripts for my Ubuntu 810 Server to allow a user to change from DHCP to a user-supplied Static IP, Subnet, Gateway and DNS Servers.
So far I have the following, where $USERCHOICE is a user-entered value in each case:
ifconfig eth0 down && ifconfig eth0 $USERCHOICE && ifconfig eth0 up;;
ifconfig eth0 down && ifconfig netmask $USERCHOICE && ifconfig eth0 up;;
ifconfig eth0 down && route add default gw $USERCHOICE && ifconfig eth0 up;;
ifconfig eth0 down && echo "nameserver $USERCHOICE" > /etc/resolv.conf && ifconfig eth0 up;;
Problems:
1.It doesn't work
, even after issuing
/etc/init.d/networking restart
2. Is there an easy way to, from a script, take multiple values and run each command using the appropriate value rather than running each component as a different option?
3. How do I specify 2 DNS Servers instead of 1?
I suspect someone out there is already doing this, and in a much more straightforward fashion that I am attempting to
Thanks for any help.
Alex