Linux – Send a packet over the network even when its target is the local host

ethernetiplinuxnetworking

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).

Best Answer

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

Related Question