Originally Published: Friday, 31 August 2001 Author: Randy le Jeune
Published to: learn_articles_firststep/General Page: 1/1 - [Std View]

Connecting To The Internet With Linux

Sometimes getting on line with Linux can be challenging, especially for the new users. This article from Linux.com Learn section clears up the line.

Connecting To The Internet

OK, nowadays a computer is all but useless unless you can use it to connect to the Internet , correct? Well, in Linux, you'll often find that this is a bit more of a challenge that putting a CD in the CD-ROM drive, plugging into a phone line and logging on to an ISP. There is a bit of configuration involved, nearly all of which is done on your side, and not the ISP's.

A Word On ISP's

I have been asked on more occasions that I care to number, "Which ISP's will work with Linux?". As simple as the questions seems, this is usually much less of a problem than most people assume. The primary requirement is that you do not use any ISP which uses any sort of proprietary protocols to connect you to their servers (i.e., AOL, which uses AOLL2TP). Also, any connection that requires software specific to Windows or MacIntosh OS's will not work on Linux. The next warning comes from dealing directly with your ISP . . . sometimes you will be able to get helpful information by calling up and talking to the tech support people at your ISP, but in my experience, you are much better going it alone. Usually when you ask a "tech support" person something technical, more often than not, they have no idea of what you are talking about and cannot answer your questions. So, I would avoid bothering with them directly as it will most likely save you time (this is not always the case, but all too often it is). Good choices are Earthlink and AT&T Worldnet, but most others should work as well. You may want to email your ISP and ask them about any support that they are able to give you on how to set up your Linux box to connect to the Internet and see if you can get any sensible answers. They may be of some help, but don't be surprised if they aren't. However, there are certain pieces of information that you will need from them (this information should have been provided to you at the time that you signed up with them):

  1. The IP address of your ISP's name servers (DNS servers).
  2. Your ISP's dial-up phone number.
  3. Your username and password.

Modems and Serial Ports

