network-configuration-files

Services in Linux are managed through the several configuration files. In this article we will walk through the network configuration files.
This article is the part of article series. Previous articles of this series.
IP address
How to assign IP address in Linux
Networking tools
From previous articles you have learned the basic of IP address and their associated commands. In this article we addressing associated configuration files.
This article is written for RHCE exam prospective so we are including simplified configuration files.
These configuration files determine whether networking is started during the system boot process or not. Check these files when you have trouble with network configuration in Exam.
  • /etc/init.d/network
  • /etc/sysconfig/network
  • /etc/sysconfig/network-scripts
  • /etc/sysconfig/network-scripts/ifcfg-eth0
  • /etc/nsswitch.conf
  • /etc/hosts
  • /etc/resolv.conf

/etc/init.d/network

/etc/init.d directory store script files. You can run the scripts directly, or use the service command to start/stop. We will demonstrate both.
Sometimes by mistake you may deactivate the network interface. Or there is an unknown error in configuration. In trouble this should be first point to check.
Execute script directly
#/etc/init.d/network status
network-status
Use service command to execute script
#service network status
service-network-status
Output will be same in both case it should list configured and active devices. Output will give you a clue for future steps. If a main device such as eth0 is not listed as active, that explains why the network seems to be down. Try to restart the network service.
#service network restart
service-network-restart
Any change made in IP configuration will not take place until you restart the network interface. This script will restart the network interface.
#/etc/init.d/network restart
network-restart
If a restart of networking services does not solve the issue move to the next steps. Next step is to get into the configuration files.

/etc/sysconfig/network

This file contains global configuration settings.
etc-sysconfig-network
This file specifies routing and host information for all network interfaces. 
It is used to contain directives which are to have global effect and not to be interface specific.
Directive that you should check here for is NETWORKING=[yes][no].
If directive NETWORKING is set to no then the /etc/init.d/network script doesn’t activate any network devices. It must be set to yes in order to start networking.
Directive HOSTNAME controls computer name. If you want to change computer name, change it here.
If networking still not start check the status of networking service.
If the settings next to runlevels 3 and 5 are off, that’s a problem.
chkconfig-list
To make sure a service is active in appropriate runlevels, run the chkconfig network on command.
chkconfig-network-on

/etc/sysconfig/network-scripts

/etc/sysconfig/network-scripts directory contain executable files based on a series of text commands. These executable files are actually scripts based on the ifup and ifdown commands customized for the network device type.
ls-network-scripts
service network restart command may return with error like it in above example for eth0. In such a situation you should try to reactivate particular network device with ifup or ifdown command.
ifup-ifdown

/etc/sysconfig/network-scripts/ifcfg-eth0

This file contain configuration for eth0 first network adaptor. What you see in the ifcfg-eth0 file depends on how that first Ethernet network adapter was configured.
ifcfg-eth0

For exam you should understand following directive

DEVICEType of device. for example lo=loopback adaptor, eth0= first Ethernet, eth1 second Ethernet etc.
IPADDRStatic IP Address
NETMASKNetwork mask or subnet mask
NETWORKNetwork ID or network address
BROADCASTBroadcast address
GATEWAYIP address of the default gateway
ONBOOTspecify whether the device is activated during the boot process
NAMEcommon name for the device
HWADDRhardware address of network interface also known as MAC address
NM_CONTROLLEDSpecify that network card should be controlled by the Network Manager service or not. If it is set to yes be sure that Network Manager running
BOOTPROTOHow IP address would be configured. dhcp for dynamic configuration, static for static ip configuration

/etc/nsswitch.conf

This file includes database search entries. It include from authentication to name services.
nsswitch
It includes the following entry which determines what database is search first.
nsswitch1
When a system gets a request to search for a hostname, the preceding directive means the /etc/hosts file is searched first.
If that name is not found in /etc/hosts, the next step is to search available configured DNS servers, normally using that configured in the /etc/resolv.conf file.

/etc/hosts

This file is used to resolve hostnames that cannot be resolved any other way. It can also be used to resolve hostnames on small networks with no DNS server.
This file by default contains a line specifying the IP address of the loopback device (127.0.0.1) as localhost.localdomain.
etc-hosts

/etc/resolv.conf

This file specifies the IP addresses of DNS servers and the search domain. Unless configured to do otherwise, the network initialization scripts populate this file.
etc-reslov
These are the files which you need to be familiar with. So go through these files again and again until you feel comfortable.