Network Configuration Files in Linux Explained

Linux saves network configurations in files. To manage a Linux network, you must know these configuration files. This tutorial explains important network configuration files and the meanings of the directives they use to save the network settings.

Network Interface Configuration files

Linux uses a separate network configuration file for each network interface to store its IP addresses and other network-related settings. It stores all network configuration files in the /etc/sysconfig/network-scripts directory.

For the naming convention, it uses the ifcfg- prefix and interface name. For example, if the interface name is eno16777736, then the name of its configuration file will ifcfg-eno16777736.

network configuration files

The following table briefly describes the files stored in the /etc/sysconfig/network-scripts/ directory.

Files Description
ifcfg-lo It stores the configuration of a loopback device. A loopback device is a virtual network interface. You can use it for testing the TCP/IP protocol stocks available on the local host.
ifcfg-* It stores the configuration of the network interface. Each file only stores the configuration of the interface that it represents.
ifup-* and ifdown-* It stores the script that enables and disables its associated protocol. For example, the ifup-ppp script file enables the ppp protocol, and the ifdown-ppp script file disables the ppp protocol.

Since RHEL8, Linux does not use script files to manage network-related settings. To manage all network-related settings, it uses NetworkManager. Because of this, on RHEL8 and later versions, you will not see ifup-* and ifdown-* script files. You will see only ifcfg-* files. Linux uses these files to store network configurations of interfaces.

network configuration files on rhel 8

Settings stored in the interface’s configuration file are applied to the interface when we start the system or activate the interface. To view these settings, you can use the cat command. For example, the following command displays the settings of the eno16777736 interface.

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

configuration directives

Configuration directives

The following table lists important directives and their descriptions.

Directive Description
BOOTPROTO Defines how the IP address should be obtained.
BRIDGE Specifies the name of the network bridge.
BROADCAST0 The broadcast address of the first IP configuration.
GATEWAY0 Gateway address of the first IP configuration.
DEFROUTE Specifies whether to use this interface as the default route or not.
DEVICE The device name of the network interface.
DNS1 The IP address of the first DNS server.
HWADDR The hardware address of the network interface.
IPADDR0 Specifies the first IP address of the interface.
IPV6INIT Specifies whether to enable IPv6 or not.
NAME Name of the interface. If not assigned manually, the device name will be used.
NETMASK0 Netmask or subnet mask address of the first IP configuration.
NM_CONTROLLED Specifies whether the Network Manager service is allowed to modify the settings stored in this file or not.
ONBOOT Whether to activate or not activate this interface on boot.
USERCTL Specifies whether the non-root users are allowed to activate this interface or not.
UUID Unique ID of this interface.
TYPE Type of this interface.

In addition to the above-listed directives, there are many other directives that you can use in the network configuration file. To view a complete list of all directives and their meanings, you can use the following command.

#man nm-settings

This command lists all directives and their meanings.

man nm-settings

The /etc/hosts file

This file maps the hostname with the IP address. After mapping a hostname with the IP address, you can use the hostname to access the services available on the destination IP address. There are two ways to map a hostname with the IP address: the DNS Server and the /etc/hosts file.

DNS servers provide a lot of functionalities. They can map millions of hostnames with IP addresses, but they are complex. They need a lot of configurations. Usually, they are not used in small networks. In a small network, you can use the /etc/hosts files. The /etc/hosts file allows you to map hostnames with IP addresses on the local system. You need to update this file manually. Each row in this file represents a unique entry. It contains an IP address in the first column, the full or official hostname in the second column, and the short or alias name in the third column.

The following image shows an example of this file.

etc hosts file

If you want to use the DNS server, do not update the /etc/hosts file. The system uses the /etc/hosts file in the first place to resolve the IP address. It sends a query to the DNS server only if it does not find an entry for that IP address in the /etc/hosts file.

The /etc/resolv.conf file

Linux stores DNS server IP addresses in this file. By default, this file is not present. Linux dynamically generates and updates this file when you configure the DNS server's IP address. When you configure or change the DNS server IP address, Linux stores it in the network configuration file available in the /etc/sysconfig/network-scripts/ directory and pushes the configuration to the /etc/resolv.conf file. Since Linux dynamically updates this file, you should not edit this file directly.

If you manually edit this file, the changes will work only until you don't restart NetworkManager. When you restart NetworkManager, it automatically updates this file from the configuration stored in the network configuration file.

To verify it, use the following steps.

  • Use the cat command to display the current configuration stored in the /etc/resolv.conf
  • Manually update the configuration file and verify the change
  • Restart the NetworkManager service
  • Use the cat command again to display the configuration

The following image shows the above exercise.

etc resolv conf file

The /etc/hostname file

There are three types of hostnames static, pretty, and transient. Services running on the local system use the static hostname to refer to the system. If the system is connected to the network, services running on other computers use the transient hostname to refer to the system. Users use the pretty hostname to refer to the system.

Of these names, the static hostname is the most important. Linux always needs it. Since it is the most important, Linux has a default static hostname (localhost.localdomain). Linux uses it when the manual static hostname is not available.

It stores the static hostname in the /etc/hostname file. You can edit this file directly or use the hostnamectl command.

etc hostname

The /etc/sysconfig/network file

Before RHEL8, the network service was used to control networking-related settings. In RHEL8, the network service was deprecated. It was replaced by NetworkManager. If the network service is absent and NetworkManager is installed, this file contains nothing. Since this file works with the network service, updating this file does not affect the NetworkManager service.

To verify it, open this file, set NETWORKING to no, save the file, and restart the NetworkManager service.

The following image shows this exercise.

network manager service

If the NetworkManager service starts, it verifies that this file does not affect the NetworkManager service.

Conclusion

In this tutorial, we discussed the essential network configuration files. These files store the network configurations Linux uses to connect and communicate with other systems on the network.

ComputerNetworkingNotes Linux Tutorials Network Configuration Files in Linux Explained