A Complete Guide to Linux Config Files
| technology | system admin - Jon Welling

A Complete Guide to Linux Config Files

Only 733t hax0rs know Nix. At least that's what the movies want you to think….

Did your eyes go cross reading that first line? Don't worry about it. That was only an attempt to spice up this rather long Linux primer a bit. You see, editing Linux configuration files can be a long, monotonous task, but it's a process that every Linux admin must learn.

Linux configuration files are the heart of the Linux operating system. These files are one of the biggest differences between the Linux and Windows operating systems. The Windows OS does use per-application configuration files as well, but Windows largely depends on something called the Registry. The Registry is an ultra-fast database that stores configurations for the Windows OS and its applications.

Linux is much simpler. Configurations for applications in Linux are stored in individual configuration files. This makes management of the Linux OS both much easier and more difficult. These configuration options are easy to change as well as migrate to other systems, but these files can be more tedious to document as well.

We couldn't possibly cover every configuration file for each Linux distribution in this mini-book. Instead, we've focused on some of the more important configuration files for a few different Linux distributions.

Each Linux distribution may use different apps or services for the same function. For instance, Red Hat and Ubuntu use different applications for networking services in their versions of Linux. We make note of this when possible and appropriate below, but if you follow the information in this guide and don't see the configuration file we mentioned, fear not, it's simply called something else for the Linux distribution you are using.

In these cases, you may have to consult the documentation for the Linux distribution that you are configuring. The general idea and process are typically close to what is mentioned below, though.

Before continuing, we need to mention two other things. First, we used the Nano text editor for the examples below. Though that should not matter (and you can use your preferred command-line text editor), this is an important distinction to note nonetheless. Second, before editing any configuration file, we strongly recommend that you make a copy of that configuration file first. When copying it, add a .bak extension to the end of that file so you understand it is a backup file later on.

cp originalFile.conf orginalFile.conf.bak

There is a strong chance you will eventually make a mistake editing these files. These backup files are important! You have been warned.

So, now that we have the introductions out of the way, start digging into the crazy world of editing Linux configuration files!

What Does This Guide Cover?

Arguably, the thing that sets Linux apart from its operating system competition is how configurable it is.

A skilled administrator can configure the Linux kernel and operating system to behave completely unique to the immediate needs of the company and network. While making those configurations usually isn’t particularly complicated, that doesn’t mean it’s easy. We’ve gathered simple explanations and instructions for editing nine of the most common Linux configurations.

Read on to learn about the following Linux operating system configuration and network configuration files:

  • Network-scripts configuration files
  • Network configuration in Oracle Linux
  • Interfaces configuration file in Debian
  • Dhclient configuration file
  • Hosts configuration file
  • Nsswitch configuration file
  • Resolv configuration file
  • Sysctl configuration file
  • Netplan configuration utility

What are Linux Configuration Files?

A configuration file, also known as a config file, is a local file that controls the operations of a program, utility or process. Linux configuration files contain the settings and instructions for different systems, utilities, applications and processes. They’re frequently plain-text files that contain a variable name (the name of the setting) followed by it's value, commands or instructions. Many Linux configuration files can be opened with a plain-text editor and updated directly, though you will most likely be using a command-line editor like Nano or Vim to edit these files.

Different Linux config files are used to configure the parameters and initial settings of different parts of the operating system’s processes. Some of these files define network access and protocols while others instruct the operating system on how to reach the internet’s name servers. A skilled administrator can manipulate the core operation of a Linux system by editing these config files.

Not only do different Linux distributions use different Linux configuration files, but the naming conventions among Linux administrators aren’t identical. Sometimes config files are referred to by file’s name alone, like “dhclient” or “nsswitch”. But they can also be referred to with the file extension afterward, with or without the period, like “dhclient.conf” or “nsswitch conf”.

Other times they might be referred to with their directory location, like “/etc/dhclient.conf” or “/etc/nsswitch conf”. Though the naming conventions of these files might change slightly, as well as their locations in the file system, the general idea of how to edit these individual configuration files is the same. A skilled admin will be able to take the knowledge from one section of this article and apply it to a different Linux distribution.

How to Edit a Linux Config File

Generally speaking, all it takes to edit a Linux config file is to find it and open it with a text editor. The vast majority of Linux configuration files store their configuration data in plain text, and altering their contents and saving the file is all it takes for an administrator to update the settings. Many different text editors will work for the job, and it usually comes down to personal preference. The vast majority of Linux config files can be found in the /etc/ directory or a sub-directory.

Most of the time these configuration files will be edited through the command line, so get comfortable with applications like Nano or Vi. Likewise, these configuration files are typically protected from normal user accounts, so don't forget to elevate your privileges before trying to edit them (Eg. Use the Sudo or SU command), otherwise you might have a bad time finding these files.

Though settings are saved immediately after saving an edited config file, applications won't pick up those settings changes until the application is restarted. In the case of something like a networking service, that means restarting the service as well.

Network-scripts Config File

Have you ever wondered how Linux configures network cards? The entire process of networking in Linux has a lot of moving parts and mechanisms. Let’s look at the configuration files for the network interfaces in Linux and how they work.

Much like Windows, Linux holds a configuration file for each network interface. It is important to note that a network interface could be either a virtual or physical device or a wired or wireless device. These configuration files tell the operating system things like the name of the interface, whether it should use DHCP, or if IPv6 should be enabled.

What is the Network-scripts Config File?

The network-scripts config file is a network configuration file in Linux that controls a network interface. The configuration parameters for a given device or digital interface are stored and edited in a configuration file unique to each interface within the network-scripts directory.

How to Configure the Network-scripts Config File

There are two ways you can edit the network interface configurations in Linux:

  • GUI environment
  • Command-line

Both REHL (and CentOS) and Ubuntu both contain graphical utilities for editing these configuration files. Those graphical utilities will be accessed in a different way depending on which graphical interface you are using.

Typically, these settings can always be found under the networking section of the system preferences or utility section, though. The networking options will list each interface available in the system. Editing these networking interfaces will have access to most of the settings mentioned above.

The other way to edit these configuration files is through your favorite text editor in the command line. In this case, you will use an application like Nano or Vi to open each configuration file and edit them. In REHL, each configuration file will be listed as a separate file as mentioned above. Ubuntu has each configuration listed within that Interface file, though, under the /etc/network/ file system path.

It is important to note that you will need elevated privileges to edit these configuration files. If you are using the GUI to edit these files, you will be prompted for the Root password upon editing each network interface. If you are using the command line to edit the Linux network interface configuration files, make sure to use the Sudo command to elevate privileges for your command-line text editor.

Each network configuration file has multiple configuration options. For simplicity, look at the table below for each configuration parameter, its expected input, and an explanation of what it does.

Option

Value

Explanation

TYPEDevice Type (Eg. Ethernet)What kind of network interface this is
BOOTPROTONone, bootp, dhcpDoes this interface use the bootp or dhcp protocol
DEFROUTEYes, noIs this interface set as the default route
IPV6_DEFROUTEYes, noIs this interface set as the default route for IPv6
IPV6INITYes, noIs IPv6 enabled
IPV4_FAILURE_FATALYes, noIs this interface disabled if IPv4 fails
IPV6_FAILURE_FATALYes, noIs this interface disabled if IPv6 fails
ONBOOTYes, noIs this interface enabled at boot
HWADDRMAC addressThis is the MAC address of the interface
IPADDRNIpv4 addressThis is the IPv4 address of the device
PREFIXNNLength of the IPv4 netmask value
GATEWAYNIPv4 addressThis is the gateway address for this interface
DNSNIPv4 addressThis is the DNS address for this interface
DOMAINDNS search domainThis is the DNS search domain of this address

Where is the Network-scripts Config File?

Each network interface has its own configuration file. Depending on which version of Linux you are using, that configuration file could be saved in a different place.

In Redhat Enterprise Linux (REHL) the location of those network interface configuration files are: /etc/sysconfig/network-scripts/

In Ubuntu/Debian based Linux distributions, that system location is /etc/network/interfaces

Each configuration file will typically have a name like ifcfg-eth# where the pound symbol is an incremental number for each network interface in REHL and CentOS while all configurations are stored in that interfaces file in Ubuntu.

For example, if you have two physical wired network cards in your system, you will most likely have two configuration files named ifcfg-eth0 and ifcfg-eth1.

An Example of the network-scripts Config File

Before editing the network interface configuration files, you may need to see which network interfaces are currently active and what their current configurations (Eg. IP address, DNS information, etc…) are first. This is easy to find out. Use the 'ifconfig' command in the command line.

eth0:  flags=4163<UP, BROADCAST, RUNNING, MULTICAST>    mtu 1500
        inet  192.168.1.3  netmask  255.255.255.0  broadcast  192.168.1.255
        inet6  fe80: :215:5dff:fe01:4303  prefixlen  64   scopeid  0x20<link>
        inet6 2601:985:281:2b60:215:5dff:fe01:4303  prefixlen  64  scopeid  0x0<global>
        ether  00:15:5d:01:43:03   tx        queuelen  1000   (Ethernet)
        RX packets 1920033  bytes  404804795  (404.8 MB)
        RX errors 0    dropped 198   overruns 0    frame 0
        TX packets 855570   bytes  366074892  (366.0 MB)
        TX errors 0    dropped 0    overruns 0    carrier 0    collisions 0
lo:  flags=73<UP, LOOPBACK, RUNNING>     mtu  65536
        inet 127.0.0.1   netmask  255.0.0.0
        inet6  : :1  prefixlen 128  scopeid  0x10<host>
loop   txqueuelen  1000   (Local Loopback)
RX packets 82302    bytes   7837655  (7.8  MB)
RX errors 0     dropped 0     overruns 0     frame 0
TX packets 82302    bytes   78376555  (7.8 MB)
TX errors 0   dropped 0   overruns 0     frame 0    collisions 0

You should see output like the screenshot above.

Network Config Files in Oracle Linux

Though most Linux distributions include a way to configure network interfaces through the GUI, sometimes using the graphical interface for OS configurations is not possible. This is most common in server and cloud environments. Distributions like Oracle Linux are commonly used for both server and cloud applications. So, how do you configure a network card in Oracle Linux without a graphical interface? By directly editing the network configuration files.

What is the Network Config File in Oracle Linux?

In Oracle Linux, the network config file is where broad network settings are stored and edited. It’s important to note that the network config file is different from the individual network interface configuration files. Broad network settings like gateway information are stored on the network configuration file. Settings like static IP addresses are stored in configuration files for each network interface separately.

Oracle Linux primarily uses two files for configuring its network environment:

  • /etc/sysconfig/network
  • /etc/sysconfig/network-scripts/…

The /etc/sysconfig/network-scripts/ directory contains multiple files for each network interface. A network interface can be physical or virtual network cards and these files contain configuration information specifically for each individual network card. Meanwhile, the so-called Network Config File (/etc/sysconfig/network) contains settings for the network stack for the system itself.

The Network Config File in Oracle Linux (located at /etc/sysconfig/network) typically only contains three pieces of information for a basic networking config:

  • Networking
  • Hostname
  • Gateway

The Networking option tells the Linux OS whether networking is even enabled on the system. This option is configured with a Boolean value (yes or no). The hostname option is the hostname of that Linux machine. Finally, the gateway tells the system the default gateway to use for this machine.

A typical network config file might look like this:

NETWORKING=yes
HOSTNAME=iAmAWebServer.localdomain
GATEWAY=192.168.1.1

Other information, like static IP addresses, is assigned to the network interfaces themselves. Those config files, for each network interface, are stored in the /etc/sysconfig/network-scripts/ directory. If your network interface was called eth0, there would be a configuration file called “ifcfg-eth0” in that directory.

Oracle Linux Network Config Example

Though going into the details of the configuration files for network interfaces specifically is beyond the scope of this article, let's take a quick look at what a typical configuration file might look like so you can compare the difference between the configuration options for the network file versus the configuration options for network interfaces themselves:

DEVICE=eth0
NM_CONTROLLED=yes
ONBOOT=yes
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME=”System eth0″
UUID=5fb06bd0-0bb0-7ffb-45f1-d6edd65f3000
HWADDR=52:54:00:91:6a:C4
PEERROUTES=yes
IPADDR=192.168.1.5
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=192.168.1.1
USERCTL=no

Though the configuration above includes multiple settings, take note that we are assigning a static IP address to this network interface. If you wanted this network interface to use DHCP instead, you would simply remove the last five lines of that configuration.

Why don't Server and Cloud Versions of Linux Have GUIs?

Linux has been the backbone of the server world for decades now. It is an incredibly stable and highly configurable OS. That is why so many businesses use it for server operations.

One of the best parts of using Linux as a server OS is that you only need to install what you need to use. That means if you need a web server, you only need to install Apache or Nginx without tons of other services and features that you don't need. This includes graphical interfaces like Gnome or KDE.

It's common to not install a graphical interface in Linux while it is being used as a server because of the number of additional resources graphical interfaces require. Using a GUI like Gnome or KDE can easily double the memory requirements for a virtual machine running Linux and impose additional processor overhead.

In this case, when using Linux as a server, you will want to be comfortable with performing configurations and operations in the command line. Servers are commonly managed through SSH, otherwise remotely logging into the computer or virtual machine through a secure command-line environment. This includes configuring network settings.

Interfaces Config File in Debian

Debian is a very powerful distribution of Linux after Red Hat’s enterprise version, it might be the most popular. Its popularity is usually due to its stability, which is also why it’s often chosen as a server OS. Configuring networking services in Debian is different than in most distributions of Linux, however. The interfaces config file in Debian is how an administrator can make sure that all interfaces are configured properly and operational. Read on and learn more about the interfaces config file.

What is the Interfaces Config File?

The interfaces config file is also known as etc/network/interfaces.conf or interfaces conf. It’s the Debian network configuration file which holds configuration information for the various network interfaces in the computer.

Like all Linux OSes, Debian maintains configuration files for network interfaces installed on the computer. These network interfaces can be virtual devices, wireless devices, or wired NICs. Unlike other Linux distributions, in Debian, all of the network interface configuration data is stored within a single file. That configuration data, as well as the applications to start and stop the network interfaces in Debian, are stored in a single directory.

Where is the Interfaces Config File in Debian?

The interfaces config file is often referred to by its directory location: /etc/network. On your Debian OS, head to /etc/network/interfaces to find where the networking magic happens.

There aren’t a lot of files here: the network directory holds the network configuration options as well as the applications to control those network configurations. It only has a single configuration file and a couple of applications. It’s not much, but everything you need to configure the network interfaces in Debian is in the /etc/network/interfaces directory.

Network Interface Applications in etc-Networks Directory

The Interfaces configuration file isn't the only file in the /etc/networks directory, though. You'll also notice what are sometimes called the 'if' apps:

  • Ifup
  • Ifdown
  • Ifquery

The 'if' apps are applications that control network interfaces in a Debian computer system. Technically, all three apps are the same application. Each has a different name to tell the application what to do, though.

The ifup app brings up the network interfaces per their configurations in the interface configuration file. That is to say, the ifup app enables the network cards. The ifdown application does the opposite. It disables the network cards. The ifquery app parses the configuration information from the interfaces file.

All three apps have additional flags they accept as commands as well. For instance, if you want to force the ifup or ifdown command, use the –force flag along with them. For a full list of optional commands, take a look at the man page for each app.

When and Why to Configure the Interfaces Config File in Debian

If you need to make manual changes to how a network interface behaves, what protocols run on it, or whether it’s active at all, you can configure all those settings and more with the interfaces config file.

Configuring network interfaces in Debian tends to be simpler than other Linux Distributions. Though most distributions generally work similarly when it comes to controlling and configuring network interfaces, Debian's approach just makes it a touch more straightforward.

An Example of Configuring an Interfaces Config File

Let's look at an example configuration:

auto eth0
allow-hotplug eth1
iface eth0 inet dhcp
iface eth0 inet6 auto
iface eth1 inet static
        address 192.168.1.2/24
        gateway 192.168.1.1
iface eth1 inet6 static
        address fec0:0:0:1::2/64
        gateway fec0:0:0:1::1

The configuration file above holds the configuration for each network interface in the computer. In this case, there are two of them: eth0 and eth1.

Speaking very broadly, here’s what that configuration is doing:

Eth0 is set to turn on automatically when Debian starts up. It has a DHCP address. Eth1 is allowed to be hot-plugged. It has a static IPv4 and IPv6 address.

Each network interface in your computer must have an entry in this file to work with Debian.


Dhclient Config File

The dhclient config file is great because it makes extending and configuring DHCP on Linux possible. Dynamic Host Configuration Protocol, or DHCP, is one of the best tools administrators have access to. Without DHCP, IT admins would spend most of their days manually configuring IP addresses for networked devices.

DHCP is mostly configured behind the scenes, but there are times when administrators need to tweak DHCP settings a bit. When you’re working on Linux, you would make those tweaks in the Linux network configuration file called dhclient.conf. So, let's discuss how this file works and what you do with it.

What is the dhclient Config File?

The dhclient config file in Linux is also known as dhclient.conf or etc/dhclient conf. The dhclient conf is the Linux network configuration file for customizing and editing settings for Dynamic Host Configuration Protocol (DHCP) on a Linux network.

When a device attaches itself to the network either through a physical wired connection or WiFi, it starts broadcasting a signal into the network looking for a DHCP server. It’s sort of like playing Marco Polo with the DHCP server: the device yells, and then the DHCP server hollers back.

Once the client device and the DHCP server find each other, the client device sends a request for an IP address. The DHCP server responds with an IP address and how long that IP address is valid for.

Of course, it’s more complicated than that in execution. There are more steps involved with the DHCP handshake. The DHCP server requires certain criteria be met by the client before it hands out an IP address. Likewise, the client has requirements the DHCP server must meet. The dhclient.conf file is the Linux network configuration file that holds those requirements.

The dhclient.conf file holds the data for things like how long it should take for the DHCP server to respond, how long the client should wait before it starts sending out DHCP requests again, and information about the client like its broadcast address and hostname.

What is DHCP?

DHCP stands for dynamic host configuration protocol. It is the system in which clients request and are assigned an IP address. In most business networks, client devices need an IP address to communicate with the network properly. Each device must have its own IP address. Otherwise, when data is being sent through the network from one device or another, the network will have no idea which device to send that data to. If two devices share the same IP address, you might run into IP collision issues.

One way to handle this is to assign a static IP address to each device. That means administrators need to manually give each device its own unique IP address that never changes. This is appropriate for some devices, like servers, where an IP address needs to be predictable all the time. Other devices, like laptops or smartphones, don't need to be predictable. Plus, manually assigning IP addresses to each of these devices would be a pain.

That's why DHCP exists. DHCP automatically keeps track of and hands out IP addresses to devices when they attach to the network. By using a DHCP server, the act of managing IP addresses is an automatic process that doesn't need involvement from administrators.

You could think of DHCP like a waiter at a restaurant. The waiter assigns guests a table. Then, they take food orders (the data) from the guests to the kitchen (the network server). Once the food is ready, the waiter takes the food back to their guests because they know which table it needs to reach. Of course, most restaurants use hosts or hostesses, but in our example it’s the waiter who knows where to send their food. Likewise, if a computer doesn't have an IP address, other devices wouldn’t know where to send data for that device.

Where is the dhclient Config File?

If you need to edit the dhclient.conf file in Linux, first locate it in the file system. Most often, the dhclient.conf file will be located in the /etc or /etc/DHCP directory. Once you find the file, open it with your favorite command-line editor. Editing this file does require elevated privileges, so don't forget to do that with the SU or SUDO command before opening it.

How to Configure the dhclient Config File

To configure the dhclient config file, you’ll need to choose from the list of commands and settings whose specific configurations you can set. The dhclient.conf file typically only needs to be edited if you need additional settings or you need to increase or decrease the timeout time that the client device waits for while communicating with the DHCP server.

Here's a list of other settings as well:

Setting

Explanation

RetryHow long the DHCP client waits to retry the DHCP request. This value is an integer value in seconds.
Select-timeoutIn some cases, networks may have multiple DHCP servers. Some servers may be preferable over others. This setting controls how long the DHCP client waits for a lease time response from a DHCP server. This value is an integer value in seconds.
RebootThis setting instructs the DHCP client how long to wait to request an address after the client reboots. This value is an integer value in seconds.
Backoff-cutoffThis setting tells the DHCP client how long to wait for the cut-off time. This is useful in an environment where a lot of devices may be making DHCP requests at the same time. This value is an integer value in seconds.
Initial-intervalThis setting tells the client how long to wait before sending another request if it does not receive a DHCP response. This is different than the retry or other settings in that it's the amount of time to wait before sending a request and not how long it should listen for a response. This value is an integer value in seconds.

When to Configure the dhclient Config File

Actually, most of the time you won't need to configure the dhclient.conf file in Linux. Linux distributions, like Red Hat or Ubuntu, do a good job configuring this file for you. Those default communications are often good enough for most situations.

Take care when editing the dhclient.conf file, though. It might increase the amount of time a client device takes to start communicating with the network. In some cases, where a device is mission-critical, it might be preferable to tweak the dhclient.conf file to shorten the time to network communication.

An Example of Configuring dhclient conf

Here is what a default dhclient.conf file will look like in Ubuntu:

option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;
send host-name = gethostname();
request subnet-mask, broadcast-address, time-offset, routers,
        domain-name, domain-name-servers, domain-search, host-name,
        dhcp6.name-servers, dhcp.domain-search, dhcp6.fqdn, dhcp6.sntp-servers
        netbios-name-servers, netbios-scope, interface-mtu,
        rfc3442-classless-static-routes, ntp-servers;
#send dhcp-client-identifier 1:0:a0:24:ab:fb:9c;
#send dhcp-lease-time 3600;
#supersede domain-name "fugue.com home.vix.com";
#prepend domain-name-servers 127.0.0.1;
#require subnet-mask, domain-name-servers;
timeout 300;
#retry 60:
#reboot 10;
#select-timeout 5;
#initial-interval 2;
#script "/sbin/dhclient-script";
#media "-link0 -link1 -link2", "link0 link1";
#reject 192.33.137.209;
#alias {
#        interface "eth0";
#        fixed-address 192.5.5.213;
#        option subnet-mask 255.255.255.255;
#}
#lease {
#  interface "eth0";
#  fixed-address 192.33.137.200;
#  medium "link0 link1";
#  option host-name "andar.swiftmedia.com";
#  option subnet-mask 255.255.255.0;
#  option broadcast-address 192.33.137.255;
#  option routers 192.33.137.250;
#  option domain-name-servers 127.0.0.1;
#  renew 2 2000/1/12 00:00:01;
#  rebind 2 2000/1/12 00:00:01;
#  expire 2 2000/1/12 00:00:01;
#}

Notice the hashtag in front of each of the lines. Those are considered comments. Any line in the dhclient.conf file that is preceded by a hashtag will be ignored by Linux (more specifically, the DHCP software).

Often the timeout setting is the setting that most Linux administrators need to change. That setting controls how long the client device waits for responses.

Hosts Config File

In the real world, there are places we know by their specific address and places we know by their generalized names. For example, if you’re going to a friend’s house for the first time and they tell you their address is “123 Oak Street”, you know what street to go to, and which house on the street you’re looking for. But on the other hand, when you go to your favorite grocery store, you probably just say, “I’m going to the store.” Believe it or not, computers trying to find a place on a network have a similar process.

For computers and devices that run Linux, a network configuration file called hosts does the work of deciding if there’s a specific IP address associated with a named host. A hosts config file is a device’s internal config file for routing tables, and you can configure it to your heart’s content. Read on and learn how it works and how to configure it for yourself.

What is the Hosts Config File?

The hosts config file in Linux is also known as the etc/hosts.conf or hosts conf. The hosts config file is a plain-text network configuration file that works like a static, mini domain name system (DNS) for that device.

Hosts config files also exist on Windows and macOS. The fundamental purpose of the hosts config file is to map domain names or hostnames to IP addresses. Because computers check the hosts file for translation from URLs to IP addresses before contacting a DNS server, configuring the hosts conf can redirect traffic directed at certain places to preferred IP addresses or block websites from devices.

What is DNS?

Understanding how the hosts config file works requires an understanding of domain name service (DNS). DNS is an old system that’s been around since the early days of the internet. DNS hasn't evolved much, but it doesn't need to because it’s lightweight and stable.

DNS is like an address book for the internet. It matches hostnames with IP addresses. When you type www.Google.com into your address bar, that request ends up at a DNS system that translates that URL with the IP address for Google’s servers.

DNS isn't only used for websites, though. DNS can be used for any networking environment — most importantly private business networks. DNS is often used to translate server names with IP addresses. It can be combined with things like DHCP servers to allow more flexibility in an IT infrastructure.

For instance, you might have a network-attached storage (NAS) device in your home or business. Let's say this storage device is called SuperAwesomeLargeStorageDrive.com. Each computer in your home or business can use that URL to connect to it, but those computers need a way of knowing the IP address for that device. If you configured each device’s hosts config file, they could find that device without typing in a string of numbers that users might forget.

Where is the Hosts Config File?

The hosts config file is found in the /etc/hosts directory. It’s a very easy network configuration file to find — most administrators use it on a regular basis. Once you’ve navigated to /etc/ and found it, you can open the hosts config file with a text editor of your choice.

How to Configure the Hosts Config File

The structure of a hosts config file is simple. It only contains three entries per line:

  1. IP address
  2. Hostname
  3. Alias

A typical entry in a hosts file might look like this:

192.168.1.2        hostComputer.com         www.hostComputer.com

The first entry is always the IP address. The second entry is the hostname or URL for that IP address. The third entry is the alias. You may not need an alias depending on your configuration, but each entry must always have an IP address as well as the hostname.

Because the hosts file is like a mini DNS for your computer, it will have the same character restrictions as a typical IP address or URL. Each entry can only contain alpha-numeric characters, periods, and hyphens. Any other characters are considered illegal characters.

There’s one exception to that rule. If you use the hash sign (#) at the beginning of an entry in the hosts file, that marks that entry as a comment. Comments are ignored by the system, so you can use any characters after that hash sign for your comment.

It's important to note that if you make any changes to the hosts file, you must either restart the networking services in Linux or reboot the computer before those changes take effect.

When to Configure the Hosts Config File

Because hosts files are a mini DNS for the computer, you can use them for all sorts of things. For instance, if you want to access a specific IP address on your network, but don't want the hostname available for everyone to use, you can add an entry in the hosts file so only that computer can access the hostname of a computer.

Hosts files are commonly used for other things like ad-blocking as well. If you know the hostname of a popular ad network, you can add an entry to the hosts config file in your computer to match that hostname with your local loopback IP address (127.0.0.1). Since the computer looks at the hosts file before a DNS server, that ad network won't resolve, and thus, your computer won't receive ads from that ad network.

Example of a Linux Hosts File

# Next lines preferred for IPv4 capable hosts

127.0.0.1    localhost

# 127.0.1.1 should be the machine’s fully qualified domain name

127.0.1.1    thishost.thisdomain.org        presenthost
192.168.1.10  yak.thisdomain.org                yak
192.168.1.13  sha.thisdomain.org                sha
146.82.138.7  master.debian.org                top
209.237.226.90 www.opensource.org

# The following lines are desirable for IPv6 capable hosts

::1       localhost ip6-localhost ip6-loopback
ff02::1     ip6-allnodes
ff02::2     ip6-allrouters

Nsswitch (Name Service Switch) Config File

Imagine all the services you use in your normal, everyday life. You fill up your gas at a gas station, get groceries at the grocery store, mail packages at the post office, go to a doctor when you’re sick or the emergency room when you’re in a hurry, and much more. Now imagine trying to explain when to use each to an alien who’d never had to do any of those things. You might struggle to name and explain each one.

A computer can struggle with all the utilities, applications and processes it has too. Fortunately, the nsswitch config file helps a device find its apps and send data to each one. And when you want to edit the core behavior of your Linux operating system, you can manually configure your nsswitch config file.

What is the Nsswitch Config File?

The Nsswitch configuration file is also known as NSswitch, nsswitch conf and etc/nsswitch.conf. It stands for Name Service Switch. The Nsswitch configuration file tells applications where to look for data and also helps the data for a device’s apps get where it needs to go. But the nsswitch config file isn't only for networking and network-based apps, it’s for all Glibc-based applications in a Linux system.

If DNS and a networking switch had a baby, it would be the Nsswitch.conf file. The nsswitch configuration file is similar to DNS in that it provides address translation for file locations, and it’s similar to a networking switch in that it forwards information based on their destination addresses. The Name Switch Service configuration file provides that address translation and forwarding for application information.

DNS is like an address book for IP addresses. It matches hostnames or URLs with a specific IP address. Networking switches take network traffic and push it in the direction it wants to go. IP packets have no concept of direction or flow. The network switch listens to that IP packet and gives it a gentle nudge in the direction it needs to go in.

The nsswitch is sort of like that but for a bunch of different applications. For example, the Name Switch Service is what tells the networking stack in Linux to first look at the hosts file before DNS. It's the same service that tells the netmasks services to look at a configuration file before a NIS server, too. It's also the same file that tells the Linux passwd file to look at the configuration file before an LDAP server.

Note that not each use mentioned above is a networking service. For example, the Linux passwd application is used to both set and confirm passwords for user profiles. It’s not a networking service. The Nsswitch conf file deals with non-network applications. Essentially, the Nsswitch conf file is simple: it tells applications where to look for data.

Where is the Nsswitch Config File?

Like many network configuration files in the Linux operating system, the Nsswitch config file can be found in the /etc/ directory. The name server switch file’s exact location is /etc/nsswitch.conf. To open and edit the nsswitch config file, you’ll want to use a text editor of your choice.

How to Configure the Nsswitch Config File

Like most Linux configuration files, the Nsswitch.conf file is white space dependent. It's structured by rows and columns. Here's an example of a Nsswitch.conf file configuration:

Passd: files ldap
Hosts: dns nis files
Groups: files [SUCCESS=merge] ldap

That's all there is to the Nsswitch.conf file, though they typically have more entries. We left it simple in this example. So, let's explain how these entries work.

The first entry is the application or service. This is where the Nsswitch.conf is like DNS. It matches the application or service with the information it needs to use. All other entries after that application or service are the data stores for that application or service. Each datastore is an ordered list according to which should be used first.

In this case, the passwd application needs to look at its configuration files first. Should those configuration files not have the information it needs, it then moves on to an LDAP service. Once the application or service finds the data it needs, it stops looking. Otherwise, if the passwd application finds the information it needs in its configuration files, it doesn't also look at the LDAP service.

Of course, that imposes some limitations. Let's look at the “Groups” entry. What if you need user groups to consult both the local configuration files as well as an LDAP service? That's where that extra command “[SUCCESS=merge]” comes into play. That tells the Groups service that even if it finds the information that it needs in its configuration files, consult the LDAP service anyway and then merge the information found in both the configuration files and LDAP service.

Why Configure the Nsswitch Config File?

In most circumstances, you may never touch the Nsswitch.conf file. The Linux OS does a good job of configuring this file automatically. On a rare occasion, if you run into an issue, you may need to manually configure this file to add or change additional resources (data stores) for applications or services.


Resolv Config File

Like many things in Linux, there are tons of ways to configure the Linux OS to use different DNS systems. Though DNS is commonly configured through the networking services in most Linux distributions, another method to add DNS to your Linux system is by manually configuring the resolv conf file.

What is the Resolv Config File?

Resolv conf, also known as resolv.conf, is the name of the configuration file in Linux that acts as a resolver: a set of routines responsible for providing access to the Internet’s Domain Name System (DNS).

The resolv configuration file isn’t unique to Linux. It holds DNS information for most Unix and Linux-based operating systems. It's a hardcoded file that systems administrators can use to designate nameservers for that specific computer system.

The Linux OS is capable of resolving nameserver data in two ways. First, the OS can use nameserver information associated with its networking configuration. That network configuration information can change depending on which Linux OS is being used (e.g. Ubuntu uses Netplan, while REHL uses the interface configuration files). Second, the Linux OS can use the resolv.conf file to find nameserver data as well.

Where is the Resolv Config File?

Resolv.conf is a network configuration file and in Linux, those are generally stored in the /etc directory. If resolv conf is maintained manually, it can be found at /etc/resolv.conf. If DHCP is enabled and in use, the resolv configuration file can be found and updated with the resolvconf utility.

How to Configure the Resolv Config File

The resolv.conf file is easy to configure. Each line of the configuration file includes the nameserver itself with the IP address for that name server. The IP address must be a valid IPv4 or IPv6 address.

IPv4 addresses must be in dot notation, while IPv6 must use colon notation as designated by the RFC 2373 spec. There are a variety of options available for the resolv.conf file as well. Options should be included at the bottom of the configuration file, preceded by the keyword Options. Each option flag can then be listed in order and separated by a space.

The resolv.conf file can only have up to three nameservers listed in it. This value is set by the resolv.h header file in the C library. Nameservers are used in ascending order as listed in the resolv.conf file. So, Linux will look at the first entry, then the second entry, and so on. It will only move on to the next entry if the prior nameserver entry's IP address does not resolve.

An Example of Configuring a Resolv Config File

Your resolv.conf network configuration file isn’t a very complicated-looking one. Each entry in your resolv conf config file should look like this:

Domain my.salesdata.com
Search example.com exampleCompany.net
Nameserver 192.168.1.1
Nameserver 8.8.8.8
Nameserver 8.8.4.4

The search criteria is not always needed. It's used to tell the system where and how to search for DNS entries. By default, the search criteria can have up to six domain names listed. These domains are used in ascending order as listed as well. In the example above, the example.com domain would be used first.

The Domain criteria have been deprecated but may still be in use in some systems. The Search criteria now replaces the Domain criteria. The Domain criteria is still valid to use but can only have one domain listed after it.

When to Manually Configure Resolv Conf

Actually, most of the time you won’t need to. Although it's very useful to know what the resolv.conf file is and how it works, it's managed automatically in most Linux distributions. For example, both REHL and Ubuntu manage the resolv.conf file behind the scenes. Any changes made to the resolv conf configuration file would eventually be overwritten by the OS in the case of those distributions.

If you need to manually define DNS entries outside of using the networking services in those Linux distributions, you will need to consult the documentation for that specific distro to see how to add those changes.

Not only that, but a resolv.conf configuration file isn’t necessary for your Linux OS to work properly. If Linux doesn't find a resolv.conf file or finds a blank one, the OS automatically uses the DNS information for the local host. In most cases, this is the DNS configured with the networking services.


Sysctl Config File

The Linux operating system is incredibly versatile, but that can be a trade-off. The alternative to versatility is often brute strength. In other words, when you have different approaches to a problem, the versatile solution is often the more elegant or the most efficient, but it usually requires fine-tuned settings and configurations.

That’s certainly the case with the Linux operating system and the settings and configurations that guide it at start-up. What hardware will the OS be operating on, and what is it going to be used for? The sysctl conf config file is the configuration file that helps the Linux kernel answer questions like that. Administrators who understand the sysctl conf file can make their Linux-powered systems even more powerful with the right configuration.

What is the Sysctl Config File?

The Sysctl conf file, also known as etc/sysctl.conf, is a system settings and configuration file that instructs the Linux OS at startup. At startup, the Linux OS or the system manager (e.g. SystemD), adds or changes settings to the Linux kernel according to the sysctl conf file.

This is important because Linux is powered by the Linux kernel. The kernel is like the brain of the OS. It controls all of the underpinnings of Linux. The rest of the OS builds on top of the kernel through various applications like XWin, Cups, or Samba.

The Linux kernel is a dynamic thing that can be compiled to work with specific hardware like a smartphone. Or it can be an all-encompassing thing that accommodates many different PC configurations like with Ubuntu or Red Hat. Kernels can be configured with specific settings or a broad range of options. Things like drivers can be included directly in the kernel or as modules that can be added or removed at any time.

This malleability and versatility is why Linux is used for so many devices. The underlying OS can be highly customized for things like IoT devices or smartphones, or it can power laptops and computers.

But when you need to make changes to the underlying kernel, you have two options. The first is to recompile the kernel or update it from your distribution. Alternatively, you can use the sysctl.conf file to change specific settings for it.

How to Configure the Sysctl Config File

Fair warning: the detailed steps of configuring the sysctl conf file are too complicated and nuanced to cover in this post. There are too many permutations and diverse implementations to capture every use case of the sysctl conf file and explain how to configure them.

That said, the sysctl.conf file is easy to edit. It just requires a lot of work to configure. What we’ll explain here is how to edit the file, and what the file structure should look like. If you need information on how to add, remove or configure individual entries, your search isn’t over. You’ll have to research further on your own.

But editing the sysctl.conf file in Linux is straightforward enough. First, open the sysctl.conf file with your favorite text editor. When you open the sysctl.conf file, make sure to open and edit it

with elevated privileges as it’s a system-protected file.

sudo nano /etc/sysctl.conf

Once inside the sysctl.conf file, add any commands you may need. In this case, commands are a kernel setting followed by its value.

Linux ignores whitespace in the sysctl.conf file, so add any whitespace you might want for organization. Don't be afraid to make it pretty and readable.

Any lines that begin with a semicolon or pound/hash symbol are considered comments by Linux. Those lines are ignored:

# I am a comment, and I am ignored
; I am also a comment and am ignored

Lines that begin with a dash ( – ) will be ignored by Linux if they fail.

-IAmAnInvalidConfig = SoIWillFailAndBeIgnored

Each entry in the sysctl.conf file is a setting for the kernel and what its new value should be. So let's take a look at what a valid entry would look like:

Net.core.netdec_max_backlog = 16000
Net.core.somaxconn = 8192

The first command tells the network stack to increase the receive queue value. The second command tells the network stack to increase the maximum number of connections.

Where is the Sysctl Config File?

The first thing to know about searching for your sysctl conf file is that your Linux distribution might not have one. Also, it can go by other names and be stored in other directories.

Depending on your system and kernel, the sysctl.conf file might be called or located in the following locations:

  • /etc/sysctl.d/*.conf
  • /run/sysctl.d/*.conf
  • /usr/local/lib/sysctl.d/*.conf
  • /usr/lib/sysctl.d/*.conf
  • /lib/sysctl.d/*.conf
  • /etc/sysctl.conf

Generally, Linux will attempt to read those files in that order. The first time it finds a valid file with valid entries, it ignores the rest of the files with the same name in other directories. So, depending on what Linux distribution you are using, you may have to look in each of those directories for those specific files.

Likewise, some Linux distributions, like REHL, will use the sysctl.conf file as a symbolic link back to another one of those files. If you are missing the sysctl.conf file in the /etc directory altogether, it is safe to create it from scratch.

A Word of Warning About the Sysctl Config File

The etc/sysctl.conf is a potentially powerful tool to tinker with if you’re not sure what you’re doing. If you run the command “sysctl –system”, you can see what commands and files the OS tries to load and in what order. But beware of using this command. It’s not a dry-run command — that means it will actively load and run operations on your OS. And if you’re not sure it should do that, you could mis-configure your settings.

If you’re new to Linux and trying to figure out sysctl conf, your best bet might be the Linux Essentials course from CBT Nuggets.


Netplan: Configuration Files

One of the beautiful things about Linux is that you can manage operating system components however you see fit. Linux as envisioned by Linus Torvalds has an open philosophy. Linux OSes take advantage of this by implementing the tools and components that they think are best for their distributions. This includes things like networking management libraries and applications. In the case of Canonical, Ubuntu uses Netplan. Since few administrators have a lot of experience using and configuring it, let’s explore how to configure a static IP address in Ubuntu with Netplan.

What is Netplan?

Netplan is a configuration manager utility for managing networking functions within the Ubuntu OS. Canonical introduced Netplan with v18.04 of Ubuntu. Netplan doesn’t control networking functions, though, it simply helps configure them.

Where are the Netplan Config files?

Netplan stores configuration files for each network interface in your computer in the /etc/netplan directory within the Ubuntu directory structure. When the system boots, Netplan takes the information from its configuration files and creates scripts for the networking services. Those scripts are typically handed off to the networking Systemd service. If configuration changes are made to those interface configuration files, either the system itself or the network service needs to be restarted.

Each network interface has its own configuration files. Each configuration file begins with a two-digit numerical value followed by a standard string. The network configuration files are initialized and used in their numerical order. For example:

 01-network-manager-all.yaml

Only that two-digit numerical value changes. The rest of the configuration file name stays the same between each file. For example, if you had two network interfaces in your computer, you would see these two file names in the /etc/netplan directory:

01-network-manager-all.yaml
02-network-manager-all.yaml

Each configuration file is written in YAML.

How to Configure Netplan Config files

As we mentioned above, Netplan uses a different configuration file for each network interface in your computer. Before we begin editing those YAML configuration files for Netplan, we need to gather a bit of background information first. This is easy enough.

From a terminal or command-line environment, use the 'ip a' command. That command will return a list of the network interfaces in your system. You need to find the name of the network interface that you want to configure from this list:

1:  lo: <LOOPBACK ,UP ,LOWER_UP> mtu 65536  qdisc noqueue  state  UNKNOWN group default qlen 1000
        link/loopback  00:00:00:00:00:00  brd  00:00:00:00:00:00
        inet 127.0.0.1/8 scope host lo
                valid_lft  forever  preferred_lft  forever
        inet6  : : 1/128  scope  host
                valid_lft  forever  preferred_lft forever
2: enp1s0: <BROADCAST, MULTICAST ,UP , LOWER_UP>  mtu 1500 qdisc  fq_codel  state UP  group  default  qlen  1000
        link/ether   52:54:00:d4:5c:cb  brd  ff:ff:ff:ff:ff:ff
        inet  192.168.1 3/24  brd  192.168.1.255  scope global  noprefixroute enp1s0

Now that we have the name of our network interface, we can configure the configuration files for it. So, go ahead and open the network configuration file in the Netplan folder in Ubuntu with your favorite command-line text editor.

 Sudo nano /etc/netplan/01-network-manager-all.yaml

These configuration files require elevated privileges to edit and save. So make sure you use the Sudo command. Likewise, if you have multiple configuration files, make sure to choose the correct file. If your system is currently configured to use DHCP, the configuration files may not have the device ID listed in it yet, but we'll cover that more below.

How to Configure a Network Card to Use DHCP in Netplan

Let's go over how to configure DHCP for network interfaces first. Configuring DHCP is the easiest of the configuration options and only requires a few lines:

network:
 version: 2
 renderer: NetworkManager

Notice that the device name isn't listed here. That's because it is not needed. This configuration is generic and tells the network services to use DHCP for all network interfaces in the computer.

How to Configure a Network Card to Use a Static IP Address in Netplan

Configuring a static IP address in Ubuntu is easy, but it does require a few additional lines in the configuration files mentioned above. So go ahead and open the configuration file using the same command above:

Sudo nano /etc/netplan/01-network-manager-all.yaml
network:
  Version: 2
  Renderer: NetworkManager/ networkd
  ethernets:
    enp1s0:
     Dhcp4: no
     Addresses: 192.168.1.2/255.255.255.0
     Gateway: 192.168.1.1
     Nameservers:
       Addresses: [192.168.1.1, 8.8.8.8]

The 'enp1s0' is the device name of my network interface displayed in the screenshot above. That will need to match the device name for your network interface that you found using the 'ip a' command.

Next, we set the Dhcp4 setting to 'no' since we don't want to use DHCP.

In the 'Addresses' field, add the IP address you want to assign followed by its netmask. In most cases, this will be 255.255.255.0. If you are not sure of what the netmask should be and are in a business environment, consult with the network administrators for your organization.

Next, the Gateway entry should be the gateway address for your network. Since my VM is in a typical home environment at this time, it's the network address for my home router.

Finally, you need to configure the nameserver entries. The nameservers are your DNS endpoints. Each nameserver entry requires two addresses within the bracket notation above. In my case, I used the IP address for my router again. Likewise, I used Google's DNS address for my secondary DNS entry (8.8.8.8).

How to Save Configurations made in Netplan in Ubuntu

After you are done making changes to the Netplan configuration files in Ubuntu, we need to test them, apply them, and then restart the appropriate networking services for those changes to take effect. So, go ahead and save your configurations and close the command-line text editor. If you are using Nano, press control+X on your keyboard for that.

Next, once back inside of Bash, type 'Sudo netplan try'. That will test the configuration changes for Netplan. Once the settings are tested, you will be prompted to press enter to save them. If your configuration changes are invalid, they will automatically revert instead. If you do not confirm those changes by pressing Enter on your keyboard, they will also revert.

Once those changes are tested and saved, type 'Sudo netplan -d apply' in Bash to apply the changes you made.

One last step. You need to restart the network services for those changes to take effect.

If you are using the standard version of Ubuntu, use the 'sudo systemctl restart network-manager' command. If you are using the server version of Ubuntu, use the 'sudo systemctl restart system-networkd' command instead. Likewise, you can restart the computer system for those changes to take effect, too.

A Last Note for Configuring Network Interfaces in Ubuntu

If you’re using a version of Ubuntu with a graphical interface, any changes you make through that graphical interface will overwrite any changes you made to the Netplan configuration files via the command line. Likewise, those settings should reflect on that graphical interface, too.

The instructions above largely apply to the server version of Ubuntu. The server version does not include a GUI, so it is common to need to configure things like network settings through the command line.


Conclusion

Hopefully this explanation of nine Linux configuration and network configuration files has served to explain and contextualize how Linux manages its OS and network operations. We covered network-scripts, Oracle Linux network configurations, the interfaces config file in Debian, dhclient configuration, hosts file configuration, the nsswitch config file, the resolve.conf config file, sysctl.conf config file and Netplan.

The blessing and the curse of Linux is that there’s always more to learn. Whether you’re aiming for a certification or just an understanding of the technology, consider taking a CBT Nuggets course in Linux. Many of the topics we touched on in this post are covered in certifying exams, like the Linux Foundation Certified System Administrator (LFCS). It’s also gone into much deeper detail in the Everything Linux Training course. Whether you make your way to the courses or not, hopefully now you’re a little more comfortable configuring your Linux OS and network.

Download

Download

Ultimate Networking Cert Guide

A 97-page guide to every Cisco, Juniper, F5, and NetApp certification, and how they fit into your career.

By submitting this form you agree that you have read, understood, and are able to consent to our privacy policy.

LEARNING ON MOBILE

Learn anytime anywhere with our mobile apps.

I have read and understood the privacy policy and am able to consent to it.

© 2021 CBT Nuggets. All rights reserved. Terms | Privacy Policy | Accessibility | Sitemap | 1550 Valley River Drive, Eugene, OR 97401 | 541-284-5522
CBT Nuggets