Ubuntu DHCP and Static Ip Address


To set a dhcp address or static ip address from the terminal on Ubuntu is a real simple task to complete. The first thing to do of course is to open up a terminal window, once the terminal opens, login in as su or use the sudo command to run the following command.

vi /etc/network/interfaces

You can also use any other editor program like nano, but I prefer vim. Once you open the file with your favorite text editor you should now see a file that resembles the one below.

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
auto eth1
iface eth1 inet dhcp

Near the middle of my file you will see the section for the primary network interface where I set eth0 to a static ip address. The address line is the where you would put the ip address that you want. The netmask is normally; network usually ends with .0 and broadcast end with .255. The gateway will be the address of your router. Setting a dhcp address is even easier, all you have to do is put auto eth1 followed by iface eth1 inet dhcp.

Once you have completed the above, you will then have to save the changes you made to the file. Now restart you network connection with the follow command.

/etc/init.d/networking restart

If you would like to learn how to make your very own Ubuntu router internet gateway?

One Response to Ubuntu DHCP and Static Ip Address

  • Annette Cutter says:

    dear friends my son has got a dell inspiron 910 mini laptop where the OS is Ubuntu Ram is 512 mb HDD is 4 Gb . now we have taken broadband connection in our home where the the ISP (internet service provider ) use only static ip address. they have provided me the ip address the gateway address dns address etc etc but was unable to connect to the internet not a single web page is opening the ISP technical department says that if your os is in windows we can make it connected as we are used to do so. but the os in your computer is ubuntu which is very new to them or it seems that they havent used/ habituated with that os. my son and i have tried several options which has been provided by google how to connect ubuntu os through static ip address but still there is not a satisfactory solution . is any body there who have Ubuntu OS and the medium of connection is adsl broadband static ip only . also i would like to mention that the auto configure option is not working we have also tried it .

    thanks in advance

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe to Newsletter

Sign Up Today

Get a free copy of Develop Your Own Database Software.
database software, pdf

For A Limited Time