DHCP servers are used almost in all organizations or even in our home routers for assigning IP addresses to get access to the internet. Usually, when we enable our network interface on our CentOS 7 or 8 systems, an IP address is assigned automatically through that DHCP server & we have access to the internet or to our LAN network. But we might be required to assign static IP addresses in our CentOS 7 or 8 machines.
So what do we do? We need to manually assign a static IP address to our servers. In this tutorial, we will learn how to assign static IP addresses in CentOS 7 or 8 machines.
There are two ways we can assign a static IP address in CentOS 8 systems,
1- Using Network manager
2- Assigning IP using network files
Let's discuss both these methods one by one.
1- Assign static IP using Network Manager
To configure a static using the network manager, we will be using a tool called 'nmtui'. NMTUI is a CLI-based user interface for Network Manager & even works for a system that does not have GUI installed.
To assign IP address, open terminal & execute the following command,
You will see the following screen,
Click on 'Edit a connection', press ‘Enter’. Use the ‘Tab’ key to navigate.
On the next screen, select the network interface from the list of interfaces & press ENTER key,
Add the IP address and other necessary details as required & complete the setup. Next, we need to restart the NetworkManager service to implement the changes,
# systemctl restart NetworkManager
2- Assigning IP using Network files
Network files for all the network interfaces are located in the directory ‘/etc/sysconfig/network-scripts'. Open the primary network interface file i.e. enp0s3, & add the following content to the file. Add what’s not in the file.
$ vi /etc/sysconfig/network-scripts/ifcfg-enp0s3
Save the file & restart the network service for changes to take effect.
# systemctl restart network
After the service has been started, our static IP has been assigned to our CentOS 8 system. To verify the assigned IP address, use the IP command,
# ip -a
That’s it, this completes our tutorial on how to assign a static IP in CentOS 7 or 8 systems. Please do send in any questions or queries using the comment box below.