# SSH - can't use server name to log in

## Robert S

When I try to log into my server from another linux box I need to use the IP address - it repeatedly asks me for my password:

 *Quote:*   

> my_name@client-machine ~ $ ssh my_server
> 
> Password:
> 
> Password:
> ...

 

Nothing shows up in my server logs when I use the server name from the client machine, but if I use the server IP address, I get logged in:

 *Quote:*   

> Nov  5 13:58:12 my_server sshd[4721]: SSH: Server;Ltype: Version;Remote: 192.168.0.28-40973;Protocol: 2.0;Client: OpenSSH_7.1p1-hpn14v9
> 
> Nov  5 13:58:12 my_server sshd[4721]: SSH: Server;Ltype: Kex;Remote: 192.168.0.28-40973;Enc: chacha20-poly1305@openssh.com;MAC: <implicit>;Comp: none [preauth]
> 
> Nov  5 13:58:15 my_server sshd[4721]: Accepted keyboard-interactive/pam for my_name from 192.168.0.28 port 40973 ssh2
> ...

 

Can somebody solve this long standing mystery?

----------

## Buffoon

You sure my_server resolves to 192.168.0.40?

How about running the client with -v switch.

----------

## Robert S

Yes - my_server does resolve to 192.168.0.40.

Here's the debug output:

 *Quote:*   

> my_name@gentoo-lvm ~ $ ssh my_server -v
> 
> OpenSSH_7.1p1-hpn14v9, OpenSSL 1.0.2e 3 Dec 2015
> 
> debug1: Reading configuration data /etc/ssh/ssh_config
> ...

 

----------

## Buffoon

```
debug1: Connecting to my_server [127.0.0.1] port 22. 
```

See the IP address?

----------

## NeddySeagoon

Robert S,

Populate /etc/hosts or make your local nameserver resolve the name to the IP address.

----------

## Robert S

I don't quite understand this.  If I ping my server it resolves to the correct address:

 *Quote:*   

> $ ping my_server
> 
> PING my_server.mydomain.com.au (192.168.0.40) 56(84) bytes of data.
> 
> 64 bytes from my_server.mydomain.com.au (192.168.0.40): icmp_seq=1 ttl=64 time=0.097 ms
> ...

 

----------

## NeddySeagoon

Robert S,

Tell us about your local nameserver. 

192.168.0.40 is a non routable address, so the internet should not be involved.

Does 

```
ssh -v my_server.mydomain.com.au
```

give you the correct IP?

Why does ping return a fully qualified domain name (including mydomain.com.au) for a non routable address?

Perhaps it is pinging your public IP?

Lots of people are going to be upset if you have a public A record pointing to 192.168.0.40.

Its harmless but it will only work from your own network.

----------

## Robert S

Think I've solved this - replaced  *Quote:*   

> 127.0.0.1 myserver myserver.mydomain.com.au localhost

 with  *Quote:*   

> 127.0.0.1 localhost

 in /etc/hosts in the server

----------

## NeddySeagoon

Robert S,

You may also need an entry for

```
192.168.0.40  my_server  my_server.mydomain.com.au
```

on my_server so that it can look up its own real IP.

Depending on what you are running on my_server, you can get a range of problems from long startup times, to things not starting at all.

----------

## Robert S

I've already done that. Had problems with long startup times (eg. sendmail) a long time ago.

----------

