Score:0

How to replace MASQUERADE with SNAT for outgoing connection in iptables

sa flag

I have a scenario like following :

PC1(192.168.1.100) ---> iptables(192.168.1.1 / PUBLIC_IP (ens160) ) ---> PUBLIC_SERVER ( SOME_IP)

I want to let my PC1 to connect to a specific port of iptables and then iptables redirect the connection to PUBLIC_SERVER for that I've written :

iptables -t nat -A PREROUTING -d 192.168.1.1 -p tcp --dport 9999 -j DNAT --to SOME_IP:9999

and for routing packet through my output interface I've written following rule :

iptables -t nat -A POSTROUTING -o ens160 -j MASQUERADE

This rule works but I want to replace the MASQUERADE part with SNAT and I think following is correct in essence but I don't get any response back from PC1 while I'm replacing this rule :

iptables -t nat -A POSTROUTING -o ens160 -j SNAT --to PUBLIC_IP

How can I replace a MASQUERADE rule with a SNAT in a similar situation while the outgoing part is located on internet not on my local network?

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.