Score:0

iptable forward outbound traffic to LAN failed

mt flag

I'm trying to redirect outbound traffics to a specific ip address and port to another server in LAN.

I used the following command on my router:

iptables -t nat -A PREROUTING -p tcp --dport 1080 -d 130.83.xx.xx -j DNAT --to-destination 192.168.1.34:1080

Which should redirect the traffic bound for 130.83.xx.xx:1080 to 192.168.1.34:1080

However when I tried to use nc to connect to 130.83.xx.xx:1080, nc will not make a successful connection.

I then dig a bit into the network traffic and realized nc got the response from 192.168.1.34 instead of 130.83.xx.xx.

https://i.stack.imgur.com/inHR7.png

I think this makes nc and potentially any other software that does this connection freak out and decides to RST it.

These are all run in VMs with bridge mode on network interface so the network traffic may look a bit weird. Packet No.1 is from the VM that runs nc 130.83.xx.xx 1080 and I think packet No.2 is from the router that does the redirection.

Looks like the router is trying to MASQURADE source ip (192.168.1.17) but did not do the same for response, am I doing something wrong or did I missed some other iptable rules to make this work?

gapsf avatar
ng flag
Add SNAT to outgoing interface
Score:0
mt flag

Found the problem. 192.168.1.34 is responding directly to 192.168.1.17 without being processed by router kernel because they are in the same subnet. So in order for this to work, I'll need to either create a vlan for each of them or physically separate them into different network.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.