-->
Page 257
dev ethn | Specifies the device onto which a routed packet should go. This is useful only if you have a multihomed system (a machine with multiple network cards). The ethn parameter specifies the interface's name. This option should always be at the end of the command line. |
In this example, the default route is set up to go to 192.168.42.1, your router:
route add -net default gw 192.168.42.1
(You'll find that many routers are set up such that their IP addresses end in .1. This isn't a rule, but a common practice.) Because this is a -net, the netmask is automatically computed.
Assuming your machine is set up as 192.168.42.12 with a netmask of 255.255.255.0, this route points to your own local area network:
route add -net 192.168.42.0 dev eth0
This keeps the router from having to send packets back to your network after they've sent to it as the default route. The last parameter, dev eth0, specifies that the 192.168.42.0 network is connected to the first Ethernet device in the system.
When route is invoked without a parameter, it displays your current routing table. The output should look something like this:
[root@denon /root]# route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.42.0 * 255.255.255.0 U 0 0 2 eth0 loopback * 255.0.0.0 U 0 0 3 lo default 192.168.42.1 0.0.0.0 UG 0 0 0 eth0
Destination is the destination network or host address for packets, and Gateway is the gateway host (typically a router) used to get to the destination. An * character is displayed if no gateway is set. Flags describe the characteristic of the route. It is possible to have more than one characteristic, as in the default route. The possible flags are
U | The route is up. |
H | The route is a host. |
G | The route is through a gateway. |
Metric gives the route a weight, a lower weight being a faster route. This is useful only for dynamic routing, so you will almost always see this as 0. The Ref column states the number of references to the route. Because this information is not used in the Linux kernel, it is always 0. Use tells you how many times this route has been looked up by your system. Iface is the network interface the route uses.
Page 258
Up until now, I've been referring to hosts by their IP addresses. Although this might be terribly convenient for the computers to use, we humans work much better with names. Obviously, some sort of translation table is needed to convert IP addresses to hostnames. But with millions of machines on the Internet and new ones popping up every day, it would be impossible for everyone to keep this sort of table up-to-date. This is where DNS comes in.
The Domain Name Service (DNS) is the protocol by which each site maintains only its own mapping of IP addresses to machine names. Each site makes this mapping a publicly queriable database so that when people from around the world want to find the corresponding IP address, they simply query the correct database and get their answer.
In order to access this database, you need to run a DNS server for your site. (A DNS server is also known as a nameserver or NS for short.) These servers come in three varieties: primary, secondary, and caching. If you are connecting to an existing network (through your campus network, for example), you will need to run only a caching server. If, on the other hand, you are setting up a new site to be accessed through the Internet, you will need to set up a primary server. Secondary servers become important as your site grows to the point that the primary server can no longer handle the load and queries to it need to be broken up across different machines.
As your machine gets started, it will need to know the mapping of some hostnames to IP addresses (for example, your NIS servers) before DNS can be referenced. This mapping is kept in the /etc/hosts file.
Following is a sample /etc/hosts file:
IP Address | Hostname | Alias |
127.0.0.1 | localhost | |
192.168.42.7 | vestax | www |
192.168.42.8 | mailhub | mailhub.domain.com |
192.168.42.6 | technics |
The leftmost column is the IP address to be resolved. The next column is that host's name. Any subsequent columns are aliases for that host. In the second line, for example, the address 192.168.42.7 is for the host vestax. Another name for vestax is www. The domain name is automatically appended to the hostname by the system; however, many people append it themselves for clarity (for example, www.domain.com).
Page 259
At the very least, you need to have the entries for
In this example, localhost is the first line, followed by vestax, your WWW server. mailhub is the machine with which sendmail communicates for mail, and finally there is technics, the name of the machine from which the /etc/hosts file came.
Every machine in your network is a DNS client. In order to know which DNS server to use, you need to configure the /etc/resolv.conf file. This file should look something like
search domain.com nameserver 192.168.42.1
where domain.com is the domain name of your site and the IP address listed after nameserver is the address of the DNS server with which you will be communicating. You can have up to three nameserver entries, each of which will be tried sequentially until one of them returns an answer.
NOTE |
You must supply the nameserver's IP address, not its hostname. After all, how is the resolver going to know what the nameserver's IP address is until it finds the nameserver? |
While configuring DNS for your site, you will need to be familiar with the following tools:
named is the daemon that needs to run on DNS servers to handle queries. If it cannot answer a query, it is its responsibility to forward the request on to a server that can. Along with queries, named is responsible for performing zone transfers. Zone transferring is the method by which changed DNS information is propagated across the Internet. You will need to install the named daemon from the BIND distribution, available from http://www.redhat.com or on the CD-ROM that comes with this book (filename bind-4.9.5p1-2.i386.rpm).