Anda di halaman 1dari 16

Top of Form Introduction to Linux Networking

One of the common questions I hear is "How do I network Linux to my Windows computer?". After counting slowly to ten and taking some deep breaths, I then proceed to ask my interlocuter just what they want to do, since the verb "to network" really doesn't mean much to me other than sales-people exchanging business cards at breakfast meetings. You see, "networking" covers a multitude of sins. The Microsoft Windows networking documentation tends to lump everything together and confuse the traditional TCP/IP 'socket' applications with the Microsoft Windows Networking applications, which use a NetBIOS interface. Consequently, people tend to speak of "networking" machines without being specific about whether they are referring to file-sharing, email, web services or other protocols. This is rather like dialling a phone number and expecting to have a meaningful conversation with the fax machine at the other end. In the Linux world, we prefer to be quite specific about the protocols and applications we use. Let's start by describing the different layers of the network protocol stack:

TCP/IP is a four-layer stack, unlike the ISO/OSI seven layer stack. The bottom layer - the physical layer - consists of the network card and associated device driver, most often Ethernet but also Token Ring, PPP (for dial-up connections) and many others. The next layer - the network layer - implements the Internet Protocol, which is the basis of all Internet communications, along with some related protocols such as ICMP. Layer three - the transport layer - consists of the TCP, UDP and similar protocols. No configuration is normally required here. Layer four - the application layer - consists of all the various application clients and servers, such as Samba (file & print server), Apache (web server) and many others, several of which can easily

justify an entire book on their basic configuration. The most important of these applications is the Domain Name Service, which many other applications depend upon. In this article, I'll consider configuration of the lower two layers and of DNS. The step-by-step instructions given here rely upon the GUI configuration tools commonly provided with Linux distributions these days, but in the main article, I'll describe the configuration files and what really happens 'under the covers'. Network Card Configuration First of all, you should know the type of network card in your machine. If you have previously installed Windows on the machine, use the Windows Control Panel to identify the card and note the IRQ and I/O port resources it uses. Device drivers - including network card drivers - can be compiled into the kernel, but more commonly, are provided as separate modules. These can be found in /lib/modules/<kernelver>/kernel/drivers/net. This directory contains the bulk of Ethernet card drivers, and there are separate subdirectories for Appletalk, Token Ring, PCMCIA, wireless and other more specialised drivers. Generally speaking, the installation program for your Linux distribution will almost always detect the network card and configure the system to load the appropriate driver. You can load a driver module with the command "modprobe <drivername>". You can optionally specify parameters such as the IRQ or IO port (generally necessary for old ISA cards), for example:
modprobe ne irq=5 io=0x300

If you are completely in the dark about the type of network card you have, and don't want to remove the lid and read the labels, there is still a way out. You can try to load all network card drivers with the command
modprobe -t drivers/net *

This will try to load all network card drivers, and you may have to watch carefully to see if one loads. Afterwards, give the lsmod command to see if your network card driver is resident in memory. This section of lsmod output shows the 8139too driver (and the mii module, which it uses) is resident:
lockd sunrpc autofs 8139too mii ide-cd cdrom st 55296 73876 11172 16160 2248 30144 31936 28852 1 1 0 1 0 0 0 0 (autoclean) [nfsd] (autoclean) [nfsd lockd] (autoclean) (unused) [8139too] (autoclean) (autoclean) [ide-cd] (unused)

On Red Hat and similar distributions, the module configuration is stored in the file /etc/modules.conf. Here is an extract, showing the relevant lines:
alias eth0 8139too alias eth1 ne2k-pci

This file could also contain options statements, like the example given below for Lycoris.

For Lycoris Desktop/LX, the module configuration is generally handled a slightly different way: The file /etc/modules/default contains a list of modules - including the network card drivers - to be loaded ay boot time and the directory /etc/modules/options may contain a file for each module that requires command line options, one option per line. For example, in configuring Lycoris Desktop/LX on one machine, I found that the installer had failed to identify and configure the network card - an elderly Intel EtherExpress Pro. No problem I know that the required driver module is called eepro.o, and that the card was configured to use IRQ 5 and I/O port 0x300. So I simply edited the file /etc/modules/default, which lists the modules loaded at system start-up, and added the eepro driver as the first line:
eepro ide-floppy sr_mod ide-scsi sound #@@ Automatically generated driver list -- don't edit up to the next @@ - line usb-uhci emu10k1 emu10k1-gp #@@ End of automatically generated driver list parport_lowlevel

Then I added a text file called eepro in the /etc/modules directory, and in it, I put the options for the eepro driver module, one per line:
irq=5 io=0x300

I could also have added a line in /etc/modules.conf, of the form:


options eepro irq=5 io=0x300

