Как использовать доменное имя для подключения через ssh к вашему linux-серверу

У меня есть собственный сервер linux (ngnix, gunicorn, python flask), который подключил его через dyndns к моему frtizbox и к моему провайдеру домена и dyndns (selfhost.de). Теперь я хотел бы подключиться к этому серверу Linux с помощью ssh следующим образом:

ssh username@domainname.de 

Это означает, что не с ip addr, потому что это меняется в случае сбоя питания или перезапуска frit box.

Я видел, что есть такие сервисы, как DDClient . Если у меня есть обе машины в локальной сети, я уже могу получить доступ через:

ssh server_name@192.....

Затем я протестировал на обеих машинах, имеющих одну и ту же локальную сеть, для соединения с pubich ip:

ssh server_name@87.38......  --> Error no route to host 

Затем я разрешил порт 22 на моем fritzbox, и это сработало!

Связана ли эта проблема с тем, что обе машины имеют один и тот же общедоступный IP-адрес?

Затем я проверил наличие моего ноутбука в другой сети (точка доступа с мобильным телефоном).

ssh server_name@87.38......  --> Error no route to host 

Наконец, я хочу достичь выше с помощью доменного имени. ..

Затем я разрешил порт 22 на моем fritzbox, и он заработал!

Теперь я также остановил свой ddclient: sudo service ddclient stop

, и я все еще могу получить доступ с помощью

ssh username@domainname.de 

Нужен ли вообще ddclient?

0
задан 24 July 2020 в 08:54

1 ответ

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 username@domainname.de 

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 ...

1
ответ дан 30 July 2020 в 22:03

Другие вопросы по тегам:

Похожие вопросы: