How to Configure Static IP on RHEL/CentOS 8
An IP Address is a unique numerical representation of a computer on a network. When you set up a text-only and GUI-less CentOS server, you may need to configure static IP on it. So, join this article to learn How to Configure Static IP on RHEL/CentOS 8. This guide will teach you three different methods to make you an expert in setting up the static IP address on your CentOS server. The three options you can use to set a static IP address include nmcli utility, nmtui utility, and editing an interface file directly. Let’s cut to the chase and move on with discovering the details.
Prerequisites to Configure Static IP on RHEL/CentOS 8
To let this content help you to achieve your purpose for configuring a Static IP on CentOS, provide all the below considerations and then, go on.
- A system running RHEL/CentOS 8 .
- A non-root user with sudo privileges.
Tutorial Configure Static IP on CentOS 8 Using 3 CMD
Since the NetworkManager daemon manages the network connections of RHEL 8 / CentOS 8, changing a Network Interface Settings needs to interact with it. Previously, you have got familiar with different types of IP Addresses .
So, stay with us on this article to see how you can set an IP address, gateway, and DNS server for a NIC. In the following, different three methods will be presented and discussed. Before going through this guide, you must find out the name of your ethernet since a static IP address cannot be configured without this name. To list all the interfaces on your system, log into your server and run the command below.
You will see two interfaces in your output. The first virtual interface is used by the system to talk with itself. The second interface is your current IPv4 address that you want to modify. Let’s review the three methods you can use to configure static IP on RHEL/CentOS 8:
1. How to Setup a Static IP Address by Directly Editing the Configuration File
Firstly, to set up the static IP address on the CentOS 8 server, modify the interface configuration file manually. The network interface configurations on CentOS 8 server are located in the ‘/etc/sysconfig/network-scripts ‘ directory by default. The directory contains network configurations that are managed by the NetworkManager service.
To view all available configuration files, go to the ‘ /etc/sysconfig/network-scripts ‘ directory.
The name of the file is composed by the ifcfg- prefix plus the name of the interface. If you inspect the file related to your NIC, the actual setup will be shown as below.
You might have set up your CentOS 8 with DHCP which sets the protocol to use at boot to set the IP address of the interface. Since your server does not use a GUI, changing the static IP address requires some applications. Here, the BOOTPROTO option is set to dhcp. The possible options to use are:
- none: No protocol should be used
- bootp: Use the bootp protocol
- dhcp: Use the dhcp protocol
To set a static IPv4 address, the value of BOOTPROTO should be changed to none , and configure your IP, route prefix, gateway, and DNS server statically. The DNS server must be reported together with a progressive number (starting from 1) because it can be specified. When the modifications are finished, the file should be something like this:
To have effective changes, put down and up again the network interface. But it will also disturb existent ssh connections via said interface:
To verify if the IP has changed, you can use the following command.
2. How to use nmcli to Configure Static IP on CentOS 8
As we mentioned, there are three methods to Configure Static IP on RHEL/CentOS 8. So far, you reviewed one of these methods. Let’s see how the second one works.
nmcli is a command line tool that you can use to control NetworkManager and change network settings for a specific interface among other things. Here, you must use this command with the connection subcommand with the modify or the edit action. The first lets you change the settings directly, while the second launch the nmcli shell, where you can operate interactively.
To use nmcli directly, you can run the command below and change the IP address of the “enp1s0” interface.
Since you have specified the routing prefix together with the IP using the so-called CIDR notation, you can use a similar syntax to change the gateway and the DNS settings:
If you prefer to not use any other boot protocol for the interface, you need to set the method to manual . In this way, the BOOTPROTO option will be set to none in the interface configuration file.
You are in the middle of learning how to configure static IP on RHEL/CentOS 8. You can also use an interactive method to perform the same changes. So, use the edit action and the name of the interface you want to edit to enter the nmcli shell .
Then, to get a list of the available ones, type help and run print to see all the connection properties or describe followed by a setting and one of its properties to get a description of the latter. Look at the example below:
And to change your interface address:
The same principle is used to change the other properties:
Finally, use the command below to save the changes you made.
To exit the nmcli shell, type the following command and press Enter.
Again, reload the interface using the command below to make the changes effective.
3. How to use nmtui to Configure Static IP on CentOS 8
So far, you learned two methods of three one to Configure Static IP on CentOS 8. Also, you reviewed the way you can change the parameter of a network interface by modifying its file manually or by using the nmcli command tool. In this section, you will learn how to control NetworkManager by using a text user interface. So, run the nmtui in your terminal to see the nmtui text user interface
Then, you should select Edit a connection and the name of the interface you desire to modify. Next, changing the values will be done as you see in the following example.
Once you see a desirable result, select ok and press enter to be taken back to the interface selection menu. To exit, select back and choose quit .
Use the command below to apply the settings you want to reload the interface connection.
How to make network configurations always be manual?
While Configure a static IP using NetworkManager, you can use the command below to do this:
How to disable NetworkManager?
If you do not want to remove the network manager, use the following command to disable it.
In this article, you learned How to Configure Static IP on RHEL/CentOS 8. Three different methods were explained with examples to help you see how to change options and what to add to the interface configuration file while you are editing it manually. The same changes could be made using nmcli as a command line tool and nmtui as a text user interface which are used to control the NetworkManager daemon.
Leave a Reply Cancel reply
Your email address will not be published. Required fields are marked.
- Linux Acronyms
Linux and Unix, Open Source, Linux Howtos
How to configure static IP address in CentOS 8 / RHEL 8
Dynamic IP can be used in home system or Local Area Network (LAN) because they are only used internally.
It can be assigned through DHCP (Dynamic Network Configuration Protocol) by either your ISP or your router.
But, you should assign a static IP address to the Linux servers that are accessible through internet.
Also, large organizations use static IP to avoid network issues due to the unavailability of DHCP servers.
- Suggested Read: How to add secondary IP address on RHEL/CentOS 8
In this article, we’ll demonstrate how to assign or configure Static IP address on RHEL 7/8 and CentOS 7/8 Server’s.
Static IP address can be configured on Red Hat system using below two methods:
- Using nmcli command
- Using Network Scripts files (ifcfg-*)
Method-1: Configure a static IP address using nmcli command on CentOS 7/8 and RHEL 7/8
The nmcli is a command line tool, which is used for controlling NetworkManager and reporting network status. It is used to create, display, edit, delete, activate, and deactivate network connections.
Before proceeding to configure a static IP address, use the ip command to identify all the available Ethernet interfaces on your system.
As we can see from the above output, We have an interface named "enp0s3" , which has a dynamic IP.
To view detailed DHCP configuration of enp0s3, run:
Let’s assume we want to assign the static IP address for “enp0s3” with the following details:
Configuring IP address
To do so, run the below nmcli commands one by one to configure static ip:
To assign a IP address:
To add a gateway:
To configure a static IP, run: This will change the “BOOTPROTO=dhcp” to “BOOTPROTO=none” .
This parameter is used to set the protocol to be used at startup to set the IP address of the interface. The options are as follows:
- none : No boot-time protocol should be used.
- dhcp : The DHCP protocol should be used.
- bootp : The BOOTP protocol should be used.
To add DNS entry, run:
To save these changes and to reload the interface, run:
You have successfully configured the interface “enp0s3” with static IP. All the new configuration has been saved permanently to the file “etc/sysconfig/network-scripts/ifcfg-enp0s3” . To view the details, run:
You can double confirm, if the new IP address is banded with the interface “enp0s3” by using ip command .
Method-2: Assign a static IP address by editing network scripts files on CentOS 7/8 and RHEL 7/8
For each network interface, a configuration file is created under the ‘/etc/sysconfig/network-scripts’ directory, which controls the interfaces for individual network devices.
When the system boots, it uses these files to determine what interfaces to bring up and how to configure them.
These files are named with the "ifcfg-" prefix and the name of the interface.
For instance, to configure a static IP address for “enp0s3” with the following details, see the below steps:
To do so, add or modify the above lines in the following configuration file.
Once you modified, run the below command to shut down the interface and bring it back:
Check if the new configurations are populated by using ip command :
In this guide, we’ve shown you how to configure a static IP in RHEL 7/8 and CentOS 7/8 using two different methods.
If you have any questions or feedback, feel free to comment below.
How to Configure VLAN Tagging Over Bonding on RHEL
September 6, 2023 September 6, 2023
How to Configure Network Bonding or Teaming on RHEL
August 28, 2023 August 28, 2023
How to add secondary IP address on RHEL/CentOS 8
August 5, 2021 August 5, 2021
About Magesh Maruthamuthu
Love to play with all Linux distribution
One Comment on “How to configure static IP address in CentOS 8 / RHEL 8”
Hi, Thank a lot
Leave a Reply Cancel reply
Your email address will not be published. Required fields are marked *
Save my name, email, and website in this browser for the next time I comment.
How to Configure Static IP Address in RHEL 8 / CentOS 8
While Working on Linux Servers , assigning Static IP address on NIC / Ethernet cards is one of the common tasks that every Linux engineer do. If one configures the Static IP address correctly on a Linux server then he/she can access it remotely over network. In this article we will demonstrate what are different ways to assign or configure Static IP address on RHEL 8 / CentOS 8 Server’s NIC.
Following are the ways to configure Static IP on a NIC,
- nmcli (command line tool)
- Network Scripts files(ifcfg-*)
- nmtui (text based user interface)
Configure Static IP Address using nmcli command line tool
Whenever we install RHEL 8 / CentOS 8 server then ‘ nmcli ’, a command line tool is installed automatically, nmcli is used by network manager and allows us to configure static ip address on Ethernet cards.
Run the below ip addr command to list Ethernet cards on your server
As we can see in above command output, we have two NICs enp0s3 & enp0s8. Currently ip address assigned to the NIC is via dhcp server.
Let’s assume we want to assign the static IP address on first NIC (enp0s3) with the following details,
- IP address = 192.168.1.4
- Netmask = 255.255.255.0
- Gateway= 192.168.1.1
- DNS = 220.127.116.11
Run the following nmcli commands one after the another to configure static ip,
List currently active Ethernet cards using “ nmcli connection ” command,
Use beneath nmcli command to assign static ip on enp0s3,
# nmcli connection modify <interface_name> ipv4.address <ip/prefix>
Note: In short form, we usually replace connection with ‘con’ keyword and modify with ‘mod’ keyword in nmcli command.
Assign ipv4 (192.168.1.4) to enp0s3 interface,
Set the gateway using below nmcli command,
Set the manual configuration (from dhcp to static),
Set DNS value as “18.104.22.168”,
To save the above changes and to reload the interface execute the beneath nmcli command,
Above command output confirms that interface enp0s3 has been configured successfully.Whatever the changes we have made using above nmcli commands, those changes is saved permanently under the file “etc/sysconfig/network-scripts/ifcfg-enp0s3”
To Confirm whether IP address has been to enp0s3 interface use the below ip command ,
Configure Static IP Address using network-scripts (ifcfg-) files
We can configure the static ip address to an ethernet card using its network-script or ‘ifcfg-‘ files. Let’s assume we want to assign the static ip address on our second Ethernet card ‘enp0s8’.
- IP= 192.168.1.91
- Netmask / Prefix = 24
Go to the directory “/etc/sysconfig/network-scripts” and look for the file ‘ifcfg- enp0s8’, if it does not exist then create it with following content,
Save and exit the file and then restart network manager service to make above changes into effect,
Now use below ip command to verify whether ip address is assigned to nic or not,
Above output confirms that static ip address has been configured successfully on the NIC ‘enp0s8’
Configure Static IP Address using ‘nmtui’ utility
nmtui is a text based user interface for controlling network manager, when we execute nmtui, it will open a text base user interface through which we can add, modify and delete connections. Apart from this nmtui can also be used to set hostname of your system.
Let’s assume we want to assign static ip address to interface enp0s3 with following details,
- IP address = 10.20.0.72
- Prefix = 24
- Gateway= 10.20.0.1
Run nmtui and follow the screen instructions, example is show
Select the first option ‘ Edit a connection ‘ and then choose the interface as ‘enp0s3’
Choose Edit and then specify the IP address, Prefix, Gateway and DNS Server ip,
Choose OK and hit enter. In the next window Choose ‘ Activate a connection ’
Select enp0s3 , Choose Deactivate & hit enter
Now choose Activate & hit enter,
Select Back and then select Quit,
Use below IP command to verify whether ip address has been assigned to interface enp0s3
Above output confirms that we have successfully assign the static IP address to interface enp0s3 using nmtui utility.
That’s all from this tutorial, we have covered three different ways to configure ipv4 address to an Ethernet card on RHEL 8 / CentOS 8 system. Please do not hesitate to share feedback and comments in comments section below.
Read Also : How to Install and Configure Nagios Core on CentOS 8 / RHEL 8
6 thoughts on “How to Configure Static IP Address in RHEL 8 / CentOS 8”
The ip tool can be used to add and remove connections, bridges, addresses, etc.
Yes, IP tool can be used to assigned the ip address but it will not persistent across the reboot.
Very good article!
It’s so usefull. here have lot of content and very easy ways this content and solution.
Very good. This article helped me a lot
Why do i lose my IP configuration after reboot in redhat 8? regardless of the method used, please i need help