Raspberry Pi: "Cannot find host"

1

1

I changed my hostname on my raspberry pi using this resource: How to Change Your Raspberry Pi (or Other Linux Device’s) Hostname.

  • When I use the host name on the ssh client to connect to the ssh server on my pi, it can't find the host.

  • If I use the IP, it connects to pi. Then I login and it shows user@newhostname .

The ip to the device is dynamic and I want it to stay that way. My device would have to associate its IP to the hostname every time it gets assigned a new IP. Maybe this isn't happening?

Benjamin Jones

Posted 2014-12-17T17:22:13.980

Reputation: 526

Did hostname lookups work before you changed the hostname? Since you tagged it with DNS, does the PI have a DNS entry for the host? – Ƭᴇcʜιᴇ007 – 2014-12-17T17:31:51.710

Well no it does not have a DNS Entry. Its part of a workstation group. edited tag. No the orginal hostname did not work. I guess I'm trying to understand how hostnametest (hostname) could be associated with ip: 192.168.0.XX , especially when the IP is dynamic. – Benjamin Jones – 2014-12-17T17:51:08.437

From the client, can you run a name server lookup? nslookup newhostname and press Enter. What comes up? – Canadian Luke – 2014-12-17T17:53:22.973

3You need either a DNS record in your DNS server, a HOSTS entry on your system, or working NetBIOS to perform hostname lookups. If you have none of those, then you have nothing to resolve the name to the IP, and so of course it doesn't work (dynamic or not). ;) – Ƭᴇcʜιᴇ007 – 2014-12-17T17:54:22.790

Answers

4

I presume you are talking about resolving the server name inside your LAN. For this to work, you must have at least one of these:

  1. A working DNS inside your own LAN (or on a companion LAN, performing this job for your LAN too).

  2. An entry in the client /etc/hosts file, associating name and IP address.

  3. A working samba server on the ssh server, where you have set the server's NetBIOS name. This allows you to be seen through Microsoft specific protocols.

  4. Lastly, you may use multicast, what Apple calls Bonjour.

Each of these possibilities is mirrored in your file /et/nsswitch.conf, in the line:

 hosts:          files dns mdns4 mdns4_minimal wins 

which determines the order in which these different services are used; the order above is best for my LAN since I do have a local DNS server, but yours may differ.

The easiest solution is most likely the one involving samba: install the samba server,

  sudo apt-get install samba

for Debian and derivatives, change accordingly if not on Debian and Co., then edit the file /etc/samba/smb.conf, and set the lines

 workgroup = WORKGROUP
 NetBIOS name = YourPCNetBIOSName

to reflect data appropriate to your pc, then restart the samba service,

 sudo service samba restart

again for Debian and derivatives, and now your ssh-client will be able to find the ssh-server through the name YourPCNetBIOSName, as specified above, provided the ssh-client does have the wins option in its own /etc/nsswitch.conf file.

You may wish to enable mdns as well, to be able to interact with Apple's pcs as well. After much trying, I discovered that the library libnss-mdns is not installed by default on Debian and derivatives, so, in order to be able to use multicast Domain Name Service (mdns) you will have to install it first:

sudo apt-get install libnss-mdns

At this point, you will be able to resolve Apple pcs as well.

MariusMatutiae

Posted 2014-12-17T17:22:13.980

Reputation: 41 321

Thanks. Yes you are right, that is what I meant. I think Im going to install samba first and go from there. I don't want my device to have a static ip, so even if I used bind9 as my dns server, I would have to have a static ip to map to the DNS, right? – Benjamin Jones – 2014-12-17T20:08:33.993

@BenjaminJones No, if you install bind9 or dnsmasq (which is much easier to handle than bind9) your name will correctly resolve to your IP whether you have a static IP or not. – MariusMatutiae – 2014-12-20T07:55:55.730