I spent hours researching how I can automate 100s of hosts that are all under one local domain. (i'm on a ubuntu linux 17.04 machine)

For example, I have node1.domain.org, node2.domain.org, and the list goes to node100.domain.org

it is practically impossible to edit the /etc/hosts file adding all the alias manually.

For example, localhost harish

manually adding hostname aliases node1.domain.org node1

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

I tried the ip route | grep default and found that the gateway to be but not clue if I should be on this gateway or of any further steps from here.

I tried cat /etc/resolv.conf and found the DNS Server I'm using

cat /etc/resolv.conf

Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)

DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN is the systemd-resolved stub resolver. run "systemd-resolve --status" to see details about the actual nameservers.

nameserver nameserver nameserver

search domain.com

I found the DNS that all my nodes are using

xcat node1 dns


Both remote node dns and my localmachine dns matched.

However, No clue why it is domain.com in resolve.conf file and not domain.org as all the nodes are under domain.org and not domain.com (but it told it will overwrite when I try to edit it and it did. I tried to run 'sudo /etc/init.d/networking restart' or 'sudo service network-manager restart' after updating it to domain.org and the file is overwritten). I observed that can SSH using all aliases such as node1 without using node1.domain.org when I did this change but the file is always overwritten on system restart or when i go on to wifi connection instead of Ethernet connection.

I also tried verifying the route command and everything looks normal, still no clue


Kernel IP routing table

Destination Gateway Genmask Flags Metric Ref Use Iface

default gateway UG 100 0 0 enp2s0f1 U 100 0 0 enp2s0f1

link-local U 1000 0 0 enp2s0f1

All I want is to ssh node1 instead of ssh node1.domain.org or ssh node50 instead of ssh node50.domain.org or do ssh into any node using its alias without adding it manually to /etc/hosts. I just want to find out a robust way to do this.

  • It's not difficult to do this, and it's not even difficult to add hundreds of hosts to a hostfile. Whatever websites you were using, never use them again. – Ken Sharp Oct 30 '18 at 16:08

Yes, use ~/.ssh/config

Host bsd1
        User bsduser
        Port 2243
Host web-backup
        Hostname www-backup.example.com
        User dauser
        Port 2229

Basically, after each Host statement, you can use pretty much any option that would be valid in the system-level ssh_config

Then simply ssh to whatever tag for the host you have to do is -

user@darkstar:~/ $ ssh web-backup
dauser@www-backup.example.com's password:
| improve this answer | |
  • You forgot to disable password authentication. – EEAA May 4 '17 at 0:07
  • Perhaps. But then look at the IP - I basically copy/pasted something from my config, which I use for experimental vms.... – ivanivan May 4 '17 at 0:37

Sure, use your ssh client config (~/.ssh/config):

Host node1
    Hostname node1.domain.org
| improve this answer | |

Honestly, it's effortless.

In ~/.ssh/config:

Host node* server*
  Hostname %h.domain.org

Now every “node” and “server” is mapped to the domain.

$ ssh node04 --> $ ssh node04.domain.org

$ ssh server12 --> $ ssh server12.domain.org

| improve this answer | |

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.