LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Conneting to a computer thru a firewall (https://www.linuxquestions.org/questions/linux-networking-3/conneting-to-a-computer-thru-a-firewall-130640/)

clau_bolson 01-01-2004 04:18 PM

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.

g-rod 01-01-2004 04:29 PM

Are you NATing (MASQUERADING) the outbound(postrouting)?

Mara 01-01-2004 04:31 PM

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:


$IPTABLES -A FORWARD -i $EXTIF -p tcp -d 192.168.1.3 --dport 5555 -j ACCEPT

 $IPTABLES -A PREROUTING -t nat -i $EXTIF -p tcp -d $EXTIP --dport 5555 -j DNAT
--to 192.168.1.3

Edit: I also agree that -t nat is not needed.

clau_bolson 01-01-2004 04:48 PM

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?

g-rod 01-01-2004 05:00 PM

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.

clau_bolson 01-01-2004 05:07 PM

Ą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.

g-rod 01-01-2004 05:08 PM

Did you have to add a postroute rule?

clau_bolson 01-01-2004 05:20 PM

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.