Although there are a number of very powerful graphic configuration tools, there may be instances, such as bare bones, server-only installations, when an administrator will have to configure networking in Linux without the aid of a configuration utility.
When this type of setup is needed, it is necessary to know exactly what files to modify and how to modify them. In this Daily Feature, I am going to show you what files to edit to configure Linux networking manually.
The first thing you need to do is configure the proper module for the server’s NIC. To find out what module a specific NIC is using, log on as root and run the /sbin/lsmod command. In the output for this command, you should see a listing similar to:
3c59x 26504 1
This listing will depend upon the card being used. In the example above, the 3c59x is the module being used by the server’s NIC. Now that the NIC’s module is known, open up the file /etc/modules.conf and check to see that there is a corresponding entry for the NIC module. If not, then you will have to enter a line similar to:
alias eth0 3c59x
The above entry assumes that you are using a card compatible with a 3Com 59x card and that it is attached to eth0. (These configurations will depend upon the individual setup.)
Be good hosts
The next step is to configure the hosts file. This file resides in the /etc directory and will contain the localhost entry (a special entry that must be present) and administrator-configured entries. Each entry will take on this form:
IP address Fully Qualified Domain Name (FDQN) alias
The hosts file will look like:
127.0.0.1 localhost.localdomain localhost
192.168.1.2 nickel.nater.org nickel
Notice that both the entries in the above file are private IP addresses. The /etc/hosts file can contain public IP addresses as well. This file is also not limited to two entries. The /etc/hosts file can act as a very simple DNS table, so an unlimited amount of entries can be entered.
Next, the primary (and secondary, if available) DNS server(s) must be configured. This configuration is taken care of in the /etc/resolve.conf file. This file takes on the form of:
In the above entry, the domain is nater.org and the primary and secondary DNS servers are listed. The third entry is present in case either the first or second nameserver cannot be found. If neither nameserver is found, bind (the system handling DNS on a Linux server) will search the entire domain (in this case, nater.org) for a nameserver.
Getting to the heart of the network configuration
There are only two files left to configure. The first is the network script located in /etc/sysconfig/. This configuration file dictates whether networking will be used and what the hostname will be. The network file takes on the form of:
Last, but not least
The final file to configure is /etc/sysconfig/network-scripts/ifcfg-eth# (where # is the numerical name of the device used for networking). Configurations in this particular file determine which device will be used for networking, which protocol will be used (manual, dhcp, and so on), whether the device will be started at boot, the IP address, the gateway address, the netmask, and, if needed, a number of IPX configurations.
The format of this file looks like:
The above information is relatively self-explanatory. The most important thing to remember is to keep everything consistent.
Rev it up
With all the configurations in place, it’s time to fire up the server. Run the command /etc/rc.d/init.d/network start and, if everything is configured correctly, the OKs will fly by and networking will be up and running. To test networking, run a simple ping command such as ping www.techrepublic.com.
If networking fails to work, then there are a couple of quick troubleshooting tips you can try. The first thing to check is the firewall. If the server is using ipchains, run the command /sbin/ipchains -F and then rerun the ping command. If this doesn’t work, run the command /sbin/ipchains -L and make sure that the input policy isn’t set to DENY. If the input policy is set to DENY, run the command /sbin/ipchains -P input ACCEPT and then rerun the ping command. If the server is running iptables instead of ipchains, substitute iptables wherever you see ipchains above.
If neither of the above commands fix networking, the most obvious place to check (outside of making sure the network, as a whole, is actually up and running) is the NIC module. Make sure the correct module is loaded into the kernel with the /sbin/lsmod command. If the correct module is not loaded, then the server has no way of knowing where and how to throw packets out to the world. If the correct module isn’t listed, revisit the first section (NIC modules) and rerun that process.
If all else fails
As a last resort, it is possible to shut down the server, remove the NIC, restart the server (letting the machine detect the removal of the hardware), shut the server down again, reinstall the NIC, reboot the NIC, and configure the NIC when/if prompted. Even if the system does not prompt you to configure the NIC, it should at least detect the installed NIC and load the correct module.