A brief analysis of different ways to configure static IP addresses in RHEL8

A brief analysis of different ways to configure static IP addresses in RHEL8

While working on a Linux server, assigning static IP address on the Network Card/Ethernet Card is one of the common tasks for every Linux engineer. If a person configures the static address correctly on the Linux server, then he/she can access it remotely over the network. In this article, we will demonstrate different ways to configure static IP address on RHEL 8 server network card.

Here's how to configure a static IP on your network card:

  • nmcli (command line tool)
  • Network script files ( ifcfg-* )
  • nmtui (text-based user interface)

Use the nmcli command line tool to configure a static IP address

Whenever we install RHEL 8 server, the command line tool nmcli is automatically installed which is used by the Network Manager and allows us to configure static IP addresses on the Ethernet card.

Run the following ip addr command to list the Ethernet cards on the RHEL 8 server:

[root@linuxtechi ~]# ip addr

As we can see in the above command output, we have two network cards enp0s3 and enp0s8 . The IP address currently assigned to the network card is obtained through the DHCP server.

Assume we want to assign a static IP address to the first NIC ( enp0s3 ), as follows:

  • IP address = 192.168.1.4
  • Network Mask = 255.255.255.0
  • Gateway = 192.168.1.1
  • DNS = 8.8.8.8

Run the following nmcli commands in sequence to configure a static IP:

Use the nmcli connection command to list the currently active Ethernet cards.

[root@linuxtechi ~]# nmcli connection
NAME UUID TYPE DEVICE
enp0s3 7c1b8444-cb65-440d-9bf6-ea0ad5e60bae ethernet enp0s3
virbr0 3020c41f-6b21-4d80-a1a6-7c1bd5867e6c bridge virbr0
[root@linuxtechi ~]#

Assign a static IP to enp0s3 using nmcli as below.

Command Syntax:

# nmcli connection modify <interface_name> ipv4.address <ip/prefix>

Note: To simplify the statements, in nmcli commands, we usually replace connection with the con keyword and replace modify with the mod keyword.

Assign an IPv4 address (192.168.1.4) to the enp0s3 network card.

[root@linuxtechi ~]# nmcli con mod enp0s3 ipv4.addresses 192.168.1.4/24

Use the following nmcli command to set the gateway,

[root@linuxtechi ~]# nmcli con mod enp0s3 ipv4.gateway 192.168.1.1

Set manual configuration (from dhcp to static),

[root@linuxtechi ~]# nmcli con mod enp0s3 ipv4.method manual

Set the DNS value to "8.8.8.8",

[root@linuxtechi ~]# nmcli con mod enp0s3 ipv4.dns "8.8.8.8"
[root@linuxtechi ~]#

To save the above changes and reload, execute the following nmcli command,

[root@linuxtechi ~]# nmcli con up enp0s3
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/4)

The above command shows that the network card enp0s3 has been successfully configured. All the changes we make using the nmcli command will be permanently saved in the file etc/sysconfig/network-scripts/ifcfg-enp0s3 .

[root@linuxtechi ~]# cat /etc/sysconfig/network-scripts/ifcfg-enp0s3 

To confirm whether the IP address is assigned to the enp0s3 network card, use the following IP command to check,

[root@linuxtechi ~]#ip addr show enp0s3

Manually configure a static IP address using a network script file (ifcfg-*)

We can use the network scripts or ifcfg-* files to configure the Ethernet card to configure the static IP address of the Ethernet card. Suppose we want to assign a static IP address on the second Ethernet card enp0s8 :

  • IP address = 192.168.1.91
  • Prefix = 24
  • Gateway = 192.168.1.1
  • DNS1 =4.2.2.2

Go to the directory /etc/sysconfig/network-scripts , look for the file ifcfg-enp0s8 , if it does not exist then create it with the following content,

[root@linuxtechi ~]# cd /etc/sysconfig/network-scripts/
[root@linuxtechi network-scripts]# vi ifcfg-enp0s8
TYPE="Ethernet"
DEVICE="enp0s8"
BOOTPROTO="static"
ONBOOT="yes"
NAME="enp0s8"
IPADDR="192.168.1.91"
PREFIX="24"
GATEWAY="192.168.1.1"
DNS1="4.2.2.2"

Save and exit the file, then restart the network manager service for the above changes to take effect,

[root@linuxtechi network-scripts]# systemctl restart NetworkManager

