Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

route -n gives:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.20.254  0.0.0.0         UG    0      0        0 eth0
192.168.20.0    0.0.0.0         255.255.255.0   U     0      0        0 eth0

ifconfig gives:

eth0  Link encap:Ethernet  HWaddr 00:0c:29:f1:76:32
      inet addr:192.168.20.10  Bcast:192.168.20.255  Mask:255.255.255.0
      inet6 addr: fe80::20c:29ff:fef1:7632/64 Scope:Link
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:6387084 errors:0 dropped:24 overruns:0 frame:0
      TX packets:374481 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000
      RX bytes:712509342 (712.5 MB)  TX bytes:37312703 (37.3 MB)
      Interrupt:18 Base address:0x2024

Why do I need 2 routes here instead of 1? What is the point of this line?

192.168.20.0    0.0.0.0         255.255.255.0   U     0      0        0 eth0

My interface address is 192.168.20.X with a netmask of 255.255.255.0, so surely the stack can tell how to get to 192.168.20.Y, why do I have that second entry in the routing table?

share|improve this question
add comment

3 Answers

up vote 1 down vote accepted

The second line is actually the exact information (as pertaining to routing) you stated in the device configuration.

It would not be sensible to have the kernel always look up infos from the device database for every routing decision if we can put that info into the routing table itself.

Imagine the same situation on a router with several attached networks. The technique seen here applies there as well and simplifies routing decisions by a great deal (Only one line more in the routing table vs. 5 interfaces to scan).

share|improve this answer
1  
This makes a lot of sense, since the interface is in the table as well, one look in the routing table does the trick. –  Mark0978 Apr 3 '13 at 18:12
add comment

It means there is no gateway needed to reach addresses within this subnet, as hosts / NICs with these addresses are in your local network and not behind any router. For all I know such entry is always present except perhaps for some point-to-point-tunnel-only setups, and if you add more addresses to your NIC, each subnet added should yield an entry like that.

Each subnet is listed within the routing table to gather all relevant information in one place for kernel to make routing decisions - it is simply more efficient than looking up connected subnets by analysing the interface configuration and most likely critical for large routers in terms of performance.

share|improve this answer
add comment

The second line from your route -n command

192.168.20.0    0.0.0.0         255.255.255.0   U     0      0        0 eth0

Says that for all addresses where the first 3 numbers are 192.168.20 no gateway is needed. 0.0.0.0 is not a legal IPv4 address. Your computer does a logical AND with the destination and the Gen Mask (also known as Netmask) 255.255.255.0 in this case because the first 3 bytes are 255 the first 3 numbers must match exactly. Because the last byte is 0. The last number can be anything.

The first line from your route -n command

0.0.0.0         192.168.20.254  0.0.0.0         UG    0      0        0 eth0

says use this gateway 192.168.20.254 for all other IP addresses. This is probably the address of your router,

share|improve this answer
    
Yes, the other is the router, I was only questioning the one one that started with 192.168.20.0 –  Mark0978 Apr 3 '13 at 18:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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