Linux comes with the networking tools. Terry shows you how to get your Linux system talking over Ethernet.
by Terry Dawson
Many people who install Linux on a machine at their workplace or university also wish to connect their machine to the local area network, so that they can make use of an Internet connection or other machines on the network. If you are one of these people and the only thing that has been stopping you is not knowing where to start, I hope this article will demonstrate that it is easy to do so-as long as you are properly prepared and know what things to watch out for.
The following are a few key areas to consider when connecting your Linux machine to a network:
The HOWTO recommends you opt for a 16 bit card such as the 3Com 3c503/16 or the SMC Elite 16/WD8013. Other cards which you might consider if you have a Vesa Local Bus or PCI motherboard are the BOCA Research cards. You might also choose an NE2000, but be careful, since some cards that claim 100% compatibility are not 100% compatible. (Their claims are based on being "100% software compatible", meaning that they provide drivers for DOS that allow, for example, NetWare access. These drivers are useless with Linux.)
Cards to avoid are the 3Com 3c501 card (it performs badly and is broken by design) and Cabletron and Xircom cards, since free Linux drivers are unlikely ever to be available for their products, because these companies have chosen to require a non-disclosure agreement before releasing programming information, which would make it illegal to write a freely distributable Linux driver.
When installing the NIC you must make sure that the card's configuration does not clash with any other installed hardware. Some cards come with a DOS program to configure them. They use a programmable interface, and you should run this to "strap" the card with the configuration you want. You should be particularly careful of the IRQ, control port address and shared memory address settings. Each of these must be free for your NIC to use and be unused by any other hardware in the computer. I use a WD8003 strapped for control port 0x280, IRQ 7 and Shared Memory 0xD0000. Be careful if you use specialized hardware such as SCSI controllers or Multiport Serial cards, as they often use IRQ or Control Port settings in similar ranges, and may conflict. After you have physically installed the NIC, your next step is to check if your kernel already has support for your card. If it doesn't, recompile it so that it does. The easiest way to check if your kernel already supports your card is to reboot your machine. Check that the card is properly detected by the kernel by reading the messages the kernel prints when it is booting. If your card is properly detected, the kernel will print a message something like:
eth0: WD80x3 at 0x280, 00 00 C0 AD 37 1C WD8003, IRQ 7, shared memory at 0xd0000-0xd1fff. wd.c:v1.10 9/23/94 Donald Becker (becker@cesdis.gsfc.nasa.gov)The settings listed should match those that you configured your card for. If your card has not been properly detected, rebuild your kernel to make sure the kernel has support. This is pretty straightforward and you have likely done it before. You simply change to the /usr/src/linux directory and run make config. You will be prompted as to whether to include various drivers. The most important sections for you to answer Yes to are:
IP address: 202.105.54.56 Network address: 202.105.54.0 Broadcast address: 202.105.54.255 Netmask: 255.255.255.0Once you have this information, be sure you have the correct software on your Linux machine. You must be particularly careful to ensure that the network tools you have (ifconfig, route) match the version of kernel you use. The NET-2-HOWTO describes where to get these tools and how to install them. If you run the ifconfig program with no command-line arguments, you will see that it lists the device mentioned in the kernel boot messages: "eth0". This is your Ethernet device. It needs to be configured with the information above, and the ifconfig program is designed to do just that. Use a command line such as:
ifconfig eth0 HOST netmask NETMASK\ broadcast BROADCAST upSo for the above example use the command line:
ifconfig eth0 202.105.54.56\ netmask 255.255.255.0\ broadcast 202.205.54.255 upIf you again run the ifconfig command with no command line arguments, you should see it now has the appropriate values configured.
Once you have your Ethernet device configured, you have one step remaining. As described earlier, the netmask tells your machine which addresses are local and which are remote. If the address is local, your Linux machine can route any datagrams directly to the Ethernet device. If they are remote, datagrams should be sent to the route which supports the link to the rest of the Internet. The router also has an address, so you will need to obtain this from your network administrator. Linux keeps a special table in memory to look up where to send datagrams. This table, called the routing table, is manipulated with the route command. In a simple installation, as you will most likely have, you will need to configure two routes for your Ethernet: one for your local network, and another that tells your Linux machine what to do with datagrams for any remote host. This latter route is called the "default" route.
The route commands are:
route add NETWORK dev eth0 route add default gw ROUTER dev eth0and for the example listed earlier (assuming the router address is as shown):
route add 202.105.54.0 dev eth0 route add default gw 202.105.54.1 dev eth0You can use the route -n command to display the contents of the routing table. The -n argument says to show the addresses as numbers and not try to look up their names, because you don't yet have your name resolver configured. To configure your name resolver, you will need to find out the address of the "NameServer" or "DNS" from your network administrator and put this address in your /etc/resolv.conf file in a line that looks like nameserver NNN.NNN.NNN.NNN, where NNN.NNN.NNN.NNN is the IP address of your nameserver.
Now you should be able to telnet to other IP hosts, both local and remote. If you have configured the name resolver of your Linux machine, then you can use their names, otherwise you should use their addresses.
In addition, the Linux Network Administrator's Guide is available from sunsite.unc.edu in the directory /pub/Linux/docs/LDP/, and can be ordered on paper from SSC (the publishers of Linux Journal) and O'Reilly & Associates.
Terry Dawson has nearly 10 years experience in packet switched data communications, and maintains the NET-2-HOWTO and HAM-HOWTO documents for fun. Terry is keen to see Linux used widely in Amateur Radio applications. He can be reached at terryd@extro.ucc.su.oz.au.