3

CentOS in particular. Say the machine is sitting on 1.2.3.4 running httpd and makes a request to http://1.2.3.4, does the machine immediately know that the request is destined for itself, and so routes it internally, or does it go out and back?

I'm interested in understanding how this works.

  • 2
    This question seems to imply that some versions of linux are smart enough to avoid going "outside" SO Question but it is short on details. This Other Question implies the same. – Forty3 Dec 1 '17 at 23:57
5

Yes, the machine does immediately know the request is is destined for itself. It does this by comparing the destination address of the packets to all known IP addresses assigned to network interfaces, marking the packet as local, consulting a special routing table (ip route show table local ) which is automatically updated with rules for locally assigned IP addresses, and replacing the network interface to deliver it with lo, even if the the destination address is not 127.0.0.1 (try tcpdump -ni lo while ping'ing a local address).

You can also use ip route get 1.2.3.4 to show how the linux kernel classifies the route (local) and via what interface it will deliver the packet, together with other information like the gateway etc.

| improve this answer | |
  • 2
    and you can use ip route get 1.2.3.4 to have it show you how it would route such a packet. – meuh Dec 2 '17 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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