If you asked most people how to get Linux to do dial on demand, they would tell you to usediald. However there is a simpler way of getting it working. This tutorial will show you how to get dial-on-demand working using wvdial and pppd. This is based on a Debian sid machine. This is also based on wvdial 1.53 and pppd 2.4.1. Most of the instruction should apply to other distributions. I assume that you want to connect to the Internet, but everything should apply to any other dial-up PPP connection. This document explains the several steps needed to getting this working.
The first step is to download and install wvdial and pppd. On Debian this can be done by using apt-get: First we make sure that we have the most recent meta-data available:
david root% apt-get update Hit http://nonus.debian.org unstable/non-US/main Packages Hit http://nonus.debian.org unstable/non-US/main Release Hit http://nonus.debian.org unstable/non-US/contrib Packages Hit http://nonus.debian.org unstable/non-US/contrib Release Hit http://nonus.debian.org unstable/non-US/non-free Packages Hit http://nonus.debian.org unstable/non-US/non-free Release Hit http://http.us.debian.org unstable/main Packages Hit http://http.us.debian.org unstable/main Release Hit http://http.us.debian.org unstable/contrib Packages Hit http://http.us.debian.org unstable/contrib Release Hit http://http.us.debian.org unstable/non-free Packages Hit http://http.us.debian.org unstable/non-free Release Hit http://http.us.debian.org unstable/main Sources Hit http://http.us.debian.org unstable/main Release Hit http://http.us.debian.org unstable/contrib Sources Hit http://http.us.debian.org unstable/contrib Release Hit http://http.us.debian.org unstable/non-free Sources Hit http://http.us.debian.org unstable/non-free Release Reading Package Lists... Done Building Dependency Tree... Done
Now we install wvdial and ppp. We don’t want to auto-configure wvdial, because we will be doing that in the next stage
david root% apt-get install ppp wvdial Reading Package Lists... Done Building Dependency Tree... Done The following NEW packages will be installed: ppp wvdial 0 packages upgraded, 2 newly installed, 0 to remove and 42 not upgraded. Need to get 332kB of archives. After unpacking 1032kB will be used. Get:1 http://http.us.debian.org unstable/main ppp 2.4.1.uus-4 [243kB] Get:2 http://http.us.debian.org unstable/main wvdial 18.104.22.168 [89.4kB] Fetched 318kB in 42s (7416B/s) Reading changelogs... Selecting previously deselected package ppp. (Reading database ... 69086 files and directories currently installed.) Unpacking ppp (from .../ppp_2.4.1.uus-4_i386.deb) ... Selecting previously deselected package wvdial. Unpacking wvdial (from .../wvdial_22.214.171.124_i386.deb) ... Setting up ppp (2.4.1.uus-4) ... Setting up wvdial (126.96.36.199) ... WVDIAL AUTOCONFIGURATION WvDial includes a program called wvdialconf, which can automatically detect your modem and create a /etc/wvdial.conf file. Autodetection may cause problems on some computers. Do you want to configure wvdial now? [Y/n] n Okay. You can run wvdialconf later or create /etc/wvdial.conf manually. david root%
Before we can attempt to get dial-on-demand working, we need to make sure that we can dial up our ISP. The easiest way to make a configuration is to use wvdialconf. Don’t worry about any warnings about not finding /etc/wvdial.conf. This is normal and wvdialconf will create it.
david root% wvdialconf /etc/wvdial.conf Scanning your serial ports for a modem. ttyS0<*1>: ATQ0 V1 E1 -- failed with 2400 baud, next try: 4800 baud ttyS0<*1>: ATQ0 V1 E1 -- OK ttyS0<*1>: ATQ0 V1 E1 Z -- OK ttyS0<*1>: ATQ0 V1 E1 S0=0 -- OK ttyS0<*1>: ATQ0 V1 E1 S0=0 &C1 -- OK ttyS0<*1>: ATQ0 V1 E1 S0=0 &C1 &D2 -- OK ttyS0<*1>: ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0 -- ERROR ttyS0<*1>: Modem Identifier: ATI -- 128K ttyS0<*1>: Speed 9600: AT -- OK ttyS0<*1>: Speed 19200: AT -- OK ttyS0<*1>: Speed 38400: AT -- OK ttyS0<*1>: Speed 57600: AT -- OK ttyS0<*1>: Speed 115200: AT -- OK ttyS0<*1>: Max speed is 115200; that should be safe. ttyS0<*1>: ATQ0 V1 E1 S0=0 &C1 &D2 -- OK Found a modem on /dev/ttyS0. /etc/wvdial.conf<Warn>: Can't read config file /etc/wvdial.conf: No such file or directory Modem configuration written to /etc/wvdial.conf. ttyS0<Info>: Speed 115200; init "ATQ0 V1 E1 S0=0 &C1 &D2" david root%
This produced the following /etc/wvdial.conf. You will have a similar file.
[Dialer Defaults] Modem = /dev/ttyS0 Baud = 115200 Init1 = ATZ Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 ISDN = 0 Modem Type = Analog Modem ; Phone = <Target Phone Number> ; Username = <Your Login Name> ; Password = <Your Password>
You can now fill in your ISP’s phone number, your username and password. You should now be able to run wvdial and connect to the Internet. Type wvdial and you should see several lines scroll past and will stop after starting pppd. To stop the connection, press <ctrl> – C. Refer to the wvdial homepage if you can not connect. Some things to check are that wvdialconf detected the right modem init strings for your modem. You should be able to find sensible init strings by looking at any MS Windows inf files for your modem. www.56k.commay be of some help.
I recommend that you re-arrange your wvdial.conf to separate the modem configuration from any ISP account details. Read the wvdial documentation for more information. Here is a similar file to my own.
[Dialer Defaults] Modem = /dev/ttyS0 Baud = 115200 Init1 = ATZ Init2 = AT &FE0x7 Init3 = AT B40 Init4 = AT S84.4=1 Init5 = AT S7=60 S50=0 L1 M1 &K3 &K44 &H3 Init6 = AT S87.2=0 Dial Command = ATDI Auto DNS = off ; use analogue modem [Dialer modem] Modem = /dev/ttyS1 Baud = 115200 Init1 = ATZ Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 S11=55 +FCLASS=0 Init3 = Init4 = Init5 = Init6 = ; display modem information [Dialer info] Init9 = AT&V ; Prevent wvdial reconnecting after being disconnected [Dialer noreconnect] Auto Reconnect = off ; BT Connect Lite service [Dialer ConnectLite] ; BT are stupid. See the man page for details Stupid Mode = on Phone = 08089933024 Username = email@example.com Password = password ; BT OpenWorld service [Dialer btopenworld] ; BT are stupid. See the man page for details Stupid Mode = on Phone = 08089933001 Username = firstname.lastname@example.org Password = password
I use a ISDN TA and have 2 ISP accounts I have also included a few useful sections. This allows me to use a modem if I need to or show information about the current device. You may want to include an option to turn the modem’s speaker off.
david root% wvdial connectlite david root% wvdial btopenworld modem info david root% wvdial connectlite noreconnect
Normally wvdial invokes pppd to negotiate the PPP connection after it has setup to the dial-up connection. We need pppd to invoke wvdial to setup the dial-up connection before it negotiates the PPP connection. Fortunately, wvdial has the ability to behave like the traditional way of using pppd, chap scripts. Unfortunately, when using wvdial normally, it passes various options to pppd on the command line, but as pppd is running wvdial, we can not do this. The solution is to put the options wvdial normally passes on the command line into an options file in /etc/ppp/peers. If you look in this directory, you should find a file called wvdial. Make a copy of this file ad call it something like dod.
david root% cd /etc/ppp/peers/ david root% ls provider wvdial wvdial-pipe david root% cp wvdial dod david root% ls dod provider wvdial wvdial-pipe david root%
We need to find out what options wvdial passes to pppd. We can do that by running wvdial and then looking at pppd’s command line. We can grep the output of ps auxw
router root% wvdial connectlite &  1567 --> WvDial: Internet dialer version 1.53 router root% --> Initializing modem. --> Sending: ATZ OK --> Sending: AT &FE0x7 AT &FE0x7 OK --> Sending: AT B40 OK --> Sending: AT S84.4=1 OK --> Sending: AT S7=60 S50=0 L1 M1 &K3 &K44 &H3 OK --> Sending: AT S87.2=0 OK --> Modem initialized. --> Sending: ATDI08089933024 --> Waiting for carrier. CONNECT 64000/NONE/PPP --> Carrier detected. Starting PPP immediately. --> Starting pppd at Fri May 17 00:26:42 2002 --> pid of pppd: 1568 router root% ps auxw | grep pppd root 1568 0.0 0.1 2068 928 tts/0 S 00:26 0:00 /usr/sbin/pppd 115200 \ modem crtscts defaultroute usehostname -detach call wvdial \ user email@example.com noipdefault idle 0 logfd 6 router root% killall wvdial Caught signal #15! Attempting to exit gracefully... router root% --> Disconnecting at Fri May 17 00:27:23 2002
We need to put all the command line arguments in the /etc/ppp/peers/dod file. We do not need to put the -detach or the call wvdial section in the file. -detach prevents pppd from going into the background and we probably want pppd to go into the background. The call wvdial section reads options from the /etc/ppp/peers/wvdial file, but as we copied the file we already have all the options that file contains.
We also need to add an option so that pppd knows to call wvdial. Add the following line, changing the target for wvdial.
connect "/usr/bin/wvdial --chat connectlite"
We should now have a file that looks something like:
noauth name wvdial connect "/usr/bin/wvdial --chat connectlite" /dev/ttyS0 115200 modem crtscts defaultroute usehostname user firstname.lastname@example.org noipdefault idle 0 logfd 6
You can now check that you can still dial up using:
david root% pppd call dod
david root% pon dod
where dod is the name of the file in /etc/ppp/peers. You can stop the connection using poff.
We now have pppd bringing up the link when we run pon and tearing down the link when we run poff. We now have to make a few changes to the /etc/ppp/peers/dod file to make the link dial-on-demand. The first change is to tell pppd to start and create the interface, but only dial up when we first need to send a packet over that interface. To do this we add the demandoption the the file.
We now have a link that dials on demand, but we still have the link on permanently after it first dials. The solution is to get pppd to stop the connection after an idle period, i.e. no packets have left the interface for a number of seconds. We need to add the idle option to the file. This option requires a argument specifying the number of seconds of idle before tearing down the link. If you specify 0, the link will stay up permanently. You will probably find that wvdial used idle 0 and that therefore already have an idle option in the file. Just change the value to a suitable value. 300 will wait 5 minutes. You may want to use a shorter timeout, especially if you have expensive phone bills.
The final problem is that normally, once pppd has closed the link, it exits. This means that once the link has come up and down once, the link will not work until someone runs ponagain. Fortunately, pppd has the persist option which prevents pppd form exiting after closing the connection.
We should finally end up with a /etc/ppp/peers/dod file similar to:
noauth name wvdial connect "/usr/bin/wvdial --chat connectlite" /dev/ttyS0 115200 modem crtscts defaultroute usehostname user email@example.com noipdefault idle 300 persist demand logfd 6
You should now find that the link will be dial-on-demand and can be started by running pon dod and stopped by poff. You could put those in a crontab to start the dial-on-demand link in the morning and turn it off in the evening, so that you don’t waste money by the link dialling due to an Internet application (like IRC) being accidentally left open.