Linux NetMag
Titel: modem sharing
URL: http://www.linuxnetmag.com/en/issue4/m4druck1.html
Published at: 27.3.2000
Author: Ronny Ziegler
Translator: Andy Ziegler


We already told you how to connect a LAN to the internet with a single telephone line using IP masquerading (Masquerading article).
But how would you get the modem or ISDN card to call the Internet Service Provider if you do not have root access?

(In this article we do not describe how you configure your modem or ISDN card to connect to the internet. That step has to be done before this article is useful.)

Topology of a net

The typical way a local area network (LAN) looks like is presented in our example:
A PC, used as a server and also maybe as a client, establishes the internet connection using a modem or ISDN card.
With IP masquerading installed on the server, all computers in the LAN get access to the internet. They have to specify the server as the gateway.

If you want to start an internet connection from a client, first you have to log into the server with telnet and start on the server the necessary dial-in script.
With ISDN for example:

  >> isdnctrl dial ippp0
  
This only works if you have root access on the server.
You should not give every LAN user the root password and should also not weaken the permissions to allow unrestricted use of the modem. Both of these methods can cause big security problems.

DialControl

A very nice way to avoid these problems is the installation of a program running on the server PC that has root access. It accepts special commands from the client programs via the network. From the client you can send the request for an internet connection and the server establishes it.
DialControl offers such a software package including a server and the corresponding client program for different platforms such as M$ Win, Linux, and any Java-VM.

First, you should concentrate on the installation of the DialControl server at the gateway PC (it's the server PC in the sketch).
Get the newest version of the DialControl server from http://homepage. swissonline.net/allenfuchs/stefan/dc/ and install the package to /usr/local. There, the directory /2-dial-control is created together with the subdirectory /Server.
The server is configured in the file /etc/dialsrv.conf.
The file should look like:

/etc/dialsrv.conf
  interface ippp0
  con_type file
  script_up /etc/dctest/up
  script_dn /etc/dctest/down
  script_esc /etc/dctest/down
  
  con_status_file /tmp/.ippp0_up
  
  con_timeout 30
  
  bind_to 192.168.1.1
  port 16007
  
  send_throughput yes
  
  pinger no
  
  filter_type allow
  filter_ip 192.168.1.11 192.168.1.14
  filter_mask 127.0.0.0 255.255.255.0
  

With the option
  interface ippp0
  
you select the device that is used to establish the internet connection. ippp0 stands for a ISDN card, ppp0 for an analog modem.
The next entry
  con_type file
  
sets the method the server uses to verify if an internet connection has been established correctly of not.
The method netdev is recommended for modems, isdn for ISDN cards and file if neither works.
This checks if a special file exists. If it does not then it "knows" that no connection exists.
This method - a little bit curious - is the simplest one and also very flexible to use because other programs can use this checking method, too. This way you can declare an internet connection system-wide. (Security risks that may occur have to be checked by the administrators themselves).

We decided to use cont_type file because then we are sure that the server really recognizes an existing internet connection.
The file has to be created if a connection is established. You simply do this in the ip-up script (at /etc/ppp/) because this script is executed while connecting.

Into this script you add the entry:

  touch /tmp/.ippp0_up
  
(if you do not want that other users to see this file and know about the internet connection, you should place it in a directory which only can be read by root.)

In SuSE, ip-up and ip-down are combined in a single script. There you have to add the entry after the option

/etc/ppp/ip-up
  [...]
     case "$BASENAME" in
      ip-up)
        #
        #Here are many other entries
        touch /tmp/.ippp0_up
      ;;
  [...]
  

To make sure that the file would be removed if the connection was closed, you correspondingly add the entry

  rm /tmp/.ippp0_up
  
into the ip-down script. In SuSE, add it below the option ip-down).

Next, you have to specify the scripts that are needed to establish or close an internet connection.
Therefore, it would be the best if you created a subdirectory with the name dctest in the /etc/ directory.

  >>mkdir /etc/dctest
  
