Hostname on DHCP - is there a definitive answer?


25 posts
by DoubleBarrel » Thu Feb 21, 2013 2:54 pm
I know this is ground that has been covered before - I know because I have been trawling through pages of posts trying to make sense of all the conflicting information - none of which seems to work, or is some sort of get-around.

So question is, how do I get my Pi's hostname to appear on my LAN so I can ping/telnet/ssh whatever to it by that hostname?

LAN is connected through a Netgear DG834GT wireless router using DHCP to assign IP numbers to the many connected devices. No matter what I seem to do I cannot get the router to recognise the hostname - always shows as UNKNOWN against the assigned IP. However, I put raspbmc on another card to play with, and guess what - that shows up no problem at all (as raspbmc!) and I can ping it, ssh to it etc all by hostname. So what is raspbmc doing to achieve this?

This is what I have tried from all the reading I've done (and for completeness I always reboot after making any changes):

1) edit /etc/hostname /etc/hosts - great, yes, changes the hostname, but it doesn't show up on the network

2) edit /etc/dhcp/dhclient.conf - have tried both
Code: Select all
send host-name = gethostname();

and the more definitive
Code: Select all
send host-name "newpihost";

and no change at all - and that's the strange thing, no matter what I put in /etc/dhcp/dhclient.conf it seems to be ignored (this seems suspicious to me, why is this not affecting anything?)

3) Some seem to suggest installing samba and winbind, or ensuring the pi has a static ip and then adding entries in every other machine's hosts file - neither solution seems the correct way of resolving (pun intended) this.

All this is being done on a fresh install of Raspbian Wheezy downloaded from this site 20/02/2013 - no other configuration has been done other than setting the timezone, and expanding the filesystem to fill the 4GB card.

I've posted in this particular forum, but I do consider myself a born again newbie as it's a little over 15 years since I last touched a unix system (many different flavours), and although a lot is coming back to me, I was never much involved in the networking side of things.

Please, can anyone help as this is driving me nuts now and I won't rest until I've cracked it! In the words of a British TV car show host, "How hard can it be?"

Thanks in advance for any help/suggestions
User avatar
Posts: 5
Joined: Thu Feb 21, 2013 1:19 pm
by DBryant » Thu Feb 21, 2013 10:02 pm
Take a look at Apple's Bonjour services, as used in iTunes.

With Bonjour installed on the Raspberry Pi, it’s then easy to reach the Pi from other devices by employing the name 'raspberrypi.local' (that is, your hostname with .local added) in ssh / ping / browser commands.

All devices in your network would ideally have an instance of Bonjour installed – on Windows you may have iTunes already installed, and if not and you don't want it, then install the “Bonjour Print Services for Windows” (you can Google for this)

Your Pi distro may have it installed already, but if not then:
Code: Select all
 sudo apt-get update
sudo apt-get install libnss-mdns


No managment of /etc/hosts is required with this solution, just remember to add .local to your hostnames on the command line. If you don't wish to ge tinvolved in the network side of things, then this should work well for you.
Posts: 281
Joined: Sat Feb 02, 2013 12:41 pm
Location: Berkshire, UK
by poing » Thu Feb 21, 2013 10:13 pm
If i follow this: http://cymplecy.wordpress.com/2012/08/09/auto-install-a-simple-samba-setup/
and then do this:
DoubleBarrel wrote:1) edit /etc/hostname /etc/hosts

I can see the Pi in Windows Explorer by its name and double click to enter its files.
Posts: 1129
Joined: Thu Mar 08, 2012 3:32 pm
by rurwin » Thu Feb 21, 2013 10:38 pm
I've just done a bit of experimenting.

On a Pi without SAMBA, the router shows UNKNOWN
On a Pi with SAMBA, the router shows the name of the Pi.

And on the Samba Pi I've just changed the hostname and renewed the lease. Although it took the new IP address, the hostname as reported by the router didn't change until I rebooted.

DHCP is not used for name resolution, so it will have no effect on other machines' pinging. That effect is down to name resolution -- Samba, or likely the Winbind part of it.
User avatar
Forum Moderator
Forum Moderator
Posts: 4108
Joined: Mon Jan 09, 2012 3:16 pm
by DoubleBarrel » Fri Feb 22, 2013 9:52 am
Thanks for the replies guys - I guess it's the samba installation that's the key as I'm pretty sure raspbmc has that in place and hence why the hostname shows up OK. That auto install script looks handy - I'll give that a go.

I'm still a little concerned that any changes I made in /etc/dhcp/dhclient.conf were not being picked up - almost as if that file was not being parsed - yet other posts here seem to suggest that (in the past at least) others had had some success - and failure! - by making changes. Another post I read suggested creating /etc/hdcp3/dhclient.conf but that didn't seem to make any difference either. If anyone has any thoughts or suggestions about this aspect, I'd be interested to know.

