When provisioning a server, it’s usually a good practice to assign static IP addresses. I have provisioned a CentOS 7 and ran
yum update -y to update the default packages.
Checking Your Current IP Address
I have logged in to the console as root so that I can check the current IP address. Enter the following command.
# ip addr
You can see that this machine has 192.168.1.107. This IP address was obtained from the DHCP server. I’m going to give it 192.168.1.27. Fortunately, CentOS 7 comes with an utility to make it easier for us to assign a static IP address.
Assign a Static IP Address
Enter nmtui in your terminal.
You will see a UI like the image below.
Hit Enter key and you will see one or more network interface for you to configure. Select the network interface and hit Enter key.
Navigate to <Show> for IPv4 and hit Enter key. And then change Automatic to Manual.
Now navigate your cursor to Addresses <Add…> and hit enter.
Add 192.168.1.27 for the static IP address (it depends on your environment), 192.168.1.1 for its gateway and we will use OpenDNS (184.108.40.206 220.127.116.11) for DNS servers. Navigate your cursor to OK at the lower right corner of the screen and hit Enter key.
Restart network daemon by entering the following command.
# systemctl restart network
At this point, the terminal might look frozen because the OS’s IP address has changed to a different one if you SSH’ed into it. Check the IP address again by entering
ip addr on it. You now should see the new static IP address you just configured.