# Are abbreviated hostnames possible?

## Malvineous

Hi all,

I frequently access a couple of servers that aren't on my domain, so I need to use a fully qualified host name.  Rather than "ssh some.really.long.name.here.com" I would rather just "ssh bob" using a short name, but since this isn't limited to SSH it has to work for any TCP/IP program (ping, scp, git, HTTP, etc.)

I think I can do this by putting the IP in /etc/hosts with the long and short name, but this will break if/when the host changes IP address.  I need something like this but without locking it to a single IP.

Does anyone know if this is possible?

----------

## tony-curtis

You can set up a search path in /etc/resolv.conf but you couldn't control which machine would be mapped to which domain.

One possibility is to have a shell script for each machine, e.g. ~/bin/bob is

```
#!/bin/sh

exec ssh bob.in.so.me.do.ma.in

```

and then you just use the short hostname to ssh.

----------

## krinn

well,

```
alias shortname='ssh longpathname'
```

and test

```
shortname cat /etc/conf.d/hostname
```

----------

## Malvineous

Yeah, the problem is then I need a shell script for ssh, a shell script for wget, a shell script for netcat and every other program I often use  :Sad: 

----------

## Christian99

edit/creat ~/.ssh/config:

```

Host foo

  HostName foo.bar.domain

  User whoever

```

then: "ssh foo" is the same as "ssh whoever@foo.bar.domain"

you can put a few more things in this file. not sure what. maybe manfiles for ssh help.

Christian

EDIT: Sorry, didn't read carefully enough. this only works for ssh, of course

----------

## ccp

If you have your own DNS server or DNS proxy server capable load local resource then you can create C-record in your domain for foreign domain.

----------

## John R. Graham

 *Christian99 wrote:*   

> Sorry, didn't read carefully enough. this only works for ssh, of course

 This works for everything:

```
IP_ADDRESS=`host some.really.long.name.here.com | awk '/has address/ { print $4; exit; }'`

echo "$IP_ADDRESS bob" >>/etc/hosts
```

  :Wink: 

- John

----------

