I am trying to forward a port from public machine to another machine that is connected via VPN. that machine connects to internet via this VPN. I am using openvpn and iptables on debian.
the vpn works as expected, except i can't get port forwarding to work. i have reviewed many other questions on stackexchange, without success.
vpn client has static ip on vpn. and the public internet address is static as well.
forwarding is enabled...
$ sysctl net.ipv4.ip_forward net.ipv4.ip_forward = 1
the port on the client is open to the public machine, via vpn interface, but is not being forwarded from public machine. i have tried many variations of the iptables commands such as
-d <public ip> and
-i eth0, but can't figure what i am doing wrong.
$ iptables -t nat -A PREROUTING -p tcp --dport 14333 -j DNAT --to-destination 10.8.0.10:14333 $ iptables -t nat -A POSTROUTING -s 10.8.0.0/8 -o eth0 -j MASQUERADE
$ iptables -t nat -L -v
Chain PREROUTING (policy ACCEPT 5252 packets, 328K bytes) pkts bytes target prot opt in out source destination 1471 85380 DNAT tcp -- any any anywhere anywhere tcp dpt:14333 to:10.8.0.10:64333 Chain INPUT (policy ACCEPT 50 packets, 2156 bytes) pkts bytes target prot opt in out source destination Chain OUTPUT (policy ACCEPT 450 packets, 29316 bytes) pkts bytes target prot opt in out source destination Chain POSTROUTING (policy ACCEPT 1998 packets, 122K bytes) pkts bytes target prot opt in out source destination 4435 272K MASQUERADE all -- any eth0 10.0.0.0/8 anywhere
public interface is
eth0 and openvpn is