10

Under Linux if you send a packet to the address of one of its network interfaces, this packet is routed internally, it is never sent over the network. That's the right thing in 99.99% of the cases.

Occasionally, when testing network configurations, it's useful to send a packet over a local link from the machine itself, with the machine itself as the target. How can I do this? At least for a bus-type link such as Ethernet, if not for a point-to-point link. I'm only interested in IP packets (both IPv4 and IPv6).

  • Tried nmap scanning? – Ruban Savvy Dec 23 '13 at 6:56
  • Are you interested in the packet physically going out to the network and getting routed back in? Or do you just want it to appear as if it did (go through the routing stack, iptables, etc)? – Patrick Dec 24 '13 at 5:05
  • @Patrick I want it to go out and reach the local router. Though staying in but looking locally as if it had gone out could also be useful in different circumstances. – Gilles 'SO- stop being evil' Dec 24 '13 at 16:04
  • @Gilles Did you ever have any success with this? I'm currently trying to do this with two TAP adapters and some simple bridging code and not having any success. The routing appears to be correct, but ARP doesn't seem to be working (packets are going out with src mac == dst mac). I could explain my setup if it would help. – Jonathon Reinhart Jul 8 '14 at 19:50
  • 1
    @Gilles I have not tried any of this, but I can imagine implementing a router in a way that it never sends anything back to where it came from, e.g. to prevent eternal bouncing between two routers. Just a thing to keep an eye on while testing in case the package goes out but never comes back. – Anthon Jul 9 '14 at 10:46
7

Each network adapter on linux has a sysctl boolean parameter accept_local (/proc/sys/net/ipv4/conf/eth0/accept_local). Try setting it to 0 for all adapters involved (additionally, you may need to modify your routing table to suit your test setup).

Also, make sure that rp_filter (/proc/sys/net/ipv4/conf/eth0/rp_filter) is enabled (not 0).

Reference: http://code.metager.de/source/xref/linux/stable/Documentation/networking/ip-sysctl.txt

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.