rurwin wrote:DHCP is not used for name resolution, so it will have no effect on other machines' pinging.
Yes I'm aware of that, I just wanted to make it clear I wanted a DHCP based solution, and not start using static IP's
User avatar
Posts: 5
Joined: Thu Feb 21, 2013 1:19 pm
by pluggy » Fri Feb 22, 2013 12:23 pm
Samba implements Netbios, which is a Windows thing. Unix type OSes don't by default..
Don't judge Linux by the Pi.......
I must not tread on too many sacred cows......
User avatar
Posts: 3636
Joined: Thu May 31, 2012 3:52 pm
Location: Barnoldswick, Lancashire,UK
by RaTTuS » Fri Feb 22, 2013 12:24 pm
if it is DHCP then the DHCP server does the naming
netbios is a windows thing
...
bascially - if your router does the DHCP then you should be able to set names there
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
User avatar
Posts: 8895
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
by rurwin » Fri Feb 22, 2013 12:45 pm
@ RaTTuS, Granted it would be nice, but it doesn't seem to happen. On the router of course, it's more aesthetic than worthwhile, since I don't spend all day looking at the router's web page, but it might be handy if I had enough Pis to confuse me.

DHCP on the Pi seems to be configured, by default, to send its hostname in the DHCP request, and the static allocation on my router has the correct hostname in it. Still, unless I run Samba, the hostname reported in the allocation is "UNKNOWN". Blame Netgear if you want; it seems they ignore the clues they are "supposed" to be using and instead use a completely different protocol. Maybe that's the best way to get the maximum amount of hardware to show a meaningful name with the minimum of configuration. Maybe they should be beaten for displaying UNKNOWN when they have been given two clues as to what the name should be. Not my problem.
User avatar
Forum Moderator
Forum Moderator
Posts: 4108
Joined: Mon Jan 09, 2012 3:16 pm
by RaTTuS » Fri Feb 22, 2013 12:52 pm
yeah - in a mixed network of Macs, windows, and linux
there are always wierdnesses

mind you I have a linux box providing DHCP services here, as well as a windows network

there are times when the apple bonjour service makes a mess of your PC - you end up with a default route of 0.0.0.0 which is not always the thing you want ...

I use dhcp to provide static address for machines I want to be static and it does not take long to just use the correct IP ..... ;-p
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
User avatar
Posts: 8895
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
by DoubleBarrel » Fri Feb 22, 2013 12:58 pm
So installing samba has indeed achieved what I needed, but I'm still not sure this is the right way to do it - yes it's all very useful to have access to the pi from windows but that was not a requirement - accessing the pi by hostname almost seems to be a side effect of installing samba.

I must be misunderstanding something fundamental, but this is what I thought happened:

Pi boots up, running as a DHCP client, looks for a DHCP server, finds one (my Netgear router), asks for an IP from the pool and says, by the way my name is "hostname" (presumably the "send host-name = gethostname();" in the dhclient.conf), router gives out an IP and registers the hostname against that IP so any other machine on the network can now make a request by hostname and the router will translate that to the real IP.

Is that not how it's supposed to work?
Is it in my case, because it's a Netgear router this is not happening?
Have I made a fundamental assumption that isn't true?

It seems to me the samba install is almost a red herring. I don't need the windows networking, all I want to achieve is the ability to access the pi by name rather than an unknown (unless I look it up on the router) IP number.

I did say networking was not my strong point!
User avatar
Posts: 5
Joined: Thu Feb 21, 2013 1:19 pm
by rurwin » Fri Feb 22, 2013 1:11 pm
DoubleBarrel wrote:...registers the hostname against that IP so any other machine on the network can now make a request by hostname and the router will translate that to the real IP.

...Have I made a fundamental assumption that isn't true?

Yes you have. DHCP is not name resolution. The DHCP server is not consulted when another machine wants to find the Pi. The most that the hostname in the DHCP request can do is to allow IP allocation by hostname and/or register that hostname against the allocated IP address in the server's tables. It can have no effect on the operation of any other machine because there is no DHCP request that says "give me the IP address of the machine with this hostname"; it isn't part of the DHCP protocol.

Name resolution is implemented by various other technologies, including Samba, DNS/bind, Bonjour and /etc/hosts, but not DHCP.
User avatar
Forum Moderator
Forum Moderator
Posts: 4108
Joined: Mon Jan 09, 2012 3:16 pm
by DoubleBarrel » Fri Feb 22, 2013 1:25 pm
Ah..... in actual fact I had assumed the router was providing some sort of DNS function in addition to the DHCP server - sorry, I do know the difference, for some reason I wasn't separating the two functions out, either in my mind or when writing my posts.

