CMPnet HP announces new 9000 A Class and R Class servers...click here for more information.



networkcomputing
 Site Guide
 Latest Updates
 '96-'98 Articles Index

 Search NWC:
 
 date
 best match
 

 Technology Guides
 Internet/Intranet
 Infrastructure
 Wide Area Systems
 Network Management
 Collaborative Computing
 OSes & Services
 Security
 Middleware
 Servers & Peripherals

 On Our Site
 UnixWorld
 Network Design Manual
 WANsites
 Careers 
 Interactive Buyer's Guide
 Interactive Report Card
 Online News
 Real-World Labs
 E-Mail Poll
 Frezza's Forum
 Workgroup Computing
 ITpro Downloads
 Well-Connected Awards

Sponsored by:
Click Here for 3COM

 CMPnet 3-D Site Map

 Site Services
 Advisory Forum
 Network Computing Links
 Best Jobs USA
 Subscriptions
 Advertising
and Marketing

 N+I
Visionary Articles

 Web Connection
 Industry White Papers
 Special Supplements
 Bookstore
 Newsletter
 Reprints

CMPnet Resources
 Home
 Site Map
 Search
 Ad Info

 Free E-mail
 Sign Up Now 

Get PointCast - free!



Linux gobbles
Microsoft


Tutorial: Set Up a Linux Internet Server Part 1

By Paul Dunne

See that old 25MHz, 386-based PC? Yes, that's right, the one gathering dust over in the corner of the office. It can't run Windows 95, but it still boots -- surely it's not quite ripe for use as that proverbial boat anchor? In this series of articles, I will show how such a modest box can do sterling work on your network -- providing Internet access, file and print services, and even firewall protection -- simply by add ing Linux. So to start with, lets get Linux up and running and connected to the Net. It will be presumed throughout that our attempt is very much a budget one: a simple dialup account to the nearest ISP, a no-name modem, and so forth.

Questions regarding this article should be directed to the author at paul@tiny1.demon.co.uk

Other installments of this Linux Internet server tutorial series include:

Introduction

A previous article in UnixWorld Online has already covered Linux background issues, and contain s plenty of useful resources. If you're not sure quite what Linux is, it might be helpful to take a look there first.

Installation

Installing Linux is straightforward nowadays -- just pick a distribution and run the install program. Before we go anywhere, though, we must check that we CAN install Linux.

Hardware requirements

Linux is modest in its hardware requirements when compared to those of most other modern OSes. Any Intel 386 or later CPU will do. In a pinch we can get by with 40 megabytes or so of hard disk space. Though it will run in only two megabytes of memory, the minimum practical RAM required is four megabytes. Even that can be a tight squeeze for some distribution's installation programs, including Slackware's, so eight megabytes is the practical base line. Linux supports a very wide range of PC hardware, so most PCs will work without further ado. To find out if a particular piece of hardware is supported, see the Linux Hardware HOWTO .

Installation can be via floppy diskettes, from a CDROM, or by NFS over the local network or the Internet.

My choice of Linux distribution (Slackware) explained

In this article, I will be using the Slackware distribution for my examples. Why Slackware? It was for long the ``standard'' distribution. It remains the easiest to adjust to one's needs, as long as one is not afraid to ``get one's hands dirty,'' so to speak. It is also in my experience the quickest to install.

Slackware installation routine

The Slackware setup program is simple and takes the user through all the stages of installation and even does some basic configuration. Rather than simply describe what the install program does, step by step, which would be superfluous, I will concentrate on explaining what is going on ``behind the scenes.''

However, first let's back up a step and make boot and root diskettes. You will most probably be doing this from DOS, with the rawrite.exe program provided on the CD. The diskettes must be formatted first in DOS; then rawrite.exe is run to write the boot and root images.

Secondly, reboot the computer with the boot diskette in the ``A:'' drive. If all goes well, Slackware will present you with a prompt to enter additional parameters. Usually, you can just ignore this and continue by pressing Enter. Sometimes, however, you may need to pass parameters to the Linux kernel to tell it what I/O address your CD-ROM drive uses, for example. A full explanation of all the options is available from the Linux BootPrompt HOWTO .

