Changing Ip Address on Ubuntu / Debian From Dhcp to Static.

By | November 20, 2009

So we start by editing the /etc/network/interfaces file, I will be using vim, however you can use any editor you like

sudo vim /etc/network/interfaces

Let’s assume you want to do the changes for eth0, you will see these lines:

auto eth0
iface eth0 inet dhcp

As you can see, the server is set to use DHCP right now.
We will change over from dhcp to static, Edit your file to the following

auto eth0
iface eth0 inet static
address (Change this you whatever address you want to specify)
netmask (Use your subnet mask)
network (Your network address)
broadcast (your broadcast address)
gateway (Your default gateway, ip of fw or router)

Save the Changes and exit the editor

Next we must edit the DNS settings in the resolv.conf file:

sudo vim /etc/resolv.conf


name server (Your Dns Servers, you can add more then one, each nameserver on a seperate line)

Save the Changes and exit the editor
Once this is complete we must restart the network interfaces

sudo /etc/init.d/networking restart

Note.. in some cases you must remove the dhcp client for the changes to work,, If so you can use the following commands

sudo apt-get remove dhcp-client
sudo apt-get remove dhcp-client3


sudo /etc/init.d/networking restart

Try pinging a site and you should be done..

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.