The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Special Forums > IP Networking
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 04-12-2009
cleanden cleanden is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 19
Switching from DHCP to Static IP

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