Your computer will then be booted into the Linux operating system, and when the boot process is complete, you will be prompted to replace the boot diskette with the root diskette.

The root diskette contains an image of a basic root file system, a minimal system from which the rest of the Linux distribution can be installed. Once this file system is mounted, you can login as root, and type ``setup'' on the command line to start installing the system.

To start with, the fdisk program will be run, and you will be asked how many partitions you wish to set up, and what types they should be. The simplest partition procedure is simply to create two partitions, one to hold the root file system, the other for swap space. This may be said to be mandatory for a machine with only four megabytes of RAM, and still highly recommended for those with more. As a crude rule of thumb, let the swap space be twice the amount of physical RAM, but always give yourself at least 16 megabytes total (physical and virtual) memory.

A more sophisticated procedure, particularly if the PC has two or more hard drives, is to create several more partitions. A good basic split is five partitions: / , /usr , /var , /tmp , and the swap partition. This makes no difference to performance when using a single IDE drive. For multiple SCSI devices, however, it would make more sense to split the file system appropriately among the various disks. More details on optimising disk partitions for Linux may be found in the Linux Partition mini-HOWTO .

Once the partitions have been set up, you select the installation media and the destination media. Most commonly, these will be respectively the CD-ROM drive and the hard disk that you have just prepared. But, you do have the option of installing from floppy disks, or over a network using NFS.

The installation process formats your chosen partition(s), using the Ext2 file system, by default. You have no good reason to chose any other file system. Formatting may be quick, or complete (that is, including checking for bad blocks); it is advisable to chose the latter. The time this takes will var y according to the size of hard disk, of course; it is somewhat slower than the DOS format program, but then it is serving a rather more sophisticated file system.

With the hard disk ready, we may choose which of the sets of applications to install. Some are mandatory, others are recommended, and others still are purely optional extras. For our purposes, the ``A'' series should be installed in toto, together with the ``N'' series. A minimal installation will fit comfortably on a 40 megabyte partition; everything takes about 150 megabytes; however, you will want to allow considerably more than that as working space.

Configuration

Once Linux is installed, the Slackware setup program does several of the simpler configuration tasks. Here's the low-down on what it does.

Local keyboard map

For anyone save U.S. readers, a keymap other than the default U.S. keymap is preferable. An alternative keyboard map file is loaded by the loadkeys(1) pr ogram. Please note that some versions of Slackware have a broken installation routine that offers to change your keyboard map, then happily continues to use the U.S. keyboard! This is simple to fix: for example, to use a U.K. keyboard, add the following line to the /etc/rc.d/rc.local system boot configuration file:


loadkeys /usr/lib/kbd/keytables/uk.map

By the way, the Linux keyboard is fully remappable. The *.map files are simple text files, easy to understand and hack. As an example, on my standard 102-key keyboard, I've swapped Caps Lock and Right Ctrl, so that the Control key is where the Good Lord intended it to be!

Mouse

Linux supports most sorts of mouse. Although we won't be running X on this box, a mouse is still useful, as Linux supports mouse-assisted cut-and-paste between virtual text consoles. The selection(1) program supports this, by running as a daemon installing it is an option during the p ackage installation phase. A link is made from the generic /dev/mouse file to the actual device file controlling the serial port to which the mouse is attached.

Modem

Modem configuration is usually a matter of making an optional link from the actual device file to /dev/modem . Any standard internal or external modem should work, with the only configuration work needed being to chose a free IRQ. Those few modems that rely on a DOS program to download firmware at runtime are obviously a problem; the solution is a garage sale! Seriously, in a pinch, if we are really stuck with such a device, booting DOS, setting up the modem, then warm-booting into Linux will work around this problem.

Host Name

Give the machine a name. You'll probably have local naming conventions to follow, so that the new machine fits in with the existing network.

Basic Network Configuration

There is a wealth of information on Linux networking, i n a variety of sources, including The Linux Journal , the NET-3 HOWTO , and Linux Networking News .

Ethernet

Configuring the Ethernet link is simple, and is done for us by the setup program. Here, I will run through what that program does ``"behind the scenes.''

There are two scripts, rc.inet1 and rc.inet2 . The first sets up basic networking, which is what we will be concerned with here. The second deals with NFS, which will be considered later.


