0

I'm using OpenVPN on a VPS which I want to forward incoming port 7999 from the external IP 198.23.248.150 to the internal IP 10.1.10.2 using iptables. I cannot seem to get the syntax correct and I have made sure forwarding is enabled:

root@insanity:~# cat /proc/sys/net/ipv4/conf/venet0/forwarding             
1

So if anyone could tell me the iptables command I'm looking to use I'd appreciate it so much. I'm losing my mind trying to figure it out.

1 Answer 1

1

You just want to:

iptables -t nat -A PREROUTING -d 198.23.248.150 -p tcp --dport 7999 -j DNAT -to-destination 10.1.10.2

and

echo 1 > /proc/sys/net/ipv4/ip_forward

Also make sure that you've enabled forwarding persistent across reboots.

# Controls IP packet forwarding net.ipv4.ip_forward = 1

in /etc/sysctl.conf

And don't forget to check routing on VPS and on the remote box which has internal IP.

4
  • I'm not sure how you mean check routing on VPS and on remote box which has internal IP. But after doing the commands you said, I can telnet to 10.1.10.2 port 7999 and get an established connection, but I cannot telnet to 198.23.248.150 port 7999 and get a connection.
    – Pei
    Mar 13, 2013 at 0:09
  • How can you connect to internal IP from Internet??
    – gevial
    Mar 13, 2013 at 5:07
  • It doesn't work: root@insanity:~# telnet 10.1.10.2 7987 Trying 10.1.10.2... Connected to 10.1.10.2. Escape character is '^]'. root@insanity:~# iptables -t nat -A PREROUTING -d 198.23.248.150 \ -p tcp --dport 7987 -j DNAT --to-destination 10.1.10.2 root@insanity:~# telnet 198.23.248.150 7987 Trying 198.23.248.150... telnet: Unable to connect to remote host: Connection refused
    – user174217
    May 17, 2013 at 15:20
  • To have connections to the external IP from the machine itself work the DNAT rules also needs to be in the OUTPUT chain.
    – mgorven
    May 17, 2013 at 18:41

You must log in to answer this question.

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