20

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?

1
  • 3
    On Linux, prefer the more modern ip addr and ip route tools. Feb 2, 2015 at 9:13

1 Answer 1

27

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.

4
  • Thanks for your reply! So can I have two different gateways in the routing table? I guess I can, but they will be two different subnet?
    – Kintarō
    Feb 2, 2015 at 1:16
  • Note that a gateway is an IP address to which you send packets for a specific network. The default gateway is an IP address to which you send packets that have no other matches in the routing table. So yes, you can have many gateways, if you have different subnets accessible via different routers. You can have multiple default gateways where you have multiple paths to the internet for example.
    – Paul
    Feb 2, 2015 at 1:19
  • You can have multiple gateways - either per subnet (smaller subnets get priority over larger ones) or by having multiple gateways for the same subnet - in which case 1 will be preferred based on metric and position in route table, or by having multiple route tables with different gateways and usong policy based routing to determine which table to use.
    – davidgo
    Mar 18, 2017 at 21:30
  • Thank you so much for this reply
    – Jason Krs
    Mar 15, 2020 at 22:54

You must log in to answer this question.

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