Windows: adding routes


To view the existing routes,

C:\> route print

To add a static route,

Syntax:

C:\> route add <target> mask <netmask> <gateway IP> metric <metric cost> if <interface>

Example:

C:\> route add 10.10.10.0 mask 255.255.255.0 192.168.1.1 metric 1

Note: If there is more than one Network Interface and if the interface is not mentioned, the interface is selected based on the gateway IP.

This Static route gets erased when the system reboots. To avoid this, use the -p (Persistent) switch to the above command:

C:\> route -p add 10.10.10.0 mask 255.255.255.0 192.168.1.1 metric 1

This writes the persistent route to the following Windows Registry key as a string value (REG_SZ):

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\PersistentRoutes

Also, you can write a small batch file with the route commands and add it to the startup folder to add the routes at startup (similar to the startup scripts in Solaris)