Linux – What does 0.0.0.0 gateway mean in routing table

linuxnetworkingroutingUbuntu

I am new to being a Linux system admin and I am learning about routing tables.

Currently I have two interfaces in my virtual machine:

vagrant@vagrant-ubuntu-trusty-64:~$ ifconfig
eth0      Link encap:Ethernet  HWaddr 08:00:27:2e:8d:5d  
          inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe2e:8d5d/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3146 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2853 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:218526 (218.5 KB)  TX bytes:212044 (212.0 KB)

eth1      Link encap:Ethernet  HWaddr 08:00:27:5b:5e:65  
          inet addr:172.28.128.3  Bcast:172.28.128.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe5b:5e65/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:14 errors:0 dropped:0 overruns:0 frame:0
          TX packets:31 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:5080 (5.0 KB)  TX bytes:4622 (4.6 KB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

When I execute route -n, I see the following tables:

vagrant@vagrant-ubuntu-trusty-64:~$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.0.2.2        0.0.0.0         UG    0      0        0 eth0
10.0.2.0        0.0.0.0         255.255.255.0   U     0      0        0 eth0
172.28.128.0    0.0.0.0         255.255.255.0   U     0      0        0 eth1

I know that the first entry is the default route. Just wonder what does the 2nd and 3rd entries gateway (0.0.0.0) mean here?

Best Answer

Where the gateway is all zeros, it means there is no gateway.

This is because the networks in question are directly attached to the machine, in that the machine has an IP address on an interface that falls into this network subnet.

Any packets for these networks don't need to be routed, as they are connected, so packets can be sent directly to the destination on the local network.

If the machine has a packet destined for another device on these networks, it will do an ARP request, to find the MAC address that is associated with the IP, and transmit the packet directly to that MAC address.