Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is there some way to define user specific hosts - like in /etc/hosts? Maybe something like ~/.hosts?

I want to be able to specify alternative host names for computers in my local network that I frequently connect to. For example when logging in using ssh, copying stuff with rsync etc.

share|improve this question

migrated from stackoverflow.com Jul 15 '09 at 13:38

This question came from our site for professional and enthusiast programmers.

1  
can you tell what you are actually wanting to do? –  Anonymous Jul 15 '09 at 13:28

2 Answers 2

up vote 19 down vote accepted

For anything ssh based (including rsync over ssh) you can add entries to your ~/.ssh/config file

e.g.

Host myhost
    Hostname myhost.example.com

Then ssh myhost will connect you to myhost.example.com

share|improve this answer
    
+1 very useful :-) –  David Z Jul 15 '09 at 14:13
    
add a "User" option and It's a great recipe for heterogenous systems. –  hayalci Jul 15 '09 at 14:16
1  
I use this approach with wildcards and bash completion for hostnames with the HOSTFILE environment variable. I end up with tab-completion of the 'alternate' hostnames quite nicely. –  ericslaw Jul 15 '09 at 14:29

Specific applications may have something you can use, like Nick suggested, but there is no user homedir equivelent of the /etc/hosts file.

When applications try to resolve hostnames it gets handled by NSS. You can check how NSS handles hostnames on your system by looking at /etc/nsswitch.conf

$ grep host /etc/nsswitch.conf 
hosts:          files dns

This means that hostnames will be resolved first against the file database (/etc/hosts), and failing that against the dns details specified in /etc/resolv.conf

share|improve this answer

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.