Configuring DHCP Addressing for Ubuntu Linux

Normally the network interface cards are configured during the installation of Linux. However, sometimes certain circumstances require you to change the addressing scheme of your system. This article will take you step by step through the process of configuring your system to use DHCP for obtaining its IP addressing information. Ubuntu has some very nice GUI tools to allow you to change your settings with the click of the mouse but this article will focus on how to make your changes from a command line in the event that you don’t have the GUI installed. Also, this tutorial is Ubuntu/Debian centric but the principles can be applied to many other Linux distributions, especially any that are based on Debian.


There is one tool that is needed, a text editor. In this article we’ll use the nano editor. Nano is a nice and easy editor that is installed by default in Ubuntu.

(*note: Commands preceded by a “$” are run as a normal user and commands preceded by a “#” are run as root.)

All of the network interface settings are contained in a text file. In order to change any settings we just need to edit the file correctly and restart the networking services. The file we need to edit is stored in /etc/network/interfaces.

The first thing we need to do is login. You know the drill…

configuring_dchp_addressing_for_ubuntu_linux0.png

Username

configuring_dchp_addressing_for_ubuntu_linux1.png

Password

configuring_dchp_addressing_for_ubuntu_linux2.png

Success!

configuring_dchp_addressing_for_ubuntu_linux3.png

In order to make any system changes like network interface settings, we need to have root privileges. Use the “su” command to change to root.

$ su

configuring_dchp_addressing_for_ubuntu_linux4.png

And the root password is required.

configuring_dchp_addressing_for_ubuntu_linux5.png

Alright, before we get into editing any settings, I want to suggest that you make a backup of the file we are editing. We are editing the file stored in /etc/network/interfaces. I don’t have a screen shot of backing up the file because I was bad and didn’t do it. However, an easy way to back the file up would be as follows:

# cp /etc/network/interfaces /etc/network/interfaces.backup

That command will give us a copy of interfaces called interfaces.backup that we can restore if necessary.

configuring_dchp_addressing_for_ubuntu_linux6.png

Now we can open the interfaces file for editing. We will use the nano editor with the “-w” option to signify no wrapping of long lines of text.

# nano -w /etc/network/interfaces

configuring_dchp_addressing_for_ubuntu_linux7.png

Since we are changing the system to use DHCP we need to remove some of the information that pertains to static IP addressing. Notice below that there are several indented lines.

We need to remove this section of data:

address 192.168.200.10
netmask 255.255.255.0
network 192.168.200.0
broadcast 192.168.200.2
# dns-* options are implemented…
dns-nameservers 192.168.200.2

configuring_dchp_addressing_for_ubuntu_linux8.png

Notice here that the interface is set to static.

configuring_dchp_addressing_for_ubuntu_linux9.png

Remove the word “static”…

configuring_dchp_addressing_for_ubuntu_linux10.png

…and replace it with “dhcp”.

configuring_dchp_addressing_for_ubuntu_linux11.png

Were all done editing, press “ctrl-x” to close the file. Nano will respond by asking if you want to save.

Press “y” to save.

configuring_dchp_addressing_for_ubuntu_linux12.png

Nano will ask for a name and path to save the file.

Just press enter to save the modifications over the original file.

configuring_dchp_addressing_for_ubuntu_linux13.png

You know the save was successful when nano tells you that it wrote X lines. If you get a save error, you most likely aren’t root.

configuring_dchp_addressing_for_ubuntu_linux14.png

To make the new setting take effect, we need to restart the networking services. That is accomplished with the following command:

# /etc/init.d/networking restart

configuring_dchp_addressing_for_ubuntu_linux15.png

Notice that when the restart is initiated we see that it is using DHCP.

configuring_dchp_addressing_for_ubuntu_linux16.png

Let’s check to see if we received an IP address dynamically. Issue the command:

# ifconfig eth0

(*substitute eth0 with the interface appropriate to your system)

configuring_dchp_addressing_for_ubuntu_linux17.png

If we see address information like below, we know that it’s working.

configuring_dchp_addressing_for_ubuntu_linux18.png

We’re all finished with our network changes, let’s log out of root privilege mode.

# exit

configuring_dchp_addressing_for_ubuntu_linux19.png

Let’s log out of user mode as well.

$ exit

configuring_dchp_addressing_for_ubuntu_linux20.png

configuring_dchp_addressing_for_ubuntu_linux21.png

Tags: , , , , ,

9 Comments so far »

  1. Stu Fisher said,

    Wrote on December 8, 2007 @ 7:13 pm

    I am having a problem similar to this on UBUNTU version 7.1 but the code in the file etc/network/interfaces is different as shown below:

    auto lo
    iface lo inet loopback

    auto eth0
    iface eth0 inet dhcp

    auto eth1
    iface eth1 inet dhcp

    auto eth2
    iface eth2 inet dhcp

    auto ath0
    iface ath0 inet dhcp

    auto wlan0
    iface wlan0 inet dhcp

    auto dsl-provider
    iface dsl-provider inet ppp
    provider dsl-provider

    pre-up /sbin/ifconfig eth0 up # line maintained by pppoeconf

  2. grand casino online said,

    Wrote on February 12, 2008 @ 11:29 pm

    grand casino online…

    Banks denigrate.overly assignable devoted …

  3. tips poker said,

    Wrote on February 17, 2008 @ 10:55 am

    tips poker…

    spreaders multiplexes minces asks?habitats …

  4. cancellation of debt said,

    Wrote on February 20, 2008 @ 11:46 pm

    cancellation of debt…

    hobbling!pinto shifted.pronouns Nazareth.sight …

  5. bingo online casino with sign up bonus said,

    Wrote on February 24, 2008 @ 2:39 am

    bingo online casino with sign up bonus…

    wearied:intelligibly?wakes sources?…

  6. bingo game show said,

    Wrote on February 28, 2008 @ 6:08 pm

    bingo game show…

    firstly flowcharts cored.inglorious.sprinkling:crypt …

  7. sécurité des jeux de hasard en ligne said,

    Wrote on August 6, 2008 @ 6:00 pm

    sécurité des jeux de hasard en ligne…

    diffusers Madagascar threading allays …

  8. pocker games online said,

    Wrote on September 1, 2008 @ 9:42 pm

    pocker games online…

    specimen:understandably stirring Malagasy …

  9. absolutely free health insurance said,

    Wrote on October 4, 2008 @ 6:48 am

    absolutely free health insurance…

    net Confucianism thanks Corinth confluent …

Comment RSS · TrackBack URI

Leave a Comment

Name: (Required)

E-mail: (Required)

Website:

Comment: