Network Configuration Files
An overview of Linux's network configuration files
Network configuration Files
There are many files under Linux where you can configure - define your Linux network. Below are some of the main files that you will come across as an administrator of a Linux system.
This file is used for configuring the DNS (Domain Name System) resolver library.The resolv.conf configuration file contains information parameters used by the DNS resolver. The DNS resolver allows for the operating system to translate domain names into IP addresses. The process is known as resolving. The path for this file is "/etc/resolv.conf"
Normally a resolv.conf file will contain a search order of domains which is used for fully qualified domain name completion when no domain suffix is used in a query. You will also find a list of name servers that will be used for DNS lookup. Normally there will be at least two nameservers supplied, one for primary and a secondary for redundancy.
Example of a resolv.conf configuration file:
#/etc/resolv.conf search mydomain.com mydomain.net nameserver 188.8.131.52 nameserver 184.108.40.206
The search list is normally determined from the local domain name. By default it only contains the local domain name. To change this you can pass the desired name search path after the search keyword. Currently a maximum of six domains may be listed.
A nameserver is specified by its IP address. If there is more than one entry for the parameter nameserver, then the resolver library will query these in the order found. Currently a maximum of three server may be specified.
The hosts file is a static lookup table for the mapping of hostnames to ip addresses. It is possible to configure your system to first look at the entries in the hosts file before consulting DNS. This preference is configured by a file located at "/etc/nsswitch.conf". Normally DNS is consulted first on most systems.
The format of the hosts file is:
IP-Address Full-Qualified-Hostname Short-Hostname
The fields within this file are separated by tabs or blanks. The hostname field may only contain alpha numeric characters, minus signs "-" and periods ".". The short-hostname or alias name is used for a shortened name or nickname.
Example of a hosts file:
127.0.0.1 localhost 192.168.1.10 foo.mydomain.org foo 192.168.1.13 bar.mydomain.org bar 220.127.116.11 master.debian.org master 18.104.22.168 www.opensource.org
Hostname is a program that is used to set or display the current hostname. The hostname file is generally read once at system boot time. If the hostname routine is executed with no arguments, then the current hostname is displayed. You may pass any of the options below to the "hostname" :
[root@centos ~]# hostname centos
Below are some of the available options that can be passed to the hostname command:
OPTIONS -a, --alias Display the alias name of the host (if used). -d, --domain Display the name of the DNS domain. Don't use the command domainname to get the DNS domain name because it will show the NIS domain name and not the DNS domain name. Use dnsdomainname instead. -F, --file filename Read the host name from the specified file. Comments (lines starting with a `#') are ignored. -f, --fqdn, --long Display the FQDN (Fully Qualified Domain Name). A FQDN consists of a short host name and the DNS domain name. Unless you are using bind or NIS for host lookups you can change the FQDN and the DNS domain name (which is part of the FQDN) in the /etc/hosts file. -h, --help Print a usage message and exit. -i, --ip-address Display the IP address(es) of the host. -n, --node Display the DECnet node name. If a parameter is given (or --file name ) the root can also set a new node name. -s, --short Display the short host name. This is the host name cut at the first dot. -V, --version Print version information on standard output and exit success- fully. -v, --verbose Be verbose and tell what's going on.
The "/etc/nsswitch.conf" file contains your settings as to how various system lookup are carried out. Here you can configure your system to use the "/etc/hosts", "/etc/passwd" files locally or use a "NIS" server or "DNS". One of the main functions of the "nsswitch.conf is to control how your network is resolved. In the examples below taken from an Ubuntu 12.04 system and a CentOS system, we can see that "files" is specified first in the search order. This means that the hosts file is looked at first before going to a nameserver. In most cases the "nsswitch.conf" file supersedes the "/etc/host.conf" file. (see below)
Ubuntu 12.04 LTS
# /etc/nsswitch.conf # # Example configuration of GNU Name Service Switch functionality. # If you have the `glibc-doc-reference' and `info' packages installed, try: # `info libc "Name Service Switch"' for information about this file. passwd: compat group: compat shadow: compat hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4 networks: files protocols: db files services: db files ethers: db files rpc: db files netgroup: nis
hosts: files dns
As we mentioned earlier, this file is superseded by the "/etc/nsswitch.conf" file. The example below is taken from a Ubuntu 12.04 installation.
order hosts,bind multi on
In the above example, resolver checks the hosts file first then DNS. The entry "multi on" indicates that multiple ip addresses can be used.
This file is used to describe networks. Each valid entry should end with a "0".
[root@centos ~]# cat /etc/networks default 0.0.0.0 loopback 127.0.0.0 link-local 169.254.0.0