Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have many servers and they all end with the same servers.company.net, so for example vded-xx-001.servers.company.net, and was wondering if it is possible to make it so i can just type the vded-xx-001 and have it append the servers.company.net automatically ?

So i would want to type

ssh user@vded-xx-001

and have it actually connect to

ssh user@vded-xx-001.servers.company.net

I have tried setting my DNS-search domain to servers.company.net, in /etc/network/interfaces, but this did not achieve the desired outcome.

Anyone able to point me in the right direction ?

Thanks in advance

share|improve this question
    
Is there any reason you can not just add search company.net to /etc/resolv.conf ? –  Hennes Apr 16 '13 at 11:21
    
@Hennes Adding search company.net and servers.company.net to resolv.conf has worked. However there is a warning at the top of the file that my changes will be overwritten, if this is the case how do i make them permanent ? –  Tim Lassie Freeborn Apr 16 '13 at 11:27
1  
I would love to answer that and rake in the extra rep, but this post already answers that quite well: :-) askubuntu.com/questions/157154/… –  Hennes Apr 16 '13 at 11:35
    
Actually, contrary to what is discussed in that question, it's normally best to include a search domain list either in /etc/network/interfaces (using a dns-search option) or in the NetworkManager connection configuration field Search domains. –  jdthood Apr 19 '13 at 14:46

3 Answers 3

Yes, you can do this by creating a config file named ~/.ssh/config and entering the following contents:

Host vded-xx-001
User user
Port 22
HostName vded-xx-001.servers.company.net

Now you just have to type this (you don't even need the username any more):

$ ssh vded-xx-001

This also works with the command-line utility scp:

$ scp filename vded-xx-001:/path/
share|improve this answer
    
I am aware that this works for individual hosts but i have hundreds and was hoping i could create a rule that picks up on VDED-* and then for the hostname does host.servers.company.net –  Tim Lassie Freeborn Apr 16 '13 at 11:24
    
@TimLassieFreeborn: you could write a script that generates the entries needed for the config file. I don't know if you can do it dynamically, though. –  Flimm Apr 16 '13 at 11:25

For a quick solution that works across different programs, you can also set the domain vded-xx-001 to redirect to a specific IP address, by editing /etc/hosts to include a line like this:

173.194.41.90  vded-xx-001

This works in your browser: http://vded-xx-001/

As well as with command-line utilities like SSH:

$ ssh user@vded-xx-001

(I personally prefer the SSH config solution though.)

share|improve this answer
up vote 0 down vote accepted

The solution to my problem was to add the search domain to resolv.conf.

This has allowed me to enter

ssh user@vded-xx-001

for any of my servers and it connect to the correct address.

Thank you @Hennes for the answer

share|improve this answer
    
Assuming you are running Ubuntu 12.04 or later, you shouldn't edit /etc/resolv.conf directly because the resolvconf utility generates that file. (Actually it generates /run/resolvconf/resolv.conf to which /etc/resolv.conf is a symbolic link.) Instead you should configure DNS settings through the interface configurer, either ifup or NetworkManager. Ifup: Edit /etc/network/interfaces and add a dns-search servers.company.net line to the stanza for the machine's external network interface. NM: Add servers.company.net to the Search domains field on the IPv4 tab for the connection. –  jdthood Apr 19 '13 at 14:30
    
If /etc/resolv.conf is not a symbolic link to ../run/resolvconf/resolv.conf on your machine then run sudo dpkg-reconfigure resolvconf to restore the symbolic link. –  jdthood Apr 19 '13 at 14:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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