HOSTNAME=`hostname`

This sets the host name by running hostname(8) . But how does hostname know what he host name is (if you see what I mean)? In Slackware, the file /etc/HOSTNAME should be manually edited so that it holds the fully-qu alified domain name. This file can then be read at boot-up, and used to set the hostname using hostname(8) , like so:


/bin/hostname `cat /etc/HOSTNAME`

Next, we configure a special device called ``lo'', short for ``loopback''. The loopback device is like a dummy network, in which the machine talks to itself. It has the standard address of 127.0.0.1, and is always required. We use:


/sbin/ifconfig lo 127.0.0.1
/sbin/route add -net 127.0.0.0

Now an optional part, that can be useful if the internet connection is a dial-up one, and is thus intermittent. We don't want the Internet host name to be unusable when the link is down; the special Linux ``dummy'' interface is designed specifically with this in mind.


/sbin/ifconfig dummy ourhost
/sbin/route add ourhost

Rather then typing in these values over and over, we set them once here.


IPADDR="192.168.1.1"	# REPLACE with YOUR
 IP address!
NETMASK="255.255.255.0"	# REPLACE with YOUR netmask!
NETWORK="192.168.1.0"	# REPLACE with YOUR network address!
BROADCAST="192.168.1.255"  # REPLACE with YOUR broadcast address, if you
			   # have one. If not, leave blank and edit below.

Set up the Ethernet device:


/sbin/ifconfig eth0 ${IPADDR} broadcast ${BROADCAST} netmask ${NETMASK}

Add a route to the local network to the routing table:


/sbin/route add ${NETWORK}

Finished!

The other networking configuration file, rc.inet2 , does not concern us here. However, note that it starts various daemons, including the various NFS servers, rpc.portmapi , and more. The install program will take care of this for you.

Name Service

Several files in /etc determine how host name to IP address translation is done.

The /etc/host.conf file

order hosts,bind
multi on

This file determines in what order name resolution shall be attempted. Here, we have specified that first the resolver will attempt to look up names in /etc/hosts , then, if that fails, attempt to use the default nameserver (as specified in /etc/resolv.conf ). The ``multi on'' means the more than one nameserver can be used.

The /etc/hosts file

This file holds a few hostname-to-address mappings that need to be available at boot-time, when no name service is available. Indeed, it can be used instead of a name server. A typical minimum file looks like this:


# For loopbacking (this is mandatory)
127.0.0.1	local		  localhost
# this host 
xxx.xxx.xx.xxx	this.hosts.ip.address
# gateway
xxx.xxx.x.xxx	the.gateway.to.the.internet

The /etc/resolv.conf file

nameserver 127.0.0.1
domain mycompany.com

The file /etc/resolv.conf file controls how the resolver library routines operate. Here, we specify localhost for the address of the name server because I run a caching name server. Alternatively, this could be the IP address of your ISP's name server(s) -- there can be a list. If you are running a local name server on another machine, then put its IP address here. The domain parameter indicates the default domain for unqualified host names.

Caching named

It can be useful to set up a minimal named . This serves as a cache, so that name lookups only have to go out over the Net once; thereafter, they are stored locally, decreasing latency.

This is not the place for a tutorial in configuring named . For further details, there is a good DNS HOWTO . For more general background, you may wish to examine the UnixWorld Online ``DNS Database Files'' tutorial article .

You may wish to use the Linux box to provide name service for the local network. This is a subject for a later article; for now, we will assume that this is being taken care of.

With installation complete, it is advisable to add a root password, and set up one or more ordinary users. Do not succumb to the temptation to use root for everyday work; this account is far too powerful, and sooner or later you will do something you will regret, such as the proverbial rm -fr / , which zaps EVERYTHING! Slackware comes with a nice little ``adduser'' program, which will do everything necessary. In any case, the manual steps are easy enough: edit /etc/passwd to add the user, the file being in the format:


user name:password:user id:group id:real name:home directory:shell

Then, create the user's home directory; and copy any useful files that may be in /etc/skel (common ones are a basic .profile , .less and .term ). Reboot and enjoy!

