Page 1 of 1

same SSH address from different connections

Posted: Mon Apr 20, 2020 9:32 pm
by TD540
From my phone I can SSH to my Pi via home network by connecting to its local DNS raspberrypi.local. Obviously that only works on my home network.

Via 4G from my phone I can also SSH to my Pi by connecting to my home's IP (via dynamic dns) because my router forwards a port to my Pi. But I can't connect this way when I'm ON the home network. So the local DNS address for local SSH'ing, and the home IP address for when away.

Is it possible to have only one SSH address that connects from anywhere?

Re: same SSH address from different connections

Posted: Mon Apr 20, 2020 10:18 pm
by rpdom
That depends on your router.

In order to connect to your external IP address from your own network it needs to support something known as "hairpin mode" where it realises that the requested address is actually it's own external address and will route the network traffic back in to your local network. Many routers do not support that mode.

Re: same SSH address from different connections

Posted: Tue Apr 21, 2020 12:53 am
by bls
The other way to solve this is with a DNS server on your local network that has LAN-local addresses (obviously), but also includes your dyndns IP. For instance, I have foobar.mydomain.com as a dynamic DNS address on the internet. My local DNS server also has a mydomain.com set up, and foobar.mydomain.com points to the same host that my router port forwards to.

Re: same SSH address from different connections

Posted: Tue Apr 21, 2020 6:50 am
by rpdom
bls wrote:
Tue Apr 21, 2020 12:53 am
The other way to solve this is with a DNS server on your local network that has LAN-local addresses (obviously), but also includes your dyndns IP. For instance, I have foobar.mydomain.com as a dynamic DNS address on the internet. My local DNS server also has a mydomain.com set up, and foobar.mydomain.com points to the same host that my router port forwards to.
Yes, this is a good workaround. I actually do that. I have DNSMasq on a Pi at home handling all my internal DHCP and DNS. It has a host entry for home.mydomain.com as 192.168.42.30, but externally the DNS for home.mydomain.com resolves as the external IP of my router.

I actually rarely use that now as I have a personal VPN running on some external servers and I can use that to connect to my home network from anywhere and get a working 192.168.42.x address with full access to all my systems.

Re: same SSH address from different connections

Posted: Tue Apr 21, 2020 1:58 pm
by bls
rpdom wrote:
Tue Apr 21, 2020 6:50 am

Yes, this is a good workaround. I actually do that. I have DNSMasq on a Pi at home handling all my internal DHCP and DNS. It has a host entry for home.mydomain.com as 192.168.42.30, but externally the DNS for home.mydomain.com resolves as the external IP of my router.

I actually rarely use that now as I have a personal VPN running on some external servers and I can use that to connect to my home network from anywhere and get a working 192.168.42.x address with full access to all my systems.
I do this also, but it's a feature, not a workaround :lol:

Having a DHCP and DNS server on a computer such as an RPi (as opposed to a router) makes it super-easy to change routers without perturbing the network. It also has a much more approachable interface (command line rather a web page jungle), and I can quickly and easily replace a dead RPi DHCP/DNS server, whereas having to replace a dead or dying router can be pretty distressing on anything other than the simplest home network.

Re: same SSH address from different connections

Posted: Tue Apr 21, 2020 8:18 pm
by TD540
So what I'm reading now is "install Pi-Hole, that'll solve the problem" ?

Re: same SSH address from different connections

Posted: Tue Apr 21, 2020 9:02 pm
by bls
TD540 wrote:
Tue Apr 21, 2020 8:18 pm
So what I'm reading now is "install Pi-Hole, that'll solve the problem" ?
I've looked at Pi-Hole, and that's definitely one way to do it.

I prefer command line, scriptable solutions, and have one for this.