Port forwarding in Ubuntu, from public ip to a client

cn flag

On a VPS with installed Ubuntu server 20.04 and OpenVPN, I need to forward all the traffic from a specific port of the vps public ip, to the same port of a VPN client.


vps public ip:
vps vpn ip:

Client IP:

vpn client ip:

Port forwarding for the port 587: >>

I have tried to run the commands on the VPS (

sudo iptables -t nat -A PREROUTING -p tcp --dport 587 -j DNAT --to-destination
sudo iptables -t nat -A POSTROUTING -p tcp -d --dport 587 -j SNAT --to-source

But the packets are not forwarded to the ip

Any idea how iptables should be configured to make a correct port forwarding?

cn flag

I have found this solution which is working as expected:

sudo sysctl net.ipv4.ip_forward=1
sudo iptables -t nat -A PREROUTING -p tcp --dport 587 -j DNAT --to-destination
#exclude "lo" interface, otherwise dns service stop working
sudo iptables -t nat -A POSTROUTING ! -o lo -j MASQUERADE
I sit in a Tesla and translated this thread with Ai:


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.