I have a dummy interface on my machine.
$ ip link add eth28 type dummy
$ ip addr add 10.10.0.5/24 dev eth28
$ ip link set dev eth28 up
I want to route the packets coming into the interface to a destination IP & port.
I tried adding the following PREROUTING rules –
$ iptables -t nat -A PREROUTING -i eth28 -p tcp -j DNAT --to-destination 127.0.0.1:3000
$ iptables -t nat -A PREROUTING -i eth28 -d 10.10.0.5 -p tcp -j DNAT --to-destination 127.0.0.1:3000
I have a server running at 127.0.0.1:3000.
$ python3 -m http.server 3000 --bind 127.0.0.1
I am trying to redirect packets via curl, however
$ curl http://10.10.0.5:3000
curl: (7) Failed to connect to 10.10.0.5 port 3000: Connection refused
Only rule that worked was –
$ iptables -t nat -A OUTPUT -d 10.10.0.5 -p tcp -j DNAT --to-destination 127.0.0.1:3000
However, this is IP address based filtering and not interface based filtering.
OUTPUT chain does not have an input interface (-i option), Pre-routing chain doesn’t filter input interfaces.
What is a way to achieve this use-case?