iptables: does a network address source include localhost?

Does the network address on the third line include localhost (which is also 192.168.1.31)? (Is there a reference for the behaviour? I can't find one -- which is why I'm here.)

Maybe it does because the local machine is on that network?

If it does then do I need one or both of the first two lines in order to exclude localhost from the block? (If it doesn't then I don't need the first two lines, right?)

Which is it?

iptables -A OUTPUT -s localhost -j ACCEPT
iptables -A OUTPUT -s 192.168.1.31 -j ACCEPT
iptables -A OUTPUT -s 192.168.1.0/24 -o enp0s6f1u2 -j DROP

(enp0s6f1u2 is a failover Internet connection (USB tethering to an Android phone with a SIM with limited data). When it's in use I need the services running on the local machine that need to keep running to use it but I want to block other machines on the network from wasting the data allowance.)


The iptables system is designed to work with IP addresses, not with hostnames. You can use hostnames as arguments, but they will be resolved to IP at the time the command is entered.

If your localhost is 192.168.1.31 there is no reason to have the localhost line.

In this case, to exclude localhost you will need to remove both lines.

Localhost is the equivalent of both 127.0.0.1 and 192.168.1.31 in your case.

Since 192.168.1.31 is part of 192.168.1.0/24, you have to specifically made a different rule for it if you want something different applied to it.