TransWikia.com

How to use domain name to connect via ssh into your linux server

Ask Ubuntu Asked by sqp_125 on December 23, 2021

I have an own linux server (ngnix, gunicorn, python flask) connected it via dyndns to my frtizbox and to my domain and dyndns provider (selfhost.de). Now I would like to connect to this linux server using ssh like this:

ssh [email protected] 

This means not with the ip addr cause this is changing in case of power breakdown or frit box restart.

I saw that there are services like ddclient. I set this service up but I do not know how to connect now using the above command: I still get this error:

ssh: connect to host domain_name.de port 22: No route to host

OS:

  • Ubuntu server: 20.04 LTS
  • Ubuntu Laptop I want to access the server with has: 18.04 LTS

Details:
If I have both machines in the local network I already can access via:

ssh server_name@192.....

Next I tested with both machines having the same local network to connect with publich ip:

ssh [email protected]......  --> Error no route to host 

I then allowed port 22 at my fritzbox and it worked!

Is this issue related to that both machines have the same public ip?

Next I tested to have my laptop in other network (hotspot with mobile phone)

ssh [email protected]......  --> Error no route to host 

Finally I want to achieve above with domain name….

I then allowed port 22 at my fritzbox and it worked!

I also stopped now my ddclient:
sudo service ddclient stop

and I still can access using

ssh [email protected] 

Do I need ddclient at all?

One Answer

Is this issue related to that both machines have the same public ip?

No, this is because your public IP points to your Fritzbox and not the machines. So you need to tell the Fritzbox what to do with requests. That is why you use "Port Forwarding". Then, the Fritzbox forwards the traffic from that port to the local machine. You can also tell the Fritzbox to forward all traffic to one machine, but don't do this if you're not 100% sure what you're doing.

I still can access using

 ssh [email protected] 

Do I need ddclient at all?

It works because your IP did not change yet. Once it changes, domainname.de will still point to the old IP address which then won't work. You need to tell the service provider your new IP address, and that is what ddclient is doing automatically for you.


Off-question notes:

Be aware that forwarding ports in your router comes with great risks. Your machine will get attacked (that is normal) and you should know how to deal with it:

  • keep software up to date (always!) and track relevant security bulletins
  • strong passwords or better: allow only key-based authentication
  • deny root login
  • use a port other than the standard port
  • use fail2ban
  • use a software firewall on the machine
  • use port-knocking

You don't necessarily need all of this at once ...

Answered by pLumo on December 23, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP