You are on page 1of 8

3 Ways to Set a Static IP Address in RHEL 8

1. How to Configure Static IP Using Network Scripts Manually

By editing the below interface file, we can configure the IP

File location- # ip a show enp0s3

Ex enp0s3 is the network port.

/etc/sysconfig/network-scripts/ifcfg-enp0s3

To find your network interface name, you can use the following nmcli command.

# nmcli con

Output:

To edit the file simply use your favorite editor and open the file:

# vim /etc/sysconfig/network-scripts/ifcfg-enp0s3

ifcfg-enp0s3 Configuration

TYPE="Ethernet"

BOOTPROTO="none"

NAME="enp0s3"

IPADDR="192.168.20.150"

NETMASK="255.255.255.0"

GATEWAY="192.168.20.1"
DEVICE="enp0s3"

ONBOOT="yes"

Then restart the NetworkManager with:

# systemctl restart NetworkManager

Alternatively, you can reload the network interface by using:

# nmcli con down enp0s3 && nmcli con up enp0s3

Now you can then check the new IP address using ip command as shown.

# ip a show enp0s3

2. How to Configure Static IP Using Nmtui Tool

Another way to configure static IP address is by using nmtui tool, is a text user interface


(TUI). To use it simply type the following command in your terminal.

# nmtui

This is will launch the program:


Network Manager Interface
Choose to edit a connection, then select the interface:

Select Network Interface


In the next window you will be able to edit the network interface settings by moving the
cursor with the arrow keys on your keyboard:
In this example, we have changed the IP address from 192.168.20.150 to 192.168.20.160.
To save the changes scroll down to the end of the page and select OK.

Then reload the network interface by choosing “Activate a connection”:

Active Network Interface


Then choose the connection name and select <Deactivate>:
Deactivate Network Interface
And now select <Activate> to activate the interface with the new settings you have given it.

Activate Network Interface


Then select <Back> to return to the main menu and then select “Quit” to exit.
Quit Network Manager
Verify that the new IP address settings have been applied with:

# ip a show enp0s3

3. How to Configure Static IP Using Nmcli Tool


Nmcli is a NetworkManager command line interface that can obtain information or
configure a network interface.
If you want to set a static IP address, you can use the following options:

Set the IP address for interface enp0s3 

# nmcli con mod enp0s3 ipv4.addresses 192.168.20.170/24


Set the gateway on :

# nmcli con mod enp0s3 ipv4.gateway 192.168.20.1

Inform the interface that it is using manual configuration (not dhcp etc.).

# nmcli con mod enp0s3 ipv4.method manual

Configure DNS if required, we are showing the example with google DNS server

# nmcli con mod enp0s3 ipv4.dns "8.8.8.8"

Reload the interface configuration:

# nmcli con up enp0s3

Your changes will be saved in /etc/sysconfig/network-scripts/ifcfg-.

Here is the configuration file generated after running the above commands:

# cat /etc/sysconfig/network-scripts/ifcfg-enp0s3

ifcfg-enp0s3 Configuration

TYPE="Ethernet"

BOOTPROTO="none"

NAME="enp0s3"

IPADDR="192.168.20.170"

NETMASK="255.255.255.0"
GATEWAY="192.168.20.1"

DEVICE="enp0s3"

ONBOOT="yes"

PROXY_METHOD="none"

BROWSER_ONLY="no"

PREFIX="24"

DEFROUTE="yes"

IPV4_FAILURE_FATAL="no"

IPV6INIT="no"

UUID="3c36b8c2-334b-57c7-91b6-4401f3489c69"

You might also like