|
Configuring your Linux server or workstation to dial the internet on
demand is accomplished as follows.
Modem compatibility
Many websites are available to help determine if your modem is compatible
with Linux, the most common being
Modem
type and compatibility with Linux
Modem setup strings
Simple
firewall package
Packages
There are two essential packages, these being pppd [to get online using
ppp] and ipchains [to 'firewall' your connection]. Two of the many optional
packages are crond [to schedule when your connection is available] and
minicom [to test your modem]
Preparation
You will need to be the 'root' user to follow these instructions. Please note - these
instructions apply in general to using a 'real' modem, that is a Modem
which does not require a software driver to run such as many winmodems.
1 . Connecting the Modem
The communications ports in Linux are named differently than in windows.
The correct communications port to use are the devices listed in the /dev
directory which begin ttyS followed. Examples are /dev/ttyS0, /dev/ttyS1,
/dev/ttyS2 and /dev/ttyS3 for Com ports 1 to 4 respectively. In this example
the modem is connected to Com2. You may also wish to ensure that your
com port is operating at an appropriate speed. You can use the setserial
command to inspect and amend the settings for the com port.
[root@ashaman]# setserial -g /dev/ttyS1
/dev/ttyS1, UART: 16550A, Port: 0x03f8, IRQ: 4
Most distributions provide a rc.serial or serial script in the init directories.
These set the com port flags at boot time for each com port. If you cannot
locate these or have reasons for setting com speeds differently then you
might create the following shell script, not forgetting to chmod +x the
script before running it.
setcom1.sh
#!/bin/bash
setserial /dev/ttyS0 uart 16550A port 0x03f8 irq 4 baud_base 115200 spd_vhi
skip_test
If you ran the above your com port may look like.
[root@ashaman bin]# setserial -g /dev/ttyS0
/dev/ttyS0, UART: 16550A, Port: 0x03f8, IRQ: 4, Flags: spd_vhi
2. Ensuring your requests for the internet are
responded to
[root@ashaman nik]# cat /proc/sys/net/ipv4/ip_forward 1
If you see 0 here then you can set this value tru by typing.
[root@ashaman nik]echo 1 >/proc/sys/net/ipv4/ip_forward
You may wish to ensure that this value is set every time that the ppp
connection is requested. Later in this guide an example is given as to
how to place this in a shell script before starting pppd.
3. Ensuring that your machine is secure
To provide a firewall and protect your machine from unwanted access you
should implement an ipchains rule set to control access and stop unwanted
visitors. Simply click here,
unpack the files and place the file firewall.sh in /usr/sbin ensuring
the file firewall.sh is executable. You can enable the firewall by specifying
the
name of the external ppp device, usually zero and in the internal networking
device.
[root@ashaman]firewall.sh ppp0 eth0
Note eth0 is necessary where you are using Linux as a gateway between
the internet and a local area network, otherwise the following command
will protect your machine.
[root@ashaman]firewall.sh ppp0
4. Resolving names on the internet
You will need to let Linux know how and where to locate internet sites.
This guide assumes that you are not using Domain Name Server local to
your box. You will need to amend at least two files. By default your Linux
distribution will have configured the other host files correctly.
/etc/host.conf
order hosts,bind
multi on
/etc/resolv.conf
nameserver 212.159.13.49
nameserver 212.159.13.50
/etc/hosts.deny
ALL:ALL
5. Configuring PPP
Distributions of Linux vary, but in general the configuration files for
PPP will be stored in /etc/ppp . In the example a simple ppp options file
will be created along with a chat script (which will dial the Modem).
PPP connections will vary depending on the service you are dialling. You
will need to amend the chat script accordingly and this is highlighted
below. PPP Connections come in two parts: the chat script and the pppd
options.
5.1 Chat Script
|
To dialup on a Connect account.
/etc/ppp/connect.sh
#!/bin/sh
exec chat -s -v \
SAY "Set modem responses" \
TIMEOUT 3 \
ABORT '\nBUSY\r' \
ABORT '\nNO ANSWER\r' \
ABORT '\nRINGING\r\n\r\nRINGING\r' \
ABORT '\n% Authentication failed\r' \
'' \rAT \
'OK-+++\c-OK' ATH0 \
SAY "Send number " \
TIMEOUT 5 \
SAY "Set modem Reponses" \
OK "ATX4V1Q0S7=70" \
OK "ATM0L0DT0808,9933,0xx" \
TIMEOUT 45 \
SAY "Wait for connect" \
CONNECT '\c'
Note: replace xx with the appropriate number for the Connect
service you are using.
|
To dialup via 0845
/etc/ppp/dial0845.sh
#!/bin/sh
exec chat -s -v \
SAY "Set modem Reponses" \
TIMEOUT 3 \
ABORT '\nBUSY\r' \
ABORT '\nNO ANSWER\r' \
ABORT '\nBLACKLISTED\r' \
ABORT '\nRINGING\r\n\r\nRINGING\r' \
'' \rAT \
'OK-+++\c-OK' ATH0 \
SAY "Send number " \
TIMEOUT 65 \
SAY "Set modem Reponses" \
OK "AT&F" \
OK "ATM0L0DT0845xxxxxx" \
SAY "Wait for connect" \
CONNECT '' \
Login:--Login: [your username here] \
Password: [you password here]
NB: replace xxxxxx with the appropriate number for your account
type.
|
If you want to configure your modem more accurately then ensure that
you surround the AT command with quotes. More details are available here.
Remember to set the scripts as executable e.g. chmod +x dial0845sh
5.2 PPP Options
Options file for dialup on a Connect account.
/etc/ppp/options
name [your username here]
hide-password
ipcp-accept-remote
ipcp-accept-local
connect-delay 2
passive
noauth
defaultroute
require-chap
asyncmap 0
demand
maxfail 0
holdoff 1
connect /etc/ppp/connect.sh
lock
crtscts
idle 1800
modem
netmask 255.255.255.0
Note you need to use either connect.sh or dial0845.sh as the connection
script. For more information about these options try man pppd.
5.3 Other Script options
/etc/ppp/chap-secret
[your username here] * [your password here]
/etc/ppp/ip-up.local
#!/bin/bash
firewall.sh ppp0
Remember to use firewall.sh ppp0 eth0 for a local area network.
5.4 To Launch ppp
[root@ashaman]/usr/sbin/pppd /dev/ttyS0 115200 noauth
From here ppp should become enabled once a request has been made to access
the internet. Once PPP is running it will automatically start the chat
script to dial the modem and access the internet . If you wish to stop
the pppd process you will need to locate its process ID and stop it. This
can be done with the following command
[root@ashaman] ps -ax | grep pppd
29064 ttyS1 S 0:00 pppd
The value 29064 is the process id of the running pppd application. You
can also find this value by typing the following command
[root@ashaman] cat /var/run/ppp0.pid 29064
In either situation you can stop the process by issuing the kill command
[root@ashaman] kill 29064
Or you could type
[root@ashaman] kill `cat /var/run/ppp0.pid`
6. Making life simpler
Some example scripts to automate stopping and starting ppp
/root/bin/connect.sh
#!/bin/bash
internetdown
ifconfig ppp0 down
echo 1 >/proc/sys/net/ipv4/ip_forward
pppd /dev/ttyS1 115200 noauth
echo "done." |
/root/bin/internetdown.sh
#!/bin/bash
for pppdevice in /var/run/ppp?.pid
do
if [ -f $pppdevice ]
then
kill `cat $pppdevice`
fi
done |
7. Automating the pppd process
You could add an entry to the cron deamon process that would call these
scripts. In this example the pppd process is started at 6am each day and
stopped at 11pm each day.
[root@ashaman] crontab -e
0 6 * * mon,tue,wed,thu,fri,sat,sun /root/bin/surf.sh
0 23 * * mon,tue,wed,thu,fri,sat,sun /root/bin/internet-down
Credits
This document was originally written by Nicholas Butler, Technical Director
of Wired4Life http://www.wired4life.org
|