10.2. Network configuration and information

10.2.1. Configuration of network interfaces

All the big, userfriendly Linux distributions come with various graphical tools, allowing for easy setup of the computer in a local network, for connecting it to an Internet Service Provider or for wireless access. These tools can be started up from the command line or from a menu:

Your system documentation provides plenty of advice and information about availability and use of tools.

Information that you will need to provide:

10.2.2. Network configuration files

The graphical helper tools edit a specific set of network configuration files, using a couple of basic commands. The exact names of the configuration files and their location in the file system is largely dependent on your Linux distribution and version. However, a couple of network configuration files are common on all UNIX systems: /etc/hosts

The /etc/hosts file always contains the localhost IP address,, which is used for interprocess communication. Never remove this line! Sometimes contains addresses of additional hosts, which can be contacted without using an external naming service such as DNS (the Domain Name Server).

A sample hosts file for a small home network:

# Do not remove the following line, or various programs
# that require network functionality will fail.       localhost.localdomain   localhost	tux.mylan.com		tux	winxp.mylan.com		winxp

Read more in man hosts. /etc/resolv.conf

The /etc/resolv.conf file configures access to a DNS server, see Section 10.3.7. This file contains your domain name and the name server(s) to contact:

search mylan.com

Read more in the resolv.conf man page. /etc/nsswitch.conf

The /etc/nsswitch.conf file defines the order in which to contact different name services. For Internet use, it is important that dns shows up in the "hosts" line:

[bob@tux ~] grep hosts /etc/nsswitch.conf
hosts:	files dns

This instructs your computer to look up hostnames and IP addresses first in the /etc/hosts file, and to contact the DNS server if a given host does not occur in the local hosts file. Other possible name services to contact are LDAP, NIS and NIS+.

More in man nsswitch.conf.

10.2.3. Network configuration commands The ip command

The distribution-specific scripts and graphical tools are front-ends to ip (or ifconfig and route on older systems) to display and configure the kernel's networking configuration.

The ip command is used for assigning IP addresses to interfaces, for setting up routes to the Internet and to other networks, for displaying TCP/IP configurations etcetera.

The following commands show IP address and routing information:

benny@home benny> ip addr show
1: lo: <LOOPBACK,UP> mtu 16436 qdisc noqueue 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet brd scope host lo
    inet6 ::1/128 scope host 
2: eth0: <BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast qlen 100
    link/ether 00:50:bf:7e:54:9a brd ff:ff:ff:ff:ff:ff
    inet brd scope global eth0
    inet6 fe80::250:bfff:fe7e:549a/10 scope link 

benny@home benny> ip route show dev eth0  scope link dev lo  scope link 
default via dev eth0 

Things to note:

  • two network interfaces, even on a system that has only one network interface card: "lo" is the local loop, used for internal network communication; "eth0" is a common name for a real interface. Do not ever change the local loop configuration, or your machine will start mallfunctioning! Wireless interfaces are usually defined as "wlan0"; modem interfaces as "ppp0", but there might be other names as well.

  • IP addresses, marked with "inet": the local loop always has, the physical interface can have any other combination.

  • The hardware address of your interface, which might be required as part of the authentication procedure to connect to a network, is marked with "ether". The local loop has 6 pairs of all zeros, the physical loop has 6 pairs of hexadecimal characters, of which the first 3 pairs are vendor-specific. The ifconfig command

While ip is the most novel way to configure a Linux system, ifconfig is still very popular. Use it without option for displaying network interface information:

