Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the ways to configure static IP addresses in RHEL8

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article focuses on "what are the ways to configure static IP addresses in RHEL8". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what are the ways to configure static IP addresses in RHEL8?"

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

Here is how to configure static IP on the Nic:

Nmcli (command line tool)

Network script file (ifcfg-*)

Nmtui (text-based user interface)

Use the nmcli command line tool to configure static IP addresses

Whenever we install the RHEL 8 server, we automatically install the command line tool nmcli, 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 command output above, we have two network cards, enp0s3 and enp0s8. The IP address currently assigned to the network card is obtained through the DHCP server.

Suppose we want to assign a static IP address on the first network card (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 command to configure static IP

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

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

Use the nmcli below to assign a static IP to enp0s3.

Command syntax:

# nmcli connection modify ipv4.address

Note: to simplify the statement, in the nmcli command, we usually replace connection with the con keyword and modify with the mod keyword.

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

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

Use the following nmcli command to set up the gateway

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

Set up 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 enp0s3Connection successfully activated (D-Bus active path: / org/freedesktop/NetworkManager/ActiveConnection/4)

The above command shows that the network card enp0s3 has been successfully configured. The changes we made with the nmcli command will be saved in the file etc/sysconfig/network-scripts/ifcfg-enp0s3 for a long time.

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

To confirm that the IP address is assigned to the enp0s3 network card, use the following IP command to view

[root@linuxtechi ~] # ip addr show enp0s3 manually configure static IP addresses using network script files (ifcfg-*)

We can configure the static IP address of the Ethernet card using the network script or ifcfg-* file that configures 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, and if it does not exist, create it with the following

[root@linuxtechi ~] # cd / etc/sysconfig/network-scripts/ [root@linuxtechi network-scripts] # vi ifcfg-enp0s8TYPE= "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, and 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 that the IP address is assigned to the network card

[root@linuxtechi ~] # ip add show enp0s83: enp0s8: 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 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 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.

Configure static IP addresses using the nmtui utility

Nmtui is a text-based user interface manager that controls the network. When we execute nmtui, it opens a text-based user interface through which we can add, modify, and delete connections. In addition, nmtui can also be used to set the hostname of the system.

Suppose we want to assign a static IP address to the 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, as shown below

[root@linuxtechi ~] # nmtui

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

Select Edit, and then specify the IP address, prefix, gateway, and domain name system server IP

Select OK, and then click enter. In the next window, select "Activate a connection"

Select "enp0s3", select "Deactivate" and click enter

Now select "Activate" and click enter

Select "Back", then select "Quit"

Verify that the IP address is assigned to interface enp0s3 using the following ip command

[root@linuxtechi ~] # ip add show enp0s32: enp0s3: mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 08 link/ether 08 enp0s3 2753 Flux 39 mtu 4d brd ff:ff:ff:ff:ff:ff inet 10.20.0.72 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 interface enp0s3 using the nmtui utility.

At this point, I believe you have a deeper understanding of "what are the methods of configuring static IP addresses in RHEL8?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report