The Linux Guide Online

Chapter 03 - Connecting to the Internet using Linux

3.1 Setting up the dummy interface

A dummy interface is used by TCP/IP to assign as IP address to your machine, which is required for both SLIP and PPP. The reason for this is simple: when you connect to the internet using an ISP, your IP addresses are often assigned dynamically and you never know what address you will have in advance. This can cause problems for TCP/IP routines in your kernel that require the IP address to function properly. When you assign an IP address, the dummy one, TCP/IP is happy. The need for this IP address is most important when your computer is not connected to your ISP, because many applications are network aware: such as email, newsreaders etc. They need some IP address to connect to even though it may not lead them anywhere.

Fortunately setting up a dummy interface is simple, all it needs is a few commands to setup and a few more to test the interface. The /etc/hosts file is an ASCII file that provides two poeces of information to the TCP/IP drivers and applications: an IP address and the names associated with that IP address. There might the following line in your copy of /etc/hosts localhost

This line basically binds the address in the first part to the name in the second part. This is a dummy interface because it doesn't lead anywhere. is a special address reserved for local machines on all networks. It basically refers to the machine itself.

If you setup the system with networking support, you probably have the file the line indicated already in place. if that is the case you don't have to do anything else. Other wise you have to setup the interface. Create the file /etc/hosts and add the line localhost

to it. The number of spaces between the IP and the name does not matter as long as there is at least one. After updating the file you need to tell TCP/IP about the new interface. Use the ifconfig command to do so. Log in as root to execute the following commands.

ifconfig lo
route add

The first command tells TCP/IP to assiciate the lo interface (the loopback or the dummy) with the IP address as shown. The second number adds the IP address to an internal table that keeps track of routes to different addresses. After you have done this test the interface with the ifconfig command again like this

$ ifconfig lo
lo Link encap: Local Loopback
inet addr: Bcase: Mask:
RX packets:0 errors:0 dropped:0 overruns:0
TX packets:12 errors:0 dropped:0 overruns:0

The output shows that the lo interface is up and running. To do another check and see if your machine is responding to the IP address ping the localhost