els@asus:~$ /sbin/ifconfig
eth0      Link encap:Ethernet  HWaddr 00:50:70:31:2C:14
          inet addr:  Bcast:  Mask:
          inet6 addr: fe80::250:70ff:fe31:2c14/64 Scope:Link
          RX packets:31977764 errors:0 dropped:0 overruns:0 frame:0
          TX packets:51896866 errors:0 dropped:0 overruns:0 carrier:0
          collisions:802207 txqueuelen:1000
          RX bytes:2806974916 (2.6 GiB)  TX bytes:2874632613 (2.6 GiB)
          Interrupt:11 Base address:0xec00
										lo        Link encap:Local Loopback
	  inet addr:  Mask:
	  inet6 addr: ::1/128 Scope:Host
	  UP LOOPBACK RUNNING  MTU:16436  Metric:1
	  RX packets:765762 errors:0 dropped:0 overruns:0 frame:0
	  TX packets:765762 errors:0 dropped:0 overruns:0 carrier:0
	  collisions:0 txqueuelen:0
	  RX bytes:624214573 (595.2 MiB)  TX bytes:624214573 (595.2 MiB)

Here, too, we note the most important aspects of the interface configuration:

  • The IP address is marked with "inet addr".

  • The hardware address follows the "HWaddr" tag.

Both ifconfig and ip display more detailed configuration information and a number of statistics about each interface and, maybe most important, whether it is "UP" and "RUNNING". PCMCIA commands

On your laptop which you usually connect to the company network using the onboard Ethernet connection, but which you are now to configure for dial-in at home or in a hotel, you might need to activate the PCMCIA card. This is done using the cardctl control utility, or the pccardctl on newer distributions.

A usage example:

cardctl insert

Now the card can be configured, either using the graphical or the command line interface. Prior to taking the card out, use this command:

cardctl eject

However, a good distribution should provide PCMCIA support in the network configuration tools, preventing users from having to execute PCMCIA commands manually. More information

Further discussion of network configuration is out of the scope of this document. Your primary source for extra information is the man pages for the services you want to set up. Additional reading:

  • The Modem-HOWTO: Help with selecting, connecting, configuring, trouble-shooting, and understanding analog modems for a PC.

  • LDP HOWTO Index, section 4.4: categorized list of HOWTOs about general networking, protocols, dial-up, DNS, VPNs, bridging, routinfg, security and more.

  • Most systems have a version of the ip-cref file (locate it using the locate command); the PS format of this file is viewable with for instance gv.

10.2.4. Network interface names

On a Linux machine, the device name lo or the local loop is linked with the internal address. The computer will have a hard time making your applications work if this device is not present; it is always there, even on computers which are not networked.

The first ethernet device, eth0 in the case of a standard network interface card, points to your local LAN IP address. Normal client machines only have one network interface card. Routers, connecting networks together, have one network device for each network they serve.

If you use a modem to connect to the Internet, your network device will probably be named ppp0.

There are many more names, for instance for Virtual Private Network interfaces (VPNs), and multiple interfaces can be active simultaneously, so that the output of the ifconfig or ip commands might become quite extensive when no options are used. Even multiple interfaces of the same type can be active. In that case, they are numbered sequentially: the first will get the number 0, the second will get a suffix of 1, the third will get 2, and so on. This is the case on many application servers, on machines which have a failover configuration, on routers, firewalls and many more.

10.2.5. Checking the host configuration with netstat

Apart from the ip command for displaying the network configuration, there's the common netstat command which has a lot of options and is generally useful on any UNIX system.

Routing information can be displayed with the -nr option to the netstat command:

bob:~> netstat -nr
Kernel IP routing table
Destination  Gateway      Genmask       Flags MSS Window irtt Iface U      40 0         0 eth0     U      40 0         0 lo       UG     40 0         0 eth0

This is a typical client machine in an IP network. It only has one network device, eth0. The lo interface is the local loop.

NoteThe modern way

The novel way to get this info from your system is by using the ip command:

ip route show

When this machine tries to contact a host that is on another network than its own, indicated by the line starting with, it will send the connection requests to the machine (router) with IP address, and it will use its primary interface, eth0, to do this.

Hosts that are on the same network, the line starting with, will also be contacted through the primary network interface, but no router is necessary, the data are just put on the network.

Machines can have much more complicated routing tables than this one, with lots of different "Destination-Gateway" pairs to connect to different networks. If you have the occasion to connect to an application server, for instance at work, it is most educating to check the routing information.

