5.4 Configuring Interfaces and the Host-to-Network Layer

5.4 Configuring Interfaces and the Host-to-Network Layer

On a Linux system, you connect the Internet layer to the physical medium, such as an Ethernet network or a modem-based connection, with a network interface. Common network interface names are eth0 (the first Ethernet card in the computer) and ppp0 (a PPP interface).

The most important command for viewing or manually configuring the network interface settings is ifconfig. To see your current interface's settings, run this command:

ifconfig -a

You do not need the -a in Linux, but other Unix variants require this option. The output should look something like this:

eth0      Link encap:Ethernet HWaddr 00:40:05:A0:7F:96
          inet addr: Bcast: Mask:
          RX packets:806961 errors:1 dropped:0 overruns:0 frame:0
          TX packets:811658 errors:0 dropped:0 overruns:0 carrier:0
          RX bytes:726765161 (693.0 Mb) TX bytes:110229902 (105.1 Mb)

lo        Link encap:Local Loopback
          inet addr: Mask:
          UP LOOPBACK RUNNING MTU:16436 Metric:1
          RX packets:44 errors:0 dropped:0 overruns:0 frame:0
          TX packets:44 errors:0 dropped:0 overruns:0 carrier:0
          RX bytes:3569 (3.4 Kb) TX bytes:3569 (3.4 Kb)

The left side contains interface names, and the right side contains the settings for each interface. You can see that each interface has an IP address (inet addr) and a subnet mask (Mask), but you should also take careful note of the lines containing UP and RUNNING, because these tell you that the interface is working.

The lo interface is a virtual network interface that is called the loopback because it "loops back" to itself. is the IP address of localhost, so connecting to this address is the same as connecting to the machine that you're currently using.

Your system calls ifconfig from one of its init.d scripts at boot time to configure the lo loopback interface. It's the only part of the network that is actually the same on any Linux machine, so it's a great place to start when you're trying to figure out how your particular distribution sets up networks. For example, in Red Hat Linux, each network interface has a script in /etc/sysconfig/network-scripts. You should be able to find the loopback device configuration by digging around in /etc with grep ifconfig.

If you have a static IP address on an Ethernet interface, your system's boot sequence should set up the interface in a manner very similar to the loopback. However, you can manually configure an IP address and netmask for an Ethernet network interface named eth0 with this command:

ifconfig eth0 address netmask mask

The preceding command allows your machine to talk to every other host in the subnet defined by address and mask, but it does not let you go beyond the subnet, because you have not supplied a default gateway (gateways will be explained in the next section).

If you do not connect your system to the network with a static IP address on an Ethernet network, but rather, have a link such as a PPP or PPP-over-Ethernet (PPPoE) DSL connection, or if you use DHCP to get host information, you do not configure your interface with ifconfig (see Sections 5.7, 5.8, and 5.9 for those cases). However, even with those other types of connections, ifconfig -a is very useful for debugging.