Route command

Updated: 11/12/2023 by Computer Hope
route command

The route command is used to manually configure the routes in a routing table.

Availability

Route is an external command that is available for the following Microsoft operating systems as route.exe.

Route syntax

Windows Vista and later syntax

ROUTE [-f] [-p] [-4|-6] command [destination] [MASK netmask] [gateway] [METRIC metric] [IF interface]
-f Clears the routing tables of all gateway entries. If this is used with one of the commands, the tables are cleared before running the command.
-p When used with the ADD command, it makes a route persistent across boots of the system. By default, routes are not preserved when the system is restarted. When used with the PRINT command, it displays the list of registered persistent routes. the -p command is ignored for all other commands, which always affect the appropriate persistent routes. This option is not supported Windows'95. command
-4 Force using IPv4.
-6 Force using IPv6.
command One of these:
PRINT Prints a route.
ADD Adds a route.
DELETE Deletes a route.
CHANGE Modifies an existing route destination.
destination Specifies the host.
MASK Specifies that the next parameter is the 'netmask' value.
netmask Specifies a subnet mask value for this route entry. If not specified, it defaults to 255.255.255.255.
gateway Specifies a gateway.
interface The interface number for the specified route.
METRIC Specifies the metric, i.e., the cost for the 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 hostname database file HOSTS.

If the command is PRINT or DELETE the destination or gateway can be a wildcard (asterisk '*'), or the gateway argument may be omitted.

If Dest contains a * or ?, it is treated as a shell pattern and only matching destination routes are printed. The '*' matches any string, and '?' matches any one char. Examples: 157.*.1, 157.*, 127.*, *224*.

Pattern match is only allowed in PRINT command.

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 IF 1
         The route addition failed: The specified mask parameter is invalid. 
		  (Destination & Mask) != Destination.

Windows XP and earlier syntax

ROUTE [-f] [-p] command [destination] [MASK netmask] [gateway] [METRIC metric] [IF interface]
-f Clears the routing tables of all the gateway entries. If this is used with one of the commands, the tables are cleared before running the command.
-p When used with the ADD command, it makes a route persistent across boots of the system. By default, routes are not preserved when the system is restarted. When used with the PRINT command, it displays the list of registered persistent routes. The -p command is ignored for all other commands, which always affect the appropriate persistent routes. This option is not supported Windows'95.
command One of these:

PRINT Prints a route.
ADD Adds a route.
DELETE Deletes a route.
CHANGE Modifies an existing route destination.

destination Specifies the host.
MASK Specifies that the next parameter is the 'netmask' value.
netmask Specifies a subnet mask value for this route entry. If not specified, it defaults to 255.255.255.255.
gateway Specifies a gateway.
interface The interface number for the specified route.
METRIC Specifies the metric, i.e., the cost for the 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 hostname database file HOSTS.

If the command is PRINT or DELETE, the destination or gateway can be a wildcard (asterisk '*'), or the gateway argument may be omitted.

If Dest contains a * or ?, it's treated as a shell pattern, and only matching destination routes are printed. The '*' matches any string, and '?' matches any one char. Examples: 157.*.1, 157.*, 127.*, *224*.

Pattern match is only allowed in PRINT command.

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 IF 1
         The route addition failed: The specified mask parameter is invalid. 
		  (Destination & Mask) != Destination.

Route examples

> route PRINT
rout ADD 157.0.0.0    MASK 255.0.0.0   157.55.80.1   METRIC 3  IF2
^destination ^mask ^gateway ^metric ^interface

When IF is not given, it tries to find the best interface for the gateway.

> route PRINT
> route PRINT 157* .... Only prints those matching 157*
> route DELETE 157.0.0.0
> route PRINT

One way to use this would be as follows: You can't ping the server that you are connecting to, but you know the IP address to be 127.16.16.10.

> route PRINT
Interface List
0x1 ........................... MS TCP Loopback interface
0x2 ...00 14 a4 c3 44 20 ...... Xircom CardBus Ethernet 10/100 Adapter
0x3 ...00 b0 d0 43 55 a5 ...... 3Com EtherLink PCI
0x4 ...00 01 b0 8f 8f 80 ...... NdisWan Adapter
Active Routes:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 127.16.8.14 127.16.8.14 1
127.0.0.0 255.0.0.0 127.0.0.1 127.0.0.1 1
127.16.0.0 255.255.0.0 127.16.8.14 127.16.8.14 1
127.16.8.14 255.255.255.255 127.0.0.1 127.0.0.1 1
192.168.50.0 255.255.255.0 192.168.50.65 192.168.50.65 2
192.168.50.65 255.255.255.255 127.0.0.1 127.0.0.1 1
192.168.50.255 255.255.255.255 192.168.50.65 192.168.50.65 1
224.0.0.0 224.0.0.0 127.16.8.14 127.16.8.14 1
224.0.0.0 224.0.0.0 192.168.50.65 192.168.50.65 1
255.255.255.255 255.255.255.255 192.168.50.65 192.168.50.65 1

Notice that no gateway for the current IP goes to 255.255.255.0, so it must be added. Now enter the following command.

> route ADD 127.16.0.0 MASK 255.255.255.0 <your current IP from winntcfg or winipcfg> METRIC 1

Next, enter the following command:

> route print
Active Routes:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 127.16.8.14 127.16.8.14 1
127.0.0.0 255.0.0.0 127.0.0.1 127.0.0.1 1
127.16.0.0 255.255.0.0 127.16.8.14 127.16.8.14 1
** 127.16.0.0 255.255.255.0 127.16.8.14 127.16.8.14 1
127.16.8.14 255.255.255.255 127.0.0.1 127.0.0.1 1
192.168.50.0 255.255.255.0 192.168.50.65 192.168.50.65 2
192.168.50.65 255.255.255.255 127.0.0.1 127.0.0.1 1
192.168.50.255 255.255.255.255 192.168.50.65 192.168.50.65 1
224.0.0.0 224.0.0.0 127.16.8.14 127.16.8.14 1
224.0.0.0 224.0.0.0 192.168.50.65 192.168.50.65 1
255.255.255.255 255.255.255.255 192.168.50.65 192.168.50.65 1

Notice the ** IP address gives me the default gateway.