To dial into an ISP, generally you will be using a modem. Some people have access to DSL or ISDN lines, but since I have no experience with these, I will only cover how to connect to your ISP via a modem. In general, you will be good to go with almost any external modem. If you have an internal modem that came with your computer when you bought it, you may have a problem, however. Most new computers that are sold to you by retailers come preloaded with some version of Windows, and more often than not, they also come with a "WinModem" installed in a PCI expansion slot on your computer's motherboard. WinModems are special in that they use the microprocessor to mimic the functions that that are normally perfomed by a modem's hardware. This makes the functioning of the modem dependant on the operating system that you are running. WinModems will not work in Linux. (Actually, there are some that may, but I don't think it is worth the trouble of trying to find see if it can be done when there are much easier ways to work around this problem.) If you discover that you have a WinModem, you do not need to get rid of it, because as far as Linux is concerned, the modem simply does not exist, and will be ignored. The easiest way around this is just to buy an external modem and connect it to a serial port on your computer. If your modem is plugged into a PCI slot (you can find this out by looking in Device manager), it is probably a WinModem. In DOS and Windows, your serial ports are usually referred to as COM1 through COM4. In Linux, they are designated a little bit differently, as the following table shows:


DOS or Windows   Linux       Linux (Old) 
COM1           /dev/ttyS0    /dev/cua0 
COM2            /dev/ttyS1   /dev/cua2 
COM3            /dev/ttyS2   /dev/cua2 
COM4            /dev/ttyS3   /dev/cua3 

Avoid using the cuax designations for your serial devices -- they are generally referred to as "callout" devices and are obsolete as of Linux kernel version 2.2. The ttySx naming convention strikes Windows users as very odd usually, but the logic behind it is simple: a tty can refer to almost any device (usually a serial device or a terminal), the "S" stands for "serial" and in Linux, you start numbering things at zero usually, and not at one.

The resolv.conf File

The resolv.conf file is located in the /etc directory. It contains the information necessary for your machine to locate your ISP's domain name servers, which convert the IP addresses to sensible names that you can use to locate various web sites. Without a name server, you would have to remember that to get to Yahoo! to do a search, you would have to type"http://216.32.74.50" in the address box of your browser. A name sever tranlsates the IP address into a name like http://www.yahoo.com, making it much easier to find the resources that you want. Your resolv.conf file should be in this format:

domain {domain}
search {name of your ISP}
nameserver {IP address of your ISP nameserver}

Normally, you will have at least two name servers and no more than three (the secondary and tertiaty ones being used as backups in case the primary name server becomes unreachable). I use Earthlink, so my resolv.conf file looks like this:

domain earthlink.net
search earthlink.net
nameserver 207.217.77.82
nameserver 207.217.120.83
nameserver 207.217.126.81

If it doesn't work, review /var/log/messages for details concerning the attempt. Use these details to troubleshoot the interface or to get help online.

The /etc/HOSTNAME File

Make sure that you have the name of your machine in this file. That's all you need. Mine looks like:

gsibbery

The /etc/ppp/options File

The options file is used to specify certain options (big surprise there!) for your method of connection. Mine looks like this:


### 
# /etc/ppp/options - options for pppd 
# 
#!/bin/sh 
/dev/ttyS0 
115200 
connect /etc/ppp/earthlink-connect 
user ELN/gsibbery 
lock 
crtscts 
defaultroute 
noipdefault 
The first line is the serial port that your modem is on. My modem is on serial port ttyS0 (or COM1 in Windows). By the way, make sure you only have one device specified as your modem. Some people get confused and try to use both /dev/ttyS0 and /dev/modem as the device file for their modem. This will produce an error. It would be OK, however, to make /dev/modem a symbolic link (shortcut) to refer to your modem. The "connect" line specifies the name and location of the chat script that I will describe below. You may have to figure which one yours is on by trial and error, or with t a tool like kermit or minicom. The next line specifies the speed at which the transmissions are to take place . . . I have a Rockwell 56K modem and the standard speed for a 56K is 115200. The "lock" option writes out a lock file to the /var/lock directory that ensures that no one else can use the modem while I am using it. Linux does this with a number of devices; if you use a device like a modem once and then find that when you try to dial out a second time, you get an error message, chances are that your modem lock file is not being deleted when you relinquish control of the device. This may seem a bit uncalled for, but remember that Linux is a multi-user system -- only one person can have exclusive access to some devices at a time. My ISP uses a version of PAP and so I need the line "user {username}". If your ISP uses a different authentication protocol, you may not need this line. The line "crtscts" means that the modem is using hardware flow control (this is almost always true under Linux). The "defaultroute" option adds a default route to your local routing table using the remote IP address as the gateway. The "noipdefault" line is used because I connect using a modem and not a cable, and my machine does not have one fixed IP address, but is assigned one from a pool of available IP addresses each time I dial in to Earthlink. If you have problems connecting, then place "debug" at the end of this file and it will write out error messages to the /var/log/ppp log and if you read over it, you will get some idea of what is going wrong. Once you've found the problem, however, remove the "debug" line from this file or it will keep writing out messages to your log file and it will get larger and larger, taking up more space without performing any useful function. Your /var/log/ppp file should look something like this:

Mar 13 19:15:02 www pppd[1071]: Script /etc/ppp/ip-down started (pid 1248)
Mar 13 19:15:02 www ppp-child[1070]: got Script /etc/ppp/ip-down started (pid 1248)
Mar 13 19:15:02 www pppd[1071]: sent [LCP TermReq id=0x2 "User request"]
Mar 13 19:15:02 www pppd[1071]: Script /etc/ppp/ip-down finished (pid 1248), status = 0x7f00
Mar 13 19:15:02 www ppp-child[1070]: got Script /etc/ppp/ip-down finished (pid 1248), status = 0x7f00
Mar 13 19:15:02 www pppd[1071]: rcvd [LCP TermAck id=0x2]
Mar 13 19:15:02 www pppd[1071]: Connection terminated.
Mar 13 19:15:02 www ppp-child[1070]: got Connection terminated.
Mar 13 19:15:02 www pppd[1071]: Connect time 35.6 minutes.
Mar 13 19:15:02 www ppp-child[1070]: got Connect time 35.6 minutes.
Mar 13 19:15:02 www pppd[1071]: Sent 178091 bytes, received 3120405 bytes.
Mar 13 19:15:02 www ppp-child[1070]: got Sent 178091 bytes, received 3120405 bytes.
Mar 13 19:15:02 www pppd[1071]: Exit.
Mar 13 19:15:02 www ppp-child[1070]: PPP daemon died (exited)
Mar 13 19:15:02 www ppp-child[1070]: restoring resolv.conf
Mar 13 19:15:02 www ppp-envoy[1068]: reopen and hangup /dev/modem
Mar 13 19:15:02 www ppp-envoy[1068]: chat_next(0)
Mar 13 19:15:02 www ppp-envoy[1068]: chat_set_timeout(10)
Mar 13 19:15:02 www ppp-envoy[1068]: chat_message(107, "Hanging up")
Mar 13 19:15:02 www ppp-envoy[1068]: chat_pause(50)
Mar 13 19:15:02 www ppp-envoy[1068]: chat_next(3)
Mar 13 19:15:02 www ppp-envoy[1068]: chat_send("+++")
Mar 13 19:15:02 www ppp-envoy[1068]: chat_pause(50)
Mar 13 19:15:02 www ppp-envoy[1068]: chat_next(5)
Mar 13 19:15:02 www ppp-envoy[1068]: chat_send("ATH")
Mar 13 19:15:02 www ppp-envoy[1068]: chat_expect("OK")
Mar 13 19:15:02 www ppp-envoy[1068]: read error from modem
Mar 13 19:15:02 www ppp-envoy[1068]: terminating 1070
Mar 13 19:15:02 www inetd[513]: pid 1068: exit status 1

Although slopping through this output may not look like the most enticing of activities, it usually will give you some hints as to where you went wrong, or whether the authentication server was expecting something that it didn't receive, and may give you the chance to make allowances for it, or to try something else. (By the way, you are generally best off by using as few of these "options" as is necessary to get your PPP connexion to work . . . if you don't need it, don't use it!)

The Chat Script File

The chat script is the file that actually does the handshaking with your ISP. Unfortunately, it is rather difficult to say exactly what information you need in this file as the details depend somewhat on your ISP. This script can have a variety of names, but is located in the /etc/ppp directory. The name of this chat script will need to be placed in your options file after the "connect" command (as shown above). I use Earthlink as my ISP, so I call my chat script earthlink-connect, but I could have chosen any name I wanted to as long as I specified it in the options file. Your ISP may be of some help in telling you what their authentication daemon expects to see in this file -- you may want to ask them whether their server requires the use of a script with certain specific expect/send pairs (what you send must be what the authenticating server expects to receive -- otherwise the server won't understand the information you are sending to it) -- if so, ask them to specify exactly what they are, so that you can configure your script correctly. Again, do not be surprised if you are given some incorrect information -- this sometimes requires a good bit of trial and error in order to figure out exactly what the server expects. by the way, this was the most annoying aspect of the whole operation to me, but once you figure out the correct options to be used, you'll find that it was rather simple all along. These expect/send pairs represent command responses that must be passed by the script in order to turn on the PPP server at the ISP but it usually looks something like this:

#!/bin/sh
# earthlink-connect: a script for dialing into Earthlink
exec /usr/sbin/chat -v
TIMEOUT 120
ABORT BUSY
ABORT 'NO CARRIER'
'' ATZ
OK ATDT344-0514
CONNECT ''
ogin: ELN/gsibbery
assword: topsecret

This probably looks a little mysterious, so let me try to explain it a little. The crunches (#) signify that the line is a comment. The "exec /usr/sbin/chat -v" line means that the program called chat, located in /usr/sbin will be executed (this is necessary for connexion to take place). The -v option stands for verbose -- this specifies that any output in the logs will be more easily readable by humans -- extremely helpful when reading and trying to troubleshoot the connexion by reading the message logs. The next few lines deal with the modem. "TIMEOUT" is the time (in seconds) before the dial-up attempt is aborted (OK, I'll admit that two minutes is a bit excessive, but if you have problems, you may want to increase the number . . . the default is usually like 30 seconds or something -- usually, but not always.). The next two lines tell the chat program to "abort" the attempted dial-up if the phone line is busy or if there is no dial tone. The next line resets the modem to the factory defaults. The next line actually dials the ISP phone number (keep in mind that this number can change with little warning). If this line doesn't work, you may want to check your ISP's dial-up number, or if you have a pulse rather than a tone telephone line, replace the "ATDT" with "ATPT". I don't think the hyphen separating the two sections of the number is necessary . . . remember to include the area code if you are dialing long-distance. The next line is the instruction to actually complete the connexion, and the next two lines are my login and password (don't try using it as I have changed them for security purposes!). With Earthlink, you need to prefix ELN/ to your username -- this is just one of the peculiarities of dealing with that ISP; this is because the Earthlink server that I dial into is an Windows NT server and it requires that you put the domain name before your username and Earthlink's domain name happens to be "ELN". Others may not require this, or may expect something different, so try to find out what your ISP expects. The reason the initial letter is left off of "login" and "password" is to allow for the fact that your ISP may use upper-case or lower-case initial letters for these words. By omitting the first letter, you avoid this difficulty. Again, there may be some difficulty here, as your ISP may expect "Name" or "userid" instead of "login". If you try a number of these and nothing works, ask them and find out. mentioning "AOL" in your conversation with a rep often works wonders, by the way.

If you try to connect, but are unsuccessful, add the "debug" line at the end of yout /etc/ppp/options file like I mentioned above, then check your /var/log/ppp and /var/log/messages files. If you see something like "auth pap" or "auth chap", then you need to use those authentication protocols. CHAP and PAP are "authentication protocols" which determine that you are really the person who should be using your account. Your pap-secrets and chap-secrets files are located in the /etc/ppp directory and should look something like this (with the appropriate username and password, of course).

#!/bin/sh
# /etc/pap-secrets
#username password
ELN/gsibbery topsecret

I think I should mention that there are many versions of each of these protocols and this might not work for each and every one, and of course some ISP's may require you to log on using more than one of these authentication schemes, so if none of this works, ask them.

The ppp-on File

One last files that you have to add is your ppp-on file, which will be located in your /usr/sbin or / directory. This is what actually turns on PPP. I couldn't start my PPP services without this file, and as it turned out, this was my main problem in getting connected. The same rules apply as before, but you need to know the subnet mask of your ISP (most are class "C" masks nowadays; that is, 255.255.255.0).

TELEPHONE=344-0514
ACCOUNT=ELN/gsibbery
PASSWORD=topsecret
LOCAL_IP=
REMOTE_IP=0.0.0.0
NETMASK=255.255.255.0

The /etc/hosts File

Normally the /etc/hosts file isn't used for much if you have a nameserver, and if you don't have a nameserver, you probably won't be going very far, as one single hosts file cannot possibly take the place of the worldwide DNS database. But you should put the name of your local host machine in here and the internal loopback address. Any aliases that you use in your other configuration files (such as /etc/hosts.deny) must also be specified in here.