0

I'd like to run a Raspberry Pi, on which I'd like to log in with ssh, connected to my router. Then I would like to access it from another RPi, which is connected to another router with physical (and network) distance.

I assume I need

  • a static IP for both RPis and the router.
  • ssh on both RPis.
  • a somehow stable internet connection and router.

Did I forget something?

How to set this up?
How to give my RPi a static IP address?

1

2 Answers 2

2

Getting a static private IP address is entirely between the RPi and its router.

For example, you could configure the router to identify the RPi by MAC address (after ensuring any MAC address randomization features on the RPi OS are switched off... usually wired connections don't randomize MAC addresses by default, but WiFi connections might) and always assign it a particular private IP.

Or if your router provides a particular private subnet (e.g. 192.168.1.0/24 i.e. usable addresses 192.168.1.1 ... 192.168.1.254) but only uses DHCP on some subset of them (e.g. DHCP offers from 192.168.1.10 to 192.168.1.127) then you could just pick one address from outside the DHCP range but within the subnet (say, 192.168.1.200) and just configure it to the RPi as a static IP address.

The rest of your question is basically asking for general home networking advice, nothing specific to Unix or Linux. Strictly speaking, that is off topic for Unix&Linux.SE. But I'll say this:

  • You don't need anything specific on the outbound ssh connection side.
  • You need the internet provider on the inbound ssh connection side to be not using Carrier-grade NAT (CGNAT) and not firewalling all inbound connections.
  • Getting a really static IP tends to have a cost, and is not always possible for home consumer internet connections. But you don't really need a static public IP for the router at the inbound SSH connection side, but a known public IP. If the public IP is non-static (as usual for consumer-grade internet connections), using a dynamic DNS service to assign a static DNS name for it is usually cheaper than getting a static IP address, and then you'll be able to connect by DNS name, even if the IP address will vary. You might even find a free dynamic DNS service for your region sometimes.
  • On the side of the inbound SSH connection, the router needs a port forwarding configured: from the internet-side of the router, a TCP port of your choice needs to be forwarded to the static private IP of the destination RPi.
2
  • That's a more general explanation. How to do it in detail?
    – Nepumuk
    Commented Jun 22, 2023 at 6:03
  • setting fixed DHCP IP and NAT (e.g. port forwarding) is router dependant, finding IP usable by router outside DHCP range is also router dependant.
    – Archemar
    Commented Jun 22, 2023 at 7:30
0

Could you elaborate on your use case?

If you want to send small amount of data between devices - you can use some free cloud MQTT providers and both devices just connect to it. You do not have to play around with the fixed IP

if you want to have SSH access and If your devices are connected to the internet you could build a VPN connections to them and access them via SSH or web remote console.

There are plenty tools for that, some of them are free to use.

I would recommend to look into: https://qbee.io/ - 2 devices for free Docs:

https://jfrog.com/connect/ - free trial docs: https://jfrog.com/connect/post/what-is-remote-ssh-a-guide-by-the-upswift-team/

For both tools NAT is not an issue. VPN is initiated from the device to cloud, so you can close 22 port if needed for inbound connections.

As a bonus in both tools you also get monitoring and more.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .