Полезная информация

TCP/IP Network Administration

TCP/IP Network AdministrationSearch this book
Previous: 6.2 TCP/IP Over a Serial Line Chapter 6
Configuring the Interface
Next: 6.4 Installing SLIP
 

6.3 Installing PPP

The procedures for installing and configuring PPP vary from implementation to implementation. [10] In this section, we use the implementation of PPP included with Linux 2.0 and the supporting configuration commands that come with it. PPP is an Internet standard and most UNIX systems include support for it in the kernel as part of the standard operating system installation. Usually this does not require any action on your part. Refer to Chapter 5 for examples of how PPP is configured in the Linux kernel. The Linux system installs the PPP physical and data link layer software (the HDLC protocol) in the kernel.

[10] Check your system documentation to find out exactly how to configure PPP on your system.

Installing PPP in the kernel is only the beginning. In this section we look at how pppd is configured to provide PPP services on a Slackware 96 Linux system.

6.3.1 The PPP Daemon

Point-to-Point Protocol is implemented on the Linux system in the PPP daemon (pppd), which was derived from a freeware PPP implementation for BSD systems. pppd can be configured to run in all modes: as a client, as a server, over dial-up connections, and over dedicated connections. Clients and servers are familiar concepts from Chapter 3, Network Services. A dedicated connection is a direct cable connection or a leased line; neither of which need to have a telephone call placed to establish the connection. A dial-up connection is a modem link that is established by dialing a telephone number.

Configuring pppd for a dedicated line is the simplest configuration. A dial-up script is not needed for a leased line or direct connection. There is no point in dynamically assigning addresses because a dedicated line always connects the same two systems. Authentication is of limited use because the dedicated line physically runs between two points. There is no way for an intruder to access the link, short of "breaking and entering" or "wiretap." A single pppd command configures a dedicated PPP link for our Linux system. We place it in the /etc/rc.d/rc.inet1 file:

pppd /dev/cua3 56000 crtscts defaultroute

The /dev/cua3 argument selects the device to which PPP is attached. It is, of course, the same port to which the dedicated line is attached. Next, the line speed is specified in bits per second (56000). The remainder of the command line is a series of keyword options. The crtscts option turns on hardware flow control. The final option, defaultroute, creates a default route using the remote server as the default gateway. [11]

[11] If a default route already exists in the routing table, the defaultroute option is ignored.

PPP exchanges IP addresses during the initial link connection process. If no address is specified on the pppd command line, the daemon sends the address of the local host, which it learns from DNS or the host table, to the remote host. Likewise, the remote system sends its address to the local host. The addresses are then used as the source and destination addresses of the link. You can override this by specifying the addresses on the command line in the form local-address:remote-address. For example:

pppd /dev/cua3 56000 crtscts defaultroute 172.16.24.1:

Here we define the local address as 172.16.24.1 and leave the remote address blank. In this case pppd sends the address from the command line and waits for the remote server to send its address. The local address is specified on the command line when it is different from the address associated with the local hostname in the host table or the DNS server. For example, the system might have an Ethernet interface that already has an address assigned. If we want to use a different address for the PPP connection, we must specify it on the pppd command line; otherwise, the PPP link will be assigned the same address as the Ethernet interface.

The pppd command has many more options than those used in these examples. [12] In fact, there are so many pppd command-line options, it is sometimes easier to put them in a file than it is to enter them all on the command line. pppd reads its options from the /etc/ppp/options file, then the ~/.ppprc file, and finally from the command line. The order in which they are processed creates a hierarchy such that options on the command line can override those in the ~/.ppprc file, which can in turn override those in the /etc/ppp/options file. This permits the system administrator to establish certain system-wide defaults in the /etc/ppp/options file while still permitting the end user to customize the PPP configuration. The /etc/ppp/options file is a convenient and flexible way to pass parameters to pppd.

[12] There is a full list of the pppd options in Appendix A, PPP Tools.

A single pppd command is all that is needed to set up and configure the software for a dedicated PPP link. Dial-up connections are more challenging.

6.3.2 Dial-Up PPP

