Change Ubuntu Server from DHCP to a Static IP Address Via SSH
If the Ubuntu Server installer has set your server to use DHCP, you will want to change it to a static IP address so that people can actually use it.
Changing this setting without a GUI will require some text editing via SSH
Open up the /etc/network/interfaces file. I’m going to use nano, but you can choose a different editor
sudo nano /etc/network/interfaces
For the primary interface, which is usually eth0, you will see these lines:
iface eth0 inet dhcp
As you can see, it’s using DHCP right now. We are going to change dhcp to static, and then there are a number of options that should be added below it. Obviously you’d customize this to your network.
iface eth0 inet static
Now we’ll need to add in the DNS settings by editing the resolv.conf file:
sudo nano /etc/resolv.conf
On the line ‘nameserver xxx.xxx.xxx.xxx’ replace the x with the IP of your name server. (You can do ifconfig /all to find out what they are)
You need to also remove the dhcp client for this to stick. You might need to remove dhcp-client3 instead.
sudo apt-get remove dhcp-client
Now we’ll just need to restart the networking components:
sudo /etc/init.d/networking restart
Ping www.google.com. If you get a response, name resolution is working(unless of course if google is in your hosts file).