ONLamp.com    
 Published on ONLamp.com (http://www.onlamp.com/)
 See this if you're having trouble printing code examples


FreeBSD Basics

Connecting to the Internet Using PPP or a Cable Modem

06/14/2000

"Why do I need to configure a connection to the Internet?"

One of the first things every new FreeBSD user wishes to do is set up a connection to the Internet. It can be overwhelming to be thrust into the world of PPP chat scripts and DHCP, especially if these terms are unfamiliar to you. I'll start today's article with some definitions of common terms and explain how these terms interrelate when you connect to the Internet. Then I'll show you how easy it is to do a basic Internet connection with FreeBSD, and leave you with some references should you wish to try more complicated configurations.

In order for two computers to exchange information, they need a connection between them, a physical device to handle the connection, and a protocol to package the data in a format both computers understand.

If the computers are physically located near each other, they will most likely be cabled together with either CAT-5 or coaxial cable to produce a LAN (Local Area Network). CAT-5 cable looks like the wire that plugs into your telephone jack, except that the connection at the end is bigger. Coaxial cable looks like cable-TV wiring. Both types of wiring will be attached to a NIC (Network Interface Card) at the back of each computer in the LAN. The NIC is responsible for transmitting electrical signals onto the wiring; these signals represent the data that the computers wish to exchange. As long as both computers are using the same protocol (rules of communication), they will be able to correctly translate the electrical signals back into the original data.

However, when you're connected to the Internet, you are really accessing other computers over a WAN (Wide Area Network). There is no way of knowing whether your data is travelling over CAT-5 cable, fiber optic cable, or transmissions from satellite links. Major telecommunications companies (e.g., MCI) control these links; you need an access point into this global network of telecommunication links. The most common way of gaining this access is through an account with either an ISP or a cable provider.

ISPs (Internet Service Providers) sell monthly access to the Internet; you access an ISP by dialing into their POP (Point of Presence) using a dial-up modem and your existing phone line or the PSTN (Public Switched Telephone Network). A modem is required to translate the digital signals used by your computer into the analog signals the telephone cabling in your home understands. Because you are dialing into another modem at the ISP using a temporary point to point connection, you need to configure the point to point protocol (PPP).

You don't need to configure PPP if you are using a cable modem, as you already have a constant connection to your cable provider. In essence, the cable modem is a "virtual" NIC connected to a very big "virtual" LAN. The cable modem does the necessary translation to make this work.

Before configuring PPP

Before configuring PPP, you need to know the following:

Note, not all modems are created equal. Some modems require built-in software to work; unfortunately, this software only works on Windows computers, hence the nickname Winmodems. For more information on Winmodems, and to see if your modem is supported, try the Winmodems Are Not Modems page.

If you need to reconfigure your kernel

If your modem is physically attached to COM3 or COM4, you'll have to rebuild your kernel, as these COM ports are disabled by default. If this is the case, as root, type:

cd /usr/src/sys/i386/conf

If this produces an error message, you didn't install /src when you installed FreeBSD. To fix that, type:

/stand/sysinstall

And select Configure and then Distributions. Use your spacebar to select src, then sys.

Press enter twice, and select your media. Exit out of /stand/sysinstall when it is finished copying the necessary files and let's try again. Type:

cd /usr/src/sys/i386/conf
ls

and you'll see something like this:

GENERIC	LINT	NEWCARD

GENERIC is the name of the default kernel configuration file that came with FreeBSD; notice the convention of using all caps to signify kernel configuration files. When creating a new kernel, always make a copy of a kernel configuration file, just in case you make things worse. LINT is a handy file that explains all the possibilities one can input in a kernel configuration file, and their required syntax. Let's enable COM ports 3 and 4:

cp GENERIC MYKERNEL
pico MYKERNEL

which will open the file in the pico editor. Press Ctrl-W and type com3 (to find the line to edit). You'll probably see something like this:

# Serial (COM) ports
device		sio0	at isa? port IO_COM1 flags 0x10 irq 4
device		sio1	at isa? port IO_COM2 irq 3
device		sio2	at isa? disable port IO_COM3 irq 5
device		sio3	at isa? disable port IO_COM4 irq 9

Remove the word disable from the entries for COM 3 and 4; also verify that the irqs are correct, and modify them if they are not. Once you've saved your file (to save the file and exit pico, press Ctrl-X), type:

/usr/sbin/config MYKERNEL
Don't forget to do a "make depend"
Kernel build directory is ../../compile/MYKERNEL
cd ../../compile/MYKERNEL
make depend

When you receive the prompt back, continue with:

make

This one takes a bit longer. Finally:

make install

To test the new kernel:

reboot

When you log back in, use:

dmesg

to verify that COM3 and COM4 were successfully found. You'll probably have to turn on your scroll lock key and use your page up key to scroll through the buffer. When you are finished, press scroll lock again to receive your prompt back.

Dialing the ISP

Now let's see if we can get the modem to dial out. As root, type:

ppp

which will invoke the ppp utility; note that you will lose your prompt when using ppp and it will only accept ppp commands. If you wish to use a regular command prompt, switch to another terminal using the Alt-Fx keys.

To talk to the modem directly, we can use terminal mode, replacing # in the command line below with the number of your COM port minus one:

term /dev/cuaa#

You should see something like this:

deflink: Entering terminal mode on /dev/cuaa#
Type ~? for help.

Modems use something called AT commands to talk with each other; AT commands always start with the letters AT followed by at least two other letters that represent the command. Since we wish to tell the modem to dial a phone number, we use this AT command (replace 1234567 with the phone number to dial):

atdt1234567

You should hear your modem dial and try to connect, followed by a connect message and then by a Login prompt. Enter your username for the ISP, then your password when prompted. You should see something like this:

	Entering PPP Mode.
	IP address is xxx.xxx.xxx.xxx
	MTU is 1524.
ppp
PPp
PPP

If you get the line "PPP" in all caps, you've been successfully authenticated and are now connected to your ISP. To disconnect from your ISP, type:

bye

This will disconnect your modem from the ISP, end the PPP program, and you will receive your regular prompt back.

Automating the PPP connection

You don't need to enter terminal mode every time you wish to dial your ISP. PPP has a configuration file, ppp.conf, that it reads whenever you start it; let's check that this file contains the information needed to connect to the ISP:

pico /etc/ppp/ppp.conf

At the top of the file, you'll see something like this:

default:

#
# Make sure that "device" references the correct serial port
# for your modem. (cuaa0 = COM1, cuaa1 = COM2)
#

set device /dev/cuaa0

That's pretty straightforward; doublecheck that the "set device" line has the correct COM port for your modem and change it if it doesn't.

Let's move further down the file to the section entitled papchap:.

This is the configuration label for PPP to dial; I hate to type more than I need to, so I usually change it to something shorter, such as isp:. Continue down to:

#
# edit the next three lines and replace the items in caps with
# the values which have been assigned by your ISP
#

set phone PHONE_NUM
set authname USERNAME
set authkey PASSWORD

Again, follow the instructions included in the ppp.conf, and replace the words in caps with the actual phone number, username, and password to your ISP. Save your changes and check whether the configuration file is successful by typing:

ppp
dial isp	(or whatever you called your configuration label)

You should hear your modem dial out and connect, and your prompt should automatically change from ppp to Ppp to PPp to PPP. Let's see if we received the necessary information we need to access the Internet from our ISP:

netstat -rnf inet

Resulting in something like:

Destination       Gateway	       Flags    Netif    Expire
default           xxx.xxx.xxx.xxx  UGSc     tun0
xxx.xxx.xxx.xxx   xxx.xxx.xxx.xxx  UH       tun0

The netstat -rnf inet command allows you to view your IPV4 routing table; tun0 is the tunnel device driver your modem uses with PPP. Flags of UG indicate that you have a gateway that is up. The IP address associated with this entry is the address of your default gateway.

You also need at least one DNS server entry to access the Internet, so let's verify you also received one of these from your ISP by typing:

more /etc/resolv.conf

and you should see entries like this:

nameserver 	xxx.xxx.xxx.xxx

If you have at least one entry, you're in business. For one more test, type:

traceroute www.freebsd.org

You should receive back a numbered list of all the routers between you and www.freebsd.org.

Giving users permission to use PPP

Now let's fine-tune our system for ppp. By default, only root can use ppp, but you don't want to be root just to access the Internet, because that isn't an administrative task. Let's look at the error message, and then fix it. Open up a terminal and log in as a regular user.

ppp

Resulting in:

/usr/sbin/ppp: Permission denied

Now as root:

pico /etc/group

Change the network: line to network:*:69:username1,username2, where username1,username2 is a comma-separated list of the users you wish to give ppp access to. Save this file, switch to a terminal one of these users is logged into, and try again:

ppp

This time, we see:

default: User access denied

What happened? We put the user in the correct group to use ppp, but we didn't tell ppp. Let's edit ppp's configuration file as root:

pico /etc/ppp/ppp.conf

At the end of the default: section, add the following line:

allow users username1 username2

Again, substitute the actual usernames and save the file. Now your users should be able to connect to the Internet using ppp.

If you would like more information on configuring ppp, check out the Pedantic PPP Primer.

Configuring a cable modem

You don't need to configure a connection to your cable provider, as you are always connected. However, you do need an IP address in order to use the Internet. Your cable provider has computers called DHCP (Dynamic Host Configuration Protocol) servers who will lease you an IP address for a period of time. In order to communicate with these DHCP servers, you must configure your NIC to use the DHCP client software that is built into FreeBSD.

If you don't know the device name of your NIC, use:
dmesg | grep Ethernet

Resulting in something like:

rl0: Ethernet address: 00:00:b4:94:9d:3f

If you're not sure if this is the right NIC, you can type:

whatis rl

and get more information:

rl(4) - RealTek 8129/8139 fast ethernet device driver

When you know the device name for your NIC, type:

/stand/sysinstall
and select Configure, and then Networking; use your spacebar to select Interfaces. If you receive a message stating: Running multi-user, assume that the network is already configured?, answer No.

Highlight the entry representing your NIC's device name and press enter.

For the message Do you want to try DHCP configuration on the interface?, answer Yes.

Assuming your cable modem is physically connected to your cable provider and their DHCP server is running, you should receive a message asking if you want to bring your interface up now; answer yes and exit.

Now, let's verify that we will continue to receive the correct DHCP information when we reboot. As root:

reboot

Toward the end of your boot messages, you should notice one or more DHCPREQUESTS followed by a DHCPACK and your DHCP information, which should include your IP address, default gateway address, DNS server address, and lease period.

To test your connectivity, try:

lynx www.freebsd.org/ports

You should be taken to the web site that hosts the descriptions of the FreeBSD ports collection -- an excellent opportunity to start browsing and downloading your favourite applications.

In our next article, we'll discuss building an X Server and a Window Manager.

Dru Lavigne is a network and systems administrator, IT instructor, author and international speaker. She has over a decade of experience administering and teaching Netware, Microsoft, Cisco, Checkpoint, SCO, Solaris, Linux, and BSD systems. A prolific author, she pens the popular FreeBSD Basics column for O'Reilly and is author of BSD Hacks and The Best of FreeBSD Basics.


Read more FreeBSD Basics columns.

Discuss this article in the O'Reilly Network Operating Systems.

Return to the BSD DevCenter.

 

Copyright © 2009 O'Reilly Media, Inc.