6

When I try to connect to my Ubuntu device with the ssh terminal command, I have to add .local suffix to Ubuntu hostname. For example, if I want to ssh to my device with its hostname, my ssh command must have the .local suffix and command has the following format:

ssh username@device_hostname.local 

I'm aware that the .local suffix was appended by avahi (zeroconf) Linux service, but is there any quick (easy) way to bypass it? I want to be able to "ssh" my device only by its hostname without .local suffix at the end of the command, like this:

ssh username@device_hostname

What exactly I want to achieve is to completely remove the .local suffix from host name. I've read about running my private DNS server, but I would like to know if there is a less complex solution.

David Foerster
  • 36,890
  • 56
  • 97
  • 151

2 Answers2

1

Your clients will need at least one way to resolve the hostname to an IP address. The mechanism you already discovered works through automatic configuration and happens within the .local domain name.

You could define the mapping from hostname to IP addresses on every client, but this is not recommended practice.

You will have to go through some kind of automatic name resolution mechanism, all of which require use of some kind of domain name in the background.

However, you can easily get rid of having to type the domain name each time by doing one of:

ssh hostname canonicalisation

If you put the following into /etc/ssh_config or ~/.ssh/config:

Host *
  CanonicalDomains local
  CanonicalizeHostname yes

ssh will automatically append local to any hostname. So when you type ssh host it will actually do ssh host.local.

search domains

While the above will work only for ssh, you can also configure a similar thing for all network connections by configuring the dns resolver on your client accordingly. It is the "classical" way of having hostname shortcuts.

Depending on which setup you have, you would add local to the list of search domains. This is what I do. There should be plenty description for this available, like this.

hardcoding to /etc/hosts

This is not recommended at all, because although it seems simple in the beginning, it will become hard to maintain soon. But it is the only way known to me that allows to completely get rid of domain names.

Edit the file /etc/hosts and add lines like this:

192.168.1.3 host3
192.168.1.4 host4

While the first word in each line is the IP address of the corresponding host. You have to do that on every client. After that you can use ssh host3, and not even in the background a domain name will be used.

-2

In /etc/hostname is the name you want to update. For example mydomiain.com and I'm assuming you have root access. The command hostname can also be used. So you'll need to update the file with vi. Whatever is in line 1 needs to be updated with your domain name. Pretty simple.