Here you place two scripts which are responsible for establishing and closing the internet connection.

/etc/dctest/up
   #!/bin/sh
   isdnctrl dial ippp0
  

In the script you just add the command you used until now to connect to the provider. Using ISDN this is isdnctrl dial ippp0. Another script for closing the connection is needed, too:

/etc/dctest/down
   #!/bin/sh
   isdnctrl hangup ippp0
  

The entry

  con_status_file /tmp/.ippp0_up
  
defines the file that has to be checked to decide if an internet connection exists or not.

  con_timeout 30
  
sets the wait time for a ready connection. After passing this time, the connecting is declared unsuccessful. This time depends on the speed of the modem on the other side of the line and on the number of scripts which are started on your PC during the establishment of the internet connection. This value has to be adjusted individually to your system.

The next two entries

  bind_to 192.168.1.1
  port 16007
  
define the IP number and the port of the server.

  send_throughput yes
  pinger no
  
should not be changed.

Finally, you specify the computers from where you are able to establish an internet connection.

  filter_type allow
  filter_ip 192.168.1.2 192.168.1.50
  filter_mask 127.0.0.0 255.255.255.0
  
The entry filter_type allow allows every IP listed at filter_ip to establish a connection. All IPs that are not listed do not have this right.

With filter_type deny you can change this rule. All listed computers are not allowed to connect but all others are allowed. (This should not be used in big networks because it is a security hole).

Behind filter_ip you have to specify two IP numbers which set an IP-interval. The defined filter_type is used for all IPs included in this interval. filter_mask specifies the subnet (if you do not know what is meant, just use the provided values. This works in most cases.)
You can specify more than one entry of any filter_*.

start the server

To avoid any other logins to the server (that's why we install DialControl) you should automatically start the the DialControl server during booting.
Therefore, the use of an init-script or an entry in the /sbin/init.d/boot.local (for SuSE) or in the /etc/rc.d/rc.local (for RedHat) looking like

  /usr/local/2-dial-control/server/dialsrv &
  

will do its job.
If you want to run the server during specific times (e.g. the telephone costs are cheaper between 18.00 and 6.00 o'clock), you need an entry in the crontab.

  >>crontab -e
  
There, you add the line
  0 18 * * * /usr/local/2-dial-control/server/dialsrv &
  0 6  * * * killall dialsrv
  

Clients

Now we will examine the part the user will see. The server works quietly and only the clients communicate to the server.
In Linux, a client for the terminal and a graphical frontend exist called XDC; it uses the GTK libraries.

The configuration of the client is very simple. Using the menu, you reach the setting where you have to specify the IP address and port number of the DialControl server. Both values were set in the configuration file of the server:

  bind_to 192.168.1.1
  port 16007
  
In addition, you can set the process for automatic dial and hangup.
Select the entry Server->Connect from the menu and the connection to the server is established. Also, the actual connection status is displayed in the info bar at the bottom of the window.
A push on the button Dial will establish the internet connection on the server and in the status bar would appear an ONLINE if it was successful. Hangup would close the connection if you were the last user. If more than one user were connected to the server and if all users had selected "dial", the server would hang up the line if all users pushed Hangup.
Of course a M$ Win client exists, too, and for all other OS's, a Java version is available.

other solutions

DialControl is not the only application that establishes an internet connection for a LAN. There are other programs which do all the same but the installation of DialControl is much easier that for the others.

Also, Masqdialer Server is preferred by many users. It comes with a lot of possible configurations and a password option. In addition, Masqdialer supports dial-in to more than one provider and the user can chose among them.
For the server, a big collection of clients for different OS's exists.
You pay for all these features with a much more complicate installation and configuration process.
If the options of DialControl were not enough for your system and you wanted to extend its use with scripts, you should think about Masqdialer in combination with a Python client. This combination should solve every problem with little effort on your part.


Links:
Homepage DialControl: http://homepage.swissonline.net/allenfuchs/stefan/dc/
Homepage Masqdialer Server: ht tp://cpwright.villagenet.com/mserver/