Red Hat Linux 7 Unleashed

Red Hat Linux 7 Unleashed

By William Ball

Setting Up PPP

Most dial-up ISPs today use PPP instead of SLIP. This is good for you because PPP is a faster and more efficient protocol. PPP and SLIP are both designed for two-way networking; in other words, your machine talking to one other machine—usually your ISP—and no other machines at the time (although it is possible to communicate with other computers on your internal network). PPP is not a replacement for a LAN protocol such as TCP/IP, but PPP can coexist with TCP/IP (which provides a transport protocol for data).

One of the major hurdles new Linux users face is setting up PPP and connecting to the Internet. If you're new to Linux, relax! You don't have to understand the intricacies of the protocol in order to use PPP, and setting up PPP on your system is not as scary as you might suspect (although if you want to examine the gritty details, look at the file ppp.c under the /usr/src/linux/drivers/net directory). You can do it manually from the command line, or by using one of several graphical interface clients. Both approaches produce the same results. However, using the command line offers the advantage that you get to understand what is going on and can use connection commands in shell scripts or crontab entries. See the section "Setting up PPP Using the PPP Scripts" for details on using shell scripts instead of the command line.

PPP uses two components on your system. The first is a daemon called pppd, which controls the use of PPP. The second is a driver called the high-level data link control (HDLC), which controls the flow of information between two machines. A third component of PPP is a routine called chat that dials the other end of the connection for you when you want it to.

Installing PPP

PPP was most likely installed for you when you installed Red Hat Linux. If it wasn't, you need to load the package before you can continue to configure the system for PPP use. The PPP library and files are included with practically every CD-ROM distribution of Linux, and you can obtain the most recent versions from the usual Linux Web and FTP sites.

You can quickly check to see if PPP is installed on your system by using the rpm command's -q option, like this:

					
   # rpm -q ppp
ppp-2.3.11-7

This example shows that PPP is installed. If for some reason PPP is not installed on your system, use Red Hat's rpm command to install the PPP package from your Red Hat Linux CD-ROM. Red Hat Linux includes version 2.3.11 of PPP. You can easily install the .rpm package (after downloading or copying from CD-ROM) like this:

					
   # rpm -ivh ppp-2.3.11-7.i386.rpm
				

Setting Up a PPP User Account

To help protect your system from hackers and break-in attempts from your ISP (remember that if your machine can communicate to the Internet, users on the Internet can communicate with your machine), it is advisable to set up a special user login for PPP. This step is optional but highly recommended.

You can add the new user account for PPP (usually called ppp for convenience) using any of the user administration scripts you want, or you can simply edit the /etc/passwd file and add the user yourself (only if you do not use password shadowing). Because the PPP login does not have a home directory per se, you don't need to create mail boxes and other paraphernalia that is normally created by a user administration script. The line you want to add to the /etc/passwd file looks like this:

ppp:*:301:51:PPP account:/tmp:/etc/ppp/pppscript

This creates a user called ppp with no password. (The asterisk in the second field can't be matched.) The user ID is 301 in this example, but you can substitute any unused user ID. The group ID is best set to a new group called ppp, although this is not necessary. The fourth field is a comment that describes the account's purpose. The home directory is set to /tmp in this case because you don't want to keep files in the ppp account home directory. The last field in the /etc/passwd entry is used for a startup script. In this case, I've created a new script called /etc/ppp/pppscript, which takes care of starting PPP properly. You will have to create this script yourself. The contents of pppscript should look like this:

#!/bin/sh
mesg n
stty -echo
exec pppd -detach silent modem crtscts

The first line invokes the Bourne shell to run the script. The second line suppresses messages for this login. The third line stops the remote from echoing everything back. The fourth line invokes the pppd daemon with some options that control its behavior. (You'll look at the pppd daemon in more detail in a few moments.) Make sure the file pppscript is executable.

Setting Up chat

Because you are going to use a modem to connect to your ISP, you need to tell PPP about the modem and how to use it. PPP uses a program called chat to handle all these details. (You can use utilities other than chat, but experience has shown that chat is the most foolproof of the options as well as one of the easiest to set up quickly.) The chat utility takes a lot of its features from the UUCP program, which makes it familiar for many veteran system administrators.

The chat utility requires a command line that tells it what number to call to connect to your ISP and what types of login responses are required. All of this information is placed on a single-line chat script. These lines are often stored in files to prevent you from having to type the commands every time you want to access the Internet.

Here's a typical chat script for a connection to an ISP:

"" ATZ OK ATDT2370400 CONNECT "" ogin: ppp word: guessme

In this example, the ISP's phone number is 237-0400, while the username and password to login are ppp and guessme. chat scripts are always set up as a conversation between the chat utility and the modem. The script parts are separated by spaces, with the chat instruction and the expected reply one after another. This chat script tells chat the following: Expect nothing from the modem to start (the two quotation marks), then send the string ATZ and wait for the reply OK. After OK is received, chat sends the string ATDT2370400 to dial out to the ISP's number. When a CONNECT string is received from the modem, send nothing and wait for the string ogin: from the ISP. (This covers all the case types such as login and Login.) After getting ogin:, send the login ppp and wait for word: (the end of password) and send the password guessme. After that, chat terminates and hands control over to PPP.

You can see in the script how the conversation goes through with each end (the modem and chat) taking turns communicating. You will need to set up a chat script like this in a file with your ISP's number and the proper login and password. Place it in an ASCII file. Use the chat command to call the file:

chat -f filename

filename is the name of the chat script file. The chat command has a lot of options for handling error conditions from your modem and the ISP, but these all complicate the script quite a bit. The easiest modifications are to build in handling for both a busy signal from the modem (the ISP's line was busy) or a no-carrier message from the modem (when it couldn't connect properly). To handle both these error conditions in the script and have chat terminate when these conditions occur, modify the script to look like this:

ABORT BUSY ABORT 'NO CARRIER'"" ATZ OK ATDT2370400
\  CONNECT "" ogin: ppp word: guessme

The two ABORT sequences in front of the older script tell chat to terminate if either the BUSY or NO CARRIER messages are sent by the modem. Make sure you use single quotation marks around the two words in NO CARRIER; otherwise, chat thinks these are two different parts of the script.

Configuring pppd

As mentioned earlier, most of the functions of PPP are controlled by a daemon called pppd. When chat has connected to a remote system and chat terminates cleanly, it hands control of the connection over to pppd. It is the pppd daemon that handles all the communications from this point forward.

The pppd daemon is usually started with arguments for the modem device and the speed of the connection. If you want to start pppd manually from the command line, your command looks like this:

pppd /dev/ttyS0 38400 crtscts defaultroute

This line tells pppd to use the serial port /dev/ttyS0 (COM1) to connect at 38,400bps. The crtscts option tells pppd to use hardware handshaking on the connection, and defaultroute tells pppd to use the local IP address for the connection.

Because most ISPs assign you a dynamic IP address when you connect, you can't hard-code the address into the pppd command line. The pppd daemon can accept any IP address the remote connection wants if you modify the command line like this:

pppd /dev/cua0 38400 crtscts IP_address:
				

You substitute whatever IP address your machine has (even 127.0.0.1) before the colon. The colon with nothing after it tells pppd to accept whatever IP address the remote sends as the other end of the connection.

The pppd daemon accepts options from configuration files if they exist. The most common configuration file for PPP is stored as /etc/ppp/options, although you may use any path and filename you want. The default settings in the /etc/ppp/options file look like this:

# /etc/ppp/options: global definitions

lock                    # use file locking UUCP-style

The single entry tells pppd to use UUCP-like file locking, which works well to prevent device problems. You can add any other valid pppd options to this file, but this suffices for most setups.

Combining chat and pppd

The way I've described setting up chat and pppd, you have to take two steps to connect to an ISP: Use chat to establish the connection and then launch pppd to use PPP over the connection. There is a way to take both steps with one command line, which can be added to the pppscript talked about earlier in this section. By calling chat from the pppd command line, you can simplify the entire process. Here's a modification of the pppd command line that accomplishes this (assuming your modem is attached to /dev/ttyS0):

					
   # /usr/sbin/pppd connect "/usr/sbin/chat -v -f chatfile" /dev/ttyS0 
					
   \115200 -detach crtscts modem defaultroute
Serial connection established.
Using interface ppp0
Connect: ppp0 <--> /dev/ttyS1
local  IP address 207.172.52.61
remote IP address 10.11.64.57

With this command, pppd calls chat with the filename chatfile (or whatever you called your chat script file), creates the link, and then finishes establishing pppd. You must have the path to your chat file easily found by chat or specify the full pathname in the command line. The -v chat option outputs information as the connection is established. As mentioned, you can substitute this line for the pppd line in the pppscript file, and then the connection will be established in one step.

After these few steps, your system is ready to use PPP to dial out to your ISP. As long as the chat script has all the instructions for connecting to the ISP's modem bank, PPP will start properly once a connection is established.

Setting Up PPP Using the PPP Scripts

Manually creating PPP scripts is one way to set up a PPP user account; however, you'll find a dialer, chat script, and PPP on and off scripts under the /usr/share/doc/ ppp-2.3.11/scripts directory when you install Red Hat Linux and PPP. Using these scripts is a lot easier; by performing a few simple edits, you'll be connected in a few minutes!

The important script files are

To set up these scripts, log in as the root operator and copy the scripts to the /etc/ppp directory:

					
   # cp /usr/share/doc/ppp*/scripts/ppp-o* /etc/ppp
				

Open the ppp-on script with your favorite text editor. Look first for the entries for your ISP's phone number and your username and password, like this:

TELEPHONE=555-1212      # The telephone number for the connection
ACCOUNT=george          # The account name for logon (as in 'George Burns')
PASSWORD=gracie         # The password for this account (and 'Gracie Allen')
LOCAL_IP=0.0.0.0        # Local IP address if known. Dynamic = 0.0.0.0
REMOTE_IP=0.0.0.0       # Remote IP address if desired. Normally 0.0.0.0

Change the values for TELEPHONE, ACCOUNT, and PASSWORD, substituting your ISP's phone number and your username and password. Next, scroll through the script until you find this:

exec /usr/sbin/pppd debug lock modem crtscts /dev/ttyS0 38400         asyncmap 20A0000 escape FF kdebug 0 $LOCAL_IP:$REMOTE_IP         noipdefault netmask $NETMASK defaultroute connect $DIALER_SCRIPT

This line of the script contains modem options for the chat script in the ppp-on-dialer script and starts the pppd daemon on your computer following a connection to your ISP's computer. Change the modem device (/dev/ttyS0 in this example) and the baud rate (38,400 in this case) to match your system and desired connection speed. When finished, save the script.

Next, use the chmod command to make these scripts executable like this:

					
   # chmod +x /etc/ppp/ppp-o*
				

To debug or check the progress of your modem connection, dialing, and connection to your ISP, use the tail command with its -f "loop forever" option like this:

					
   # tail -f /var/log/messages
				

Then, to connect to your ISP, execute the ppp-on script (as root):

					
   # /etc/ppp/ppp-on
				

To stop your PPP connection, use the ppp-off script (as root):

					
   # /etc/ppp/ppp-off
				

You can also move the ppp-on and ppp-off scripts to a recognized $PATH, such as /usr/local/bin.

Setting Up PPP with Red Hat's Dialup Configuration Tool

Using a manual PPP chat script or the PPP connection scripts is an easy way to start and stop a PPP connection. These manual scripts have the advantage of working with or without a graphical interface, such as the X Window System. The disadvantage of using these scripts becomes apparent when you must use or maintain multiple ISP accounts, have security issues for passwords, or want the point-and-click convenience of a graphical interface to PPP setup and connections.

Fortunately, Red Hat Linux comes with an easy-to-use dialup configuration tool. You must run an X session in order to use this tool, which is named rp3-config. For example, to start the client using the GNOME desktop panel, click the Programs, Internet menu then click the Dialup Configuration Tool menu item. The tool's window will then appear (as shown in Figure 6.1). Note that you can also start the tool by using the rp3-config command like this from the command line of a terminal window:

					
   # rp3-config
				
06fig01.jpg

Figure 6.1 Red Hat's dialup configuration tool is one way to set up a PPP connection when using Linux.

Click the Next button to start the configuration. If the symbolic link /dev/modem does not exist, you'll see a dialog box as shown in Figure 6.2. Click the Next button to continue.

06fig02.jpg

Figure 6.2 The rp3-config tool can also help you set up your system's modem.

If a modem is found, the tool will display a dialog box, as shown in Figure 6.3. Click the Keep This Modem button, then click Next to continue.

06fig03.jpg

Figure 6.3 Configuring a modem is a snap using Red Hat's new dialup configuration tool.

Next, enter a name for the dialup account (such as name of your ISP), along with the ISP's dialup number, as shown in Figure 6.4.

06fig04.jpg

Figure 6.4 Enter a name and phone number for your PPP connection.

Click the Next button, then enter (in the dialog box shown in Figure 6.5) your assigned username and password (given to you by your ISP).

After you click the Next button, you'll be asked to select your ISP. Click your ISP, click Next, then click Finish to save your account. (Note that you may also have to close any remaining dialogs.) To start your PPP connection from the GNOME's desktop panel, select Programs, Internet, then click the RH PPP Dialer menu item .You can also access this menu from KDE's desktop panel menu. You'll see a small dialog, as shown in Figure 6.6, that lists the ISP accounts you've created.

06fig05.jpg

Figure 6.5 Enter your username and password for your PPP connection.

06fig06.gif

Figure 6.6 Click your ISP, then click OK to start your connection.

To start a PPP connection, first click a desired (defined) ISP, then click OK. Note that in order to successfully connect, you may need to have entries for your ISP's DNS servers in your system's /etc/resolv.conf file.

Setting Up PPP with the kppp Client

Red Hat Linux includes the K Desktop Environment and its suite of graphical clients for X. One of these clients is the kppp tool, a state-of-the-art PPP and Internet connection utility. This client has among its features

To launch the kppp client if you're using a newer version of KDE, click the Application Starter button on the K desktop's panel, select Internet, and click the Internet Dialer menu item (or the kppp menu item if you are using the current stable version of KDE). You can also launch kppp from the command line of a terminal window:

					
   # kppp &
				

The client's main dialog box will appear, as shown in Figure 6.7.

06fig07.gif

Figure 6.7 Click the Setup button to define new PPP accounts.

A Configuration dialog box appears when you click the Setup button. The dialog box is shown in Figure 6.8.

06fig08.gif

Figure 6.8 Click the New button to start configuring a PPP account.

If you click the New button, you'll be asked if you want to use KDE's new PPP wizard, or to go through the standard, dialog-based setup, as shown in Figure 6.9.

06fig09.gif

Figure 6.9 KDE's kppp now offers a wizard-based setup for PPP connections for seven different countries.

If you live in Austria, Denmark, Germany, New Zealand, Norway, Portugal, or the United Kingdom and you're using the latest version of kppp, click the Wizard button, and you'll then be asked a series of questions regarding your account and ISP. U.S. users should select the Dialog setup button. A New Account dialog box then appears, as shown in Figure 6.10.

06fig10.gif

Figure 6.10 Enter a name and phone number for your PPP connection, then select the type of Authentication.

Enter the name of your ISP, along with your ISP's phone number. Most users will then want to select an Authentication, such as Script-based. When finished, click the IP tab at the top of the New Account dialog box. You'll see the IP dialog box like that shown in Figure 6.11 in which you select the type of IP address assigned to your computer after establishing a PPP connection with your ISP. If your account provides a static, or permanent IP address, enter that information in the IP dialog box.

06fig11.gif

Figure 6.11 Select dynamic addressing or enter a static IP address if assigned from your ISP.

When finished, click the DNS tab in the New Account dialog box. The DNS, or Domain Name Services, dialog box shown in Figure 6.12 is used to specify the domain name and IP address(es) of your ISP's DNS servers. These servers provide translation service of active hostnames to IP numbers and back again.

06fig12.gif

Figure 6.12 Enter your ISP's domain name and DNS IP addresses in the dialog box.

To enter a DNS IP address, type in each IP number (provided by your ISP) and then click the Add button. When finished, click the Login Script tab (if you use the common script-based log in procedure). The Login Script dialog box appears, as shown in Figure 6.13.

06fig13.gif

Figure 6.13 Login scripts for usernames and passwords are entered in the Login Script dialog box.

The script used here is in the form expect prompt, send prompt, and is similar to the chat script discussed earlier in this chapter. Select the Expect keyword and then type in a portion of the prompt (such as ogin:) and click the Add button. Since your ISP will next expect a username, select the Send keyword and then type in your username and click the Add button. Repeat this step for your password. When finished, click OK. You'll see the Accounts dialog box as shown in Figure 6.14.

06fig14.gif

Figure 6.14 When you finish defining your PPP account, make sure to check the device, modem, and PPP settings for kppp.

Click the Device tab to configure your modem (as shown in Figure 6.15).

06fig15.gif

Figure 6.15 The Device tab in the kppp Configuration dialog box is used for modem settings.

Select the correct device and connection speed for your modem. When finished, click the Modem tab. A dialog box appears, as shown in Figure 6.16.

06fig16.gif

Figure 6.16 The Modem tab in the kppp Configuration dialog box is used to set default modem commands and to query or test your modem.

Use the buttons in the dialog box to change the default modem AT commands, to query your modem, or to test your modem by using kppp's built-in terminal program. You can also change your modem's volume by using the slider control in the dialog box. When finished, click the Misc. tab at the top of the dialog box. The options dialog box will appear, as shown in Figure 6.17.

06fig17.gif

Figure 6.17 Use the Misc. tab in the kppp Configuration dialog box to set how kppp uses its interface.

Select or unselect the various options in this dialog box according to your taste. If you click Dock into Panel on Connect, kppp will display a tiny modem icon with blinking send and receive lights! When finished, click OK. You'll see the main kppp window that is shown in Figure 6.18.

06fig18.gif

Figure 6.18 To start your PPP connection, click the Connect button in the KPPP window.

If you click Show Log Window (see Figure 6.18) and then click the Connect button to start your PPP connection, you'll see a login script window (see Figure 6.19).

06fig19.gif

Figure 6.19 The kppp login script window shows dialing and connection progress of your connection.

If you've set kppp to dock in your KDE panel, you can then right-click the resulting tiny modem icon in panel and select Details from the pop-up menu. A kppp Statistics dialog box appears, as shown in Figure 6.20. The dialog box shows your PPP connection's IP addresses, modem status lights, various packet information (similar to information returned by the pppstats command), and a scrolling load indicator of your PPP activity for the session.

06fig20.gif

Figure 6.20 The kppp Statistics window shows detailed PPP connection information, along with a load progress of your connection.

To close your connection, right-click the kppp indicator in your panel and then click the Disconnection menu item.

Setting Up PPP Using the wvdial Command

The wvdial command is yet another connection tool you'll find in your Red Hat Linux distribution. This command-line tool uses a single configuration file named wvdial.conf, located under the /etc directory. You can quickly create a bare-bones configuration file using the wvdialconf command like this:

					
   # wvdialconf /etc/wvdial.conf
Scanning your serial ports for a modem.
ttyS1<*1>: ATQ0 V1 E1 -- OK
ttyS1<*1>: ATQ0 V1 E1 Z -- OK
ttyS1<*1>: ATQ0 V1 E1 S0=0 -- OK
ttyS1<*1>: ATQ0 V1 E1 S0=0 &C1 -- OK
ttyS1<*1>: ATQ0 V1 E1 S0=0 &C1 &D2 -- OK
ttyS1<*1>: ATQ0 V1 E1 S0=0 &C1 &D2 S11=55 -- OK
ttyS1<*1>: ATQ0 V1 E1 S0=0 &C1 &D2 S11=55 +FCLASS=0 -- OK
...

The command will scan your computer's serial ports, test any found modem, and then create your wvdial.conf file. You should then open the file with your favorite text editor and edit the Dialer Defaults section. The default will look like this:

[Dialer Defaults]
Modem = /dev/ttyS1
Baud = 115200
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 S11=55 +FCLASS=0
; Phone = <Target Phone Number>
; Username = <Your Login Name>
; Password = <Your Password>

Remove the leading semicolon (;) in the last three lines, then replace the information between brackets with your ISP's phone number, and your username and password. The change may look something like this:

[Dialer Defaults]
Modem = /dev/ttyS1
Baud = 115200
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 S11=55 +FCLASS=0
Phone = 703 321 4887
Username = bball
Password = mypassword
				

Save the file, then start your connection from the command line using the wvdial command, like this:

					
   # wvdial
--> WvDial: Internet dialer version 1.41
--> Initializing modem.
--> Sending: ATZ
ATZ
OK
--> Sending: ATQ0 V1 E1 S0=0 &C1 &D2 S11=55 +FCLASS=0
ATQ0 V1 E1 S0=0 &C1 &D2 S11=55 +FCLASS=0
OK
--> Modem initialized.
--> Sending: ATDT 703 321 4887
--> Waiting for carrier.
ATDT 703 321 4887
CONNECT 115200 V42bis
--> Carrier detected.  Waiting for prompt.
** Ascend TNT8.BRD Terminal Server **
Login:
--> Looks like a login prompt.
--> Sending: bball
bball
Password:
--> Looks like a password prompt.
--> Sending: (password)
    Entering PPP Session.
    IP address is 207.172.33.49
    MTU is 1006.
--> Looks like a welcome message.
--> Starting pppd at Wed Jul 12 20:21:30 2000

The wvdial command will output diagnostic information during the connection, and will even reconnect if the connection is dropped! To end your session, press Ctrl+C.

Share ThisShare This

Informit Network