5
$ /sbin/route -n 
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.122.1   0.0.0.0         UG    0      0        0 ens3
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 ens3

$ /sbin/ifconfig
ens3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.122.202  netmask 255.255.255.0  broadcast 192.168.122.255
        inet6 fe80::5054:ff:fe99:5eee  prefixlen 64  scopeid 0x20<link>
        ether 52:54:00:99:5e:ee  txqueuelen 1000  (Ethernet)
        RX packets 14906  bytes 18020195 (17.1 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 7390  bytes 786783 (768.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 35568

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 496  bytes 39840 (38.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 496  bytes 39840 (38.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

When a packet reaches the host and the packet is destined for the loop back address (127.0.0.1),

  • will it be transmitted to ens3 (192.168.122.202) and then to gateway (192.168.122.1), according to the first rule in the routing table?

  • If yes, isn't that wrong, since the intended destination (127.0.0.1) is in the local host?

Is there really no routing entry when destination addresses are loopback addresses?

Thanks.

0

1 Answer 1

11

The routing table isn’t the first thing taken into account when the kernel processes a packet; there’s a rule table which comes first, which you can see with ip rule list. ip route list (and the deprecated route) list the main table, but there’s a local table which has higher priority and lists all the routes involving the loopback interface; run ip route show table local to see them.

Packets addressed to a loopback address don’t leave the system.

3
  • 1
    Or ip -4 route show table all to show all the IPv4 entries Mar 26, 2019 at 13:57
  • Can the deprecated route only access the routing table main, no the other two local and default?
    – Tim
    Mar 26, 2019 at 23:36
  • I get the impression it can only access the main routing table, yes. Mar 27, 2019 at 5:41

You must log in to answer this question.

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