OK it all becomes clear now why I need samba - I thought this was unnecessary before as I thought it was just duplicating a DNS function I thought the Netgear router was providing in some way.

Thanks for bringing that lightbulb moment of clarity to me - much appreciated! :D
User avatar
Posts: 5
Joined: Thu Feb 21, 2013 1:19 pm
by jackokring » Fri Feb 22, 2013 1:58 pm
A DHCP request can supply the hostname, so that a clever DNS proxy can be updated by the DHCP daemon. The gateway does not necessarily run a DNS proxy, it may just route forward any DNS requests, using the name servers it got when doing its DHCP on the ISP network. Not all routers use a DNS proxy, which checks the local DNS cache before doing a name server forward.

Android hot spots seem to use a DNS proxy, as raspberrypi.local works for me.
Pi[NFA]=B256R0USB CL4SD8GB Raspbian Stock.
Pi[Work]=A+256 CL4SD8GB Raspbian Stock.
My favourite constant 1.65056745028
User avatar
Posts: 815
Joined: Tue Jul 31, 2012 8:27 am
Location: London, UK
by rurwin » Fri Feb 22, 2013 2:05 pm
Raspberrypi.local is a Bonjour form, isn't it?
User avatar
Forum Moderator
Forum Moderator
Posts: 4108
Joined: Mon Jan 09, 2012 3:16 pm
by DBryant » Fri Feb 22, 2013 2:08 pm
Indeed!
Posts: 281
Joined: Sat Feb 02, 2013 12:41 pm
Location: Berkshire, UK
by erwinb » Tue Feb 26, 2013 10:03 pm
You could run a DNS server to solve the names resolution. Then you can set up a fixed name for a certain IP address, say you assign the name "pi" to 192.168.1.25 or what ever your IP range may be.

In your router (DHCP server) you make a fixed reservation for assigning the address 192.168.1.25 to the mac address of the raspberry pi. This will guarantee that you always have the same address assigned to the pi. The DNS will assure that you can use the name pi on your network to connect to the raspberry pi.
Posts: 9
Joined: Sat Feb 16, 2013 12:15 am
by virgesmith » Sun Mar 03, 2013 4:11 pm
I've been frustrated by unresolved hostnames for ages, but I finally seem to have fixed them - thanks largely due to this thread - so thought I'd share what I did.

Basically I have 2 pis running raspbian and annoyingly one is contactable via the hostname, the other not. Also noticed the "invisible" device cant resolve visible ones, so it'a a two-way problem.

I couldnt understand it at all because the hostname was set on both machines in /etc/hostname, and /etc/hosts, /etc/dhcp/dhclient.conf, /etc/resolv.conf were identical between the machines (apart from the actual hostname of course). To be honest I gave up on it, then had another crack at it yesterday - much googling and tedious side-by-side comparison of config files.

Finally I discovered a difference in a config file - /etc/nsswitch.conf. The visible hostname pi had the line
Code: Select all
hosts:          files mdns4_minimal [NOTFOUND=return] dns mdns4

whereas the invisible one had
Code: Select all
hosts:          files dns

So I changed it, rebooted the pi and bingo, the router saw the hostname. Rather disappointingly I still couldn't ping/ssh using the hostname. Back to square one, then reading this post inspired me to check package install differences between the pis:
Code: Select all
dpkg --get-selections | grep dns

Now the difference with the visible pi was it had libdns88 and libnss-mdns, but the invisible one didnt. So a quick
Code: Select all
sudo apt-get install libdns libnss-mdns

did the trick nicely. Didnt even need a reboot, hostname became visible immediately. Also worked on a debian sheevaplug.

Not exactly an expert in this area so don't know if the nsswitch edit is even necessary, and not sure you actually need libdns88, but included in just in case. Hope of some help...
Posts: 1
Joined: Fri Nov 09, 2012 11:44 am
by STH_ICT » Wed Oct 08, 2014 12:56 pm
Hi

I just want to mention, that it worked for me when I installed samba (sudo apt-get install samba) and then removed it again (sudo apt-get remove samba). So I assume the installation of samba added/modified some config files which haven't been removed when removing samba again. Unfortunately I have no clue how to find out which config files. To know this would be great to get it work without having to install (and remove) samba.
Posts: 1
Joined: Wed Oct 08, 2014 12:51 pm
by Samson74 » Wed Oct 15, 2014 1:04 pm
Hi,

I would love to get an answere to this problem. I solved it by installing and removing samba in my case (as someon mentioned before).
Still, I spend at least 8h in figuring out what is actually wrong ... and I still don't know the answere, just an unsatisfying solution.

