% Linux Installation and Getting Started    -*- TeX -*-
% tcpip.tex
% Copyright (c) 1992, 1993 by Matt Welsh <mdw@sunsite.unc.edu>
%
% This file is freely redistributable, but you must preserve this copyright 
% notice on all copies, and it must be distributed only as part of "Linux 
% Installation and Getting Started". This file's use is covered by the 
% copyright for the entire document, in the file "copyright.tex".

\section{Networking with TCP/IP}\label{sec-tcpip}
\index{networking!TCP/IP|(}
\index{TCP/IP|(}
Linux supports a full implementation of the TCP/IP (Transport Control
Protocol/Internet Protocol) networking protocols. TCP/IP has become the
most successful mechanism for networking computers worldwide. 
With Linux and an Ethernet card, you can network your machine to a local
area network, or (with the proper network connections), to the Internet---the
worldwide TCP/IP network. 

Hooking up a small LAN of UNIX machines is easy. It simply requires an
Ethernet controller in each machine and the appropriate Ethernet cables
and other hardware. Or, if your business or university provides 
access to the Internet, you can easily add your Linux machine to this network.

\index{TCP/IP!NET-2 implementation of}
\index{NET-2}
\index{networking!NET-2}
The current implementation of TCP/IP and related protocols for Linux
is called ``NET-2''. This has no relationship to the so-called NET-2 release
of BSD UNIX; instead, ``NET-2'' in this context means the second 
implementation of TCP/IP for Linux. 

\index{NET-2!support for serial line Internet protocol (SLIP)}
\index{SLIP}
\index{networking!SLIP}
\index{serial line Internet protocol}
Linux NET-2 also supports SLIP---Serial Line Internet Protocol. SLIP
allows you to have dialup Internet access using a modem.
If your business or university provides SLIP access, you can dial in to the
SLIP server and put your machine on the Internet over the phone line.
Alternately, if your Linux machine also has Ethernet access to the Internet,
you can set up your Linux box as a SLIP server. 

For complete information on setting up TCP/IP under Linux, we
encourage you to read the Linux NET-2 HOWTO, available via anonymous
FTP from {\tt sunsite.unc.edu}. The NET-2 HOWTO is a complete guide to 
configuring TCP/IP, including Ethernet and SLIP connections, under Linux.
The Linux Ethernet HOWTO is a related document that describes configuration
of various Ethernet card drivers for Linux.
The {\em Linux Network Administrator's Guide}, from the Linux
Documentation Project, is also available. See Appendix~\ref{app-sources-num}
for more information on these documents.

Also of interest is the book {\em TCP/IP Network Administration}, by 
Craig Hunt. It contains complete information on using and configuring
TCP/IP on UNIX systems. 

\subsection{Hardware Requirements}
\index{TCP/IP!hardware requirements for}
You can use Linux TCP/IP without any networking hardware at all---configuring
``loopback'' mode allows you to talk to yourself. This is necessary for
some applications and games which use the ``loopback'' network device. 

\index{ethernet!supported cards}
\index{hardware support!ethernet cards}
\index{networking!ethernet cards, supported}
However, if you want to use Linux with an Ethernet TCP/IP network, you need
one of the following Ethernet cards:
3com 3c503, 3c503/16; 
Novell NE1000, NE2000;
Western Digital WD8003, WD8013;
Hewlett Packard HP27245, HP27247, HP27250. 

The following clones are reported 
to work: WD-80x3 clones: LANNET LEC-45; NE2000 clones: Alta Combo, Artisoft 
LANtastic AE-2, Asante Etherpak 2001/2003, D-Link Ethernet II, 
LTC E-NET/16 P/N 8300-200-002, Network Solutions HE-203, SVEC 4 Dimension 
Ethernet, 4-Dimension FD0490 EtherBoard 16, and D-Link DE-600, SMC Elite 16.

See the Linux Ethernet HOWTO for a more complete discussion of Linux 
Ethernet hardware compatibility.

Linux also supports SLIP, which allows you to use a modem to access the
Internet over the phone line. In this case, you'll need a modem 
compatible with your SLIP server---most servers require a 14.4bps V.32bis
modem. 

\subsection{Configuring TCP/IP on your system}

\index{TCP/IP!configuring}
In this section we're going to discuss how to configure an Ethernet 
TCP/IP connection on your system. Note that this method should work for
many systems, but certainly not all. This discussion should be enough
to get you on the right path to configuring the network parameters of
your machine, but there are numerous caveats and fine details not mentioned
here. We direct you to the {\em Linux Network Administrators' Guide\/}
and the NET-2-HOWTO for more information.\footnote{Some of this information 
is adapted from the NET-2-HOWTO by Terry Dawson and Matt Welsh.}

First of all, we assume that you have a Linux system that has the TCP/IP
software installed. This includes basic clients such as {\tt telnet} 
and {\tt ftp}, system administration commands such as {\tt ifconfig}
and {\tt route} (usually found in {\tt /etc}), and networking configuration
files (such as {\tt /etc/hosts}). The other Linux-related networking
documents described above explain how to go about installing the 
Linux networking software if you do not have it already. 

We also assume that your kernel has been configured and compiled with
TCP/IP support enabled. See Section~\ref{sec-sysadm-upgrade} for information
on compiling your kernel. To enable networking, you must answer ``yes'' to the
appropriate questions during the {\tt make config} step, and rebuild the
kernel. 

Once this has been done, you must modify a number of configuration 
files used by NET-2. For the most part this is a simple procedure. 
Unfortunately, however, there is wide disagreement between Linux
distributions as to where the various TCP/IP configuration files
and support programs should go. Much of the time, they can be found
in {\tt /etc}, but in other cases may be found in {\tt /usr/etc}, 
{\tt /usr/etc/inet}, or other bizarre locations. In the worst case
you'll have to use the {\tt find} command to locate the files on your
system. Also note that not all distributions keep the NET-2 configuration
files and software in the same location---they may be spread across
several directories.

The following information applies primarily to Ethernet connections.
If you're planning to use SLIP, read this section to understand the
concepts, and follow the SLIP-specific instructions in the following
section.

\subsubsection{Your network configuration}

\index{TCP/IP!configuring}
Before you can configure TCP/IP, you need to determine the following
information about your network setup. In most cases, your local
network administrator can provide you with this information.
\begin{itemize}
\index{TCP/IP!IP address}
\index{IP address!defined}
\item IP address. This is the unique machine address in dotted-decimal
	  format. An example is 128.253.153.54. Your network admins will 
	  provide you with this number. 
	  
	  If you're only configuring loopback mode (i.e. no SLIP, no ethernet 
	  card, just TCP/IP connections to your own machine) then your 
	  IP address is 127.0.0.1.

\index{TCP/IP!network mask}
\index{network mask!defined}
\item Your network mask (``netmask''). This is a dotted quad, similar
to the IP address, which determines which portion of the IP address
specifies the subnetwork number, and which portion specifies the host on
that subnet. (If you're shaky on these TCP/IP networking terms, we
suggest reading some introductory material on network administration.)
  The network mask
  is a pattern of bits, which when overlayed onto an address on your
  network, will tell you which subnet that address lives on. This is
  very important for routing, and if you find, for example, that you
  can happily talk to people outside your network, but not to some
  people within your network, there is a good chance that you have
  an incorrect mask specified.

  Your network administrators 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 Class B
  networks use 255.255.0.0. The NET-2 code will automatically select
  a mask that assumes no subnetting as a default if you do not specify one.

  This applies as well to the loopback port. Since the
  loopback port's address is always 127.0.0.1, the netmask for
  this port is always 255.0.0.0. You can either specify this
  explicitly or rely on the default mask.

\index{TCP/IP!network address}
\index{network address!defined}
\item Your network address. This is your IP address masked bitwise-ANDed the 
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. With a netmask of 255.255.0.0, 
	  this would be 128.253.0.0. 

  If you're only using loopback, you don't have a network address.

\index{TCP/IP!broadcast address}
\index{broadcast address!defined}
\item Your broadcast address. 
The broadcast address is used to broadcast packets to every machine on your
subnet. Therefore, if the host number of machines on your subnet is 
given by the last byte of the IP address (netmask 255.255.255.0), 
  your broadcast address will be your network address ORed with 0.0.0.255.

  For example, if your IP address is 128.253.154.32, and your netmask is
  255.255.255.0, your broadcast address is 128.253.154.255.

  Note that for historical reasons, some networks are setup to use
  the network address as the broadcast address, if you have any doubt,
  check with your network administrators. (In many cases, it will
  suffice to duplicate the network configuration of other machines on 
  your subnet, substituting your own IP address, of course.) 

 If you're only using loopback, you don't have a broadcast address.

\index{TCP/IP!gateway address}
\index{gateway address!defined}
\item Your gateway address. This is the address of the machine which
	  is your ``gateway'' to the outside world (i.e. machines not on your
	  subnet). In many cases the gateway machine has an IP address 
	  identical to yours but with a ``.1'' as its host address; e.g., if 
	  your IP address is 128.253.154.32, your gateway might be 
	  128.253.154.1.  Your network admins will provide you with the IP 
	  address of your gateway.

	  In fact, you may have multiple gateways. A {\em gateway} is 
	  simply a machine that lives on two different networks (has
	  IP addresses on different subnets), and routes packets between
	  them. Many networks have a single gateway to ``the outside
	  world'' (the network directly adjacent to your own), 
	  but in some cases you will have multiple gateways---one for
	  each adjacent network. 

	  If you're only using loopback, you don't have a gateway address.
	  The same is true if your network is isolated from all others.
	
\index{TCP/IP!nameserver address}
\index{nameserver address!defined}
\item Your nameserver address. Most machines on the net have a name
	  server which translates hostnames into IP addresses for them. 
	  Your network admins will tell you the address of your name server.
	  You can also run a server on your own machine by running
	  {\tt named}, in which case the nameserver address is 127.0.0.1. 
	  Unless you absolutely {\em must\/} run your own name server, 
	  we suggest using the one provided to you on the network (if 
	  any). Configuration of {\tt named} is another issue altogether;
	  our priority at this point is to get you talking to the network.
	  You can deal with name resolution issues later.

	  If you're only using loopback, you don't have a nameserver
	  address. 
\end{itemize}

SLIP users: You may or may not require any of the above information,
except for a nameserver address. When using SLIP, your IP address is
usually determined in one of two ways: Either (a) you have a ``static''
IP address, which is the same every time you connect to the network, or
(b) you have a ``dynamic'' IP address, which is allocated from a pool
available addresses when you connect to the server. In the following
section on SLIP configuration this is covered in more detail.

	NET-2 supports full routing, multiple routes, subnetworking (at
	this stage on byte boundaries only), the whole nine yards. The above
	describes most basic TCP/IP configurations. Yours may be quite
	different: when in doubt, consult your local network gurus and check
	out the man pages for {\tt route} and {\tt ifconfig}.
	Configuring TCP/IP networks is very much beyond the scope of
	this book; the above should be enough to get most people started.

\subsubsection{The networking {\tt rc} files}

\index{TCP/IP!configuration scripts for}
\index{configuration scripts!for TCP/IP}
\index{rc@{\tt rc}!files!defined}
{\tt rc} files are systemwide configuration scripts executed at boot
time by {\tt init}, which start up all of the basic system daemons
(such as {\tt sendmail}, {\tt cron}, etc.) and configure things
such as the network parameters, system hostname, and so on.
{\tt rc} files are usually found in the directory {\tt /etc/rc.d} but
on other systems may be in {\tt /etc}. 

\index{rc@{\tt rc}!files!for TCP/IP}
\index{TCP/IP!rc.inet1@{\tt rc.inet1}}
\index{rc.inet1@{\tt rc.inet1}}
\index{TCP/IP!rc.inet2@{\tt rc.inet2}}
\index{rc.inet2@{\tt rc.inet2}}
Here, we're going to describe the {\tt rc} files used to configure
TCP/IP. There are two of them: {\tt rc.inet1} and {\tt rc.inet2}.
{\tt rc.inet1} is used to configure the basic network parameters
(such as IP addresses and routing information) and {\tt rc.inet2} 
fires up the TCP/IP daemons ({\tt telnetd}, {\tt ftpd}, and so forth).

\index{TCP/IP!rc.inet@{\tt rc.inet}}
\index{rc.inet@{\tt rc.inet}}
\index{TCP/IP!rc.net@{\tt rc.net}}
\index{rc.net@{\tt rc.net}}
Many systems combine these two files into one, usually called {\tt rc.inet}
or {\tt rc.net}. The names given to your {\tt rc} files doesn't matter, 
as long as they perform the correct functions and are executed at boot time by
{\tt init}. To ensure this, you may need to edit {\tt /etc/inittab} 
and uncomment lines to execute the appropriate {\tt rc} file(s). In the
worst case you will have to create the {\tt rc.inet1}  and {\tt rc.inet2}
files from scratch and add entries for them to {\tt /etc/inittab}.

As we said, {\tt rc.inet1} configures the basic network interface.
This includes your IP and network address, and the routing table information
for your network. The routing tables are used to route outgoing (and
incoming) network datagrams to other machines. On most simple configurations,
you have three routes: One for sending packets to your own machine, 
another for sending packets to other machines on your network, and
another for sending packets to machines outside of your network (through
the gateway machine). Two programs are used to configure these parameters:
{\tt ifconfig} and {\tt route}. Both of these are usually found in {\tt /etc}.

\index{TCP/IP!ifconfig@{\tt ifconfig}}
\index{ifconfig@{\tt ifconfig}}
\index{route@{\tt route}}
\index{TCP/IP!route@{\tt route}}
{\tt ifconfig} is used for configuring the network device interface with 
the parameters that it requires to function, such as the IP address, network 
mask, broadcast address and the like.
{\tt route} is used to create and modify entries in the routing table.

\index{rc.inet1@{\tt rc.inet1}!sample}
\index{TCP/IP!rc.inet1@{\tt rc.inet1}!sample}
For most configurations, an {\tt rc.inet1} file that looks like the following
should work. You will, of course, have to edit this for your own system.
Do {\em not\/} use the sample IP and network addresses listed here for
your own system; they correspond to an actual machine on the Internet.

\begin{tscreen}\begin{verbatim}
#!/bin/sh
# This is /etc/rc.d/rc.inet1 -- Configure the TCP/IP interfaces

# First, configure the loopback device

HOSTNAME=`hostname`

/etc/ifconfig lo 127.0.0.1      # uses default netmask 255.0.0.0
/etc/route add 127.0.0.1        # a route to point to the loopback device

# Next, configure the ethernet device. If you're only using loopback or 
# SLIP, comment out the rest of these lines.

# Edit for your setup.
IPADDR="128.253.154.32"         # REPLACE with YOUR IP address
NETMASK="255.255.255.0"	        # REPLACE with YOUR netmask
NETWORK="128.253.154.0"         # REPLACE with YOUR network address
BROADCAST="128.253.154.255"     # REPLACE with YOUR broadcast address, if you
                                # have one. If not, leave blank and edit below.
GATEWAY="128.253.154.1"         # REPLACE with YOUR gateway address!

/etc/ifconfig eth0 ${IPADDR} netmask ${NETMASK} broadcast ${BROADCAST}

# If you don't have a broadcast address, change the above line to just:
# /etc/ifconfig eth0 ${IPADDR} netmask ${NETMASK} 

/etc/route add ${NETWORK}

# The following is only necessary if you have a gateway; that is, your
# network is connected to the outside world.
/etc/route add default gw ${GATEWAY} metric 1

# End of Ethernet Configuration
\end{verbatim}\end{tscreen}

Again, you may have to tweak this file somewhat to get it
to work. The above should be sufficient for the majority of simple
network configurations, but certainly not all.

\index{rc.inet2@{\tt rc.inet2}}
\index{inetd@{\tt inetd}}
\index{TCP/IP!inetd@{\tt inetd}}
{\tt rc.inet2} starts up various servers used by the TCP/IP suite. 
The most important of these is {\tt inetd}. {\tt inetd} sits in the
background and listens to various network ports. When a machine
tries to make a connection to a certain port (for example, the
incoming {\tt telnet} port), {\tt inetd} forks off a copy of the
appropriate daemon for that port (in the case of the {\tt telnet}
port, {\tt inetd} starts {\tt in.telnetd}). This is simpler than
running many separate, standalone daemons (e.g., individual copies
of {\tt telnetd}, {\tt ftpd}, and so forth)---{\tt inetd} starts up
the daemons only when they are needed.

\index{TCP/IP!syslogd@{\tt syslogd}}
\index{syslogd@{\tt syslogd}}
\index{routed@{\tt routed}}
\index{TCP/IP!routed@{\tt routed}}
{\tt syslogd} is the system logging daemon---it accumulates log messages
from various applications and stores them into log files based on
the configuration information in {\tt /etc/syslogd.conf}.
{\tt routed} is a server used to maintain dynamic routing information.
When your system attempts to send packets to another network, it may
require additional routing table entries in order to do so. 
{\tt routed} takes care of manipulating the routing table without
the need for user intervention.

\index{networking!NFS}
\index{NFS}
Our example {\tt rc.inet2}, below, only starts up the bare minimum
of servers. There are many other servers as well---many of which have
to do with NFS configuration. When attempting to setup TCP/IP on your
system, it's usually best to start with a minimal configuration and
add more complex pieces (such as NFS) when you have things working.

Note that in the below file, we assume that all of the network daemons
are held in {\tt /etc}. As usual, edit this for your own configuration.

\index{rc.inet2@{\tt rc.inet2}!sample}
\index{TCP/IP!rc.inet2@{\tt rc.inet2}!sample}
\begin{tscreen}\begin{verbatim}
#! /bin/sh
# Sample /etc/rc.d/rc.inet2

# Start syslogd
if [ -f /etc/syslogd ]
then
      /etc/syslogd
fi

# Start inetd
if [ -f /etc/inetd ]
then
      /etc/inetd
fi

# Start routed
if [ -f /etc/routed ]
then
      /etc/routed -q 
fi

# Done!
\end{verbatim}\end{tscreen}

\index{TCP/IP!named@{\tt named}}
\index{named@{\tt named}}
Among the various additional servers that you may want to start in
{\tt rc.inet2} is {\tt named}. {\tt named} is a name server---it 
is responsible for translating (local) IP addresses to names, and vice
versa. If you don't have a nameserver elsewhere on the network, or
want to provide local machine names to other machines in your domain,
it may be necessary to run {\tt named}. (For most configurations it
is not necessary, however.) {\tt named} configuration is somewhat
complex and requires planning; we refer interested readers to a good
book on TCP/IP network administration.

\subsubsection{{\tt /etc/hosts}}

\index{TCP/IP!/etc/hosts@{\tt /etc/hosts}}
\index{/etc/hosts@{\tt /etc/hosts}}
{\tt /etc/hosts} contains a list of IP addresses and the hostnames that
they correspond to. In general, {\tt /etc/hosts} only contains entries
for your local machine, and perhaps other ``important'' machines (such
as your nameserver or gateway). Your local name server will provide 
address-to-name mappings for other machines on the network, transparently.

For example, if your machine is {\tt loomer.vpizza.com} with the IP address 
128.253.154.32, your {\tt /etc/hosts} would look like:
\begin{tscreen}\begin{verbatim}
127.0.0.1               localhost
128.253.154.32          loomer.vpizza.com loomer
\end{verbatim}\end{tscreen}
If you're only using 
loopback, the only line in {\tt /etc/hosts} should be for 127.0.0.1, with
both {\tt localhost} and your hostname after it.
	
\subsubsection{{\tt /etc/networks}}

\index{TCP/IP!/etc/networks@{\tt /etc/networks}}
\index{/etc/networks@{\tt /etc/networks}}
The {\tt /etc/networks} file lists the names and addresses of your own,
and other, networks. It is used by the {\tt route} command, and allows
you to specify a network by name, should you so desire.

\index{route@{\tt route}!entry in /etc/networks required for@entry in {\tt /etc/networks} required for}
Every network you wish to add a route to using the {\tt route}
command (generally called from {\tt rc.inet1}---see above) {\em must\/} 
have an entry in {\tt /etc/networks}.

As an example,
\begin{tscreen}\begin{verbatim}
default		0.0.0.0		# default route    - mandatory
loopnet		127.0.0.0	# loopback network - mandatory
mynet		128.253.154.0	# Modify for your own network address
\end{verbatim}\end{tscreen}
	
\subsubsection{{\tt /etc/host.conf}}

\index{TCP/IP!/etc/host.conf@{\tt /etc/host.conf}}
\index{/etc/host.conf@{\tt /etc/host.conf}}
This file is used to specify how your system will resolve hostnames.
It should contain the two lines:
\begin{tscreen}\begin{verbatim}
order hosts,bind
multi on
\end{verbatim}\end{tscreen}
These lines tell the resolve libraries to first check the 
{\tt /etc/hosts} file for any names to lookup, and then ask the nameserver
(if one is present). The {\tt multi} entry allows you to have multiple
IP addresses for a given machine name in {\tt /etc/hosts}.

\subsubsection{{\tt /etc/resolv.conf}}

\index{TCP/IP!/etc/resolve.conf@{\tt /etc/resolve.conf}}
\index{/etc/resolve.conf@{\tt /etc/resolve.conf}}
This file configures the name resolver, specifying the 
address of your name server (if any) and your domain name.
Your domain name is your fully-qualified hostname (if you're a
registered machine on the Internet, for example), with the hostname
chopped off. That is, if your full hostname is {\tt loomer.vpizza.com},
your domain name is just {\tt vpizza.com}.

For example, if your machine is {\tt goober.norelco.com}, and has a
nameserver at the address 128.253.154.5, your {\tt /etc/resolv.conf} would 
look like:
\begin{tscreen}\begin{verbatim}
domain      norelco.com
nameserver  127.253.154.5
\end{verbatim}\end{tscreen}
	You can specify more than one nameserver---each must have a
	{\tt nameserver} line of its own in {\tt resolv.conf}.

\subsubsection{Setting your hostname}

\index{hostname!setting}
\index{hostname@{\tt hostname}}
You should set your system hostname with the {\tt hostname} command.
This is usually called from {\tt /etc/rc} or {\tt /etc/rc.local};
simply search your system {\tt rc} files to determine where it is
invoked. For example, if your (full) hostname is {\tt loomer.vpizza.com},
edit the appropriate {\tt rc} file to execute the command:
\begin{tscreen}
/bin/hostname loomer.vpizza.com
\end{tscreen}
Note that the {\tt hostname} executable may not be found in {\tt /bin}
on your system.

\subsubsection{Trying it out}

\index{TCP/IP!troubleshooting}
\index{TCP/IP!debugging}
Once you have all of these files set up, you should be able to reboot
your new kernel and attempt to use the network. There are many places where
things can go wrong, so it's a good idea to test individual aspects of
the network configuration (e.g., it's probably not a good idea to test
your network configuration by firing up Mosaic over a network-based X
connection).

\index{netstat@{\tt netstat}}
\index{TCP/IP!displaying routing tables}
You can use the {\tt netstat} command to display your routing tables;
this is usually the source of the most trouble. The {\tt netstat}
man page describes the exact syntax of this command in detail. 
In order to test network connectivity, we suggest using a client such
as {\tt telnet} to connect to machines both on your local subnetwork
and external networks. This will help to narrow down the source
of the problem. (For example, if you're unable to connect to local machines,
but can connect to machines on other networks, more than likely there
is a problem with your netmask and routing table configuration).
You can also invoke the {\tt route} command directly (as {\tt root}) to
play with the entries in your routing table.

You should also test network connectivity by specifying IP addresses
directly, instead of hostnames. For example, if you have problems with
the command
\begin{tscreen}
\$ {\em telnet shoop.vpizza.com}
\end{tscreen}
the cause may be incorrect nameserver configuration. Try using
the actual IP address of the machine in question; if that works, then
you know that your basic network setup is (more than likely) correct, 
and the problem lies in your specification of the name server address.

Debugging network configurations can be a difficult task, and we can't
begin to cover it here. If you are unable to get help from a local guru
we strongly suggest reading the {\em Linux Network Administrators' Guide}
from the LDP.

\subsection{SLIP Configuration}

\index{TCP/IP!over serial line|(}
\index{serial line Internet protocol|(}
\index{SLIP|(}
\index{TCP/IP!SLIP|(}
SLIP (Serial Line Internet Protocol) allows you to use TCP/IP 
over a serial line, be that a phone line, with a dialup modem, or
a leased asynchronous line of some sort. Of course, to use SLIP you'll
need access to a dial-in SLIP server in your area. Many universities
and businesses provide SLIP access for a modest fee. 

\index{dip@{\tt dip}}
\index{slattach@{\tt slattach}}
There are two major SLIP-related programs available---{\tt dip} and
{\tt slattach}. Both of these programs are used to initiate a SLIP
connection over a serial device. It is {\em necessary} to use one 
of these programs in order to enable SLIP---it will not suffice to
dial up the SLIP server (with a communications program such as 
{\tt kermit}) and issue {\tt ifconfig} and {\tt route} commands. 
This is because {\tt dip} and {\tt slattach} issue a special 
{\em ioctl()\/} system call to seize control of the serial device to
be used as a SLIP interface. 

{\tt dip} can be used to dial up a SLIP server, 
do some handshaking to login to the server (exchanging your username
and password, for example) and then initate the SLIP connection over the
open serial line. {\tt slattach}, on the other hand, does very little
other than grab the serial device for use by SLIP. It is useful if you
have a permanent line to your SLIP server and no modem dialup or handshaking
is necessary to initiate the connection. Most dialup SLIP users should
use {\tt dip}, on the other hand.

{\tt dip} can also be used to configure your Linux system as a SLIP
server, where other machines can dial into your own and connect to the
network through a secondary Ethernet connection on your machine.
See the documentation and man pages for {\tt dip} for more information
on this procedure.

\index{TCP/IP!point-to-point connection}
\index{TCP/IP!PPP}
\index{networking!PPP}
\index{PPP}
SLIP is quite unlike Ethernet, in that there are only two machines
on the ``network''---the SLIP host (that's you) and the SLIP server. 
For this reason, SLIP is often referred to as a ``point-to-point'' 
connection. A generalization of this idea, known as PPP (Point to Point
Protocol) has also been implemented for Linux. 

When you initiate a connection to a SLIP server, the SLIP server will
give you an IP address based on (usually) one of two methods. Some
SLIP servers allocate ``static'' IP addresses---in which case your
IP address will be the same every time you connect to the server.
However, many SLIP servers allocate IP addresses dynamically---in which
case you receive a different IP address each time you connect. 
In general, the SLIP server will print the values of your IP and
gateway addresses when you connect. {\tt dip} is capable of reading
these values from the output of the SLIP server login session and
using them to configure the SLIP device.

Essentially, configuring a SLIP connection is just like configuring
for loopback or ethernet. The main differences are discussed below.
Read the previous section on configuring the basic TCP/IP files, 
and apply the changes described below.

\subsubsection{Static IP address SLIP connections using {\tt dip}}
\label{sec-adv-slip-dip}

\index{TCP/IP!SLIP!static IP address with dip@static IP address with {\tt dip}}
\index{SLIP!static IP address with dip@static IP address with {\tt dip}}
\index{dip@{\tt dip}!static IP address with}
If you are using a static-allocation SLIP server, you may want to include
entries for your IP address and hostname in {\tt /etc/hosts}. 
Also, configure these files listed in the above section: 
{\tt rc.inet2}, {\tt host.conf}, and {\tt resolv.conf}.

Also, configure {\tt rc.inet1}, as described above. However, you only want to
execute {\tt ifconfig} and {\tt route} commands for the loopback device.
If you use {\tt dip} to connect to the SLIP server, it will execute
the appropriate {\tt ifconfig} and {\tt route} commands for the SLIP 
device for you. (If you're using {\tt slattach}, on the other hand, you
{\em will\/} need to include {\tt ifconfig}/{\tt route} commands in 
{\tt rc.inet1} for the SLIP device---see below.)

{\tt dip} {\em should\/} configure your routing tables appropriately
for the SLIP connection when you connect. In some cases, however, {\tt dip}'s
behavior may not be correct for your configuration, and you'll have to
run {\tt ifconfig} or {\tt route} commands by hand after connecting
to the server with {\tt dip} (this is most easily done from within
a shell script that runs {\tt dip} and immediately executes the 
appropriate configuration commands). Your gateway is, in most cases,
the address of the SLIP server. You may know this address before hand,
or the gateway address will be printed by the SLIP server when you
connect. Your {\tt dip} chat script (described below) can obtain this
information from the SLIP server.

{\tt ifconfig} may require use of the {\tt pointopoint} argument, if
{\tt dip} doesn't configure the interface correctly. For example,
if your SLIP server address is 128.253.154.2, and your IP address
is 128.253.154.32, you may need to run the command
\begin{tscreen}
ifconfig sl0 128.253.154.32 pointopoint 128.253.154.2
\end{tscreen}
as {\tt root}, after connecting with {\tt dip}. The man pages for
{\tt ifconfig} will come in handy.

\index{TCP/IP!SLIP!device names for}
\index{SLIP!device names for}
Note that SLIP device names used with the {\tt ifconfig} and {\tt route}
commands are {\tt sl0}, {\tt sl1} and so on (as opposed
to {\tt eth0}, {\tt eth1}, etc. for Ethernet devices).

In Section~\ref{sec-adv-using-dip}, below, we explain how to configure
{\tt dip} to connect to the SLIP server.

\subsubsection{Static IP address SLIP connections using {\tt slattach}}

\index{TCP/IP!SLIP!static IP address with slattach@static IP address with {\tt slattach}}
\index{SLIP!static IP address with slattach@static IP address with {\tt slattach}}
\index{stattach@{\tt slattach}!static IP addresses with}
If you have a leased line or cable running directly to your SLIP
server, then there is no need to use {\tt dip} to initiate a connection.
{\tt slattach} can be used to configure the SLIP device instead.

In this case, your {\tt /etc/rc.inet1} file should look something like
the following:
\begin{tscreen}\begin{verbatim}
#!/bin/sh
IPADDR="128.253.154.32"         # Replace with your IP address
REMADDR="128.253.154.2"		# Replace with your SLIP server address

# Modify the following for the appropriate serial device for the SLIP
# connection:
slattach -p cslip -s 19200 /dev/ttyS0
/etc/ifconfig sl0 $IPADDR pointopoint $REMADDR up
/etc/route add default gw $REMADDR
\end{verbatim}\end{tscreen}

{\tt slattach} allocates the first unallocated SLIP device ({\tt sl0}, 
{\tt sl1}, etc.) to the serial line specified. 

Note that the first parameter to {\tt slattach} is the SLIP protocol to use.
At present the only valid values are {\tt slip} and {\tt cslip}. 
{\tt slip} is regular SLIP, as you would expect, and {\tt cslip} is
SLIP with datagram header compression. In most cases you should use
{\tt cslip}; however, if you seem to be having problems with this, 
try {\tt slip}.

If you have more than one SLIP interface then you will have routing
considerations to make. You will have to decide what routes to
add, and those decisions can only be made on the basis of the
actual layout of your network connections. A book on TCP/IP network
configuration, as well as the man pages to {\tt route}, will be of
use. 

\subsubsection{Dynamic IP address SLIP connections using {\tt dip}}

\index{TCP/IP!SLIP!dynamic IP address with dip@dynamic IP address with {\tt dip}}
\index{SLIP!dynamic IP address with dip@dynamic IP address with {\tt dip}}
\index{dip@{\tt dip}!dynamic IP address with}
If your SLIP server allocates an IP address dynamically, then you 
certainly don't know your address in advance---therefore, you can't
include an entry for it in {\tt /etc/hosts}. (You should, however,
include an entry for your host with the loopback address, 127.0.0.1.) 

Many SLIP servers print your IP address (as well as the server's address)
when you connect. For example, one type of SLIP server prints a string
such as,
\begin{tscreen}
Your IP address is 128.253.154.44. \\
Server address is 128.253.154.2.
\end{tscreen}
{\tt dip} can capture these numbers from the output of the server and use them
to configure the SLIP device.

See Section~\ref{sec-adv-slip-dip}, above, for information on configuring
your various TCP/IP files for use with SLIP. Below, we explain how to
configure {\tt dip} to connect to the SLIP server.

\subsection{Using {\tt dip}}
\label{sec-adv-using-dip}

\index{dip@{\tt dip}!connecting to SLIP server with|(}
\index{SLIP!connecting to server with dip@connecting to servier with {\tt dip}}
{\tt dip} can simplify the process of connecting to a SLIP server,
logging in, and configuring the SLIP device. Unless you have a leased
line running to your SLIP server, {\tt dip} is the way to go.

\index{dip@{\tt dip}!chat script for|(}
To use {\tt dip}, you'll need to write a ``chat script'' which
contains a list of commands used to communicate with the SLIP server
at login time. These commands can automatically send your username/password
to the server, as well as get information on your IP address from the server.

Here is an example {\tt dip} chat script, for use with a dynamic IP address
server. For static servers, you will need to set the variables
{\tt \$local} and {\tt \$remote} to the values of your local IP address
and server IP address, respectively, at the top of the script. See the
{\tt dip} man page for details.

\begin{tscreen}\begin{verbatim}
main:
  # Set Maximum Transfer Unit. This is the maximum size of packets 
  # transmitted on the SLIP device. Many SLIP servers use either 1500 or
  # 1006; check with your network admins when in doubt. 
  get $mtu 1500

  # Make the SLIP route the default route on your system.
  default

  # Set the desired serial port and speed.
  port cua03
  speed 38400

  # Reset the modem and terminal line. If this causes trouble for you,
  # comment it out.
  reset

  # Prepare for dialing. Replace the following with your 
  # modem initialization string.
  send ATT&C1&D2\\N3&Q5%M3%C1N1W1L1S48=7\r
  wait OK 2
  if $errlvl != 0 goto error
  # Dial the SLIP server
  dial 2546000
  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 for the login prompt
  wait login: 10
  if $errlvl != 0 goto error

  # Send your username
  send USERNAME\n

  # Wait for password prompt
  wait ord: 5
  if $errlvl != 0 goto error

  # Send password.
  send PASSWORD\n

  # Wait for SLIP server ready prompt
  wait annex: 30
  if $errlvl != 0 goto error

  # Send commands to SLIP server to initate connection. 
  send slip\n
  wait Annex 30

  # Get the remote IP address from the SLIP server. The `get...remote' 
  # command reads text in the form xxx.xxx.xxx.xxx, and assigns it
  # to the variable given as the second argument (here, $remote).
  get $remote remote
  if $errlvl != 0 goto error
  wait Your 30

  # Get local IP address from SLIP server, assign to variable $local.
  get $local remote
  if $errlvl != 0 goto error

  # Fire up the SLIP connection
done:
  print CONNECTED to $remote at $rmtip
  print GATEWAY address $rmtip
  print LOCAL address $local
  mode SLIP
  goto exit
error:
  print SLIP to $remote failed.

exit:
\end{verbatim}\end{tscreen}

{\tt dip} automatically executes {\tt ifconfig} and {\tt route} commands
based on the values of the variables {\tt \$local} and {\tt \$remote}.
Here, those variables are assigned using the {\tt get\ldots remote} 
command, which obtains text from the SLIP server and assigns it to the
named variable. 

If the {\tt ifconfig} and {\tt route} commands that {\tt dip} runs for you
don't work, you can either run the correct commands in a shell script
after executing {\tt dip}, or modify the source for {\tt dip} itself.
Running {\tt dip} with the {\tt -v} option will print debugging information
while the connection is being set up, which should help you to determine
where things might be going awry.

Now, in order to run {\tt dip} and open the SLIP connection, you can use
a command such as:
\begin{tscreen}
\verb!/etc/dip/dip -v /etc/dip/mychat 2>&1!
\end{tscreen}
Where the various {\tt dip} files, and the chat script ({\tt mychat.dip}),
are stored in {\tt /etc/dip}. 
\index{dip@{\tt dip}!chat script for|)}
\index{dip@{\tt dip}!connecting to SLIP server with|)}

The above discussion should be enough to get you well on your way to
talking to the network, either via Ethernet or SLIP. Again, we strongly
suggest looking into a book on TCP/IP network configuration, especially
if your network has any special routing considerations, other than those
mentioned here.
\index{TCP/IP!over serial line|)}
\index{serial line Internet protocol|)}
\index{SLIP|)}
\index{TCP/IP!SLIP|)}
\index{networking!TCP/IP|)}
\index{TCP/IP|)}
