Conneting to a computer thru a firewall
Hi, I think this is extremely simple but I'm stuck.
I have a direct connection to the internet and a private network. I have to enter one of the computers in the private network from the internet. This computer is a linux box with openssh listening in port 22. (ip 192.168.5.2) So I have another box with two network boards, one connected to the internet (ip xx.xx.xx.xx) and another conected to my internal network (192.168.5.37) in this box every port is closed as read with netstat. So far I've wrote: iptables -t nat -A PREROUTING -p tcp -d xx.xx.xx.xx --dport 22 -j DNAT --to 192.168.5.2:22 iptables -A FORWARD -p tcp -d 192.168.5.2 --dport 22 -j ACCEPT but nothing happens, (I am trying to enter from my Windows box using Putty, using xx.xx.xx.xx port 22 as the IP) Please help me, I'm here working on Jan 1 because this has to be ready for tomorrow. Thanks and happy 2004 for you all. |
Are you NATing (MASQUERADING) the outbound(postrouting)?
|
I'm not sure if you need :22 with --to when the port is gived by --dport. Here's part of my firewall (port 5555 is freeciv, btw)
I think that EXTIF and EXTIP are easy to understand. Code:
|
Thanks for your quick answers
g-rod: no, this is a box I set up just for this purpose. Should I? Mara: I rewrote the iptables commands just as yours but nothing happens. iptables -t nat -L -v shows that there are packages entering through that chain. In theory there is nothing more to do, is there? |
Yes you need to translate the source address as the packets go back out.
iptables -t nat -I POSTROUTING -o eth0 -j MASQUERADE; or iptables -t nat -I POSTROUTING -s 192.168.5.2 -o eth0 -j SNAT --to-source <public ip>; The first way NATS all private ips to the ip of the firewall. The second one maps only the ssh machine to a uniwue public address. I think you want the second one. I am assuming the eth0 is your external facing nic. |
ĄSOLVED!
Also I had to add the gateway to the internal machine! (thanks to another question in this forum) Well, thanks again and a happy new year for you. |
Did you have to add a postroute rule?
|
no, I had to write
route add default gw 192.168.5.37 in the machine I was trying to access (192.168.2.2) I wrote the three rules in the gateway, yes: FORWARD PREROUTING POSTROUTING Well, now it works, and that's what matters. |
All times are GMT -5. The time now is 01:13 PM. |