$ Ping localhost
PING localhost ( 56 data bytes
64 bytes from icmp_seq=0 ttl=225 time=0.8 ms
64 bytes from icmp_seq=0 ttl=225 time=0.7 ms
64 bytes from icmp_seq=0 ttl=225 time=0.7 ms
64 bytes from icmp_seq=0 ttl=225 time=0.7 ms
64 bytes from icmp_seq=0 ttl=225 time=0.7 ms

--- localhost ping statistics ---
5 packets transmitted, 5 packets received, 0% packet loss
round trip min/avg/max = 0.7/0.7/0.8

To stop the ping command use the ctrl+c keys. If you are unable to ping then test the setup and re-perform if necessary.

3.2 Using an existing LAN

This is probably one of the simplest things to do in Linux. Being built with networking in mind Linux has a number of tools that will help you configure the network. Keeping in mind this will be used by the majority users, especially if you are in a University where there is already a running LAN in place, we shall make this part as simple as possible. The whole process can also be done by configuring the reqiusite files and with the command lines, but we shall keep it simple now and leave the manual setup as an exercise, recommending it highly if the user really wants to know about Networking and its internals.

To connect using the LAN you will need the following pieces of information. First in your own machine you will need to have the network interface configured and working. If you have set up the system properly and have configured the loopback interface, you already have it in place.

Additionally you will need information about the network. Specifically you will need the names of the gateway, and the dns servers for your LAN. You may find this by either looking into the configuration of another machine that is connected to the Internet, or by contacting the system administrator of your network. We are assuming that you will only connect to the Internet, and therefore will have only one set of servers to configure. More complex networks need a more elaborate setup.

Now that you have the information, it is time to fire up one of the programs to change all the files for you. Choose from a variety of programs. The program netconfig is a simple utility for a straight forward specification of the information you have gathered. For simple connections and LAN configurations this is the best. If you want more control you may want to use the netconf utility that allows you to specify the same in tabbed pages. Looking for a X program? Use netcfg.

3.3 Setting up PPP

Most ISPs use PPP or (Point to Point Protocol) instead of the SLIP that is good because PPP is a faster and more efficient protocol. We shall use the command line approach to setting up the PPP as it will give a better understanding of the process.

PPP uses two components on your system. The fiest is a daemon called the pppd, which controls the use of ppp. The second is a driver called the high-level data link control (HDLC), which controls the data flow between two machines. A third component of PPP is a routine called the chat that dials the other end of the connection for you.

3.3.1 Installing PPP

Check if PPP was already installed on your system when you set it up (and say chose dial up networking option in the menu). Or you may install the rpm from your installation package. Mount the CD-ROM and run the following command.

rpm -ivh /mnt/cdrom/RedHat/RPMS/ppp-X_X_.rpm

Where X is the number in your installation. The PPP is now installed.s

3.3.2 Setting up a PPP user account

To help protect your machine against hackers and other attacks, it is advisable to setup a special login for the PPP. This is optional but highly recommended.
Create a user called ppp, preferably belonging to a new group called ppp, without a password and a temporary root directory (/tmp). The startup shell script should however point to the script /etc/ppp/pppscript. You will have to create this script yourself (whence you may name it as you like) and it should be an executable with the following entries

mesg n
stty -echo
exec pppd -detach silent modem crtscts

The fourth line is what actually executes the ppp daemon. Make sure that the script is executable.

3.3.3 Setting up chat

PPP uses a program called chat to handle the details of connecting through the modem, to connect to the ISP. (others too can be used but this is the simplest and the easiest to setup and use) The information to connect to the ISP is generally stored in a file. A typical chat script looks like the following

"" ATZ OK ATDT2370400 CONNECT "" ogin: ppp word: guessme

chat scripts are conversation between the chat utility and the modem. The scripts are separated by spaces, with the chat instruction and the expected reply. You may put this string in a file with the correct number and the login and password. Then you can run the dialup with

chat -f filename

where filename is where the sequence is stored. You may choose to modify the earlier string to the following to take care of the error conditions of busy signal and a no-carrier signal.

ABORT BUSY 'NOCARRIER' "" ATZ OK 2370400 CONNECT "" ogin: ppp word: guessme

Once the connection is established the chat program then terminates and hands over the control to PPP.

3.3.4 Configuring pppd

Once the chat is done this daemon takes over the communication and handles it from this point onwards. The pppd is started with arguments about the modem device and the speed of the connection. Starting pppd manually from the command line looks like this

pppd /dev/cua0 38400 crtscts defaultroute

This line tells the serial port /dev/cua0 (COM1) to connect at 38,400bps. The crtscts options tells pppd to use the hardware handshaking on the connection, and defaultroute tells it to use the local IP address for the connection. Because your IP address is dynamic, you mat change the last address to any address (even and end it with a ':'. This tells pppd to use whatever IP address the remote sends as the other end of the connection.

pppd /dev/cua0 38400 crtscts

The pppd also stores its default options in a file /etc/ppp/options that has many options to change the way pppd connects or authenticates etc.

3.3.5 Combining chat and pppd

Till now we have looked at the process of dialup as two processes the chat and the pppd. Combine both of them as shown here

pppd connect "chat -f filename" /dev/cua0 38400 -detatch crtscts modem defaultroute

With this command the pppd will chat with the chat file, create the link and the finish by establishing the pppd. After these few steps, your system is ready to use PPP to dial out your ISP. As long as the chat file has all the instructions to connect to the ISP's modem bank, PPP will start properly once a connection is established.

3.4 Setting up SLIP

The fastest way of setting up the SLIP is by using the slattach program. This requires the name of the port that SLIP will use (which has a nodem attached for the connection usually). The command to set up slattach is

slattach /dev/cua0 &

In this case the COM1 is configured as the SLIP port. You can use any other port attached to your system. The ampersand sign at the end causes the program to run in the background, so that you get your shell prompt back.

When you run slattach, the port is renamed to /dev/sl0 to show that it is the first SLIP device. It doesn't matter what serial port you used for the connection. If you create more than one SLIP port they will be numbered sequentially.

Linux uses CSLIP (Compressed SLIP) by default as it packs more information in the same space. If however your ISP does not support CSLIP you may have to force Linux to use SLIP by

slattach -p slip /dev/cua0 &

Other valid connection types are cslip, adaptive, and slip6.

Once the SLIP device has been created the Linux kernel must be informed of it through the ifconfig command. The ifoconfig requires the name of the remote machine to compete the connection.

ifconfig sl0 mymachine-slip pointopoint remotemachine

is the command line. The first argument is the name of the interface that you have created using the slattach command. Change the mymachine to the name of your machine, and the remotemachine with the name of the machine at the other end. The word pointopoint tells the ifconfig command that this is a point-to-point connection (do not confuse with PPP). The next step after configuring the device is to add it to the route table.

route add remotemachine

Many ISPs don't tell the name of their remote machines. That is fine because these machine names are only placeholders. You can substitute any name you want that identifies the other end of the connection.

Thus you have seen the process of setting up a PPP and SLIP network for use with your Internet connection. You can also use both these protocols for intranet too. PPP and SLIP are almost transparent to you once the interfaces are properly setup.