6. ifconfig route lo eth0 ppp0 sl0

The TCP/IP core, talks to real and virtual devices, to send and receive packets. TCP/IP doesn't KNOW you have an ethernet card, you have to tell it. Each device has to be configured with it's IP address.

Every TCP/IP machine MUST have the loopback device configured, and it is always Never-the-less, you have to configure it, just like any other TCP/IP device. This is done in /etc/rc.d/rc.inet1 (or other!).

6.1 interface names
6.2 ethernet card devices
6.3 different ethernet card devices
6.4 ppp0, sl0 and /dev/modem
6.5 ifconfig and route
6.6 the loopback device
6.7 the ethernet device
6.8 the SECOND ethernet device
6.9 /etc/rc.d/rc.inet1
6.10 default route
6.11 scripts for the PPP device (or DIP)
6.12 What didn't happen ...
6.13 ifconfig
6.14 route


interface names

NOTE: eth0 and /dev/eth0 are completely different, but get linked together to be the working device! eth0 is the TCP/IP interface channel, it talks TCP/IP. /dev/eth0 is the card hardware. It talks IRQ, DMA and packets. /dev/eth0 can be accessed by programs, "eth0" can only be accessed from within the kernel.

lo is a special interface, that doesn't have any hardware. Any IP packet ("datagram") written out to lo, re-appears as a packet-in.


ethernet card devices

/dev/eth0 is the device driver's filesystem node, that holds the kernel major and minor device numbers. They correspond to the kernel driver code (probably packaged as a module) which can do occasional tasks like initialising the card, and regular tasks like transmitting and receiving packets.

Ethernet is a protocol beneath the TCP/IP protocol (but has evolved with it). It uses ethernet addresses, not IP addresses, hence the card has two addresses: the hardware address which is stored on a PROM on the card, and an IP address that comes from the command line.

The ethernet card, automatically filters out traffic that this host is interested in receiving. This reduces CPU load, because the machine never sees packets that would get ignored anyway.

If you switch the card into "promiscuous" mode, every packet on the LAN gets through the hardware filter. That is how LAN sniffers work. Also some packets are "broadcast" to every other card on the LAN, using the broadcast address, and kernel gets interrupted by every such packet.

You can also make the card behave as though it has several hardware addresses, when the PC looks like several PC's

But now that you know that, you can forget it! Thanks to careful design of the various standards and components, it just happens!


different ethernet card devices

All ethernet cards are much the same, and /dev/eth0 is a common denominator. However NE2000 cards are different from 3COM cards, and Western Digital cards (etc).

The kernel driver that is relevent to you, is selected by you in /etc/conf.modules (or is groped by the kernel at boot time). The driver/module that sucessfully detects it own hardware, installs itself as the /dev/eth0 device. If you have a second cards, you configure it in conf.modules to be /dev/eth1 (etc).

All ethernet cards send and receive complete (checksummed) packets, with typically upto 1500 bytes of data. HINT: for efficiency, write your application to use 1024 bytes of data, then allow yourself to add a few bytes for your own data headers.

NOTE: If your etherenet card driver is a module, you must start /sbin/kerneld before it is needed, ie in /etc/rc.d/rc.S and NOT /etc/rc.d/rc.local which is called after /etc/rc.d/rc.inet1

Redhat users should look in /etc/sysconfig/network-scripts for their ifcfg-eth0 parameters (like rc.inet1).


ppp0, sl0 and /dev/modem

/dev/modem is probably a link to /dev/cua2 or /dev/ttyS2, the serial port. It understands single bytes coming in and out.

IP (and hence TCP/IP), prefers to communicate in complete packets, not bytes, so the SLIP protocol, and sl0 device, converts between the two. sl0 allows for long delays between bytes, and other serial behavior that TCP/IP doesn't want to know about. ppp0 is an IP device just like sl0

PPP uses a form of SLIP, and does the same bytes to packets handling, but it also adds line controls, and session negociation.

When you establish a SLIP connection, on /dev/modem, you run an ioctl() system call, which "converts" a serial line into an IP interface. PPP is a protocol above SLIP, which does lots of extra things, but is basically the same. For the curious:

.. extract from slattach.c ...
if (ioctl(fd, TCSETS, &tstate) < 0) { ...
if (ioctl(fd, TIOCSETD, &slipdisc) < 0) { ...
if (ioctl(fd, SIOCSIFENCAP, &mode) <0) { ...

You probably run dip or pppd to do the slattach for you, but you could write your own "dip" program, or even run the components from the command line (ie slattach(8) is a program that converts a tty line to an IP-like inteface, that will allocate it the 'sl0' device. You then run ifconfig to bring that device up - you need to be root to do that, then route packets down it.

That's how you could use a null modem cable as an IP link between two machines, though it's easier to let pppd do the work, by running (at both ends):

pppd /dev/ttyS1 38400 crtscts passive


ifconfig and route

LOOPBACK, SLIP, PPP and ETHERNET interfaces, need to be configured to start and stop them, and to set the running parameters. You have to tell the interface, using ifconfig, what IP address it is, and how to filter in/out BROADCAST addresses.

You have to tell the TCP/IP core, that the interface is there, and what LAN it is connected to. This is currently changing, so that running ifconfig, also does the really obvious route command (ie the single step from kernel to interface to LAN). However, older Linux versions, and other UNIX versions require the route command to point out the obvious.

In addition, route also does the not-so-obvious configuration of what is next-door-but-one. IP addresses are not schematic. All hosts on a LAN share a scheme, but adjacent LAN's don't.

Normally you don't worry too much about that, and let your favourite gateway tell you how to route your packets (or do the routing for you), but it helps to know that the gateay itself has to be told, and that you have to tell your own machine to make that gateway the default route.

To understand single step routing, look at the ifconfig and route commands for the loopback device, and re-apply the same idea. Each interface needs it's own script, or pair of commands in a script. With slackware, this is usually /etc/rc.d/rc.inet1.


the loopback device

If you don't have ethernet, or dial_up running, you can still be a TCP/IP host, by attaching the loopback interface.

Everybody needs the the loopback device, but it still has to be configured in. eg in /etc/rc.d/rc.inet1

/sbin/ifconfig lo
/sbin/route add -net

That's all there is to it! Maybe other devices take additional parameters, and routing to the default gateway adds a bit, but the rest of it is just shell scripts with lots of extra syntax, that clouds the view of what is actually happening.

Fortunately, the modern ifconfig and route are better at "guessing" the NETMASK (8 bit host part), and broadcast address (host all 1's). IE unless you are something strange, you don't have to specify them or calculate them (saves a lot of shell script lines). See Issue-5-Planning (your own IP addresses) for how to calculate them.

Now that you have the loopback device working, you can test your own web server and cgi scripts. You can telnet localhost 25 and talk to your own sendmail daemon, be your own web proxy (etc).


the ethernet device


/sbin/ifconfig eth0 ${IPADDR} 
/sbin/route add -net ${NETWORK} netmask ${NETMASK}

Normally, TCP/IP over the ethernet device stays active for the lifetime of the machine. However, you can bring it down with:

/sbin/ifconfig eth0 down


the SECOND ethernet device

This will be much the same as for eth0, but for eth1.

You may need to decide which card is which ( eg /etc/modules.conf), and whether your box is a router or gateway between the two LANS, (or simply attached to both).

You can use the same FQHN for both, but usually, one would be called jackdaw.lan_67.priv the other called jackdaw.lan_68.priv

/sbin/ifconfig eth0 
/sbin/route add -net netmask

/sbin/ifconfig eth1 
/sbin/route add -net netmask

If you don't like having the numbers in the scripts, you can use names instead, and put the numbers in /etc/hosts, probably with a strange abbreviation/alias, to avoid any confusion with re-use of the FQHN, eg jackdaw_eth0. I just wanted you to see that /etc/hosts is just an "extra", it's the ifconfig command that defines your address.



This is the file that contains the above commands, on a Slackware system. You may see extra shell script commands to extract those parameters from elsewhere, and call the real command line. This just adds to the complexity of what is rather simple.


default route

The route command is used for complicated and blindingly obvious routing. IE: as well as telling TCP/IP that lan_99 is acessed through a gateway on lan_68 (not lan_67), you have to tell it that lan_67 is accessed via the lan_67 interface.

route is also called, so that packets with no known route, get send down a default path, to a specific gateway/router. IE a packet destined for sunsite.unc.edu, goes to the route table and doesn't know where to go. It isn't on the LAN, and isn't on your ISP's "local" network. So it goes down the default route, to your ISP's gateway, which then knows how to send it.

The following command is run by pppd or dip, but if your machine is only connected by ethernet, and you have a local gateway, you include it in rc.inet1 The metric is a 'hop count'.

# /sbin/route add default gw ${GATEWAY} metric 1


scripts for the PPP device (or DIP)

When you connect to the internet, the "default" route will be your ISP's routing gateway. pppd will call route for you.

The calls to ifconfig, route (and slattach as required), are built-in to the pppd binary, or dip binary (and script). You just have to select and specify the correct parameters.

Since you start PPP (or SLIP) using a command script, the commands don't appear in /etc/rc.d/.

When you start PPP, you (usually) need a chat script to do the dialing, and other configuration files. Look in /etc/ppp/.


What didn't happen ...

If it works, great! But if it didn't, what can you do?

Reread your scripts, and run them manually (there is nothing special about the /etc/rc.d scripts, other than they are run at boot time as root).

You can find out what did happen, using the ifconfig and route commands. Without any parameters, they tell you their current view of the world.



This lists all configured interfaces, and their current parameters. It also hows how many packets have been send/received by each.

lo        Link encap:Local Loopback  
          inet addr:  Bcast:  Mask:
          RX packets:12 errors:0 dropped:0 overruns:0
          TX packets:12 errors:0 dropped:0 overruns:0

eth0      Link encap:10Mbps Ethernet  HWaddr 00:C0:DF:45:08:DA
          inet addr:  Bcast:  Mask:
          RX packets:0 errors:0 dropped:0 overruns:0
          TX packets:0 errors:0 dropped:0 overruns:0
          Interrupt:12 Base address:0x300 

ppp0      Link encap:Point-Point Protocol  
          inet addr:  P-t-P:  Mask:
          UP POINTOPOINT RUNNING  MTU:1500  Metric:1
          RX packets:494 errors:0 dropped:0 overruns:0
          TX packets:498 errors:0 dropped:0 overruns:0



This lists all configured routes, both routes to LAN's and routes to gateways then beyond.

Kernel routing table
Destination     Gateway         Genmask         Flags MSS    Window Use Iface
tdc_gw.dircon.c *      UH    1500   0        0 ppp0    *        U     1500   0        0 eth0
loopback        *            U     3584   0        1 lo
default         tdc_gw.dircon.c *               UG    1500   0        5 ppp0