LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   IPTABLES PORT TRANSLATION / REDIRECT to a different address (http://www.linuxquestions.org/questions/linux-newbie-8/iptables-port-translation-redirect-to-a-different-address-806320/)

daveginorge 05-06-2010 10:56 AM

IPTABLES PORT TRANSLATION / REDIRECT to a different address
 
Hi All
CentOS 5.x

We have 5 CentOS servers performing different tasks. We use VNC for all the servers as they are screen mouse and keyboardless. That all works no problem. I need to be able to log into all from remote locations outside the local network, at present I log into the firewall and run VNC from there to access the rest, this makes things a little slow on the screen. I would like to access the servers on separate ports and have the firewall redirect them to port 5900 on the relevant servers

eg.
lan interface eth0
public interface eth1
firewall-box 192.168.1.1
server1 192.168.1.2
How do I get vnc to be redirected to port 5900 on server1 when I type public_address:5901 in the vnc client
I have tried
Code:

iptables -A FORWARD -p tcp -i ethi --dport 5901 -s $192.168.1.2 -j ACCEPT
iptables -t nat -A PREROUTING -i eth1 -p-tcp --dport 5901 -j DNAT --to 192.168.1.2:5900

This does not work. I have googled a whole lot but all examples show redirect to the local machine.

Is this possible.
Thanks in advance

imitheos 05-07-2010 10:25 AM

Quote:

Originally Posted by daveginorge (Post 3959371)
no problem. I need to be able to log into all from remote locations outside the local network, at present I log into the firewall and run VNC from there to access the rest, this makes things a little slow on the screen. I would like to access the servers on separate ports and have the firewall redirect them to port 5900 on the relevant servers

eg.
lan interface eth0
public interface eth1
firewall-box 192.168.1.1
server1 192.168.1.2
How do I get vnc to be redirected to port 5900 on server1 when I type public_address:5901 in the vnc client
I have tried
Code:

iptables -A FORWARD -p tcp -i ethi --dport 5901 -s $192.168.1.2 -j ACCEPT
iptables -t nat -A PREROUTING -i eth1 -p-tcp --dport 5901 -j DNAT --to 192.168.1.2:5900

This does not work. I have googled a whole lot but all examples show redirect to the local machine.

Is this possible.
Thanks in advance

Have you tried the following ?
Code:

iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 5901 -j DNAT --to-destination 192.168.1.2:5900
iptables -A FORWARD -p tcp --dport 5900 -d 192.168.1.2 -j ACCEPT


arenasa 05-07-2010 02:59 PM

Could be a typo (ethi instead of eth1)... on the first line of your example?


All times are GMT -5. The time now is 11:32 PM.