set hostname on dhcp


11 posts
by damaru » Thu Jun 07, 2012 8:53 pm
I am reposting this here since it might be useful for other. (and that my older post got deleted)

I use my rpi headless so I needed an easy way to track which ip it got when connecting to the network. I uses dhcp but when connecting to a bigger network it becomes hard to find where it is.

to do that I changed the

Code: Select all
/etc/dhcp/dhcpclient.conf

uncommented the send host-name and added a more suitable host-name:

Code: Select all
send host-name "raspberry.pi";

So now I can simply :

Code: Select all
ssh pi@raspberry


to connect to my freshly connected computer. Also since I use lighttp I can simply browse to

http://raspberry/

and my main page shows up!
User avatar
Posts: 38
Joined: Fri May 11, 2012 2:11 am
Location: Canada
by grumpyoldgit » Thu Jun 07, 2012 9:15 pm
I have seen this elsewhere on here in relation to getting a hostname to appear on the list of addresses on a router.


You need to edit the instructions as the file is called dhclient.conf.
Although this procedure enables the Pi to show up on a router I cannot ssh or ping it by the hostname.
User avatar
Posts: 1458
Joined: Thu Jan 05, 2012 12:20 pm
by aXon » Thu Jun 07, 2012 9:37 pm
Hi

I use avahi to detect which IP address my raspberry pi has. It is also called Zeroconf/Bonjour/Rendezvous, initiated by Apple and so far mostly used in Mac applications. Observation post shows all announced services in the local network. Development is discontinued, but still available as download http://www.macupdate.com/app/mac/18505/observation-post . On linux machines you can also use
Code: Select all
avahi-browse -arp

to show all available services and resolved IP addresses.

My services definition in /etc/avahi/services/multiple.service looks like this:
Code: Select all
<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
        <name replace-wildcards="yes">%h</name>
        <service>
                <type>_device-info._tcp</type>
                <port>0</port>
                <txt-record>model=RackMac</txt-record>
        </service>
        <service>
                <type>_ssh._tcp</type>
                <port>22</port>
        </service>
</service-group>
Posts: 2
Joined: Wed Jun 06, 2012 10:07 pm
by damaru » Thu Jun 07, 2012 10:26 pm
Is it just my brain not working or I can't find how to edit my old post ?? Seems like I can edit post I just wrote (like what I am doing right now ) but can't edit older post :(

And grumpyoldgit, yes I was surprise I could ssh to that host. I am not sure if it's due to me being on mac or because my router uses openwrt ? But it's working just as described throughout the network from http to ssh...
User avatar
Posts: 38
Joined: Fri May 11, 2012 2:11 am
Location: Canada
by Joe Schmoe » Thu Jun 07, 2012 11:01 pm
Re: Editing posts

I think the rules are that you can only edit a post if it is the last one in the thread. I.e., once someone else has (possibly) commented upon your post, then you aren't allowed to change it.
Posts: 1461
Joined: Sun Jan 15, 2012 1:11 pm
by grumpyoldgit » Fri Jun 08, 2012 12:19 am
damaru wrote:Is it just my brain not working or I can't find how to edit my old post ?? Seems like I can edit post I just wrote (like what I am doing right now ) but can't edit older post :(

And grumpyoldgit, yes I was surprise I could ssh to that host. I am not sure if it's due to me being on mac or because my router uses openwrt ? But it's working just as described throughout the network from http to ssh...


I am at a bit of a loss then. I am trying to SSH and ping from Lubuntu 12.04 and the hostname does not get recognised though it is there now on the router.
User avatar
Posts: 1458
Joined: Thu Jan 05, 2012 12:20 pm
by AndyD » Fri Jun 08, 2012 1:43 am
grumpyoldgit wrote:Although this procedure enables the Pi to show up on a router I cannot ssh or ping it by the hostname.


Probably because when you ssh hostname the hostname is turned into an IP address by either looking in the hosts file http://en.wikipedia.org/wiki/Hosts_%28file%29 or by querying the DNS server http://en.wikipedia.org/wiki/Domain_Name_System. Most people don't run their own local DNS server and so use the one provided by their ISP.

damaru wrote:yes I was surprise I could ssh to that host. I am not sure if it's due to me being on mac or because my router uses openwrt ? But it's working just as described throughout the network from http to ssh...


Possibly because OpenWrt has a dnsmasq http://wiki.openwrt.org/doc/uci/dhcp#using.plain.dnsmasq.conf http://www.thekelleys.org.uk/dnsmasq/doc.html
Posts: 143
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
by damaru » Fri Jun 08, 2012 2:36 am
yes OpenWrt seems to be the culprit here - I am trying from home on a linux only network with few machines and openwrt router and I can easily ssh pi@raspberry or view my lighttp server with http://raspberry/

Sad that it's not a more generalized behavior for the router as it would be a nice simple hack to simplify the ssh login to a headless pi...

What router are you using grumpyoldgit ? (might be time to switch to openwrt! another really kool project based on linux!!)
User avatar
Posts: 38
Joined: Fri May 11, 2012 2:11 am
Location: Canada
by Joe Schmoe » Fri Jun 08, 2012 10:21 am
damaru wrote:I use my rpi headless so I needed an easy way to track which ip it got when connecting to the network. I uses dhcp but when connecting to a bigger network it becomes hard to find where it is.

to do that I changed the

/etc/dhcp/dhcpclient.conf

uncommented the send host-name and added a more suitable host-name:

send host-name "raspberry.pi";


Yes. I can confirm that this method works. You have to do /etc/init.d/networking restart
of course, to get it to "take". Also, the file is, as GoG notes, dhclient.conf (no "cp")

Anyway, going off-topic for a moment, does anyone know how to do the same thing on a Mac? My Mac does not show up in my DHCP table. The net tells me that this is a bug in the Mac side of things - that if the hostname is greater than 15 characters, it won't work - and that the fix is to make sure your hostname is less than 16. And, indeed, my hostname is longer than 15.

But interestingly enough, I noticed that the router display seems to truncate the name to 15 as well. So, maybe both parties are partly responsible for the dilemma.
Posts: 1461
Joined: Sun Jan 15, 2012 1:11 pm
by AndrewS » Mon Jun 11, 2012 10:37 am
When I was with BeBroadband, the ISP-provided router did local DNS resolution of local DHCP hostnames. But now I'm with VirginMedia (after moving house) the ISP-provided router doesn't do local DNS resolution :(
So I've configured DHCP on my VM router to always allocate a fixed IP address to my Pi's MAC address, and then set up an entry in /etc/hosts on each of my machines (or %systemroot%\system32\drivers\etc\hosts on Windows) to map the IP address to raspberrypi.
User avatar
Posts: 1454
Joined: Sun Apr 22, 2012 4:50 pm
Location: Cambridge, UK
by meltwater » Mon Jul 02, 2012 2:20 pm
Perfect...This was just what I was looking for to make my ssh and vnc sessions a lot easier when switching networks!
_________________________________
http://www.themagpi.com/
A Magazine for Raspberry Pi Users

Read Online or Download for Free.
Released at the start of each month.

Meltwater's Pi Hardware - pihardware.com

Like the MagPi? @TheMagP1 @TheMagPiTeam
User avatar
Posts: 852
Joined: Tue Oct 18, 2011 11:38 am