-2

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,

127.0.0.1 localhost

127.0.1.1 harish

manually adding hostname aliases

10.2.1.3 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 10.1.10.1 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 127.0.0.53 is the systemd-resolved stub resolver. run "systemd-resolve --status" to see details about the actual nameservers.

nameserver 10.2.254.254 nameserver 8.8.8.8 nameserver 127.0.0.53

search domain.com

I found the DNS that all my nodes are using

xcat node1 dns

SERVER: 10.2.254.254#53(10.2.254.254)

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

route

Kernel IP routing table

Destination Gateway Genmask Flags Metric Ref Use Iface

default gateway 0.0.0.0 UG 100 0 0 enp2s0f1

10.1.10.0 0.0.0.0 255.255.255.0 U 100 0 0 enp2s0f1

link-local 0.0.0.0 255.255.0.0 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
4

Yes, use ~/.ssh/config

Host bsd1
        Hostname 10.9.9.2
        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:
  • 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
1

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

Host node1
    Hostname node1.domain.org
1

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

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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