A direct connect cable can connect just two systems. When a third system is purchased, it cannot be added to the network. For that reason, most people use expandable network technologies, such as Ethernet, for connecting systems in a local area. Additionally, leased lines are expensive. They are primarily used by large organizations to connect together networks of systems. For these reasons, using PPP for dedicated network connections is less common than using it for dial-up connections.

Several different utilities provide dial-up support for PPP. Dial-up IP (dip) is a popular package for simplifying the process of dialing the remote server, performing the login, and attaching PPP to the resulting connection. We discuss dip in this section because it is popular and because it comes with Slackware 96 Linux, which is the system we have been using for our PPP examples.

One of the most important features of dip is a scripting language that lets you automate all of the steps necessary to set up an operational PPP link. Appendix A covers all of the scripting commands supported by the 3.3.7o-uri version of dip. You can list the commands supported by your system by running dip in test mode (-t) and then entering the help command:

> dip -t
DIP: Dialup IP Protocol Driver version 3.3.7o-uri (8 Feb 96)
Written by Fred N. van Kempen, MicroWalt Corporation.

DIP> help
DIP knows about the following commands:

        beep     bootp    break    chatkey  config   
        databits dec      default  dial     echo     
        flush    get      goto     help     if       
        inc      init     mode     modem    netmask  
        onexit   parity   password proxyarp print    
        psend    port     quit     reset    send     
        shell    sleep    speed    stopbits term     
        timeout  wait     

DIP> quit

These commands can configure the interface, control the execution of the script, and process errors. Only a subset of the commands is required for a minimal script:

# Ask PPP to provide the local IP address
get $local 0.0.0.0
# Select the port and set the line speed
port cua1
speed 38400
# Reset the modem and flush the terminal
reset
flush
# Dial the PPP server and wait for the CONNECT response
dial *70,301-555-1234
wait CONNECT
# Give the server 2 seconds to get ready
sleep 2
# Send a carriage-return to wake up the server
send \r
# Wait for the Login> prompt and send the username
wait ogin>
send kristin\r
# Wait for the Password> prompt and send the password
wait word>
password
# Wait for the PPP server's command-line prompt
wait >
# Send the command required by the PPP server
send ppp enabled\r
# Set the interface to PPP mode
mode PPP
# Exit the script
exit

The get command at the beginning of the script allows PPP to provide the local and remote addresses. $local is a script variable. There are several available script variables; all of which are covered in Appendix A. $local normally stores the local address, which can be set statically in the script. A PPP server, however, is capable of assigning an address to the local system dynamically. We take advantage of this capability by giving a local address of all zeros. This peculiar syntax tells dip to let pppd handle the address assignments. A pppd client can get addresses in three ways:

The next two lines select the physical device to which the modem is connected and set the speed at which the device operates. The port command assumes the path /dev, so the full device path is not used. On most PC UNIX systems the value provided to the port command is cua0, cua1, cua2, or cua3. These values correspond to MS-DOS ports COM1 to COM4. The speed command sets the maximum speed used to send data to the modem on this port. The default speed is 38400. Change it if your modem accepts data at a different speed.

The reset command resets the modem by sending it the Hayes modem interrupt (+++) followed by the Hayes modem reset command (ATZ). This version of dip uses the Hayes modem AT command set and works only with Hayes-compatible modems. [13] Fortunately, that includes most brands of modems. After being reset, the modem responds with a message indicating that the modem is ready to accept input. The flush command removes this message, and any others that might have been displayed by the modem, out of the input queue. Use flush to avoid the problems that can be caused by unexpected data in the queue.

[13] If your modem doesn't use the full Hayes modem command set, avoid using dip commands, such as rest and dial, that generate Hayes commands. Use send instead. It allows you to send any string you want to the modem.

The next command dials the remote server. The dial command sends a standard Hayes ATD dial command to the modem. It passes the entire string provided on the command line to the modem as part of the ATD command. The sample dial command generates ATD*70,301-555-1234. This causes the modem to dial *70 (which turns off call waiting), and then area code 301, exchange 555, and number 1234. [14] When this modem successfully connects to the remote modem, it displays the message CONNECT. The wait command waits for that message from the modem.

[14] If you have call waiting, turn it off before you attempt to make a SLIP or PPP connection. Different local telephone companies may use different codes to disable call waiting.