Best G'
Posts: 1
Joined: Wed Oct 15, 2014 12:43 pm
by Azmo » Thu Nov 06, 2014 9:04 am
I've been having trouble trying to solve this problem as well. I haven't tried installing and uninstalling SAMBA yet but I did find a similar solution on stackoverflow:
http://raspberrypi.stackexchange.com/questions/7640/rpi-not-reachable-via-its-hostname-in-lan

I'm using "Angry IP Scanner" to scan my local network for my PI and it now shows it's Hostname, but it is appended with ".local".

My guess is that installing SAMBA will also install somekind of broadcast protocol thing, which and what that might be I do not know.
Posts: 1
Joined: Thu Nov 06, 2014 8:57 am
by DougieLawson » Thu Nov 06, 2014 5:50 pm
Azmo wrote:I'm using "Angry IP Scanner" to scan my local network for my PI and it now shows it's Hostname, but it is appended with ".local".

That's a feechur of mDNS (aka avahi-daemon aka Bonjour). You can change the suffix.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

Since 2012: 1B*5, 2B*2, B+, A+, Zero*2, 3B*3

Please post ALL technical questions on the forum. Do not send private messages.
User avatar
Posts: 26082
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
by jproehl » Fri Apr 24, 2015 5:44 am
Hi all:

Just in case this still hasn't been resolved, I believe the answer is that you have to edit your /etc/samba/smb.conf file. The samba hostname is hard wired in there from when samba was configured.

I found this after cloning an RPi and changing the hostname in /etc/hosts and /etc/hostname and then pinging my network only to see that the original hostname (from the cloned system) was still reported to the router.

Hope this helps!
Posts: 9
Joined: Mon Mar 23, 2015 4:40 pm
by eSKape » Sun Jun 21, 2015 6:22 pm
Hi folks.

Had the same problem, and after reading through this thread, I looked at /etc/samba/smb.conf and saw these lines:
Code: Select all
# This will prevent nmbd to search for NetBIOS names through DNS.
   dns proxy = no


I went with it and changed it to yes, and now it works. I can ping "pi" and go to http://pi/. I'm not linux-savvy, but I'd guess, that samba is already installed, when the /etc/samba directory exists?

And I also guess, that now my router is using the DHCP-provided hostname in it's DNS-service?
Posts: 1
Joined: Sun Jun 21, 2015 6:14 pm
by bobaboba » Tue May 03, 2016 4:27 pm
If I connect my (Jessie) Pi via Ethernet I can address it from any other machine by name.
If I connect it by wifi I can't, although I can of course connect via IP address (not handy because it's not static)
Same router (which is the dhcp server).
The above comments don't seem to address this fundamental difference between Jessie and Wheezy.
Unsolved (by me ) so far.
Posts: 1
Joined: Tue Oct 13, 2015 7:09 pm
by eldiabolosk » Thu Nov 24, 2016 7:44 pm
I found this blog after I did did go back and forth on the hostnames showing on my router and in nmap either as unknownB827EBC0xxxx or as raspberrypi on some new Jessie installs. I did lot of mad stuff, comapring configs, kernells, etc till I woke up this morning.
I had a question stuck in my mind:
I did change the hostname and the wifi network (I run two separate wifi SSIDs). I did run nmap -sL 192.168.1.1/24 and it did show me the old "raspberrypi" hostname instead of the new "rrtpes01" hostname. Two questions came to my mind how come it knows it as "raspberrypi" and not as "unknownB827EBC0xxxx " and and why is it still know as "raspberrypi" ?
I logged into my router and and it did show it as "raspberrypi" on a wifi network "1" instead or hidden "2".
at this point my /etc/dhcpcd.conf had static IP set:
##Added by EB 2016_11_20
send hostname="rrtpes01"

static ip_address=192.168.1.180/24
static routers=192.168.1.254
static domain_name_servers=192.168.1.254

nmap before change:
Nmap scan report for raspberrypi (192.168.1.180)


1) commented out static settings:
##static ip_address=192.168.1.180/24
##static routers=192.168.1.254
##static domain_name_servers=192.168.1.254

2) reboot
and it was there.

From router:
rrtpes01 Wireless b8:27:eb:fe:xx:xx wifi2 192.168.1.180

3) set back to static and run "nmap" again
result:
Nmap scan report for rrtpes01 (192.168.1.180)

=============================
Two more things before this trick this worked:
ssh rrtpes01.local
or
ssh 192.168.1.180

This would fail
ssh rrtpes01

After change it works.
pedro@postak ~ $ ssh rrtpes01
pedro@rrtpes01's password:


===
Just figured I share and maybe someone know why this did the trick, and offers and explanation

Ed
Posts: 15
Joined: Wed Aug 15, 2012 12:27 am