Network Configuration Files in Linux Explained

Linux saves network configurations in files. We must understand these files to manage a Linux system on the network. This tutorial explains these files and the configurations they save.

Network Interface Configuration files

Linux stores each network interface's IP addresses and other network-related settings in a separate network configuration file in the /etc/sysconfig/network-scripts directory. The naming convention uses the ifcfg— prefix and interface name. For example, if the interface name is eno16777736, then the name of its configuration file will be 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 to test the TCP/IP protocol stacks 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 turns its associated protocol on and off. For example, the ifup-ppp script file enables the ppp protocol, and the ifdown-ppp script file turns off the ppp protocol.

Starting RHEL8, Linux has deprecated using script files to manage network-related settings. Instead, it uses NetworkManager to manage all network-related settings. Because of this, on RHEL8 and later versions, we do not see ifup—* and ifdown—* script files. We see only ifcfg—* files. Linux uses these files to store network configurations of interfaces.

Network configuration files on RHEL 9

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, we 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 essential directives and their descriptions.

Directive Description
BOOTPROTO Defines how the system obtains IP address.
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.
NAME Name of the interface. The system uses the device name if we do not assign it manually.
NETMASK0 Netmask or subnet mask address of the first IP configuration.
NM_CONTROLLED Specifies whether the Network Manager service can modify the settings stored in this file.
ONBOOT Whether to activate this interface on boot.
USERCTL Specifies whether the non-root users are allowed to activate this interface.
UUID Unique ID of this interface.
TYPE Type of this interface.

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

#man nm-settings

man nm-settings

The /etc/hosts file

This file maps the hostname with the IP address. After mapping a hostname with the IP address, we 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, small networks do not use them. They use the /etc/hosts files. The /etc/hosts file allows us to map hostnames with IP addresses on the local system. We 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 complete 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.

The /etc/hosts file

Do not update the /etc/hosts file If you want to use the DNS server. 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 we configure the DNS server's IP address. When we 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 it directly.

If you manually edit this file, the changes will work until you 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.

The /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 part of a 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 compulsory. Since it is mandatory, Linux has the default static hostname (localhost.localdomain). Linux uses it if we do not configure a static hostname manually. It stores the static hostname in the /etc/hostname file. You can edit this file directly or use the hostnamectl command.

The /etc/hostname

The /etc/sysconfig/network file

Before version 8, RHEL used the network service to control networking-related settings. In version 8, it deprecated the network service and replaced it with 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.

The NetworkManager service

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

This tutorial is part of the tutorial series Managing Basic Networking (RHCSA / RHCE) Study Guide. Other parts of this series are the following.

Chapter 01  Managing Basic Networking RHCSA Exam
Chapter 02  Predictable Consistent Network Device Naming
Chapter 03  Linux ip Address Command Usages and Examples
Chapter 04  Linux ip Command Cheat Sheet
Chapter 05  The ip Command v/s the ifconfig Command
Chapter 06  Understanding Linux Network Manager Fundamental
Chapter 07  Managing Linux NetworkManager
Chapter 08  Linux NetworkManager Tools and Utilities
Chapter 09  The nmcli Command on Linux Examples and Usages
Chapter 10  The nmtui Command and Utility on Linux
Chapter 11  The nm-connection-editor Command on Linux
Chapter 12  How to Configure IP Address in Linux
Chapter 13  How to Configure Multiple IP Addresses on Linux
Chapter 14  How to Configure IPv6 on Linux
Chapter 15  Basic Linux Commands for Network Testing
Chapter 16  Network Configuration Files in Linux Explained
Chapter 17  The /etc/hosts, /etc/resolv.conf, and /etc/nsswitch.conf Files
Chapter 18  How to Change the Hostname on Linux

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

We do not accept any kind of Guest Post. Except Guest post submission, for any other query (such as adverting opportunity, product advertisement, feedback, suggestion, error reporting and technical issue) or simply just say to hello mail us ComputerNetworkingNotes@gmail.com