A must command if you do any networking. This one allows you to modify and add to your routing tables. The routing tables is what makes it happen. It is what specifies where packages are sent to reach places. It is the first place to look when you run into problems like "host unreachable or not found" in a network environment.
Route [-f] [command] [destination] [MASK netmask] [gateway] [METRIC metric]
| -f | Clears the routing tables of all gateway entries. This is executed prior to the commands if applied together with a command |
| prints a route | |
| ADD | Adds a route |
| DELETE | Deletes a route |
| CHANGE | Modifies an existing route |
| Destination | Specifies destination host |
| MASK | Specifies that the next parameter is the netmask |
| netmask | Specifies a subnet mask value to be associated with this route entry. If none is specified. It will default to 255.255.255.255 |
| Gateway | gateway Specifies Gateway |
| METRIC | Specifies that the next parameter 'metric' is the cost for this destination |
All symbolic names used for destination are looked up in the network
database
file NETWORKS. The symbolic names for gateway are looked up in the host name
database file HOSTS.
If the command is PRINT or DELETE, wildcards may be used for the destination
and gateway, or the gateway argument may be omitted.
Diagnostic Notes:
Invalid MASK generates an error, that is when (DEST & MASK) != DEST.
Example> route ADD 157.0.0.0 MASK 155.0.0.0 157.55.80.1
The route addition failed: 87
Examples:
> route PRINT
> route ADD 157.0.0.0 MASK 255.0.0.0 157.55.80.1 METRIC 3
^destination ^mask
^gateway
^metric
> route PRINT
> route DELETE 157.0.0.0
> route PRINT
Now lets look at an example and see what it all means. This happens to be mine. At the moment, I'm connected to the Internet through a dial-up connection and have a Network card installed which connects to my local LAN. The IP address for the network card is 192.168.255.240 with a netmask of 255.255.255.0. My Internet connection provides a dynamic IP address and at present it is 153.34.43.7 with a netmask of 255.255.0.0
C:\>route print
Active Routes:
| Network Address | Netmask | Gateway Address | Interface | metric |
| 0.0.0.0. | 0.0.0.0 | 153.34.43.7 | 153.34.43.7 | 1 |
| 127.0.0.0 | 255.0.0.0 | 127.0.0.1 | 127.0.0.1 | 1 |
| 153.34.0.0 | 255.255.0.0 | 153.34.43.7 | 153.34.43.7 | 1 |
| 153.34.43.7 | 255.255.255.255 | 127.0.0.1 | 127.0.0.1 | 1 |
| 153.34.255.255 | 255.255.255.255 | 153.34.43.7 | 153.34.43.7 | 1 |
| 192.168.255.0 | 255.255.255.0 | 192.168.255.240 | 192.168.255.240 | 2 |
| 192.168.255.240 | 255.255.255.255 | 127.0.0.1 | 127.0.0.1 | 1 |
| 192.168.255.255 | 255.255.255.255 | 192.168.255.240 | 192.168.255.240 | 1 |
| 224.0.0.0 | 224.0.0.0 | 153.34.43.7 | 153.34.43.7 | 1 |
| 224.0.0.0 | 224.0.0.0 | 192.168.255.240 | 192.168.255.240 | 1 |
| 255.255.255.255 | 255.255.255.255 | 192.168.255.240 | 192.168.255.240 | 1 |
I will disconnect and then see what the routing table look like. It changed to the one below.
| Network Address | Netmask | Gateway Address | Interface | metric |
| 127.0.0.0 | 255.0.0.0 | 127.0.0.1 | 127.0.0.1 | 1 |
| 192.168.255.0 | 255.255.255.0 | 192.168.255.240 | 192.168.255.240 | 1 |
| 192.168.255.240 | 255.255.255.255 | 127.0.0.1 | 127.0.0.1 | 1 |
| 192.168.255.255 | 255.255.255.255 | 192.168.255.240 | 192.168.255.240 | 1 |
| 224.0.0.0 | 224.0.0.0 | 192.168.255.240 | 192.168.255.240 | 1 |
| 255.255.255.255 | 255.255.255.255 | 192.168.255.240 | 192.168.255.240 | 1 |
Now for some information as to what this means.
Routing is the number one function of IP. Each packet is labeled with source and destination addresses. It is the job of IP to figure out what to do. It compares the addresses to the routing table and decides what needs to be done with the packet. It has basically three choices
Pass it up a layer in the local host
Forward it through one of the attached interfaces - network card or Dial-up
dump it
In order to decide what to do it uses the routing table and selects action in the following order
Host route - a unique route to a specified IP address
Subnet route
To the network
And if none of above fits then to the default
Lets look at the top one first and start:
The first line is the default route signified by the 0.0.0.0 and notice it uses the 153.34.43.7 (the dial-up) as a gateway and interface. This means this is the place packets are sent if no other route is found.
The second line is the loopback -127.0.0.0. That is me
The third line is the network 153.34 and notice that the path to this network is also through the dial-up connection. This is the network for my dynamic IP address at the moment. It is the same path as the default which sound reasonable. Any IP packet needs to go there (unless local) and I'm hoping they (the ISP) has the routers to take care of the rest.
The forth line is the route for my computer (local host). Note that it specifies the loopback address. This again seems quite reasonable. Why not handle my own stuff internally rather than sending it all over the place.
The fifth line is the network broadcast address which again specifies my IP address. sounds reasonable.
The sixth line is getting more interesting. This is the network route for my local LAN network. The path and gateway for the route to this network is my Network card address 192.168.255.240. That sounds reasonable since any packets sent to any of the IP addresses 192.168.255.xxx needs to be shipped on my local LAN through the network card - not through the dial-up interface. Note that the metric for this one is 2 thus other routes would take precedence.
The seventh line again is the route for my computer on the local network. Again it specifies the loopback. Reasonable as above -I'll handle that internally. No need to send stuff destined for me all over.
The eight line again is my local network broadcast address and it specifies my IP (the network card)
The ninth and tenth line are the mulicast IP addresses for one for each network.
The eleventh Line is the limited broadcast address. Note this one is only for my local network and I do not have one for the dial-up one.
Now look ast what happened when I disconnected:
All the dial-up connection routes disappeared. The routes for my local LAN remained but the metric for the network route changed to 1. Furthermore, there is no default route anymore. I do not need one since the only items I'm connected to is the local LAN which is handled by the network route and myself which is taken care of by loopback.
If I had had several subnets on my local network with routers connecting them, I would need a default route to access the other subnets and the gateway would have been the router.
Notice also that in the first example there is no connection or routes between the Dial-up networking and the local LAN. I can get and send IP packets (datagrams) to both places and can receive from both. I have to separate and isolated network connection - one which goes to network 192.168.255 and another which goes anyplace else (whatever the ISP is capable of accessing).
Think about this when assigning IP addresses for your local network nilly
willy. What would happen if I had assigned my local network a network address in use??
Then , when on the net I was trying to access a place that was on that same network.
Copyrighted All rights reserved
Last revised: May 29, 2005.