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:
TYPE="Ethernet"
BOOTPROTO="none"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
NAME="nic1"
UUID="e24c5ba8-46ad-41ed-af8e-1fb6f75d98bc"
DEVICE="eno16777984"
ONBOOT="yes"
IPADDR="192.168.1.20"
NETMASK="255.255.255.0"
GATEWAY="192.168.1.254"
DNS1="192.168.1.1"
DNS2=""
DNS3=""
DOMAIN="home"
IPV6_PEERDNS="yes"
IPV6_PEERROUTES="yes"
IPV6_PRIVACY="no"
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.
# ifdown
# ifup
Following those two commands, the network interface is taken offline and online, and the configuration is reloaded.
Simple, right? Hope you enjoyed the article!