In fact, I could also have used an alias statement to load the eepro module, just like in Red Hat. Whichever technique your system uses, once you have the correct network card driver modules loaded, you can turn your attention to configuring the next layer of the protocol stack. IP Configuration While Linux can support a variety of network protocols, such as Novell Netware IPX and Appletalk protocols, the vast majority of systems use TCP/IP. IP configuration will require you to know the IP address of the machine being configured, the netmask for the network it is on, and the default route or gateway which leads to the outside world. You should also know the hostname of your machine, as well as the domain it is part of (note that DNS domains have little or nothing to do with Windows NT domains). For example, the machine I am typing this on is called "freya", and it is in the "cullen.lesbell.com.au" domain. Concatenate these two (with an additional dot), and you get the fully-qualified domain name (FQDN) of the machine: "freya.cullen.lesbell.com.au". You will generally also need to know the IP address of one or more domain name servers (DNS's) - either your own, on your network, or perhaps those supplied by your ISP. Setting the IP Address, Netmask and Default Route As you probably know, UNIX/Linux systems are configured by a hierarchy of scripts when they start up, and these scripts use other, short, scripts to set the values of variables as they run. Each

interface is configured by a file in /etc/sysconfig/network-scripts - for example, the eth0 interface is configured by the file "ifcfg-eth0", while a wireless card interface might be configured by /etc/sysconfig/network-scripts/ifcfg-wlan0. Here's an example:
DEVICE=eth0 BOOTPROTO=static BROADCAST=192.168.168.255 IPADDR=192.168.168.8 NETMASK=255.255.255.0 NETWORK=192.168.168.0 ONBOOT=yes

You can edit this file as required to change any of these options, or you can use a GUI if you prefer. (On Red Hat 8.0, use the command "redhat-config-network" while on Red Hat 7.3 and earlier, use "netconfig"). The hostname is set from the file /etc/sysconfig/network. Here's an example:
NETWORKING=yes GATEWAY=192.168.168.252 GATEWAYDEV="" HOSTNAME=asgard.cullen.lesbell.com.au

The default gateway can be set by a "GATEWAY=" statement in either /etc/sysconfig/network or /etc/sysconfig/network-scripts/ifcfg-ifname - in the latter case, each interface can have a specific default route that applies if the interface is up, but not if it is down. Here's the /etc/sysconfig/network script from a Lycoris Desktop/LX system:
NETWORKING=yes HOSTNAME=baldur.cullen.lesbell.com.au IF_LIST='lo eth tr sl ppp'

while here's the /etc/sysconfig/network-scripts/ifcfg-eth0 file:


#!/bin/sh #>>>Device type: ethernet #>>>Variable declarations: DEVICE=eth0 IPADDR=192.168.168.10 NETMASK=255.255.255.0 NETWORK=192.168.168.0 BROADCAST=192.168.168.255 GATEWAY=192.168.168.252 ONBOOT=yes #>>>End variable declarations BASIC=no

In both cases, you can see it is very similar to a Red Hat system. Configuring DNS DNS configuration is also done similarly under the covers. The first point is that, for simple cases, you don't need a DNS at all. If you just have a few machines in a SoHo network, you can enter their IP addresses, FQDN's and hostnames (or aliases) into the file /etc/hosts:
# Do not remove the following line, or various programs # that require network functionality will fail.

127.0.0.1 192.168.168.8 192.168.168.10

localhost.localdomain localhost asgard.cullen.lesbell.com.au asgard baldur.cullen.lesbell.com.au baldur

Each line consists of an IP address, the fully qualified domain name of the corrseponding machine, and the hostname or alias, with the first two lines referring to the local machine itself. You can add as many machines into this file as you like, but before too long, maintaining the hosts file on all of them becomes a pain and at that point, setting up a DNS starts to seem worth the effort. Even if you don't have your own DNS, you will certainly want to refer to your ISP's DNS, so that you can refer to outside hosts by name, rather than IP address. I dread to think what would happen if you were forced to remember 203.18.241.23, rather than www.pcuser.com.au. The file that sets up the DNS client (technically called the resolver) on your machine is /etc/resolv.conf. It will contain one or more nameserver entries, which specify the IP addresses of the domain name servers you will use for lookups, and either a domain entry or a search entry. A domain entry just names the domain that this machine is in, while a search entry can specify a list of domains to be searched whenever you specify just a hostname and not a FQDN. For example, with this setup in /etc/resolv.conf:
search cullen.lesbell.com.au lesbell.com.au nameserver 192.168.168.1 nameserver 192.168.168.252

I can sit at freya.cullen.lesbell.com.au, point my browser to "http://www" and have it find www.lesbell.com.au (after it figures out there's no www.cullen.lesbell.com.au, that is). And if the nameserver on 192.168.168.1 doesn't respond, after a timeout my machine will fall back to using 192.168.168.252. There you have it - once the basics of the underlying TCP/IP networking are set up, it makes it a lot easier to configure the services - like email, web server, etc, - that sit on top. Step By Step: Network Configuration for Lycoris Desktop/LX Step 1: Configure the network interface:

Open the Control Center, navigate to "Internet and Network" and click on "Network Interfaces". You will need to supply the root pasword when prompted. Check that the interface you want to configure appears in the list - if it doesn't refer to the main article and attempt to load and configure the correct driver module. If your network has a DHCP server, then simply click on "Dynamic Addresses with DHCP"; otherwise, select "Manual" and fill in the IP address of this host, the netmask of the network, and the IP address of the default gateway. The "Broadcast" address field should be auto-completed, based on the values you enter for the IP address and netmask. Check that the interface is enabled, the default route is enabled, and save your work. Step 2. Configure the hostname:

Click on "Hostname and DNS", and ensure the "General" tab has been selected. IF required, enter the hostname in the first field, and then the domain in the "default domain" field. If you are not part of a registered domain, I suggest concocting a name in the ".pvt" top-level domain, as this doesn't exist and can't cause any clashes. If you are not running NIS (and I bet you're not) you should move "NIS/YP" to the bottom of the "services" list. Step 3. Configure DNS:

Click on the DNS tab. For each DNS, either on your corporate network or supplied by your ISP, enter it into the "Name Servers" field and press "Save". You can adjust the order in which the DNS's will be consulted with the up and down arrow buttons. If you want to search any other domains (this can save you having to type anything other than the basic hostnames), then add them in the "Search Domains" list in the same way. Step 4. Configure the hosts file:

Finally, if you have any other local machines which you want to access by name, but you don't have a DNS, then click on the "Hosts" tab and enter them, clicking on "Save" for each one. Then click on "OK". Network Configuration for Red Hat 8.0 Step 1. Configure the network:

Click on the red hat, "System Settings", "Network", then type in the root password. In the "Network Configuration" dialog, you will see a list of interfaces. Select the one that you want to configure, and click on "Edit...", or to add one, click on "Add..." Step 2. If adding a device, select the device type:

As you can see, Red Hat 8.0 supports a huge variety of types of network connections. If you are installing a wireless card, you might know that they mostly appear under "Ethernet Adapters", but you should choose "Wireless Connection" so that you have the opportunity to set the SSID, Channel, WEP key, etc. Step 3. If adding a device, specify the type:

You should also specify the name of the device, along with any resources, if these are not autodetected. Step 4. If editing the interface, configure the interface:

Either select DHCP or static configuration. For the latter, enter the IP address, subnet mask and default gateway address. Make sure that "Activate device when computer starts" is checked, and click on "OK". Step 5. Configure the hosts file:

If you have other local machines which you want to access by name, but you don't have a local DNS, then click on the "Hosts" tab and enter them by clicking on "Add..." for each one, filling in the IP address and hostname, along with any short-form aliases, and clicking on "OK". Step 6. Configure the hostname and DNS lookups:

Click on the "DNS" tab, and enter the local machine's hostname, then enter the IP address of each DNS, either those on your corporate network or those supplied by your ISP. You can also add any other domains you want to be searched at this point. Finally, click on "Close" to save your work. References and Further Reading For more information on wireless networking with Linux, click here. For more information on debugging network configuration problems, click here. Tech Terms: IP Address: IP V4 addresses are 32 bits in length, and are usually written in "dotted quad" notation: each of the four bytes is written down in decimal, with dots between them, such as 207.46.249.27 or 129.42.19.99. On an intranet, we often use "private internet addresses", which often start with 192.168. - for example, 192.168.0.254. Subnet Mask: Part of any address represents a network, and part identifies a specific host (actually, an interface) on that network. The question is, which part is the network, and which part is the host? This question is answered by the Subnet Mask: written out in binary, it consists of 1's for those positions which are part of the network address, and 0's for those positions that are part of the host address. For example: 11111111111111111111111100000000

which means that the first three bytes identify the network, and the last byte identifies the host. This could more easily be written in dotted quad notation as "255.255.255.0". Since modern Internet addressing requires that subnet masks have to consist of a contiguous string of one's followed by a contiguous string of zeros, the shortest way to write a network address together with the associated subnet mask is as the IP address of the network, a slash and the number of ones in the subnet mask - for example, 192.168.0.0/24. Default Router (or Default Gateway): In IP routing, each host and router needs to know the IP address of at least one gateway on the same network which can forward datagrams to distant destinations. In the simplest and commonest case, there is only one gateway leading out of a network, and so all the hosts on that network forward outgoing datagrams to that default gateway, which takes care of things from there. Domain Name Server (DNS): A domain name server is a software service or daemon which maintains a directory of host names and IP addresses. Given a hostname, it can supply the IP address - rather like looking up a telephone directory - but it can also do the reverse, converting IP addresses into hostnames. If a DNS does not know the answer to a query, it can usually consult other DNS's until gets an answer. Most corporate networks have one or more DNS's, while home users generally consult their Internet Service Provider's DNS's. Hostname: The name of a machine. For example: "frodo", "wookie", etc. Fully-Qualified Domain Name: The globally unique name of a machine in a specific domain. For example: "frodo.rivendell.middle-earth.net", "wookie.millenium-falcon.com". If you have found this information valuable, please consider donating to the Red Cross appeal for the victims of the Christchurch earthquake, by clicking here: http://www.redcross.org.nz/donate
Page last updated: 04/Jan/2005 Back to Home Copyright 1987-2010 Les Bell and Associates Pty Ltd. All rights reserved. webmaster@lesbell.com.au ...........................
Bottom of Form

Anda mungkin juga menyukai