672 674




Linux Unleashed, Third Edition:SLIP and PPP





-->















Previous
Table of Contents
Next




Dialing Out with chat
PPP requires you to establish a modem connection to the remote machine before it can take over and handle the communications. There are several utilities available to do this, although the most commonly used is chat. The chat program is popular because it uses a scripting style similar to that used by UUCP.
To use chat, assemble a command line that looks almost the same as a UUCP /etc/Systems file entry. For example, to call a remote machine with a Hayes-compatible modem (using the AT command set) at the number 555-1234, use the following command. It is formatted as a chat script, UUCP style:


chat “” ATZ OK ATDT5551234 CONNECT “” login: ppp word: secret1


All the entries are in UUCP’s send-expect format, with whatever you send to the specified remote located after what you receive from it. The chat script always starts with an expect string, which must be set to empty because the modem won’t respond without any signal to it. After the empty string, first send the ATZ (reset) command and wait for an OK back from the modem, then send the dial command. After a CONNECT message is received back from the modem, the login script for the remote machine is executed and goes like this: Send a blank character first, then the login: (login) prompt appears, next, send the login name ppp, wait for the word: (password) prompt, and finally, send the password (substituting your login name and password, of course). After the login is complete, chat terminates but leaves the line open.
If the other end of the connection doesn’t answer with a login script as soon as their modem answers, you may have to force a BREAK command down the line to jog the remote end. This is done with the following command:


chat -v “” ATZ OK ATDT5551234 CONNECT “” ogin:-BREAK-ogin: ppp word:
secret1


There’s a security problem with this type of chat entry because any user doing a ps -ef command can see the entire command line (with its passwords). If you are the only user of your system this isn’t a concern, but to save yourself any problems, you can embed the script portion of the command in a file and read the file in to chat. This causes the script to not appear on a ps output. To call a file for use with chat, use the -f option:


chat -f chat_file


The chat_file will contain the following line:


“” ATZ OK ATDT5551234 CONNECT “” login: ppp word: secret1


The chat script can help you detect common error conditions such as a busy line or no connection established. The messages from your modem (the standard Hayes command set uses the messages BUSY and NO CARRIER, respectively) are embedded in the chat script with the ABORT option, which allows you to exit from the chat script gracefully if one of these error conditions occurs. To handle these abort conditions, embed the chat keyword ABORT followed by the message that should trigger an abort, prior to your normal chat script. For example, to modify the chat script above to abort on a BUSY or NO CARRIER message from the modem, the script looks like this:


ABORT BUSY ABORT ’NO CARRIER’ “” ATZ OK ATDT5551234 CONNECT “” login: ppp
word: secret1


We needed two ABORT commands because each takes only one argument. The rest of the chat script is as usual. Note the need to put quotation marks around the NO CARRIER message because otherwise the space in the middle will confuse the script.
Running pppd
If you have a PPP connection already established and your machine is logged in to a remote using the PPP account, you can start the pppd daemon to control the PPP session. If your machine is using the device /dev/cua1 (the Linux designation for the first serial port with modem control) for its PPP connection at 38400 baud, start the pppd daemon with the following command:


pppd /dev/cua1 38400 crtscts defaultroute


This command tells the kernel to switch the interface on /dev/cua1 to PPP and establish an IP link to the remote machine. The crtscts option, which is usually used on any PPP connection above 9600 baud, turns on handshaking.
The local system uses an IP address that is taken from the local hostname unless one is specified on the pppd command line (which you will seldom need to do because the local host IP address should be correct for the PPP line). If you want to force the local or remote IP addresses to be something other than the machine’s default values, you can add the addresses with an option to pppd. The general format is to specify the local IP address, a colon, then the remote IP address:


147.23.43.1:36.23.1.34


When added to the pppd command line, the preceding option sets the local IP address as 147.23.43.1 and the remote IP address to 36.23.1.34, regardless of what the local values are. If you want to modify only one IP address, leave the other portion blank:


147.23.43.1:


This command sets the local IP address and accepts the remote IP address as whatever the machine sends.

You can use chat to establish the connection in the first place, which allows you to embed the chat command as part of the pppd command. This is best done when reading the contents of the chat script from a file (using the -f option). For example, you can issue the pppd command:


pppd connect “chat -f chat_file” /dev/cua1 38400 -detach crtscts modem
defaultroute


chat_file holds the expect-send sequences looked at earlier. You will notice a few modifications to the pppd command other than the addition of the chat command in quotation marks. The -detach command tells pppd not to detach from the console and move to background. The modem keyword tells pppd to monitor the modem port (in case the line drops prematurely) and hang up the line when the call is finished.



Previous
Table of Contents
Next














Wyszukiwarka

Podobne podstrony:
670 672
669 672
672,39,artykul
2012 2lZ2id 674
672 675
674 679
README (674)
README (674)

więcej podobnych podstron