Translate this Page

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
address 10.0.0.1
netmask 255.255.255.0
network 10.0.0.0
broadcast 10.0.0.255
gateway 10.0.0.1
#
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 255.255.255.0; 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?

facebooktwittergoogle_plusredditpinterestlinkedinmail

Leave a Reply