iptables: what does "--src-type LOCAL" mean exactly?

I believe the answer that addr-type LOCAL means loopback is wrong, because it is only a partial answer and is extremely misleading. LOCAL means ANY IP assigned on one of the interfaces of the host, including the loopback. If you say that LOCAL is simply 127.0.0.0/8 (as sasanet has stated), then you'd limit it to the loopback interface, which is plain wrong.

Moreover, the IP can even be routable and public. For the host it's irrelevant, because from its perspective that IP is going to refer to the host itself. If you curl or ping to the public ip assigned on one if its interfaces, it will obviously not going to send the packet out, it will route it locally. example:

ip address show dev eth0:

 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9001 qdisc mq state UP group default qlen 1000
    link/ether 0a:e7:8b:89:d5:f4 brd ff:ff:ff:ff:ff:ff
    inet 172.31.20.254/20 brd 172.31.31.255 scope global dynamic eth0
       valid_lft 3110sec preferred_lft 3110sec

ip route show table local:

local 172.31.20.254 dev eth0 proto kernel scope host src 172.31.20.254

(as already stated, it is obviously irrelevant if the ip is private or public, as long as it is assigned to the network interface)


Pretty good explanation here: http://security.maruhn.com/iptables-tutorial/x6330.html

Another discussion about it: http://www.linuxquestions.org/questions/linux-networking-3/wtf-addrtype-in-iptables-manpage-746659/


The terminology "local route" means the packets will be delivered "locally" to your host, because the destination is assigned to one of your host's interfaces. It does not only mean localhost, as in loopback addresses (nor 169.254/16 as in "link-local" addresses).

Linux uses the Netlink protocol to send messages between kernel space and user space—one of the Netlink families therein is NETLINK_ROUTE, which can be used to receive routing updates, modify interface addresses, etc. For example, the ip-route command from iproute2 uses this.

Looking at the addrtype source code of iptables, you'll see references to linux/rtnetlink.h, which defines RTN_LOCAL as a message type. The rtnetlink(7) man page describes RTN_LOCAL as:

rtm_type          Route type
───────────────────────────────────────────────────────────
RTN_LOCAL         a local interface route

None of this feels exactly clear when you read about it, and some of the best references I can find are miscellaneous Internet sources, so it's understandable why there's confusion.