Change your Ubuntu server from a dynamic to static IP address

To allow your Ubuntu server to work with a static IP, you need to amend a couple of files. If you have Webmin installed, its much easier to do this in the network interface section of the System settings. However details below are how to do this from the command ssh terminal prompt.

Edit your interface file

sudo vi /etc/network/interfaces

Change it to look the same as the following – obviously amending it to have your relevant network details in.

auto eth0
iface eth0 inet static

Press shift ZZ to save the file once amended.

Amend DNS settings

We need to add in the DNS settings by editing the resolv.conf file:

sudo vi /etc/resolv.conf

On the line nameserver replace the x with the IP of your name server.

Remove DHCP client

This will remove the now unecessary software used for acquiring DHCP

apt-get remove dhcp3-client

Restart interfaces

Restart your network services to initialise changes using the following command:

sudo /etc/init.d/networking restart

Add the gateway route

To allow your machine to get out to the internet you may need to add the gateway in manually. You can do this as follows:

/sbin/route add -net gw x.x.x.x eth0

Where X is your gateway

Test it works

Then do a test to check all is working:


You should get a nice long list of replies if it is successful. Press Ctrl + C to stop this list.

Share this post
You may also like