I observed a weird behaviour on linux:
First, I clean all routes and iptables rules:
ip route flush table main
ip route flush table default
ip route flush table local
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
iptables -t nat -F
iptables -t mangle -F
iptables -F
iptables -X
ip6tables -P INPUT ACCEPT
ip6tables -P FORWARD ACCEPT
ip6tables -P OUTPUT ACCEPT
ip6tables -t nat -F
ip6tables -t mangle -F
ip6tables -F
ip6tables -X
Then I add a local route:
ip route add local 127.0.0.1 dev lo proto kernel scope host src 127.0.0.1 table local
Then, on a terminal I open a port with nc -lp 12345
and on another terminal I connect to it with nc 127.0.0.1 12345
and I can send and receive data between the netcat server and client.
So for now, all is good.
Now, from it and after killing the previous netcat server and client, if I run:
iptables -t nat -A POSTROUTING -j MASQUERADE
and I restart the netcat server, then the client fail to connect. Do you know why?
I notice that adding ip route add local 192.168.0.10 dev wlan0 proto kernel scope host src 192.168.0.10 table local
make the netcat connection works again. However, I don't understand why the wlan0 interface (that has 192.168.0.10 as IP) can influence the loopback interface?
For information, I am using ArchLinux