Network Configuration Files in Linux Explained

This tutorial explains network configuration files of Linux in detail. Learn where the Linux stores network configuration files and how to edit them.

To store IP addresses and other related settings, Linux uses a separate configuration file for each network interface. All these Configuration files are stored in the /etc/sysconfig/network-scripts directory.

Name of configuration files starts with the ifcfg-. After the ifcfg-, to keep each file separate, name of the interface is used. For example, if the interface name is eno16777736 then the name of its configuration file will be the ifcfg-eno16777736.

The following image shows a sample output of the /etc/sysconfig/network-scripts directory.

listing /etc/sysconfig/network-scripts directory

The following table briefly describes the files stored in this directory.

Files Description
ifcfg-lo Stores the configuration of loopback device. Loopback device is a virtual network interface. It is used to test the TCP/IP protocol stocks in local host.
ifcfg-* Stores the configuration of the network interface. Each file only stores the configuration of that interface, which it represents.
ifup-* and ifdown-* Stores the scripts which activate and deactivate their associated protocols. For example, the ifup-ppp and ifdown files activate and deactivate the ppp protocol respectively.

Settings stored in the interface’s configuration file are applied on 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

The following image shows how a configuration file looks like.

configuration directives of network inteface file

The following table lists important directives of this file with description.

Directive Description
BOOTPROTO Defines how the IP address should be obtained. Four values can be used here; dhcp, bootp, none and static. Use the value "dhcp", to obtain IP from the dhcp server. To boot from a network boot server and get IP, use the value "bootp". To assign IP manually, use the value "static". Use the value "none" if you don't want to assign the IP address.
BRIDGE Specifies the name of the network bridge.
BROADCAST0 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 Device name of the network interface.
DNS1 IP address of the first DNS server.
HWADDR Hardware address of the network interface.
IPADDR0 Specifies the first IP address of interface.
IPV6INIT Specifies whether to enable to 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 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.

Although you can edit configuration files directly, but you should use available configuration tools for editing and updating these files. Using a configuration tool reduces the chances of incorrect editing in configuration files. The next parts of this tutorial explain network configuration tools in detail with practical examples.

The /etc/sysconfig/network file

This file, based on how the network interfaces are configured, may contain none, one or two configuration directives. If a system is configured to get IP configuration from the DHCP server, there will be no configuration in this file.

Two directives that may appear in this file are; GATEWAY and NETWORKING.

GATEWAY directive shows the IP address of default gateway. This directive appears only if the same IP address is used for the default gateway in all network interfaces.

NETWORKING directive is used to control the network service. It can be configured with two values; yes and no. If the value "no" is used, the network service does not start.

If you run the "ip addr show" command and see no output or you start network service and it does not start then it means all network devices are currently inactive. In this situation, the first thing that you should check is the contents of the /etc/sysconfig/network configuration file. This file either should not contain the NETWORKING directive or if it contains, its value must be set to "yes".

To understand how the "NETWORKING=no" directive affects the network service practically, follow these steps in your test system.

  • Take the backup of the /etc/sysconfig/network file.
  • Delete the NETWORKING directive or set its value to "yes".
  • Check the status of network service.
  • Add the "NETWORKING=no" directive in the /etc/sysconfig/network file
  • Restart the network service.
  • Remove the "NETWORKING=no" directive or restore the original file back
  • Check the status of network service again.

The following image shows the status of network service when the /etc/sysconfig/network file does not contain the NETWORKING directive.

/etc/sysconfig/network file

Next image shows how the "NETWORKING=no" directive affects the network service.

networking=no directive

As we can see in the above image, the "NETWORKING=no" directive does not let the network service starts. To start network service again, either we have to remove this directive or set its value to "yes". After this, we can start network service again. The following image shows these steps.

networking=yes directives

The /etc/hosts file

This file is used to map the hostname with IP address. Once hostname and IP address are mapped, hostname can be used to access the services available on the destination IP address. A hostname can be mapped with an IP address in two ways; through the DNS server and through the /etc/hosts file.

DNS server provides this facility in more dynamic and flexible way but also requires a lot of complex configuration. Due to complexity, usually DNS server is not used in small networks.

The /etc/hosts file also provides this functionality in local system but requires manual mapping of all hostnames with their IP addresses.

Each row in this file represents a unique entry. It contains an IP address in the first column, full or official hostname in the second column and short or alias name in third column.

The following image shows an example of this file.

/etc/hosts file

If DNS server is configured in network, do not update the /etc/hosts file. System uses the /etc/hosts file in first place to resolve the IP address. If it finds no entry for a hostname in this file only then it uses the configured DNS server.

The /etc/hostname file

This file sets the hostname of the system. A hostname typically consists of two different parts; hostname and DNS domain name in which the host resides. These two parts together make a FQDN (Fully Qualified Domain Name) which looks like

The following image shows an example of this file.

/etc/hostname file

Just like other configuration files, you can use available commands to update this file or can edit it directly.

The following image shows an example of direct updating.

changing hostname

To apply the change in hostname either restart the system or logout from the current session.

verifying hostname

That’s all for this tutorial. If you like this tutorial, please don’t forget to share it with friends through your favorite social network.

ComputerNetworkingNotes Linux Tutorials Network Configuration Files in Linux Explained