0

I'm conecting to a VPN in Windows to access a remote computer (Linux) with a static IP. From this remote computer I have access to different machines (database, svn, etc.).

I am trying to set up my remote computer to have access from my Windows machine to the database, the svn server, etc, because working on a remote connection is very slow.

So I tried the next lines in /etc/rc.local, but it doesn't work:

/sbin/iptables -P FORWARD ACCEPT
/sbin/iptables --table nat -A POSTROUTING -o eth0 -j MASQUERADE

/sbin/iptables -t nat -A PREROUTING -i eth0 -p tcp -d B1.B2.B3.B4 --dport 89 -j DNAT --to R1.R2.R3.R4:89
/sbin/iptables -A FORWARD -p tcp -d R1.R2.R3.R4 --dport 89 -j ACCEPT

Where B1.B2.B3.B4 is my remote database IP, 89 is the port we use to access the database, and R1.R2.R3.R4 is my remote machine IP.

What is wrong in this configuration?

Thanks.

2 Answers 2

1

Make sure ip_forward is enabled:

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

Also, you need to make sure the VPN pushes routes for B1.B2.B3.B4 to your Windows machine when connecting; if not, you'll have to add the routes yourself.

I think the MASQUERADE rule should be enough, but write it like this:

iptables -t nat -A POSTROUTING -s WINDOWS_BOX_VPN_IP -j MASQUERADE

But if you don't want to mess with iptables, you can use SSH to setup tunnels to your remote services, for example (you need some Windows SSH client that can create tunnels, I'm giving an example how to run this from a linux box):

ssh [email protected] -L 8989:B1.B2.B3.B4:89

This will create a tunnel on localhost:8989 which will forward the connection to B1.B2.B3.B4:89 (look for "Local port forwarding", http://chamibuddhika.wordpress.com/2012/03/21/ssh-tunnelling-explained/ )

3
  • Thanks for your answer. ip_forward is enabled, and I tried with your MASQUERADE rule but it doesn't work either. Your solution with SSH tunneling sounds good, but here I have my SSH port closed, so I cannot implement that solution.
    – maqjav
    Oct 17, 2013 at 6:57
  • If you can establish the VPN, you should be able to SSH afterwards, through the VPN tunnel.
    – Unknown
    Oct 17, 2013 at 7:01
  • Unknown thanks for your time and your answers, at the end I decided to use the solution I posted ahead, but anyway your solution it's good too. Thanks.
    – maqjav
    Oct 21, 2013 at 10:52
0

At the end I found Rinetd that allows TCP redirections with an easy configuration.

According to my question, the configuration I had to add in /etc/rinetd.conf is:

 R1.R2.R3.R4 89 B1.B2.B3.B4 89

Then I run Rinetd:

 /usr/sbin/rinetd

And that's all.

If you want to run it automatically everytime you restart your computer, you can add the command before in the file /etc/rc.local

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.