0

In my routing table (ip route show command), I've got the following entries:

0.0.0.0/1 via 10.8.3.1 dev tun0
default via 192.168.1.1 dev wlan0

What is the difference between 0.0.0.0 and default? All default traffic is currently being routed through tun0, but if both lines have the same purpose, shouldn't the second line take precedence over the first line?

2 Answers 2

4

A routing table entry requires a prefix length, ie. 0.0.0.0 /1 in your case.

That entry matches only 0.0.0.0 through 127.255.255.255 (with 127.0.0.0/8 being non-routable as loopback range - thx @tontongerrit), so it's not a default route (that needs to match anything: 0.0.0.0 /0).

Using 0.0.0.0/1 and 128.0.0.0/1 in combination as a practical default route is a trick used with some VPN clients to point into a tunnel interface, so they don't have to remove your previous default route, pointing to the Internet. Since /1 prefixes are longer than the /0 prefix they take precedence.

1
  • Thanks, that explains!
    – Subbeh
    May 11 at 6:44
3

In routing, the more specific route (= the higher netmask value - the number behind the "/") takes precedence over the less specific route (lower netmask value). The default route, as stated above, has a netmask of /0. It is the lowest possible number, and it is the solution of last resort, if there is no more specific prefix in the routing table for a specific IP address, then traffic will be routed there.

0.0.0.0/1 covers 0.0.0.1 to 126.255.255.255 (not 127/8 which would typically refer to loopback IPs), and that route will be preferred over 0.0.0.0/0 (= default) if your destination IP address falls into the former range, simply because that prefix is more specific.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.