Узбекистан, Бухара, Бухарский институт высоких технологий, 2013 |
Configuring PPP
Dynamic IP configuration
If you have to accept dynamic IP addresses, user PPP can help. In fact, it provides fine control over which addresses you accept and which you do not. To allow negotiation of IP addresses, you specify how many bits of the IP addresses at each end are of interest to you. For static addresses, you can specify them exactly:
set ifaddr 139.130.136.133 139.130.136.129
You can normally maintain some control over the addressing, for example to ensure that the addresses assigned don't confict with other network connections. The addresses assigned to you when the link comes up are almost invariably part of a single subnet. You can specify that subnet and allow negotiation of the host part of the address. For example, you may say " I don't care what address I get, as long as the first three bytes are 139.130.136, and the address at the other end starts with 139. " You can do this by specifying the number of bits that interest you after the address:
set ifaddr 139.130.136.133/24 139.130.136.129/8
This says that you would prefer the addresses you state, but that you require the first 24 bits of the local interface address and the first eight bits of the remote interface address to be as stated.
If you really don't care which address you get, specify the local IP address as 0:
set ifaddr 0 0
If you do this, you can't use the -auto modes, because you need to send a packet to the interface to trigger dialing. Use one of the previous methods in this situation.
Running user PPP
After setting up your PPP configuration, run it like this:
$ ppp Working in interactive mode Using interface: tun0 ppp ON freebie> dial papchap this is the name of the entry in ppp.conf Dial attempt 1 of 1 Phone: 1234567 the phone number dial OK! modem connection established login OK! authentication complete ppp ON freebie> Packet mode. PPP is running ppp ON freebie> PPP ON freebie> and the network connection is complete
You'll notice that the prompt (ppp) changes to upper case (PPP) when the connection is up and running. At the same time, ppp writes some messages to the log file /var/log/ppp.log:
Sep 2 15:12:38 freebie ppp[23679]: Phase: Using interface: tun0 Sep 2 15:12:38 freebie ppp[23679]: Phase: PPP Started. Sep 2 15:12:47 freebie ppp[23679]: Phase: Phone: 1234567 Sep 2 15:13:08 freebie ppp[23679]: Phase: *Connected! Sep 2 15:13:11 freebie ppp[23679]: Phase: NewPhase: Authenticate Sep 2 15:13:11 freebie ppp[23679]: Phase: his = c223, mine = 0 Sep 2 15:13:11 freebie ppp[23679]: Phase: Valsize = 16, Name = way3.Adelaide Sep 2 15:13:11 freebie ppp[23679]: Phase: NewPhase: Network Sep 2 15:13:11 freebie ppp[23679]: Phase: Unknown protocol 0x8207 Sep 2 15:13:11 freebie ppp[23679]: Link: myaddr = 139.130.136.133 hisaddr = 139.1 30.136.129 Sep 2 15:13:11 freebie ppp[23679]: Link: OsLinkup: 139.130.136.129 Sep 2 15:14:11 freebie ppp[23679]: Phase: HDLC errors -> FCS: 0 ADDR: 0 COMD: 0 PRO TO: 1
You'll notice a couple of messages that look like errors. In fact, they're not: Unknown protocol 0x8207 means that the other end requested a protocol that ppp doesn’t know (and, in fact, is not in the RFCs. This is a real example, and the protocol is in fact Novell's lPX). The other message is HDLC errors -> FCS: 0 ADDR: 0 COMD: 0 PROTO: 1. In fact, this relates to the same " problem. "
How long do we stay connected?
The following entries in /etc/defaults/rc.conf relate to user ppp:
#User ppp configuration. ppp_enable="NO" # Start user-ppp (or NO). ppp_mode="auto" # Choice of "auto", "ddial", "direct" or "dedicated". #For details see man page for ppp(8). Default is auto. ppp_nat="YES" # Use PPP's internal network address translation or NO. ppp_profile="papchap" # Which profile to use from /etc/ppp/ppp. conf. ppp_user="root" # Which user to run ppp as
Now our PPP connection is up and running. How do we stop it again? There are two possibilities:
- To stop the connection, but to leave the ppp process active, enter close:
PPP ON freebie> close ppp ON freebie>
- To stop the connection and the ppp process, enter q or quit:
PPP ON freebie> q #
There are a couple of problems with this method: first, a connection to an ISP usually costs money in proportion to the time you are connected, so you don’t want to stay connected longer than necessary. On the other hand, you don’t want the connection to drop while you're using it. User PPP approaches these problems with a compromise: when the line has been idle for a certain time (in other words, when no data has gone in either direction during this time), it disconnects. This time is called the idle timeout, and by default it is set to 180 seconds. You can set it explicitly:
set timeout 300
This sets the idle timeout to 300 seconds (5 minutes).
Automating the process
Finally, setting up the connection this way takes a lot of time. You can automate it in a number of ways:
- If you have a permanent connection, you can tell user PPP to stay up all the time. Use the -ddial modifier:
$ ppp -ddial papchap
Again, papchap is the name of the PPP profile. This version dials immediately and keeps the connection up regardless of whether traffic is passing or not.
- If you want to be able to connect to the Net automatically whenever you have something to say, use the -auto modifer:
$ ppp -auto papchap
In this case, user PPP does not dial immediately. As soon as you attempt to send data to the Net, however, it dials automatically. When the line has been idle for the idle timeout period, it disconnects again and waits for more data before dialing. This only makes sense for static addresses or when you know that no IP connections remain alive after the line disconnects.
- Finally, you can just write
$ ppp -background papchap
The -background option tells user PPP to dial immediately and stay in the background. After the idle timeout period, the user PPP process disconnects and exits. If you want to connect again, you must restart the process.