Please note the new address for this forum : forum.excito.org. The old address redirects here but I don't know for how long. Thanks !
New user's registration have been closed due to high spamming and low trafic on this forum. Please contact forum admins directly if you need an account. Thanks !
SSH access to NATted internal server
SSH access to NATted internal server
Hello firewall and SSH gurus...
I have tried to get SSH/SCP access to my web server in my internal network from outside.
My work machine -> B3 -> Web server
The goal would be to be able to transfer files easily between my work machine and my web server.
B3 is acting as server-router-fw and I have tried to forward a port to my web servers ssh port. (tried with external port 40 to web server port 22), does not work.
Then I tried to use SSH tunneling,
workmachine# ssh -L5650:localhost:5650 b3hostname
and
b3# ssh -L5650:localhost:22 webserverhost (ip is 192.168.1.2)
(opened port 5650 on b3 firewall)
When I try ssh -p 5650 localhost I get "ssh_exchange_identification: Connection closed by remote host"
I can get to my webserver from my B3 but copying files with SCP is not that convenient. Any ideas how to make this work, should not be difficult, I'm just missing the obvious I hope.
I have tried to get SSH/SCP access to my web server in my internal network from outside.
My work machine -> B3 -> Web server
The goal would be to be able to transfer files easily between my work machine and my web server.
B3 is acting as server-router-fw and I have tried to forward a port to my web servers ssh port. (tried with external port 40 to web server port 22), does not work.
Then I tried to use SSH tunneling,
workmachine# ssh -L5650:localhost:5650 b3hostname
and
b3# ssh -L5650:localhost:22 webserverhost (ip is 192.168.1.2)
(opened port 5650 on b3 firewall)
When I try ssh -p 5650 localhost I get "ssh_exchange_identification: Connection closed by remote host"
I can get to my webserver from my B3 but copying files with SCP is not that convenient. Any ideas how to make this work, should not be difficult, I'm just missing the obvious I hope.
Re: SSH access to NATted internal server
Need two rules in the firewall:
Code: Select all
## Adds a portforwarding rule
# iptables -t nat -A PREROUTING -i eth0 -p tcp -m tcp --dport <ext_port> \
--to-destination <webserver>:22
## Actually allow traffic to pass that way
# iptables -A FORWARD -i eth0 -o br0 -p tcp -m tcp -d <webserver> --dport 22 -j ACCEPT
Re: SSH access to NATted internal server
Thanks Gordon,
I'm putting that to /etc/networking/firewall.conf but when I try to "restore" the rules I get "failed at line 63"
line 63 contains
iptables -t nat -A PREROUTING -i eth0 -p tcp -m tcp --dport 3022 --to-destination 192.168.1.2:22
Sorry for being a noob, but...
- is that the correct file and
- should I remove the hash character in the front of the line?
I'm putting that to /etc/networking/firewall.conf but when I try to "restore" the rules I get "failed at line 63"
line 63 contains
iptables -t nat -A PREROUTING -i eth0 -p tcp -m tcp --dport 3022 --to-destination 192.168.1.2:22
Sorry for being a noob, but...
- is that the correct file and
- should I remove the hash character in the front of the line?
Re: SSH access to NATted internal server
I'm sorry, my bad. I forgot to write down the target
This is the correct line:
This is the correct line:
Code: Select all
## Adds a portforwarding rule
# iptables -t nat -A PREROUTING -i eth0 -p tcp -m tcp --dport <ext_port> \
-j DNAT --to-destination <webserver>:22
## Actually allow traffic to pass that way
# iptables -A FORWARD -i eth0 -o br0 -p tcp -m tcp -d <webserver> --dport 22 -j ACCEPT
Re: SSH access to NATted internal server
Still the same error message when restoring the rules.
Re: SSH access to NATted internal server
Hmmm, that's strange...
Although I did make quite a few changes to the original setup. Can you verify that "/lib/modules/2.6.38/kernel/net/ipv4/netfilter/iptable_nat.ko" exists? Or just try
Although I did make quite a few changes to the original setup. Can you verify that "/lib/modules/2.6.38/kernel/net/ipv4/netfilter/iptable_nat.ko" exists? Or just try
Code: Select all
# modprobe iptable_nat
Re: SSH access to NATted internal server
Yes it does exist, but the modprobe command does not do anything.Gordon wrote:Hmmm, that's strange...
Although I did make quite a few changes to the original setup. Can you verify that "/lib/modules/2.6.38/kernel/net/ipv4/netfilter/iptable_nat.ko" exists? Or just tryCode: Select all
# modprobe iptable_nat
Re: SSH access to NATted internal server
That's okay - it means the module is already loaded.Nrde wrote:Yes it does exist, but the modprobe command does not do anything.
I'm not sure what could be wrong - if I type the command at the prompt the rule gets added without issue. So let's recap with your values:
Code: Select all
iptables -t nat -A PREROUTING -i eth0 -p tcp -m tcp --dport 3022 \
-j DNAT --to-destination 192.168.1.2:22
iptables -A FORWARD -i eth0 -o br0 -p tcp -m tcp -d 192.168.1.2 --dport 22 -j ACCEPT
Re: SSH access to NATted internal server
Thanks again,
I copy pasted as a root to command line, the web interface displays port 3022 to be riderected to port 22 of my webserver.
However trying to connect from work with ssh -p 3022 myb3-ip does not work...
How can I see what rules iptables is actually using, maybe there's something left from previous attempts?
I copy pasted as a root to command line, the web interface displays port 3022 to be riderected to port 22 of my webserver.
However trying to connect from work with ssh -p 3022 myb3-ip does not work...
How can I see what rules iptables is actually using, maybe there's something left from previous attempts?
Re: SSH access to NATted internal server
Did you add both lines?
Also, as I am referring to my own B3 I may have made the wrong assumption that you have a WiFi enabled B3. If yours does not have WiFi you need to change the outgoing interface br0 to eth1.
Troubleshooting netfilter is not real easy. Afaik there's no debug option. You could possibly prepend rules with the same filters but a LOG target - this would allow you to verify that the rule can actually be reached and that the filters match. Something else you can do is install and run tcpdump on the B3's LAN interface to see if traffic is being generated when you try to connect. Note that any problem may not be in how the B3 is configured, but also depends on how your webserver responds to incoming packets.e.g. does your webserver use the B3 as its default router?
Also, as I am referring to my own B3 I may have made the wrong assumption that you have a WiFi enabled B3. If yours does not have WiFi you need to change the outgoing interface br0 to eth1.
Troubleshooting netfilter is not real easy. Afaik there's no debug option. You could possibly prepend rules with the same filters but a LOG target - this would allow you to verify that the rule can actually be reached and that the filters match. Something else you can do is install and run tcpdump on the B3's LAN interface to see if traffic is being generated when you try to connect. Note that any problem may not be in how the B3 is configured, but also depends on how your webserver responds to incoming packets.e.g. does your webserver use the B3 as its default router?