3

I have a VPS with a public IP that is running OpenVPN and a local server that is the only VPN client on this.

Is it possible to route incoming traffic on lets say port 80 to the client?

My local server runs on mobile data where I do not get a public IP. The result im looking for is a simple website displaying data which I can access by browsing to the VPNs IP.

1
  • I have somewhat answered your question, but as a suggestion, next time try giving some more information, like openvpn version and which OS are you working on. I've given an iptables answer but on RHEL/CentOS it could be better to use firewalld, for example, as well as you could also be talking about unix distributions which would hardly have iptables available. Your OpenVPN setup may also interfere with whether my answer will work or not, so please let me know if it works or not!
    – Zip
    Commented Dec 24, 2019 at 0:15

1 Answer 1

0

As explained here you should be able to use iptables to forward traffic from a port, in one interface, to some other IP that may be on other interface. Just have in mind that you may need to configure your OpenVPN server to always issue your local server with the same IP, which you can find out how to do here.

In essence,

  1. make sure that forwarding is allowed on your server
sudo sysctl net.ipv4.ip_forward=1
  1. Assuming that your VPN IP is 10.0.0.1 and that your server external interface is eth0, forward connections from port 80 externally to your VPN IP and allow it to answer:
iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 80 -j DNAT --to-destination 10.0.0.1:80
iptables -A FORWARD -p tcp -d 10.0.0.1 --dport 80 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT

To debug connection issues tcpdump is your friend, as in:

# Print all packets on port 80 that pass through the eth0 interface
sudo tcpdump -ni eth0 port 80

Please note that as a general recommendation you should always use encryption, so much that by default the 443 port would also be required to enable HTTPS.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .