Skip to content

Introduction

For novice users who are new to GNU/Linux for the first time, the first thing to consider is how to connect the machine to the Internet after installing the operating system. This article will tell you how to configure the IP address, subnet mask, gateway and DNS. There are several ways for reference. Whether you are a novice or a familiar, I believe you can quickly get started.

nmtui

NetworkManager is a standard Linux network configuration tool suite, which supports server and desktop environments. Nowadays, most popular distributions support it. This set of network configuration tools is suitable for Rocky Linux 8 and later versions. If you want to configure network information graphically (i.e. the command line nmtui), you only need to do this:

shell > dnf -y install NetworkManager NetworkManager-tui
shell > nmtui
NetworkManager TUI
Edit a connection
Activate a connection
Set system hostname
Quit
\<OK>

You can use the Tab key or the Up Down Left Right key to select the specific If you want to change the network information, please select Edit a connection and then Enter. Select a different network card and select Edit.. to edit.

DHCP IPv4

For IPv4, if it is to obtain network information with DHCP, you only need to select IPv4 CONFIGURATION <Automatic>, and run in your terminal systemctl restart NetworkManager.service. This will work in most cases. In rare cases, you need to disable and enable the network card for the change to take effect. For example: nmcli connection down ens33, nmcli connection up ens33

Manually fix network information

If you want to manually fix all IPv4 network information, you need to select <Manual> after IPv4 CONFIGURATION and add it line by line. For example, I like this:

ItemValue
Addresses192.168.100.4/24
Gateway192.168.100.1
DNS servers8.8.8.8

Then click \< OK >, return to the terminal interface step by step, and execute systemctl restart NetworkManager.service. Similarly, in rare cases, the network card needs to be switched on and off to take effect.

Change the way of configuration files

All RHEL 7.x or 8.x distributions, whether upstream or downstream, are configured in the same way. The configuration file of network information is stored in the /etc/sysconfig/network-scripts/ directory, and one network card corresponds to one configuration file. The configuration file has many parameters, as shown in the following table. Notice! The parameters must be capitalized.

Warning

In RHEL 9.x distributions, the location of the directory where the NIC configuration file is stored has been changed, i.e., /etc/NetworkManager/system-connections/. See here for more information.

shell > ls /etc/sysconfig/network-scripts/
ifcfg-ens33
Parameter nameMeaningExample
DEVICESystem logical device nameDEVICE=ens33
ONBOOTWhether the network card starts automatically with the system, you can choose yes or no>TYPENetwork card interface type, usually EthernetTYPE=Ethernet
BOOTPROTOThe way to obtain ip, it can be DHCP dynamic acquisition, or static manual configuration using staticBOOTPROTO=static
IPADDRThe ip address of the network card, when BOOTPROTO=static, this parameter will take effectIPADDR=192.168.100.4
HWADDRHardware address, ie MAC addressHWADDR=00:0C:29:84:F6:9C
NETMASKDecimal subnet maskNETMASK=255.255.255.0
PREFIXSubnet mask, represented by numbersPREFIX=24
GATEWAYGateway, if there are multiple network cards, this parameter can only appear onceGATEWAY=192.168.100.1
PEERDNSWhen it is yes, the DNS parameters defined here will modify /etc/resolv.conf; when it is no, /etc/resolv.conf will not be modified. When using DHCP, the default is yesPEERDNS=yes
DNS1The primary DNS is selected, it takes effect only when PEERDNS=noDNS1=8.8.8.8
DNS2Alternative DNS, only effective when PEERDNS=noDNS2=114.114.114.114
BROWSER_ONLYWhether to allow only browsersBROWSER_ONLY=no
USERCTLWhether ordinary users are allowed to control the network card device, yes means allow, no means not allowedUSERCTL=no
UUIDUniversal unique identification code, the main function is to identify the hardware, generally speaking, it is not necessary to fill in
PROXY_METHODProxy method, generally none, can be left blank
IPV4_FAILURE_FATALIf it is yes, it means that the device will be disabled after ipv4 configuration fails; if it is no, it means it will not be disabled.IPV4_FAILURE_FATAL=no
IPV6INITWhether to enable IPV6, yes to enable, no not to enable. When IPV6INIT=yes, the two parameters IPV6ADDR and IPV6_DEFAULTGW can also be enabled. The former represents the IPV6 address and the latter represents the designated gatewayIPV6INIT=yes
IPV6_AUTOCONFWhether to use IPV6 automatic configuration, yes means use; no means do not useIPV6_AUTOCONF=yes
IPV6_DEFROUTEWhether to give IPV6 the default routeIPV6_DEFROUTE=yes
IPV6_FAILURE_FATALAfter IPV6 configuration fails, whether to disable the deviceIPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODEGenerate IPV6 address model, optional values ​​are stable-privacy and eui64IPV6_ADDR_GEN_MODE=stable-privacy

After the configuration file is modified successfully, remember to restart the network card service systemctl restart NetworkManager.service.

TYPE=Ethernet
ONBOOT=yes
DEVICE=ens33
USERCTL=no
IPV4_FAILURE_FATAL=no
BROWSER_ONLY=no
BOOTPROTO=static
PEERDNS=no
IPADDR=192.168.100.4
PREFIX=24
GATEWAY=192.168.100.1
DNS1=8.8.8.8
DNS2=114.114.114.114
TYPE=Ethernet
ONBOOT=yes
DEVICE=ens33
USERCTL=no
BROWSER_ONLY=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no

View network information

ip a or nmcli device show

Author: tianci li

Contributors: Steven Spencer, Neil Hanlon