Configuring a static IP address on your CentOS 7 machine can be a daunting task, but fear not - we’ve got you covered! You’ll be up and running in no time with just a few simple steps.
Before diving into the commands needed to get that shiny new static IP address configured, let's take a quick look at what exactly an IPv4 is and why it matters.
What is IPV4?
IPv4 stands for Internet Protocol version 4 and gives each device connected to the internet an identifiable address; this allows data packets transmitted over the web to find their intended destination without getting lost along the way.
Now that you know why having a static IP address matters, let's jump into setting one up on your machine running CentOS 7.
1. Network Manager
To do this, you’ll need to open the Network Manager configuration files located in the /etc/sysconfig/network-scripts directory.
Once it's open, locate a file named ifcfg-eth0 and open it using your favourite text editor; be sure to make a backup of this file before making any changes! Inside the file, you should see various settings, such as IPADDR, NETMASK, and GATEWAY, followed by their corresponding values. Update these values to bind a static IP address to that particular interface.
Finally, save all the changes made to the ifcfg-eth0 file and restart the network service with either /sbin/service network restart or systemctl restart network. Once the process is complete, you should have a static IP address set up on your CentOS 7 machine!
2. Switch back to DHCP
Now that you’ve configured a static IP address on your CentOS 7 machine, there may be times when you want to switch back to using DHCP.
To do this, simply open the ifcfg-eth0 file again and remove all values associated with the IPADDR, NETMASK, GATEWAY and DNS variables. Then run /sbin/service network restart or systemctl restart network once more, and everything should be good to go.
And that's it! Configuring a static IP address on CentOS 7 isn’t as complicated as it may seem, and with a few simple steps, you can have your machine up and running in no time. Good luck!