Now use the following ip command to verify whether the IP address is assigned to the network card,

[root@linuxtechi ~]# ip add show enp0s8
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
 link/ether 08:00:27:7c:bb:cb brd ff:ff:ff:ff:ff:ff
 inet 192.168.1.91/24 brd 192.168.1.255 scope global noprefixroute enp0s8
 valid_lft forever preferred_lft forever
 inet6 fe80::a00:27ff:fe7c:bbcb/64 scope link
 valid_lft forever preferred_lft forever
[root@linuxtechi ~]#

The above output confirms that the static IP address has been successfully configured on the network card enp0s8 .

Configuring a static IP address using the nmtui utility

nmtui is a text-based user interface for controlling network managers. When we execute nmtui , it will open a text-based user interface through which we can add, modify, and delete connections. In addition, nmtui can also be used to set the system's hostname.

Assume we want to assign a static IP address to network card enp0s3 with the following details,

  • IP address = 10.20.0.72
  • Prefix = 24
  • Gateway = 10.20.0.1
  • DNS1 =4.2.2.2

Run nmtui and follow the on-screen instructions, an example is shown below,

[root@linuxtechi ~]# nmtui 

Select the first option "Edit a connection" and then select the interface as "enp0s3".

Select "Edit" and specify the IP address, prefix, gateway and DNS server IP.

Select OK and hit Enter. In the next window, select "Activate a connection".

Select "enp0s3", select "Deactivate" and press Enter,

Now select "Activate" and hit enter.

Select Back, then Quit.

Verify that the IP address has been assigned to the interface enp0s3 using the ip command below,

[root@linuxtechi ~]# ip add show enp0s3
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
 link/ether 08:00:27:53:39:4d brd ff:ff:ff:ff:ff:ff
 inet 10.20.0.72/24 brd 10.20.0.255 scope global noprefixroute enp0s3
 valid_lft forever preferred_lft forever
 inet6 fe80::421d:5abf:58bd:c47e/64 scope link noprefixroute
 valid_lft forever preferred_lft forever
[root@linuxtechi ~]#

The above output shows that we have successfully assigned a static IP address to the interface enp0s3 using nmtui utility.

That’s all for this tutorial, we have covered three different methods to configure IPv4 address for Ethernet card on RHEL 8 system. Please share your feedback and comments in the comments section below.

via: https://www.linuxtechi.com/configure-static-ip-address-rhel8/

Summarize

The above are the different methods of configuring static IP addresses in RHEL8 introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • How to build a multi-node Elastic stack cluster on RHEL8 /CentOS8
  • How to configure static IP address for virtual machines in VMware
  • How to configure a static IP address for CentOS 7 (2 ways)
  • Ubuntu16.04 static IP address setting (NAT method)
  • Docker container specifies a fixed IP/static IP address in a custom network segment
  • How to use PowerShell script to automatically obtain IP address and set static IP address using DHCP of network card
  • Code for setting static IP and DNS server address using VBS
  • Using vbs to configure static IP address

<<:  Vue implements a simple shopping cart example

>>:  MySQL 8.0.12 installation graphic tutorial

Recommend

Introduction to document.activeELement focus element in JavaScript

Table of contents 1. The default focus is on the ...

Explanation of the steps for Tomcat to support https access

How to make tomcat support https access step: (1)...

Node.js+postman to simulate HTTP server and client interaction

Table of contents 1. Node builds HTTP server 2. H...

CSS element hiding principle and display:none and visibility:hidden

1. CSS element hiding <br />In CSS, there ar...

Sample code for implementing history in vuex

I have recently been developing a visual operatio...

JavaScript String Object Methods

Table of contents Methods of String Object Method...

Implementing WeChat tap animation effect based on CSS3 animation attribute

Seeing the recent popular WeChat tap function, I ...

Element dynamic routing breadcrumbs implementation example

To master: localStorage, component encapsulation ...

Organize the common knowledge points of CocosCreator

Table of contents 1. Scene loading 2. Find Node 1...

Web page CSS priority is explained in detail for you

Before talking about CSS priority, we need to und...

In-depth analysis of MySQL data type DECIMAL

Preface: When we need to store decimals and have ...

Solution to overflow:hidden failure in CSS

Cause of failure Today, when I was writing a caro...

How to quickly copy large files under Linux

Copy data When copying data remotely, we usually ...