I have a home network with dynamic ip addresses. I would like to obtain ssh-connect from one linux desktop to another one (actually, Ubuntu to CentOS). I can connect with ip address:

loom@ubuntu-desktop:~ $ ssh

The problem is dynamic ip. Next day I must know the new ip to connect. I unsuccessfully tried to use hostname rather than ip:

loom@ubuntu-desktop:~ $ ssh centos-desktop
ssh: Could not resolve hostname centos-desktop: Name or service not known

loom@ubuntu-desktop:~ $ ssh centos-desktop.area
ssh: Could not resolve hostname centos-desktop.area: Name or service not known

There are hosts files for both computers. Centos   localhost localhost.localdomain localhost4 localhost4.localdomain4   centos-desktop.area centos-desktop
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

and Ubuntu   localhost   ubuntu-desktop.area ubuntu-desktop

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

How can I organize ssh access in my network?



Multicast DNS uses a special domain called "local". Host names are automatically registered in this domain.

You should find it already works if you try ssh ubuntu-desktop.local on the ubuntu system, but obviously that's not going to be very useful...

The responder is implemented by Avahi service, which is already a part of all recent distributions.

The resolver is implemented as additional nsswitch module mdns, which unfortunately is not included in RHEL/CentOS.

However, mdns module can be installed from EPEL repository (so be sure to enable it first).

Next, install the necessary packages:

# yum -y install avahi nss-mdns

# systemctl start avahi-service avahi-daemon

# systemctl enable avahi-service avahi-daemon

Next, enable the mdns module in /etc/nsswitch.conf by modifying the hosts: line:

hosts: files mdns_minimal [NOTFOUND=return] dns mdns

If you're using IPv4 only, then use mdns4_minimal and mdns4 instead.

  • Thank you. However, I've got an error, when tried to start avahi-service: Failed to start avahi-service.service: Unit avahi-service.service failed to load: No such file or directory. – Loom Feb 24 '17 at 16:01
  • 1
    Huh. Actually I've never seen it spelled avahi-service before, only avahi-daemon. – sourcejedi Feb 24 '17 at 16:16
  • @Loom ^ does this answer your original question now? – sourcejedi Mar 19 '17 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.