Since the PC has a dynamic address, it must be assigned a hostname.
- If the dynamic IP is internal to your network and you control the DHCP/DNS server such as Dnsmasq, you can make it assign a hostname.
- If the dynamic IP is ISP-assigned, use a DDNS service such as DynDNS to assign your PC a hostname.
Once your PC has a proper hostname, you can setup your server as the SSH jumphost:
- Install your laptop's public SSH key in the server and the PC.
In your laptop's ~/.ssh/config
, add the following
Host <PC_hostname>
ProxyJump <server_hostname>
There are 2 alternatives that don't use DDNS.
Make the PC dump its IP in the server:
- PC dumps its IP in
user@server:~/pc-ip-addr.txt
at 1-minute intervals.
- In the laptop, read the file and SSH to the PC's IP.
Make PC maintain a permanent SSH connection to server:
- In the PC,
ssh user@server -R 2222:localhost:2222
- In the laptop,
ssh user@server "ssh user@localhost -p2222"
I heard that connecting via VPN is similar to connecting device to your local network. So I thought I can use VPN connection instead of dynamic dns. Is it possible? Is it possible to do with out services like dynnds? – Артур Мурадянц – 2017-07-26T11:31:39.210
It's true that a VPN connection makes your device "local". Since your IP is dynamic, your your laptop needs a way to identify the PC. I've edited the answer above to include 2 DDNS-free methods. Tell me which you prefer and I'll provide more details. – Eugene Chow – 2017-07-27T01:39:27.413