The sleep 2 command inserts a two-second delay into the script. It is often useful to delay at the beginning of the connection to allow the remote server to initialize. Remember that the CONNECT message is displayed by the modem, not by the remote server. The remote server may have several steps to execute before it is ready to accept input. A small delay can sometimes avoid unexplained intermittent problems.

The send command sends a carriage return (\r) to the remote system. Once the modems are connected, anything sent from the local system goes all the way to the remote system. The send command can send any string. In the sample script the remote server requires a carriage return before it issues its first prompt. The carriage return is entered as \r and the newline is entered as \n.

The remote server then prompts for the username with Login>. The wait ogin> command detects this prompt and the send kristin command sends the username kristin as a response. The server then prompts for the password with Password>. The password command causes the script to ask the local user to manually enter the password. It is possible to store the password in a send command inside the script. However, this is a potential security problem if an unauthorized person gains access to the script and reads the password. The password command improves security.

If the password is accepted, our remote server prompts for input with the greater than (>) symbol. Many servers require a command to set the correct protocol mode. The server in our example supports several different protocols. We must tell it to use PPP by using send to pass it the correct command.

The script finishes with a few commands that set the correct environment on the local host. The mode command tells the local host to use the PPP protocol on this link. The protocol selected must match the protocol running on the remote server. Protocol values that are valid for the dip mode command are SLIP, CSLIP, PPP, and TERM. SLIP and CSLIP are variations of the SLIP protocol, which is discussed in the next section. TERM is terminal emulation mode. PPP is the Point-to-Point Protocol. Finally, the exit command ends the script, while dip keeps running in the background servicing the link.

This simple script does work and it should give you a good idea of the wait/send structure of a dip script. However, your scripts will probably be more complicated. The sample script is not robust because it does not do any error checking. If an expected response does not materialize, the sample script hangs. To address this problem, use a timeout on each wait command. For example, the wait OK 10 command tells the system to wait 10 seconds for the OK response. When the OK response is detected, the $errlvl script variable is set to zero and the script falls through to the next command. If the OK response is not returned before the 10-second timer expires, $errlvl is set to a non-zero value and the script continues on to the next command. The $errlvl variable is combined with the if and goto commands to provide error handling in dip scripts. Refer to Appendix A for more details.

Once the script is created it is executed with the dip command. Assume that the sample script shown above was saved to a file named start-ppp.dip. The following command executes the script, creating a PPP link between the local system and the remote server:

> dip start-ppp

Terminate the PPP connection with the command dip -k. This closes the connection and kills the background dip process.

pppd options are not configured in the dip script. dip creates the PPP connection; it doesn't customize pppd. pppd options are stored in the /etc/ppp/options file.

Assuming the dip script shown above, we might use the following pppd options:

noipdefault
ipcp-accept-local
ipcp-accept-remote
defaultroute

The noipdefault option tells the client not to look up the local address. ipcp-accept-local tells the client to obtain its local address from the remote server. The ipcp-accept-remote option tells the system to accept the remote address from the remote server. Finally, pppd sets the PPP link as the default route. This is the same defaultroute option we saw on the pppd command line in an earlier example. Any pppd option that can be invoked on the command line can be put in the /etc/ppp/options file and thus be invoked when pppd is started by a dip script.

I use dip on my home computer to set up my dial PPP connection. Personally, I find dip simple and straightforward to use. In part, that is because I am familiar with the dip scripting language. You may prefer to use the chat command that comes with the pppd software package.

6.3.3 chat

A chat script is a simple "expect/send" script consisting of the strings the system expects and the strings the system sends in response. The script is organized as a list of expect/send pairs. chat does not really have a scripting language, but it does have some special characters that can be used to create more complex scripts. The chat script to perform the same dial-up and login functions as the sample dip script would contain:

'' ATZ
OK ATDT*70,301-555-1234
CONNECT \d\d\r
ogin> kristin
word> Wats?Wat?
> 'set port ppp enabled'