Internet Connection

Having installed and configured Linux, our final step is to get the Internet link up and running.

Dialup Link

The mechanics of setting up a dial-up link are so dependent on the particular ISP chosen that there isn't much to say in a general article like this one. I prefer SLIP, but many ISPs don't give you the choice anymore. Again, I prefer a static IP address, but most ISPs are now using dynamic addressing. It is worth shelling out a little more to get either a dial-up link with a static address, or a permanent line; but there are work arounds for the worst-case scenario, PPP with dynamic addressing. Space is too limited to consider to delve into making a Linux box happy with dynamic addressing; see the Linux Dynamic IP mini-HOWTO for details.

As an example, I will run through co nfiguring a dial-up link using my preferred configuration, SLIP with a static IP address. The procedure here is simple. A script is written or, more likely, copied from someone else and modified. Here's an example of my local dialup IP connection support program , which takes care of all the ``housekeeping'' of raising and dropping the link, which includes calling the remote computer, adding routing table entries, and the rest. This script is run as often as connections to the Internet are desired, typically from cron(8) .

Using PPP is quite similar. The pppd program, which generally has path name /usr/sbin/pppd , is used. Here, for example, is the command line invocation (put in a script so I don't have to type it out each time) that I would use to connect to my ISP using PPP:


pppd connect 'chat "" ATDT01716640666 CONNECT "" \
ogin: tiny1 word: duh! ocol: PPP' \
/dev/cua3 115200 -detach debug cr
tscts modem defaultroute \
158.152.37.217:158.152.1.222

Where chat is another program called by pppd to actually dial up and log in to the remote termianl server.

The arguments to the chat program are expect-send string pairs:

""
Expect nothing (don't wait for a prompt)

ATDT01716640666
Send the dialing command to the modem

CONNECT
Expect the answer ``CONNECT''

""
Send a return (null text followed by usual return)

ogin: tiny1 word: duh! ocol: PPP
This is the sequence of expect-send strings needed to log in to my ISP. You can also think of these sequences as question-answer pairs, the first being the ``question'' (sent from the ISP), the second the ``answer'' (returned by chat ). Note: only the last few characters need to be specified, as in ``word:'' instead of ``password:'', which has the advantage that you don't need to worry if ``Password:'' is capitalized or not.

The other options are as follows:

Here, /dev/cua3 is the callout serial port that my modem is on; 115200 is the baud rate on that line; -detach tells pppd not to put itself in the background; crtscts says to use hardware flow control on the line; modem tells pppd that this is a modem device so that the program will hang up the phone before terminating; defaultroute makes the PPP link the default route, which is usually what you want; and finally, 158.152.37.217:158.152.1.222 specifies the local and the remote IP addresses, respectively. Note that if you're using dynamic IP addressing, then the noipdefault option would be specified to request this second IP address from the remote hos t.

Permanent Line

A permanent line is simplicity itself, given what has gone before. Use slattach(8) to attach the SLIP interface to the device, like so:


slattach -p slip -s 19200 /dev/ttyS0

The -p option sets the protocol to use on the line. The default is set to cslip , that is, compressed SLIP. Other possible values are slip (normal SLIP), ppp (Point-to-Point Protocol) and kiss (AX.25 TNC protocol). The -s option sets a specific line speed, other than the default.

Then ifconfig and route are used to configure the interface and add the routing table entries respectively, in just the same way as the Ethernet device was configured above.


/etc/ifconfig sl0 $IPADDR pointtopoint $REMADDR up
/etc/route add default gw $REMADDR

Conclusion

At the end of this process, we have a fully-fledged Internet host, capable of performing any of the tasks we might expect such a box to undertake. In our next installment, we set up a Firewall to protect your local network.

Author Biography

Paul Dunne is a writer and consultant who specialises in Linux. He has a home page that describes in more detail what he does.

Print This Page


e-mail Send as e-mail


NWC Home Site Guide WANsites UnixWorld Network Design Manual
Technology
Guides
Careers Network Computing Links ITpro Downloads Interactive Buyer's Guide
Online News Latest Updates Real World Labs Subscriptions WorkGroup Computing



HOME



CMPnet Click here to visit Toshiba.