Configuring Your Computer on a LAN

While Red Hat Linux usually configures your computer to connect to a LAN, you may want to change your configuration for various reasons. Say you have Linux on a laptop computer that you want to connect to another network. Or suppose you ve acquired some computers from a different department. Or you re installing a second network card on your computer and need to make sure the configuration of each network card is correct. Or perhaps Red Hat Linux does not detect your network card.

Red Hat Linux normally configures your network cards during the installation process. All you need is a detectable network card with a Linux driver and a Dynamic Host Configuration Protocol (DHCP) server. Alternatively, you can enter IP address and hostname information manually. If you re connecting to an NIS network, you may need to enter the appropriate names during the installation process. Chapter 28 covers NIS in more detail.

But when problems arise, it s important to know where to look to solve network configuration problems for your Linux computer. Some basic commands include ifconfig and arp (for configuring your network card) and various commands related to the hostname.

It s also useful to understand the basic network configuration files. The /etc/sysconfig/network file is just the start of a series of important Linux network configuration files.

Configuring with ifconfig

Perhaps the key Linux network configuration command is ifconfig , in the /sbin directory. With the right options, you can use this command to assign IP addresses, hardware ports, and network masks, as well as activate or deactivate a network card. It s easy to check your current network configuration. As shown in Figure 21.1, there are two active network components on my computer: an Ethernet card ( eth0 ) and a loopback device ( lo ). As you can see, eth0 includes connection information presumably for the LAN. The loopback device helps you make sure that Linux is properly connected to the TCP/IP protocol stack.

click to expand
Figure 21.1: ifconfig output

It s easy to assign a new IP address to your network card. The following command assigns a new IPv4 address to eth1 :

 # ifconfig eth1 10.122.238.3 

As discussed later in this chapter, the standard network mask for this IP address is 255.0.0.0. You can also specify a different network mask with the new IP address:

 # ifconfig eth1 netmask 255.255.255.0 10.122.238.3 

Red Hat Linux has had problems in the past with assigning IRQ ports or I/O addresses to a second (or later) network card. You can assign different hardware addresses to a network card. For example, the following commands assign IRQ 9 and I/O address 0x300 to the third Ethernet card on your computer:

 # ifconfig eth1 irq 9 # ifconfig eth1 io_addr 0x300 

As you can see in Figure 21.1, these settings correspond to the Interrupt and Base address settings in the output from ifconfig . If you see an error, the interrupt or address may already be assigned or reserved for plug-and-play. .

You can use this command to activate or deactivate your network adapter. For example, the following commands deactivate and activate the eth0 network adapter:

 # ifconfig eth0 down # ifconfig eth0 up 

Configuring with arp

The Address Resolution Protocol (ARP) associates IP addresses with hardware addresses on a network card. Once your computer has made contact with another computer on your network, they exchange hardware addresses, which are then stored in an ARP database. Not surprisingly, you can find this database on your own computer by issuing the arp command (which identifies a problem):

 #  arp  Address      HWtype HWaddress           Flags Mask  Iface 192.168.7.2  ether  00:12:B5:64:3B:B2   C           eth0 RH9laptop   ether  00:60:0B:8A:41:93   C           eth0 192.168.7.2  ether  52:A5:CB:32:52:A2   C           eth0 experimental ether  00:20:78:09:D3:6A   C           eth0 

Depending on how contact was made, the Address column lists either the IP address or the name of the remote computer. The computer name is taken from /etc/ hosts for your convenience. The HWtype column shows the type of network adapter. The HWaddress column lists the hardware address of the adapter, in hexadecimal notation.

This output shows a duplicate IP address, which can stop communication on your network. You can remove the associated computer s entry in your ARP table by using the arp -d computername command. Be sure to substitute the name or IP address of the offending computer for computername .

The Hostname Commands

Several commands are available for defining or listing the name of your computer on various networks. These commands are illustrated in Table 21.1. With all but the dnsdomainname command, you can set the name of your computer. For example, the hostname ilovehackers command sets the name of your computer to ilovehackers .

Table 21.1: Hostname Commands

Command

Function

hostname

Lists or sets the hostname for the local computer

domainname

Lists or sets the NIS domain name

dnsdomainname

Lists the FQDN for the DNS server for your network

nisdomainname

See domainname

ypdomainname

See domainname

Network Configuration Files

Red Hat Linux contains many important network configuration files. These include basic configuration files commonly used on other Linux distributions, such as /etc/hosts , /etc/resolv.conf , and /etc/host.conf . Red Hat Linux also includes some newer configuration files that determine basic network settings in the /etc/sysconfig directory.

Tip  

Red Hat is working toward consolidating configuration data, especially related to network settings, in the /etc/sysconfig directory. If you re not sure where to look for configuration data, this directory is a good place to start.

Static Hostnames ”/etc/hosts

In the first days of the ARPAnet, only a handful of computers ran on this worldwide network. Those computers that were running Unix used the /etc/hosts file as a static database of computer names and IP addresses. Whenever a new university would join this network, it was relatively easy to change /etc/hosts and share a copy of this file with all computers.

While it is no longer practical to use /etc/hosts for the Internet, it is still a viable option for smaller networks. As long as you make sure that every computer on your LAN has the same copy of this file, it can serve your network well.

This file is fairly simple; each line includes an IP address, a fully qualified domain name (FQDN), and/or a hostname:

 192.168.23.121   linux1.mommabears.com   linux1 

DNS Servers ”/etc/resolv.conf

The alternative to /etc/hosts is a Domain Name Service (DNS) server. In Linux, DNS is implemented through the Berkeley Internet Name Domain ( bind ), using the named daemon. (DNS is covered in detail in Chapter 24 .) If you have IP addresses for your DNS servers, you can enter them in the /etc/resolv.conf configuration file.

This is a simple file; every DNS server is known as a nameserver; this file associates it with an IP address. If you re connecting your network to an ISP, you might add the IP addresses of your ISP s DNS server to your file, in lines similar to this one:

 nameserver 207.217.126.81 

Search Order ”/etc/host.conf

There are two databases of hostnames and IP addresses: /etc/hosts and DNS servers. The order is determined by /etc/host.conf . Normally, this file contains only one line:

 order hosts,bind 

This line configures your Linux computer to search for the right IP address in your /etc/hosts file, before checking bind , which, as described in the last section, is the Linux name for a DNS server. You could even include an NIS server in this list; see the discussion on /etc/nsswitch.conf in Chapter 28 for more information.

Basic Network Settings ”/etc/sysconfig/network

Basic network configuration data is listed in /etc/sysconfig/network . If you re having problems with your network, this is a good place to look. You should see the NETWORKING=yes line at the start of this file. Other variables are shown in Table 21.2. Not all of these variables are required in this configuration file; some are unneeded if you use a DHCP server. Others may be located in network-adapter specific files in the /etc/sysconfig/networking/devices directory.

Table 21.2: /etc/sysconfig/network Variables

Variable

Description

NETWORKING

This is yes or no; yes is required to let Red Hat Linux run networking.

HOSTNAME

The hostname name of your computer.

GATEWAY

The Gateway IP address of your computer.

GATEWAYDEV

The network device, such as eth1 , that is connected to the network with the gateway; needed if you have more than one network card on the computer.

NISDOMAIN

The domain name of your NIS system, if available.

 


Mastering Red Hat Linux 9
Building Tablet PC Applications (Pro-Developer)
ISBN: 078214179X
EAN: 2147483647
Year: 2005
Pages: 220

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net