Each line in the script begins with an expected string and ends with the string sent as a response. The modem does not send a string until it receives a command. The first line on the script says, in effect, "expect nothing and send the modem a reset command." The pair of single quotes (") at the beginning of the line tells chat to expect nothing. The script then waits for the modem's OK prompt and dials the remote server. When the modem displays the CONNECT message, the script delays two seconds (\d\d) and then sends a carriage return (\r). Each \d special character causes a one-second delay. The \r special character is the carriage return. chat has many special characters that can be used in the expect strings and the send strings. [15] Finally, the script ends by sending the username, password, and remote server configuration command in response to the server's prompts.

[15] See Appendix A for more details.

Create the script with your favorite editor and save it in a file such as dial-server. Test the script using chat with the -V option, which logs the script execution through stderr:

% chat -V -f dial-server

Invoking the chat script is not sufficient to configure the PPP line. It must be combined with pppd to do the whole job. The connection command-line option allows you to start pppd and invoke a dial-up script all in one command:

# pppd /dev/cua1 56700 connect "chat -V -f dial-server" \
     -detach crtscts modem defaultroute

The chat command following the connect option is used to perform the dial-up and login. Any package capable of doing the job could be called here; it doesn't have to be chat.

The pppd command has some other options that are used when PPP is run as a dial-up client. The modem option causes pppd to monitor the carrier-detect (DCD) indicator of the modem. This indicator tells pppd when the connection is made and when the connection is broken. pppd monitors DCD to know when the remote server hangs up the line. The -detach option prevents pppd from detaching from the terminal to run as a background process. This is only necessary when running chat with the -V option. When you are done debugging the chat script, you can remove the -V option from the chat subcommand and the -detach option from the pppd command. An alternative is to use -v on the chat command. -v does not require pppd to remain attached to a terminal because it sends the chat logging information to syslogd instead of to stderr. We have seen all of the other options on this command line before.

6.3.4 PPP Daemon Security

A major benefit of PPP over SLIP is the enhanced security PPP provides. Put the following pppd options in the /etc/ppp/options file to enhance security:

lock
auth
usehostname
domain nuts.com

The first option, lock, makes pppd use UUCP-style lock files. This prevents other applications, such as UUCP or a terminal emulator, from interfering with the PPP connection. The auth option requires the remote system to be authenticated before the PPP link is established. This option causes the local system to request authentication data from the remote system. It does not cause the remote system to request similar data from the local system. If the remote system administrator wants to authenticate your system before allowing a connection, she must put the auth keyword in the configuration of her system. The usehostname option requires that the hostname is used in the authentication process and prevents the user from setting an arbitrary name for the local system with the name option. (More on authentication in a minute.) The final option makes sure that the local hostname is fully qualified with the specified domain before it is used in any authentication procedure.

Recall that the ~/.ppprc file and the pppd command-line options can override options set in the /etc/ppp/options file, which could be a security problem. For this reason, several options, once configured in the /etc/ppp/options file, cannot be overridden. That includes the options just listed.

pppd supports two authentication protocols: Challenge Handshake Authentication Protocol (CHAP) and Password Authentication Protocol (PAP). PAP is a simple password security system that is vulnerable to all of the attacks of any reusable password system. CHAP, however, is an advanced authentication system that does not use reusable passwords and that repeatedly re-authenticates the remote system.

Two files are used in the authentication process, the /etc/ppp/chap-secrets file and the /etc/ppp/pap-secrets file. Given the options file shown above, pppd first attempts to authenticate the remote system with CHAP. To do this, there must be data in the chap-secrets file and the remote system must respond to the CHAP challenge. If either of these conditions are not true, pppd attempts to authenticate the remote system with PAP. If there is no applicable entry in the pap-secrets file or the remote system does not respond to the PAP challenge, the PPP connection is not established. This process allows you to authenticate remote systems with CHAP (the preferred protocol), if they support it, and to fall back to PAP for systems that support only PAP. For this to work, however, you must have the correct entries in both files.

Each entry in the chap-secrets file contains up to four fields:

client

The name of the computer that must answer the challenge, i.e., the computer that must be authenticated before the connection is made. This is not necessarily a client that is seeking access to a PPP server. Client is the term used in most of the documentation, but really this is the respondent - the system that responds to the challenge. Both ends of a PPP link can be forced to undergo authentication. In your chap-secrets file you will probably have two entries for each remote system: one entry to authenticate the remote system and a corresponding entry to authenticate your system when it is challenged by the remote system.

server

The name of the system that issues the CHAP challenge, i.e., the computer that requires the authentication before the PPP link is established. This is not necessarily a PPP server. The client system can require the server to authenticate itself. Server is the term used in most documentation, but really this is the authenticator - the system that authenticates the response.

secret

The secret key that is used to encrypt the challenge string before it is sent back to the system that issued the challenge.

address

An address, written as a hostname or an IP address, that is acceptable for the host named in the first field. If the host listed in the first field attempts to use an address other than the address listed here, the connection is terminated even if the remote host properly encrypts the challenge response. This field is optional.

A sample chap-secrets file for the host macadamia might contain:

cashew     macadamia  Peopledon'tknowyou    172.16.15.3
macadamia  cashew     andtrustisajoke.      172.16.15.1

The first entry is used to validate cashew, the remote PPP server. cashew is being authenticated and the system performing the authentication is macadamia. The secret key is "Peopledon'tknowyou". The allowable address is 172.16.15.3, which is the address assigned to cashew in the host table. The second entry is used to validate macadamia when cashew issues the challenge. The secret key is "andtrustisajoke.". The only address macadamia is allowed to use is 172.16.15.1. A pair of entries, one for each end of the link, is normal. The chap-secret file usually contains two entries for every PPP link: one entry for validating the remote system and one entry for answering the challenge of that remote system.

Use PAP only when you must. If you deal with a system that does not support CHAP, make an entry for that system in the pap-secrets file. The format of pap-secrets entries is the same as those used in the chap-secrets file. A system that does not support CHAP might have the following entry in the pap-secrets file:

acorn     macadamia  Wherearethestrong?  acorn.nuts.com
macadamia acorn      Whoarethetrusted?   macadamia.nuts.com

Again we have a pair of entries: one for the remote system and one for our system. We support CHAP but the remote system does not. Thus we must be able to respond using the PAP protocol in case the remote system requests authentication.

PPP authentication improves security in a dial-up environment. It is most important when you run the PPP server into which remote systems dial. In the next section, we look at PPP server configuration.

6.3.5 PPP Server Configuration

The PPP server is started by the /etc/ppp/ppplogin script. [16] ppplogin is a login shell script for dial-in PPP users. Replace the login shell entry in the /etc/passwd file with the path of ppplogin to start the server. A modified /etc/passwd entry might contain:

[16] The example is for Linux systems running pppd. It may be different on your system. Check your system's documentation.

craig:wJxX.iPuPzg:101:100:Craig Hunt:/tmp:/etc/ppp/ppplogin

The fields are exactly the same as any /etc/passwd entry: username, password, uid, gid, gcos information, home directory, and login shell. For a remote PPP user, the home directory is /tmp and the login shell is the full path of the ppplogin program. The encrypted password must be set using the passwd program, just as it is for any user. And the login process is the same as it is for any user. When getty detects incoming traffic on the serial port it invokes login to authenticate the user. login verifies the username and the password entered by the user and starts the login shell. In this case the login shell is actually a shell script that configures the PPP port and starts the PPP daemon. Our sample /etc/ppp/ppplogin script is:

#!/bin/sh
mesg -n
stty -echo
exec /sbin/pppd auth passive crtscts modem

The first two lines demonstrate that the ppplogin file can contain more than just the pppd command. The mesg -n command makes sure that other users cannot write to this terminal with talk, write, or similar programs. The stty command turns off character echoing. On some systems, characters typed at the terminal are echoed from the remote host instead of being locally echoed by the terminal; this behavior is called full duplex. We don't want to echo anything back on a PPP link, so we turn full duplex off.

The key line in the script is, of course, the line that starts pppd. We start the daemon with several options, but one thing that is not included on the command line is the tty device name. In all of the previous pppd examples, we provided a device name. When it is not provided, as is this case, pppd uses the controlling terminal as its device and doesn't put itself in background mode. This is just what we want. We want to use the device that login was servicing when it invoked the ppplogin script.

The auth command-line option tells pppd to authenticate the remote system, which of course requires us to place an entry for that system in the chap-secrets or the pap-secret file. The crtscts option turns on hardware flow control, and the modem option tells PPP to monitor the modem's DCD indicator so that it can detect when the remote system drops the line. We have seen all of these options before. The one new option is passive. With passive set, the local system waits until it receives a valid LCP packet from the remote system, even if the remote system fails to respond to its first packet. Normally, the local system would drop the connection if the remote system fails to respond in a timely manner. This option gives the remote system time to initialize its own PPP daemon.

Creating an appropriate ppplogin script and defining it as a login shell in the /etc/passwd file are all that is necessary to run pppd as a server.

6.3.6 Solaris PPP

dip and pppd are available for Linux, BSD, AIX, Ultrix, OSF/1, and SunOS. If you have a different operating system, you probably won't use these packages. Solaris is a good example of a system that uses a different set of commands to configure PPP.

PPP is implemented under Solaris as the Asynchronous PPP Daemon (aspppd). aspppd is configured by the /etc/asppp.cf file. The asppp.cf file is divided into two sections: an ifconfig section and a path section.

ifconfig ipdptp0 plumb macadamia cashew up

path
   interface ipdptp0
   peer_system_name cashew
   inactivity_timeout 300

The ifconfig command configures the PPP interface (ipdptp0) as a point to point link with a local address of macadamia and a destination address of cashew. The ifconfig command does not have to define the destination address of the link. However, if you always connect to the same remote server, it will probably be defined here as the destination address. We saw all of these options in the discussion of the ifconfig command earlier in this chapter.

The more interesting part of this file is the path section, which defines the PPP environment. The interface statement identifies the interface used for the connection. It must be one of the PPP interfaces defined in the ifconfig section. In the example, only one is defined, so it must be ipdptp0. The peer_system_name statement identifies the system at the remote end of the connection, which may be the same address as the destination address from the ifconfig statement as it is in our example. But it doesn't have to be. It is possible to have no destination address on the ifconfig command and several path sections if you connect to several different remote hosts. The hostname on the peer_system_name statement is used in the dialing process as described later.

The path section ends with an inactivity_timeout statement. The command in the sample sets the timeout to 300 seconds. This is interesting because it points to a nice feature of the Solaris system. Solaris automatically dials the remote system when it detect data that needs to be delivered through that system. Further, it automatically disconnects the PPP link when it is inactive for the specified time. With this feature you can use a PPP link without manually initiating the dial program and without tying up phone lines when the link is not in use.

Like pppd, aspppd does not have a built-in dial facility. It relies on an external program to do the dialing. In the case of aspppd, it utilizes the dial-up facility that comes with UUCP. Here's how.

First, the serial port, the modem attached to it, and the speed at which they operate are defined in the /etc/uucp/Devices file. For example, here we define an Automatic Call Unit (ACU is another name for a modem) attached to serial port B (cua/b) that operates at any speed defined in the Systems file, and that has the modem characteristics defined by the "hayes" entry in the Dialers file:

ACU cua/b - Any hayes

Next, the modem characteristics, such as its initialization setting and dial command, are defined in the /etc/uucp/Dialers file. The initialization and dial commands are defined as a chat script using the standard expect/send format and the standard set of chat special characters. For example:

hayes =,-, "" \dA\pTE1V1X1Q0S2=255S12=255\r\c OK\r \EATDT\T\r\c CONNECT

The system comes with Devices and Dialers pre-configured. The pre-configured entries are probably compatible with the modem on your system. The /etc/uucp/Systems file may be the only configuration file that you modify. In the systems file you need to enter the name of the remote system, select the modem you'll use, enter the telephone number, and enter a chat script to handle the login. For example:

cashew Any ACU 19200 5551234 "" \r ogin> kristin word> Wats?Watt? >
     set ppp on

In this one line, we identify cashew as the remote system, declare that we allow connections to and from that hosts at any time of the day (Any), select the ACU entry in the Devices file to specify the port and modem, set the line speed to 19200, send the dialer the telephone number, and define the login chat script.

This is not a book about UUCP, so we won't go into further details about these files. I'd suggest Using and Managing UUCP (by Ed Ravin, O'Reilly & Associates) for more information about UUCP and the Solaris TCP/IP Network Administration Guide (where did they come up with such a great name?) for more information about aspppd.


Previous: 6.2 TCP/IP Over a Serial Line TCP/IP Network AdministrationNext: 6.4 Installing SLIP
6.2 TCP/IP Over a Serial Line Book Index6.4 Installing SLIP