I have two rules in my routing tables. The default route, which is to the gateway, and a second route which forwards everything in the network segment to * or to no gateway. Is this second rule necessary so that local packets do not by default go to the router first, or is the nic smart enough to check its own settings and see that if a packet is sending is in it's network segment, not to send it to the gateway?
1 Answers
In general, you will see two rules (at least) in your routing table on most flavors of *nix.
You'll have a route to your local network (for this example, 10.11.12.0/24):
10.11.12.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
And one identifying your default route.
0.0.0.0 10.11.12.1 0.0.0.0 UG 0 0 0 eth0
So, what this effectively tells your kernel, is:
send any packets going to 10.11.12.0/24
out eth0, directly, without specifically sending them to the default router (flags: U = route is UP)
send any packets to any address other than the local network (0.0.0.0 matches anything) to the gateway (10.11.12.1) (flags: U = route is Up, G = gateway).
If you have more interfaces, or you are multi-homed, or if you have specific network or host routes configured, you may see more routes than that, but this is sort of the minimum that you'd see on a regular basis.
By configuring and bringing up the interface, the kernel will automatically create that local network route.
You don't need to manually add that route.

- 19,697
0.0.0.0
in netstat, or*
in the output ofroute -e
just means that there is no gateway set for that route, and that packets are just routed out a particular interface. you will only see that with directly connected networks. – Tim Kennedy Dec 29 '11 at 06:01