Hello everybody and welcome to another fun article that takes us back to basics in the world of Linux. I know this article might seem too basic, but a lot of people ask me “How do I change my IP address on my Linux box?” all the time. For that, I’ve created this simple to follow guide to come to your aid.
Now that we’ve got the introduction done, let’s jump in and change the network configuration on a CentOS server.
I’m using a virtual machine, so I’m going to have my console open to the server, but you can use Putty or Terminal depending on your needs or your environment.
Once we’ve logged in, we’re at the default prompt, so the first thing we’ll do is change our working directory to the network-scripts one.
# cd /etc/sysconfig/network-scripts
Now in that folder we will have a file named ifcfg- and the type of network connection that you have. It can be eno for VMware machines or eth for other types of VMs or physical machines. But it always starts with ifcfg-.
In my case the network interface is ifcfg-eno16777984.
So what I’m going to do next is to edit that file using vi and change the values.
# vi ifcfg-eno16777984
Now we are going to get the following output:
This file is pretty self-explanatory. We will need to change the value of IPADDR, NETMASK, GATEWAY and DNS to the values we want and then just reload the network adapter.
After we’ve changed the values, we will perform the following steps for the system to reload the network configuration.
Following those two commands, the network interface is taken offline and online, and the configuration is reloaded.
Simple, right? Hope you enjoyed the article!