InternetNetworkingOnline SecurityWeb Development

How to Set or Change the IP Address & DNS Settings on a Ubuntu Server

By October 12, 2011 August 4th, 2013 No Comments

Many newcomers to the Linux platform find the command-line interface (CLI) a little daunting at first, but with a little bit of research and an ounce of Mr. Common Sense’s inspiration, it’s not that hard to learn the basics.

In this article I’ll be discussing the common task of changing the IP address and DNS settings on your server. Most of the time you’ll want to use a static IP for your server and it’s best to do this during installation, but if you need to move your server to a different location or change its IP settings for any other reason, here are the simple steps.

1. Open up the Network Interfaces file

To open the file using the vi text editor, type sudo vi /etc/network/interfaces and press ENTER. You’ll then be prompted for your admin password. Enter this, and then vi will open up with your current IP settings. It might look something like this:

auto eth0
iface eth0 inet static
In order to make changes to this file you need to enter one of the text-editing modes. Using the arrow keys, move the cursor to where you want it and then either press x to delete text at the current point, or i to enter insertion mode. That will let you edit the file like a normal text file.
Once you’re finished, press the Esc key to exit whichever mode you’re in, and then type :wq! to save and exit the file, then press ENTER.

2. Change DNS Settings

Your DNS settings are located in the resolv.conf file – to edit this, type sudo vi /etc/resolv.conf
Edit the file in the same way you edited the network interfaces file.

3. Restart Networking for Changes to Take Effect

To restart the networking services, run this command: sudo /etc/init.d/networking restart
Depending on other settings on your network and its infrastructure, you may be able to ping an address such as or simply ping your gateway to test the connection. If not, you could always try running sudo apt-get update to test your connection.
Paul Freeman-Powell

Paul Freeman-Powell

Paul (@paulfp) is the main presenter of the award-winning Switched On Network YouTube Channel, which covers a variety of interesting topics usually relating to his love of technology and all things geeky. He also founded and runs Innobella Media, where he leads in all aspects of video production, video editing, sound & lighting. A father of 3 children including twins, his hobbies used to include photography, playing the drums and cycling. With a degree in Modern European Languages, Paul speaks French, Spanish and a little bit of Italian, and holds dual British & Irish citizenship.

Leave a Reply

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