This guide provides different methods, how to Configure static IP address in Centos 8 / RHEL8.
After installing Linux System, the first step every Linux Engineer will do is to assign static IP address on NIC / Ethernet card, so they can have access of their system over the network.
Methods 1 – Configure Static IP in CentOS 8 / RHEL 8 using NetworkManager
- 1.1 – Using the text user interface tool, nmtui.
- 1.2 – Using the command-line tool, nmcli.
1.1 – Configure a network interface using the NetworkManager’s tool, nmtui
nmtui is curser-based text user interface tool (TUI) for NetworkManager.
This tool is used in command line window. It comes with NetworkManager-tui package, which is not coming by default with NetworkManager package. But you can install it using following command.
The process to change IP using nmtui:
Launch the nmtui tool
You will see NetworkManager text user interface starting menu will appear.
- To navigate options, use the arrow keys or press Tab key to step forwards. Once you select desire option then press Enter.
- Chose Edit a connection option to edit a connection and then using Tab key bring selection on OK button at bottom right side then press enter
- Then on next screen chose your interface, in my case its eno1. See picture below.
After you chose to edit your interface, now here on next screen specify IP Address, prefix, Gateway and DNS Server. Then using tab key navigates to ok then press enter.
In next window chose your network interfaces which is eno1 and deactivate.
Then chose connection again and click activate button.
Select Back and then select Quit.
Use ifconfig command to verify whether ip address has been assigned to interface eno1
Above output is showing we have successfully assigned a static IP address to eno1 interface using nmtui tool.
The following commands are also available:
Above command will open edit connection window directly see below picture.
1.2 – Configure a network interface Using the command-line tool, nmcli.
What is nmcli?
nmcli (NetworkManager Command Line Interface) is the command-line utility to configure IP settings through NetworkManager. Using nmcli command line tool you can create, display, edit, delete, activate, and deactivate network connections, as well as control and display network device status.
To display available network devices
Above output showing nmcli device command list all available network devices in system. Also you can see highlighted device state showing unmanaged there is connected also in green color. A device state can be:
- i) It means it’s under the NetworkManager control, and a managed device may be connected, meaning its configured and activated, or disconnected, it means not configured but it is ready to be activated again.
- i) This state mean this device is not under the control of NetworkManager
- 2.1 – Edit network configuration script file ifcfg-* manually.
- 1: BOOTPROTO – none option is specified, since we are using static ip so we no protocol should be there. In case if you want to get ip from DHCP server so BOOTPROTO should BOOTPROTO=dhcp.
- 2: IPADDR – This option we used to specify IP address.
- 3: PREFIX – Used to define network prefix in our case it is /24 network.
- 4: GATEWAY – used to define default gateway for this network.
- 5: DNS – Using this option we can define multiple DNS server with progressive number, starting from 1. See point number 5, showing DNS1 & DNS2.
Some useful nmcli device commands switches:
-f, field This option specifies what fields can be displayed in output.
Example: Specify which field you want to see in output.
-p, prettyThis option print output in human-readable format
See Example below
nmcli device command takes many arguments but most commonly used are: show, status, connect, set, disconnect, modify, edit and wifi. You can see further details by entering nmcli device help command.
Assign Static IP Using nmcli.
Bellow command will assign a static ip address to our interface eno1
we used shorter version of nmcli connection modify command by replacing connection keyword with con and modifiy with mod.
Assign gateway using below command.
Set method of interface eno1 from dhcp to static using below command.
Setting up DNS server IP
Now to save all changes we have made, use following nmcli command.
To confirm changes use below IP command
We can see above output shows, Static ip address is configured successfully on eno1 interface.
Methods 2 – configure static IP in CentOS 8 / RHEL8 without using NetworkManager.
2.1 – Edit network configuration script file ifcfg-* manually
A configuration script file is created for each network interface inside /etec/sysconfig/network-scripts/ directory. All configuration script file name started with ifcfg- plus the name of the interface. If I view my system interface eno1 script file, see how it looks like.
Above configuration showing static ip configuration where we use:
After you finish editing your network configuration script file, you must put interface down and up again to make our changes effective.
Be aware that this will disrupt existent ssh connections via said interface:
You can verify changes using ip addr command.
We learn three methods we can use to configure static IP on CentOS 8 / RHEL 8. We see what options we should change and what we should add in the interface configuration file when editing it manually, and how to perform the same changes using nmtui and nmcli, which are respectively a text user interface command line utility; both are used to control the NetworkManager daemon.