Change Ubuntu Server from DHCP to a Static IP

sometime Ubuntu Server installer is set to use DHCP, and later You want to change it Static IP, so that people can access it and it would not dynamically assigned ip.

Server usually don’t have GUI interface so we need to do it using bash commands.

Let’s open up the /etc/network/interfaces file. I’m going to use my favourite editor vi, but you can choose your own.

sudo vi /etc/network/interfaces

For the primary interface, which is usually eth0, you will see these lines:

auto eth0
iface eth0 inet dhcp

As it can be seen that it is using DHCP right now. We are going to change dhcp to static according some general network setup, but you can customise and change the ips according to your network.

auto yeth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1

Now we’ll need to add in the DNS settings by editing the resolv.conf file:

sudo vi /etc/resolv.conf

On the line ‘name server xxx.xxx.xxx.xxx’ replace the x with the IP of your name server. (You might use ifconfig /all to find out)

You might also need to remove the dhcp client for this to stick. You might need to remove dhcp-client3 instead.

sudo apt-get remove dhcp-client

Now restart the networking components:

sudo /etc/init.d/networking restart

Ping www.google.com. If you get a response, name resolution is working (unless google is in your hosts file 🙂 ).

Leave a Reply

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


5 + = eight