8 Configuring the Network Devices.

Contents of this section

`With some fencing wire and a pair of pliers I can build anything'

If everything has gone ok so far, then you will have a Linux kernel which support the network devices you intend to use, you also have the network tools with which to configure them. Now comes the fun part! You'll need to configure each of the devices you intend to use. This configuration generally amounts to telling each devices things like what its IP address will be, and what network it is connected to.

In past versions of this document I have presented near complete versions of the various configuration files and included comments to modify or delete lines from them as appropriate. From this version I will take a slightly different approach which I hope will result in you having a complete set of uncluttered configuration files that you have built from scratch so you know exactly what is in them, and why. I'll describe each of these files, and their function, as we come to them.

8.1 What information do I need before I begin ?

Before you can configure the networking software, you will need to know a number of pieces of information about your network connection. Your network provider or administrator will be able to provide you with most of them.

IP Address.

This is the unique machine address, in dotted decimal notation, that your machine will use. An example is 128.253.153.54. Your network administrator will provide you with this information.

If you will be using a slip or plip connection you may not need this information, so skip it until we get to the slip device.

If you're using the loopback device only, ie no ethernet,slip or plip support, then you won't need an ip address has the loopback port always uses the address 127.0.0.1.

Network Mask (`netmask').

For performance reasons it is desirable to to limit the number of hosts on any particular segment of a network. For this reason it is common for network administrators to divide their network into a number of smaller networks, known as subnets, which each have a portion of the network addresses assigned to them. The network mask is a pattern of bits, which when overlayed onto an address on your network, will tell you which subnetwork it belongs to. This is very important for routing, and if you find for example, that you can happily tal to people outside your network, not to some people on your own network, then it is quite likely that you have specified an incorrect subnet mask.

Your network adminstrators will have chosen the netmask when the network was designed, and therefore they should be able to supply you with the correct mask to use. Most networks are class-C subnetworks which use 255.255.255.0 as their netmask. Other larger networks use class-B netmasks (255.255.0.0). The NET-2/NET-3 code will automatically select a default mask when you assign an address to a device. The default assumes that your network has not been subnetted.

The NET-2/NET-3 code will choose the following masks by default:

For addresses with the first byte:
1-127         255.0.0.0         (Class A)
128-191       255.255.0.0       (Class B)
192+          255.255.255.0     (Class C)

if one of these doesn't work for you, try another. If this doesn't work ask your network administrator or local network guru (dime a dozen) for help.

You don't need to worry about a netmask for the loopback port, or if you are running slip/plip.

Network Address.

This is your IP address masked (bitwise AND) with your netmask. For example:

If your netmask is:           255.255.255.0
and your IP address is:       128.253.154.32    &&
                              ---------------
your Network address is:      128.253.154.0     =

Broadcast Address.

`A shout is a whisper that everyone hears whether they need to or not'

This is normally your network address logically ORed with your netmask inverted. This is simpler than it sounds. For a Class-C network, with network mask 255.255.255.0, your Broadcast Address will be your network address (calculated above), logically ORed with 0.0.0.255, the network mask inverted.

A worked example might look like:

If your netmask is:          255.255.255.0      !
the netmask inverted is:       0.  0.  0.255    =
If your Network address is:  128.253.154.0      ||
                             ----------------
Your broadcast address is:   128.253.154.255    =

Note that for historical reasons some networks use the network address as the broadcast address. If you have any doubts contact your network administrator.

If you have access to a sniffer, or soem other device capable of providing you with a trace of your network traffic, then you might be able to determine both the network and broadcast addresses by watching other traffic on the lan. Keep an eye open for, (or filter everything except), ethernet frames destined for the ethernet broadcast address: ff:ff:ff:ff:ff:ff. If any of them has an IP source address of your local router, and the protocol ID is not ARP, then check the destination IP address, because this datagram may well be a RIP routing broadcast from your router, in which case the destination IP address will be your broadcast address.

Once again, if you're not sure, check with your network administrator, they'd rather help you, than have you connect your machine misconfigured.

Router (`Gateway') Address.

`There must be some way out of here.'

This is the address of the machine that connects your network to the rest of the Internet. It is your `gateway' to the outside world. A couple of conventions exist for allocating addresses to routers which your network might follow, they are: The router is the lowest numbered address on the network, the router is the highest numbered host on the network, the router is allocated an address when it needs one. Probably the most common is the first, where the router will have an address that is mostly the same as your own, except with a .1 as the last byte. eg. if you address is 128.253.154.32, then your router might be 128.253.154.1. The router can have any address valid on your network and function properly, the address doesn't matter at all. There may in fact even be more than one router on your network. You will probably need to talk to your network adminstrator to properly identify your router address.

If you're using only loopback then you don't need a router address. If you're using SLIP or PPP, then your router address will be your SLIP/PPP server address.

Nameserver Address.

Most machines on the net have access to a name server which translates human tolerable hostnames into machine tolerable addresses, and vice versa Your network administrators will again tell you the address of your nearest nameserver. You can in fact run a nameserver on your own machine by running named, in which case your nameserver address will be 127.0.0.1, the loopback port address. However it is not required that you run named at all; see section `named' for more information.

If you're only using loopback then you don't need to know the nameserver address since you're only going to be talking to your own machine.

NOTE for SLIP/PLIP/PPP users.

You may or may not in fact need to know any of the above information. Whether you do or not will depend on exactly how your network connection is achieved, and the capabilities of the machine at the other end of the link. You'll find more detail in the section relevant to configuration of the SLIP/PLIP and PPP devices.

8.2 /etc/rc.d/rc.inet1,2 or /etc/rc.net

While the commands to configure your network devices can be typed manually each time, you will probably want to record them somewhere so that they your network is configured automatically when you boot your machine.

The `rc' files are specifically designed for this purpose. For the non-unix-wizard: `rc' file are run at bootup time by the init program and start up all of the basic system programs such as syslog, update, and cron. They are analagous to the MS-DOS autoexec.bat file, and rc might stand for `runtime commands'. By convention these files are kept under the /etc directory. For NET-2/NET-3 these files are found in /etc/rc.d and are called rc.inet1 and rc.inet2. The first rc file that gets called at bootup time is /etc/rc, and it in turn calls others, such as rc.inet1, which in turn might called rc.inet2. It doesn't really matter where they are kept, or what they are called, so long as init can find them.

In some distributions the rc file for the network is called rc.net and is in the /etc subdirectory. The rc.net file on these systems is simply the rc.inet1 and the rc.inet2 files combined into one file that gets executed. It doesn't matter where the commands appear, so long as you configure the interfaces before starting the network daemons and applications.

I will refer to these files as rc.inet1 and rc.inet2, and I keep them in the /etc/rc.d, so if you are using one of the distributions that uses rc.net, or you want to keep the files somewhere else, then you will have to make appropriate adjustments as you go.

We will be building these files from scratch as we go.

rc.inet1

The rc.inet1 file configures the basic tcp/ip interaces for your machine using two programs: /sbin/ifconfig, and /sbin/route.

ifconfig

/sbin/ifconfig is used for configuring your interface with the parameters that they require to function, such as their IP address, network mask, broadcast addresses and similar. You can use the ifconfig command with no parameters to display the configuration of all network devices. Please check the ifconfig man page for more detail on its use.

route

/sbin/route is used to create, modify, and delete entries in a table (the routing table) that the networking code will look at when it has a datagram that it needs to transmit. The routing table lists destination address, and the interface that that address is reachable via. You can use the route command with no parameters to display the contents of the routing table. Please check the route man page for more detail on its use.

rc.inet2

The rc.inet2 file starts any network daemons such as inetd, portmapper and so on. This will be covered in more detail in section `rc.inet2', so for the moment we will concentrate on rc.inet1. I have mentioned this file here so that if you have some other configuration, such as a single rc.net file you will understand what the second half of it represents. it is important to remember that you must start your network applications and daemons after you have configured your network devices.

8.3 Configuring the Loopback device (mandatory).

The loopback device isn't really a hardware device. It is a software construct that looks like a physical interface. Its fucntion is to happily allow you to connect to yourself, and to test network software without actually having to be connected to a network of any kind. This great if you are developing network software and you have a slip connection. You can write and test the code locally, and then when you are ready to test it on a live network, eatablish your slip connection and test it out. You won't hurt others users if your program misbehaves.

By convention, the loopback device always has an IP address of 127.0.0.1 and so you will use this address when configuring it.

The loopback device for Linux is called `lo'. You will now make the first entry into your rc.inet1 file. The following code fragment will work for you:

#!/bin/sh
#
# rc.inet1   --  configures network devices.
#
# Attach the loopback device.
/sbin/ifconfig lo 127.0.0.1
#
# Add a route to point to the loopback device.
/sbin/route add 127.0.0.1
# End loopback
#

You have used the ifconfig program to give the loopback interface its IP address, and route program to create an entry in the routing table that will ensure that all datagrams destined for 127.0.0.1 will be sent to the loopback port.

There are two important points to note here.

Firstly, the netmask and broadcast addresses have been allowed to take the default values for the loopback device described earlier in section `Network Mask'. To see what they are, try the ifconfig program without any arguments.

# ifconfig
lo        Link encap Local Loopback  
          inet addr 127.0.0.1  Bcast 127.255.255.255  Mask 255.0.0.0
          UP BROADCAST LOOPBACK RUNNING  MTU 2000  Metric 1
          RX packets 0 errors 0 dropped 0 overrun 0
          TX packets 30 errors 0 dropped 0 overrun 0
#

Secondly, its not obvious how the route command chose the loopback device as the device for the route to 127.0.0.1. The route program is smart enough to know that 127.0.0.1 belongs to the network supported by the loopback device. It works this out by check the IP address and the netmask. You can use the route command with no arguments to display the contents of the routing table:

# route
Kernel routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
127.0.0.0       *               255.0.0.0       U     0      0       30 lo
# 

8.4 Configuring an ethernet device. (optional)

You'll only be interested in this section if you wish to configure an ethernet card., if not, then skip on ahead to the next section.

To configure an ethernet card is only slightly more complicated than configuring the loopback device. This time you should probably specify explicitly the network mask and the broadcast address, unless you are sure that the defaults will work ok, and they probably will.

For this you will need the IP address that you have been assigned, the network mask in use on your network, and the broadcast address in use.

The first ethernet device for a Linux system is called `eth0', the second `eth1' and so forth. You will now add a section to your rc.inet1 file. The following code fragment will work for you if you change the addresses specified for real ones:

#
# Attach an ethernet device
#
#  configure the IP address, netmask and broadcast address.
/sbin/ifconfig eth0 IPA.IPA.IPA.IPA
/sbin/ifconfig eth0 netmask NMK.NMK.NMK.NMK
/sbin/ifconfig eth0 broadcast BCA.BCA.BCA.BCA
#
# add a network route to point to it:
/sbin/route add -net NWA.NWA.NWA.NWA device eth0
#
# End ethernet
#

Where: IPA.IPA.IPA.IPA represents your IP Address. NMK.NMK.NMK.NMK represents your netmask. BCA.BCA.BCA.BCA represents your Broadcast address. NWA.NWA.NWA.NWA represents your Network Address.

