The UNIX and Linux Forums  


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



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 05:55 PM
Static wojtyla High Level Programming 6 02-25-2005 11:57 AM
Static IP google IP Networking 7 05-18-2003 08:33 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #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
  #2 (permalink)  
Old 04-19-2009
dr.house dr.house is offline
Registered User
  
 

Join Date: Dec 2008
Location: Switzerland
Posts: 229
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

  ;;

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:40 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0