1

I have two Ubuntu 18.04 and 20.x installs at home and trying to ssh between them, I can connect by Internal IP but not by hostname Setup:

Machine A: 192.x.x.115

Machine B: 192.x.x.125

both installs have ssh running and I can connect fine using internal IP.

From Machine B I would like to connect to Machine A using hostname or hostname.ddns.net

Here are things I have setup:

Machine A:

machineA> /etc/hosts

127.0.0.1    machineA.ddns.net machineA

192.x.x.115 machineA

machineA> /etc/hostname

machineA.ddns.net

machineA> /etc/resolv.conf

nameserver 127.0.0.53
options edns0 trust-ad
search hsd1.xx.isp.net

Machine B:

machineB> ssh user@192.x.x.115 # i.e machineA is successful

machineB> ssh -vvv user@machineA.ddns.net gives

Connecting to machineA.ddns.net [ISP assigned address] port 22.

ssh: connect to host machineA.ddns.net port 22: Connection timed out

machineB> ssh -vvv user@machineA

ssh: Could not resolve hostname machineA: Name or service not known

SSH_from_external_to_machineA is successful

ssh user@machineA.ddns.net # is successful

commands tried on machineA:

machineA> sudo service ssh status # gives active(running)

machineA> sudo netstat -alnp | grep :22 # shows :22 with LISTEN

machineA> sudo iptables -A INPUT -p tcp --dport ssh -j ACCEPT

  1. I feel ISP is not blocking ssh from ssh since I can connect from external using machineA.ddns.net

  2. Router is allowing port 22 since I can connect using IP.

I feel hostname is not resolved correctly, please review and let me know if I am missing any additional steps.

Thanks,

Additional edits:

machineB> ping machineA_Hostname is successful

machineB> nslookup machineA.ddns.net is showing external IP as expected

machineB> ssh machineA # Could not resolve hostname: Name or service not known

machineB> ssh machineA.ddns.net attempts to connect to exact external IP that was reported by ping and 'Connection timed out'

2 Answers2

0

You wanna ssh machine_B from machine_A via hostname, right?

so just put the internal IP of machine_B with a desired name (for calling machine_B) in machine_A

in order to do that, just edit /etc/hosts of machine_A and add something like below:

192.168.222.1 my_lovely_machine_B

now if you type:

ssh user@my_lovely_machine_B

that should work!

BUT if you don't want to bother yourself for hardcoding the internal IP address and make changes everytime (Because IP addresses may change) you can do two things.

First approach: The hard approach but the practical one: you need to run a DNS service such as BIND to get what you want

Second approach: The simple one but not good for every scenario (For you is OK): write a bash script for automation of setting static IP for machine_B and let it run on every startup. in this way you don't need to worry about IP changes and always your machine_B has the same IP.

0

To avoid hardcoding the internal IP address, setup avahi-daemon on Ubuntu for so you can reach hostname ubuntu.local from host OS.

sudo apt-get install avahi-daemon avahi-discover avahi-utils libnss-mdns mdns-scan