Note the use of the -net argument to the route command. This tells route that the route to be added is a route to a network, and not to a host. There is an alternative method of achieving this, you can leave off the -net if you have the network address listed in the /etc/networks file. This is covered later in section `/etc/networks'.

8.5 Configuring a SLIP device (optional)

SLIP (Serial Line Internet Protocol) allow syou to use tcp/up over a serial line, be that a phone line with a dialup modem, or a leased line of some sort. Of course to use slip need access to a slip-server in your area. Many universities and businesses provide slip access all over the world.

slip uses the serial ports on your machine to carry IP datagrams. To do this it must take control of the serial device. Slip device names are named sl0, sl1 etc. How do these correspond to your serial devices ? The networking code used what is called an ioctl (i/o control) call to change the serial devices into slip devices. There are two programs supplied that can do this, they are called dip and slattach

dip

dip (Dialup IP) is a smart program that is able to ser the speed of the serial device, command your modem to dial the remote end of the link, automatically log you into the remote server, search for messages sent to you by the server, and extract information for them such as your IP address, and performance the ioctl necessary to switch your serial port into slip mode. dip has a powerful scripting ability, and it is this that you can exploit to automate your logon procedure.

slattach

slattach on the other is a very simple program that, that is very easy to use, but does not have the sophistication of dip. slattach is ideal to use where you have a permanent connection to your server, such as a physical cable, or a leased line.

When do I use which ?

When do you use which ? You would use dip when your link to the machine that is your slip server is a dialup modem, or some other termporary link. You would use slattach when you have a leased line, perhaps a cable, between your machine and the server, and there is no special action needed to get the link working. See section `Permanent Slip connection' for more information.

Configuring slip is much like configuring an Ethernet interface (read section `Configuring an ethernet device' above). However there are a few key differences.

First of all, slip links are unlink ethernet networks in that there is only ever two hosts on the network, one at each end of the link. Unlike an ethernet that is available for use as soon are you are cabled, with slip, depending on the type of link you have, you may have to initialise your network connection in some special way.

If you are using dip then this would not normally be done at boot time, but at some time later, when you were ready to use the link. It is possible to automate this procedure. If you are using slattach then you will probably want to add a section to your rc.inet1 file. This will be described soon.

There are two major types of slip servers: Dynamic IP address servers and static IP address servers. Almost every slip server will prompt you to login using a username and password when dialing in. dip can handle logging you in automatically.

Static slip server with a dialup line and DIP.

A static slip server in one in which you have been supplied an IP address that is exclusively yours. Each time you connect to the server, you will configure your slip port with that address. The static slip server will answer your modem call, possibly prompt you for a username and password, and the route any datagrams destined for your address to you via that connection. If you have a static server, then you may want to put entries for your hostname and IP addresss (since you know what it will be) into your /etc/hosts. You should also configure some other files such as: rc.inet2, host.conf, resolv.conf, /etc/HOSTNAME, and rc.local. Remember that when configuring rc.inet1, you don't need to add any special commands for your slip connection since it dip that does all of the hard work for you in configuring your interface. You will need to give dip the appropriate information, and it will ocnfigure the interface for you after commanding the modem to establish the call, and loggin you into your slip server.

If this is how your slip server works then you can move to section `Using Dip' to learn how to configure dip appropriately.

Dynamic slip server with a dialup line and DIP.

A dynamic slip server is one which allocates you an IP address randomly, from a pool of addresses, each time you logon. This means that there is no guarantee that you will have any particular address each time, and that address may well be used by someone else after you have logged off. The netework administrator who configured the slip server will have assigned a pool of address for the slip server to use, when the server receives a new incoming call, it finds the first unused address, guidees the caller through the login process, and then prints a welcome message that contains the IP address it has allocated, and will proceed to use that IP address for the duration of that call.

Configuring for this type of server is similar to configuring for a static server, except that you must add a step where you obtain the IP address that the server has allocated for you and configure your slip device with that.

Again, dip does the hard work, and new versions are smart enough to not only log you in, but to also able to automatically read the IP address printed in the welcome message, and store it so that you can have it configure your slip device with it.

If this is how your slip server works then you can move to section `Using Dip' to learn how to configure dip appropriately.

Using DIP.

As explained earlier, dip is a powerful program that can simplify and automate the process of dialling into the slip server, logging you in, starting the connection, and configuring your slip devices with the appropriate ifconfig and route commands.

Essentially to use dip you'll write a `chat script', which is basically a list of commands that dip understands that tell dip how to perform each of the actions you want it to perform. See sample.dip in the net-32 package for an explanation. dip is quite a powerful program, with many options. Instead of going into all of them here you should looks at the man page, README and sample files from tsx-11, and the net-032 distribution.

You may notice that the sample.dip script assumes that you're using a static slip server, so you know what your IP address is beforehand. For dynamic slip servers, the newer versions of dip include a command you can use to automatically read and configure your slip device with the IP address that the dynamic server allocates for you. The following sample was supplied by Paul Mossip, and is probably a good starting point for you. You might like to save it as /etc/dipscript:

#
# Connection script for SLIP to knoware.nl.mugnet.org
#

  # Fetch the IP address of our target host.
main:

  # Set the desired serial port and speed.
  port /dev/cua0
  speed 38400

  # Reset the modem and terminal line.
  reset

  # Prepare for dialing.
  send ATZ1\r
  wait OK 4
  if $errlvl != 0 goto error
  dial 666-0999                    ## Change to your servers number!
  if $errlvl != 0 goto error
  wait CONNECT 60
  if $errlvl != 0 goto error

  # We are connected.  Login to the system.
login:
  sleep 3
  send \r\n\r\n
  wait gracelands> 20              ## Change to your servers prompt
  if $errlvl != 0 goto error
  send login\n
  wait name: 10                    ## Wait username: prompt
  if $errlvl != 0 goto erro
  send elvisp\n                    ## Change to your own!
  wait ord: 10                     ## Wait password prompt
  if $errlvl != 0 goto error
  send alive\n                     ## Change to your own!
  wait gracelands> 10
  if $errlvl != 0 goto error
  send slip\n                      ## Change to suit your server
  wait SLIP 30                     ## Wait for SLIP prompt
  if $errlvl != 0 goto error
  get $local remote 10             ## Assumes the server sends your IP..
  if $errlvl != 0 goto error       ## address as soon as you enter slip.
  get $remote gracelands           ## slip server address from /etc/hosts
done:
  print CONNECTED to $remote with address $rmtip we are $local
  default
  mode SLIP
  goto exit
error:
  print SLIP to $host failed.
exit:
#
# End dip script

The above example assumes you are calling a dynamic slip server, if you are calling a static slip server, then remove the lines:

get $local remote 10             ## Assumes the server sends your IP..
if $errlvl != 0 goto error       ## address as soon as you enter slip.

When dip is given the get $local command it searches the incoming text from the remote end for a string that looks like an IP address, ie strings numbers seperated by `.' characters. This modification was put in place specifically for dynamic slip servers, so that the process of reading the IP address granted by the server could be automated.

The example above will automaticaly create a default route via your slip link, if this is not what you want, you might have an ethernet connection that should be your default route, then remove the default command from the script. After this script has finished running, if you do an ifconfig command, you will see that you have a device sl0. This is your slip device. Should you need to, you can modify its configuration, after the dip command has finished, manually using the ifconfig and route commands.

Please note that dip allows you to select a number of different protocols to use with the mode command, the most common example is cslip for slip with compression. Please note that both ends of the link must agree, so you should ensure that whatever you select agrees with what your server is set to.

The above example is fairly robust and should cope with most errors. Please refer to the dip man page for more information. Naturally you could, for example, code the script to do such things as redial the server if it doesn't get a connection within a prescribed period of time, or even try a series of servers if you have access to more than one.

Permament slip connection using a leased line and slattach.

If you have a cable between two machines, or are fortunate enough to have a leased line, or some other permanent serial connection between your machine and another, then you don't need to go to all the trouble of using dip tao set up your serial link. slattach is a very simple to use utility that will allow you to do just enough fucntionality to configure your connection.

SInce your connection will be a permanent one, you will want to add some commands to your rc.inet1 file. In essence all you need to do for a permament connection is ensure that you configure the serial device to the correct speed and switch the serial device into slip mode. slattach allows you to do this with one command. Add the following to your rc.inet1 file:

#
# Attach a leased line static slip connection
#
#  configure /dev/cua0 for 19.2kbps and cslip
/sbin/slattach -p cslip -s 19200 /dev/cua0 &
/sbin/ifconfig sl0 IPA.IPA.IPA.IPA pointopoint IPR.IPR.IPR.IPR up
#
# End static slip.

Where: IPA.IPA.IPA.IPA represents your IP address. IPR.IPR.IPR.IPR represents the IP address of the remote end.

slattach allocated the first unallocated slip deive to the serial device specified. slattach starts with sl0. Therefore the first slattach command attaches slip device sl0 to the serial device specified, and sl1 the next time, etc.

slattach allows you to configure a number of different protocols with the -p argument, in your case you will use either slip or cslip depending on whether you want to use compression or not. Note: both ends must agree on whether you do want compression or not.

8.6 Configuring a PLIP device. (optional)

plip (Parallel Line IP), is like slip, in that it is used for providing a point to point network connection between two machines, except that it is designed to use the parallel printer ports on your machine instead of the serial ports. Because it is possible to transfer more than one bit at a time with a parallel port, it is possible to attain higher speeds with the plip interface than with a standard serial device. In addition, even the simplest of parallel ports, printer ports, can be used, in lieu of you having to purchase comparitvely expensive 16550AFN UART's for your serial ports.

The Linux plip interface is compatible with the Crywyr Packet Driver PLIP, and this will mean that you can connect your Linux machine to a DOS machine running any other sort of tcp/ip software via plip.

When compiling the kernel, there is only file that might need to be looked at to configure plip. That file is /usr/src/linux/driver/net/CONFIG, and it contains plip timers in mS. The defaults are probably ok in most cases. You will probably need to increase them if you have an especially slow computer, in which case the timers to increase are actually on the other computer.

To configure a plip interface, you will need to add the following lines to your rc.inet1 file:

#
# Attach a PLIP interface
#
#  configure parallel port lp0 as a plip device
/sbin/ifconfig pl0 IPA.IPA.IPA.IPA pointopoint IPR.IPR.IPR.IPR up
#
# End plip

Where: IPA.IPA.IPA.IPA represents your IP address. IPR.IPR.IPR.IPR represents the IP address of the remote machine.

The pointopoint parameter has the same meaning as for slip, in that it specifies the address of the machine at the other end of the link.

In almost all respects you can treat a plip interface as though it were a slip interface, except that neither dip nor slattach can be, or are, used.

PLIP cabling diagram.

plip has been designed to use cables with the same pinout sa those commonly used by the better known of the MS-DOS based pc-pc file transfer programs.

The pinout diagram (taken from /usr/src/linux/drivers/net/plip.c) looks as follows:

Pin Name    Connect pin - pin
---------   -------------------------------
INIT        16 - 16
SLCTIN      17 - 17
GROUND      25 - 25
D0->ERROR   2 - 15
ERROR->D0   15 - 2
D1->SLCT    3 - 13
SLCT->D1    13 - 3
D2->PAPOUT  4 - 12
PAPOUT->D2  12 - 4
D3->ACK     5 - 10
ACK->D3     10 - 5
D4->BUSY    6 - 11
BUSY->D4    11 - 6
D5          7*
D6          8*
D7          9*
STROBE      1*
FEED        14*

Notes: Do not connect the pins marked with an asterisk `*'. Extra grounds are 18,19,20,21,22,23, and 24.

If the cable you are using has a metallic shield, it should be connected to the metallic DB-25 shell at one end only.

Next Chapter, Previous Chapter

Table of contents of this chapter, General table of contents

Top of the document, Beginning of this Chapter