User specific /etc/hosts files?

12

2

Is it possible to have a user specific hosts file, or some other way to map a ip address to a name on a Linux system. I want to be able to ssh to my local machine from an on campus lab without having to memorize my IP address.

I have a full unix account that I use from the lab, but not access to /etc/hosts. My home computer has a fairly static IP address, and it changes little enough I could update it by hand on the remote system.

Ideally I would be able to say ssh me@my_machine.

Edit: About OS, the OS of the host may vary, from Redhat to Ubuntu to even sometimes FreeBSD. I have multiple machines I use with the same account (yay giant University networks) and am just looking for a way to streamline connecting to specific machines.

I am also not interested in something like dynamic dns. By fairly static, I mean that last academic year, I saw my IP address change about 4 times over 9 months. myname.dyndns.org isn't a whole lot better than an IP address as far as typing (I am lazy :P). Maybe sometime I will use something like dyndns to watch for IP changes, but for now I not too worried.

Mike Cooper

Posted 2009-09-30T21:37:39.930

Reputation: 2 036

None of the answers here have anything to do with a user-specific host file -____- – ThorSummoner – 2015-06-05T17:31:48.153

Answers

16

Use a ~/.ssh/config file with something like

Host my-machine

User me

HostName 192.168.63.1

This way, you can even skip the "me@" and do just "ssh my-machine"

codehead

Posted 2009-09-30T21:37:39.930

Reputation: 521

Will this also work with ssh using tools such as scp and rsync? – Mike Cooper – 2009-10-01T06:43:04.460

it will_______________ – Kim – 2009-10-01T07:01:51.163

5

This is how I handle it...

In .bash_aliases

alias myhomepc='ssh me@111.222.333.444'
alias mydevpc='ssh me@mydevpc.work.com'

And then just use it like so:

myworkpc:~ $ myhomepc
Password: 
Last login: Mon Sep 21 15:54:04 2009 from 111.222.333.445
myhomepc:~ $

Using a service like dyndns mentioned above is really handy as well.

djhowell

Posted 2009-09-30T21:37:39.930

Reputation: 3 535

I'd recommend this on top of the dynamic DNS method actually. This way you don't have to worry about your IP changing, plus you have a shorter command to type. alias myhomepc='ssh me@mybox.dyndns.org – John T – 2009-09-30T21:52:58.603

.bash_aliases isn't always read by bash. To be sure, you might need to put it in ~/.bashrc – Atmocreations – 2009-09-30T22:01:54.840

1

What OS are you on specifically? Alternatively, if your router supports DDNS you can register with Dyndns.org and get a free domain name from them. The router will automatically update their record for your domain when the IP changes.

MDMarra

Posted 2009-09-30T21:37:39.930

Reputation: 19 580

1

Consider DynDNS or No-IP. Even if your IP does change, the updater utility will let the DynDNS/No-IP server know your IP has changed and continue to forward to it accordingly. You can have an address like me@mybox.dyndns.org or me@unixbox.no-ip.org.

John T

Posted 2009-09-30T21:37:39.930

Reputation: 149 037

Or if you're using a router with third-party firmware, it can automatically update the DynDNS record each time the DHCP lease is renewed. For reference, I am using Tomato firmware on a Linksys WRT54G to do this. – EmmEff – 2009-09-30T22:46:08.027