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:
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 bbc.co.uk or simply ping your gateway to test the connection. If not, you could always try running sudo apt-get update to test your connection.