![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| IP Networking Learn TCP/IP, Internet Protocol, Routing, Routers, Network protocols in this UNIX and Linux forum. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to configure DHCP to Static IP | lee30320 | IP Networking | 5 | 01-27-2009 03:56 AM |
| dhcp and static ip conflicts. | ts97783 | IP Networking | 1 | 11-01-2008 10:08 AM |
| HP-UX 10.xx Changing from static IP to DHCP | Steelysteel | HP-UX | 1 | 08-27-2007 04:55 PM |
| Static | wojtyla | High Level Programming | 6 | 02-25-2005 11:57 AM |
| Static IP | IP Networking | 7 | 05-18-2003 07:33 PM | |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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 restart2. 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 |
|
||||
|
The following code of mine (quoted in extracts) has been used to allow for updating the network settings of a Debian-based live system at boot time ...:
Code:
eth0|eth1)
updateConsole
echo -ne "\e[33m"
echo ""
echo " \|||/ "
echo " (0 0) "
echo "-------ooO-(_)-Ooo-----------------------"
echo ""
echo "Attempting to upset, er, setup <$OPTION> ..."
echo ""
ADDRESS="192.168.110.100"
echo -n "Address [192.168.110.100]: "
read address
if [ "$address" != "" ]
then
ADDRESS="$address"
fi
GATEWAY="192.168.110.101"
echo -n "Gateway [192.168.110.101]: "
read gateway
if [ "$gateway" != "" ]
then
GATEWAY="$gateway"
fi
echo ""
echo -ne "\e[0m"
ETH=/etc/network/interfaces
mv $ETH $ETH.dhcp
ifconfig lo 127.0.0.1
route add 127.0.0.0 lo
ifconfig "$OPTION" "$ADDRESS" netmask 255.255.255.0
route add "$ADDRESS" "$OPTION"
route add default gw "$GATEWAY" "$OPTION" > /dev/null 2>&1
DNS=/etc/resolv.conf
mv $DNS $DNS.dhcp && touch $DNS
echo "nameserver 208.67.220.220" >> $DNS
echo "nameserver 208.67.222.222" >> $DNS
ping -c 1 housisms.net > /dev/null 2>&1
if [ $? -eq 0 ]
then
echo -ne "\e[32m"
echo "You're now part of the 'World Wide Wait'."
SAVE="yes"
else
echo -ne "\e[31m"
echo "Nice try - to no avail, I'm (not) afraid."
SAVE="no"
fi
echo ""
echo -ne "\e[0m"
if [ "$SAVE" = "yes" ]
then
BROADCAST="`echo $ADDRESS | awk -F '.' '{ print $1"."$2"."$3".255"}'`"
touch $ETH
echo "auto lo" >> $ETH
echo "iface lo inet loopback" >> $ETH
echo "auto $OPTION" >> $ETH
echo "iface $OPTION inet static" >> $ETH
echo "address $ADDRESS" >> $ETH
echo "netmask 255.255.255.0" >> $ETH
echo "broadcast $BROADCAST" >> $ETH
echo "gateway $GATEWAY" >> $ETH
fi
;;
|
| Sponsored Links | ||
|
|