Windows 7: how can I add an IP range in the "route" command?
The route command is all about routing ranges of IP. The key to doing ranges is using the netmask portion of the route command.
Basic IP networking lesson
An IPv4 address is a 32 bit number that represents an address on the internet. Taken in binary, the IP address 10.0.0.1
would look like this:
10 .0 .0 .1
00001010 00000000 0000000 00000001
The netmask specifies which portion of the address is the fixed part of the range by specifying a binary 1, and the variable portion of the range is a 0. So, a netmask of 255.255.255.255
represents all bits are fixed and therefore will only route the give IP. A netmask of 0.0.0.0
means all bits are variable, or in other words this matches every IP address. 0.0.0.0
is used for the default route. So, if you want to specify a range, you just need to specify the bits in the netmask you want to match.
If you wanted a route to apply to all the addresses from 10.0.0.0
to 10.0.0.255
your route command would look like
Dest Ip Netmask Gateway
route ADD 10.0.0.0 MASK 255.255.255.0 10.0.0.1
If you wanted a route to apply to only 10.0.0.100
and 10.0.0.103
your command would look like
route ADD 10.0.0.100 MASK 255.255.255.252 10.0.0.1
And if you wanted a route to apply to all addresses 10.0.0.0
to 10.255.255.255
your route would look like
route ADD 10.0.0.0 MASK 255.0.0.0 10.0.0.1
You can also specify in the route
command the interface it should use using the IF
parameter:
route ADD 10.0.0.0 MASK 255.0.0.0 10.0.0.1 IF 2