In order to communicate with machines outside your local area network, you need to use a router. This device is the link between your network and the rest of the world. When you need to communicate to a machine outside of your LAN, your host will send the message to the router, which will forward it on through the outside network. The same is true for packets coming in from the outside network. The router will receive the packet and forward it to your host.
If you used the Red Hat installation procedure for configuring your network, this has already been configured for you. For a host connected to the Internet, you should have at the very least three possible routes: a loopback, a route to your LAN, and a default route to your router. By running route without any parameters, you can see your current routing table. The format of the route command is route cmd type target_ip netmask gateway options where cmd is either add or del depending on whether you want to add or delete a route, respectively. If you use del, you then only need the target_ip parameter, which specifies the IP address for which you are routing.
If, on the other hand, you used the add command, you need to specify type to be either -net or -host, where -net is a network that you are routing to and -host is a specific host you are routing to.
The target_ip address specifies either the network or host IP address to which you are routing. There is a special keyword for this option: default. If you specify default instead of an actual IP address, all packets that do not have a specific route listed in the route table will be sent to this route.
netmask allows you to specify the netmask to the network you are routing to. Note that this applies only when using the -net option. The netmask option is used like this: netmask mask_number where mask_number is the actual netmask in dotted notation.
gateway specifies which gateway to use for sending packets to target_ip. For example, if your default route points to the Internet (a likely situation), then your gateway setting should point to your router connecting to the Internet. For example, if the router were 192.168.42.1, this option would be specified as gw 192.168.42.1. You can use hostnames if you want to, so long as they appear in the /etc/hosts file. (See the section "The Domain Name Service," later in this chapter, for details.)
The options available in addition to the ones already stated are as follows:
Uses numerical addresses instead of trying to resolve IP - addresses to hostnames. This is used when invoking route n without either the add or del parameter so you can see which routes are currently set.
Previous | Table of Contents | Next
Specifies the device onto which a routed packet should go. This is useful only if you have a dev multihomed system (a machine with multiple ethn network cards). The ethn parameter specifies the interface's name. This option should always be at the end of the command line.
Was this article helpful?