My networking knowledge is always spotty, never have done much network administration; a lot is done by trial and error. And restricting my ssh tunnel isn't working right for some reason. Let me explain:
I have a home network, with a home server, let's call it home.example.com. My internet connection is ... too complicated to explain, it goes through several NAT layers to get to the outside world. And does not have a static address on the outside. But I have several server ports at home that I need to be able to access from the big world. I have a cloud-hosted external FreeBSD server, which is accessible on the public internet. Let's call it external.example.com. So to be able to access my home server via ssh, I first set its sshd up to listen on port 2222, and then I run the following ssh command at home:
ssh -N -R *:44444:localhost:2222 user@external.example.com
This works good (obviously, with a few extra -o options to make the connection more reliable), and now if I go do "ssh -p 44444 user@external.example.com", that is forwarded to port 2222 on my home machine, and I get into the ssh server at home and am logged in. Great. If I look on the external server with netstat, I see the following (my external machine's network address is 10.99.88.77, and the dynamic external IP address of my home server is 123.45.67.89):
So far, so good. But for security reasons, I want to restrict this further: I want the tunneled port to only be visible on the loopback port of the external machine, so it doesn't expose it on its external interface. That would mean that I would have to "double hop", first ssh to the external machine itself, get a shell, and then do a second ssh to the home server, but I can live with that. Looking at the ssh documentation, it says that the -R option can take a bind address, so I try this:
ssh -N -R 127.0.0.1:44444: localhost:2222 user@external.example.com
But it doesn't do anything: The port 44444 on the external machine is still accepting connections from everywhere, and I get exactly the same netstat output. And yes, before you even ask: The option GatewayPorts in /etc/ssh/sshd.config is set to yes. There are no messages when starting the ssh tunnel, and no warnings or errors in any system log (auth.log or messages or any others).
What am I doing wrong? Do I not understand what the discussion of "bind address" in the man page for ssh means?
I have a home network, with a home server, let's call it home.example.com. My internet connection is ... too complicated to explain, it goes through several NAT layers to get to the outside world. And does not have a static address on the outside. But I have several server ports at home that I need to be able to access from the big world. I have a cloud-hosted external FreeBSD server, which is accessible on the public internet. Let's call it external.example.com. So to be able to access my home server via ssh, I first set its sshd up to listen on port 2222, and then I run the following ssh command at home:
ssh -N -R *:44444:localhost:2222 user@external.example.com
This works good (obviously, with a few extra -o options to make the connection more reliable), and now if I go do "ssh -p 44444 user@external.example.com", that is forwarded to port 2222 on my home machine, and I get into the ssh server at home and am logged in. Great. If I look on the external server with netstat, I see the following (my external machine's network address is 10.99.88.77, and the dynamic external IP address of my home server is 123.45.67.89):
Code:
netstat -n4a
Active Internet connections (including servers)
Proto Recv-Q Send-Q Local Address Foreign Address (state)
tcp4 0 440 10.99.88.77.22 123.45.67.89.17638 ESTABLISHED
tcp4 0 0 *.44444 *.* LISTEN
...
So far, so good. But for security reasons, I want to restrict this further: I want the tunneled port to only be visible on the loopback port of the external machine, so it doesn't expose it on its external interface. That would mean that I would have to "double hop", first ssh to the external machine itself, get a shell, and then do a second ssh to the home server, but I can live with that. Looking at the ssh documentation, it says that the -R option can take a bind address, so I try this:
ssh -N -R 127.0.0.1:44444: localhost:2222 user@external.example.com
But it doesn't do anything: The port 44444 on the external machine is still accepting connections from everywhere, and I get exactly the same netstat output. And yes, before you even ask: The option GatewayPorts in /etc/ssh/sshd.config is set to yes. There are no messages when starting the ssh tunnel, and no warnings or errors in any system log (auth.log or messages or any others).
What am I doing wrong? Do I not understand what the discussion of "bind address" in the man page for ssh means?