10.2.6. Other hosts

An impressive amount of tools is focused on network management and remote administration of Linux machines. Your local Linux software mirror will offer plenty of those. It would lead us too far to discuss them in this document, so please refer to the program-specific documentation.

We will only discuss some common UNIX/Linux text tools in this section. The host command

To display information on hosts or domains, use the host command:

[emmy@pc10 emmy]$ host www.eunet.be
www.eunet.be. has address

[emmy@pc10 emmy]$ host -t any eunet.be
eunet.be. SOA dns.eunet.be. hostmaster.Belgium.EU.net. 
  2002021300 28800 7200 604800 86400
eunet.be. mail is handled by 50 pophost.eunet.be.
eunet.be. name server ns.EU.net.
eunet.be. name server dns.eunet.be.

Similar information can be displayed using the dig command, which gives additional information about how records are stored in the name server. The ping command

To check if a host is alive, use ping. If your system is configured to send more than one packet, interrupt ping with the Ctrl+C key combination:

[emmy@pc10 emmy]$ ping a.host.be 
PING a.host.be ( from 56(84) bytes of data.
64 bytes from a.host.be( ttl=244 time=99.977msec
--- a.host.be ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max/mdev = 99.977/99.977/99.977/0.000 ms The traceroute command

To check the route that packets follow to a network host, use the traceroute command:

[emmy@pc10 emmy]$ /usr/sbin/traceroute www.eunet.be
traceroute to www.eunet.be(,30 hops max,38b packets
1 blob (  
       0.297ms  0.257ms  0.174ms
2 adsl-65.myprovider.be ( 
       12.120ms 13.058ms 13.009ms
3 (  
       13.845ms 14.308ms 12.756ms
4 gigabitethernet2-2.intl2.gam.brussels.skynet.be (
       13.123ms 13.164ms 12.527ms
5 pecbru2.car.belbone.be ( 
       16.336ms 13.889ms 13.028ms
6 ser-2-1-110-ias-be-vil-ar01.kpnbelgium.be (
       14.602ms 15.546ms 15.959ms
7 unknown-195-207-939.eunet.be ( 
       16.514ms 17.661ms 18.889ms
8 S0-1-0.Leuven.Belgium.EU.net ( 
       22.714ms 19.193ms 18.432ms
9 dukat.Belgium.EU.net ( 22.758ms * 25.263ms

On some systems, traceroute has been renamed to tracepath. The whois command

Specific domain name information can be queried using the whois command, as is explained by many whois servers, like the one below:

[emmy@pc10 emmy]$ whois cnn.com

Whois Server Version 1.3

	$<--snap server message-->

   Domain Name: CNN.COM
   Whois Server: whois.networksolutions.com
   Referral URL: http://www.networksolutions.com
   Name Server: TWDNS-01.NS.AOL.COM
   Name Server: TWDNS-02.NS.AOL.COM
   Name Server: TWDNS-03.NS.AOL.COM
   Name Server: TWDNS-04.NS.AOL.COM
   Updated Date: 12-mar-2002
>>> Last update of whois database: Fri, 5 Apr 2002 05:04:55 EST <<<

The Registry database contains ONLY .COM, .NET, .ORG, .EDU domains
and Registrars.


        $<--snap server message-->

Turner Broadcasting (CNN-DOM)
   1 CNN Center
   Atlanta, GA 30303

   Domain Name: CNN.COM

   Administrative Contact:
        $<--snap contactinfo-->   
   Technical Contact:
        $<--snap contactinfo-->   
   Billing Contact:
	$<--snap contactinfo-->
   Record last updated on 12-Mar-2002.
   Record expires on 23-Sep-2009.
   Record created on 22-Sep-1993.
   Database last updated on 4-Apr-2002 20:10:00 EST.

   Domain servers in listed order:


For other domain names than .com, .net, .org and .edu, you might need to specify the whois server, such as this one for .be domains:

whois domain.be@whois.dns.be