33

On Windows 7 I have been using the command route add to add routing entries with a gateway. I now want to add a routing entry with no gateway, where the route is directly reachable.

Windows 7 calls such routes "on-link". I have tried creating on-link routes using the route add command and omitting the gateway entry, but that hasn't worked.

How can I create an on-link route in Windows 7?

3 Answers 3

55

You need to put 0.0.0.0 in the gateway entry to create an "on-link" route.

For example, enter the following command in cmd.exe or bash:

route add 10.10.10.100 mask 255.255.255.0 0.0.0.0

3
  • Please describe steps required to do it.
    – gronostaj
    Jul 2, 2013 at 14:46
  • 4
    how do I specify the interface?
    – Jroonk
    Feb 5, 2019 at 2:49
  • What's the on-link for IPV6?
    – Shayan
    Nov 23, 2019 at 21:27
1

You can add an interface using the command

route add 10.10.10.100 mask 255.255.255.0 0.0.0.0 IF <26>
1

The answers here are right when it comes to ipv4, but ipv6 information is missing, so for the others like me looking for ipv6 equivalent, the "on-link" bit would be simply ::. So if you want to add a v6 route to, for example fe80::edc8:81a:d696:331/128 (single ip6), command would be:

route add fe80::edc8:81a:d696:331/128 ::

And in case you want to specify the interface, just add if <number> to the end of the command. Say, if you want to specify interface 10:

route add fe80::edc8:81a:d696:331/128 :: if 10

(usually interface 1 should be the loopback device)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .