How to get hostname for osmc from DHCP server


I have transmission configured on my raspberry and I use two android app to search/download torrent.It works very well.
The problem is that I should use always the ip.
In general it does not change but sometimes it does.

So I thought to register an hostname to dhcp server of my router.

I configured the file:

and I wrote:
send host-name “raspberry”;

but it does not work. Is there something else I can do?

I noticed that hostname command return “osmc”, where this value is retrieved?
What about domain

We don’t use dhclient for DHCP, so that won’t do anything.

The hostname is set in /etc/hostname like most other Linux distributions. Just edit this and reboot.

You should also edit /etc/hosts if you do this too (although libnss-myhostname limits the need for this)

Or you can edit the device name in Kodi Settings. That will update /etc/hostname as well and update the hostname without a reboot


Ok, forgot my second question probably stupid.
Can you tell me what do you use to assign an hostname for DHCP. My goal is to use that name in my android app to connect to raspberry.

I copied the smb.conf file from /etc/samba/ to the same directory and named it smb-local.conf and then edited it. Make sure the workgroup is the same, and add the lines “netbios name = raspberry” and “server string = raspberry” (I usually add them directly below the workgroup line) then save and close.
Next edit the smb.conf file and make sure the line “config file = /etc/samba/smb.local.conf” is there at the top.

This seemed to work for me.

I think here is the misconcept. to Have your android app be able to access your OSMC you would need your DHCP/DNS server know about it and tell ot the android app. So you really have to check your DHCP/DNS server to do this correctly/

His question is not about SMB but just plain DNS resolution

No sorry. When I ask for http://raspberry from my android phone, the query is routed to DNS on router. The router should know that to raspberry name is associated the ip 198.162.0.x.

The purpose of /etc/dhcp/dhclient.conf is this on most unix system, but here it does not work.

I’ll try the change on KODI but if this only modify /etc/hostname it is not what I am looking for.

OSMC includes Avahi, so http://raspberry.local will work if your network supports DNS multicasting

You are perfectly right.
That is exactly what I expected the /etc/dhcp/dhclient.conf do (on most unix system) but here do not work.

Try my post above. I have a dd-wrt router with static ip’s assigned with hostnames and DNS still didn’t resolve the hostname until I added those lines in the smb-local.conf file. Make sure every location stated previously used the same device name as well.
I also hit my 5 pi’s by hostname on my android devices using this method.

@fzinken: “His question is not about SMB but just plain DNS resolution” I know that, but adding those settings helps with DNS resolution for some reason.

I think this is not related to my question. I do not want access to raspberry filesystem via samba.

To be honest I have in mind to do this in future but this is a subject for another topic.

Ok, you do not need to grant any access, but installing it and making the changes I mentioned should fix the issue.

Like @sam said If you have rooted your android phone or you use a PC, you can also edit the hosts file. If you have a static ip on your pi then you can do this for example pi.local

and then anytime you visit http://pi.local from that machine, will redirect to the pi.
I have a php server on my pi, and run multiple domains there…all under a different .tk domain name.

No. This does not solve the issue. If Dhcp server assign a different IP (sometime this occur) I have to change configuration. With this drawback it is better use directly the IP.
I am studying a solutIon. For the moment I noticed that doing ping osmc.local on raspberry it correct resolve the name asking for name resolution to my ruote.
When I try on windows machine it seems use my ISP dns server. I think I am close to resolution.

But why dont you set a static ip on the pi ? This way it will always have that ip. If you are afraid of IP conflicts with other machines in the house then do this:
Set your DHCP on your router to start giving IPs from (example)
Then set all the static IPs you want bellow that value. For example
PC -
Pi -
This way any new device that enters the LAN will get an ip above .10.
Then editing your hosts file will allow you to always have the proper ip assigned.
Not to mention that in the future if you ever want to have access to your pi from ‘the outside world’ you’ll be sure that protforwarding will work, since the router will always find the pi on the current LAN address

Yes. This could be a solution. It makes perfectly sense.
I have already thought about it, I am only investigating why the dhcp does not work as expected.
Thank you!!!

1 Like

As suggested by Sanbird I reserved to Pi and DHCP assign ip starting from
In this way I solved part of problem. At least I know that Pi will have always same ip.
Looking at router webui (netgear) I see that has associated the name osmc. In fact from raspberry I can ping I cannot ping it from android e windows devices.
But where this name come from?
I finally understand that osmc does not use dhcp client but connman. I tried to search info but it’s not clear to me how it works. The only thing I know is that my windows machine ask for name resolution to isp dns and not to the router. I do not know how to configure my router.

Here you can see 2nd figure that is exactly like mine:

as you can see you can decide the dns ip. I have now “Get automatically from isp”.

Probably this is my first problem. Once this is solved I think I am able to use hostname from android w windows device.

wow…dont play with these :stuck_out_tongue:
Your ISP ip must be set to automatic, unless you have a static ip provided by your ISP…In that case you put your static ip there.

This this simplest solution to your problem.
In ‘windows search’ search for Notepad, then right click on it, and Run as administrator.
Browse to location C:\Windows\System32\drivers\etc\ and open hosts file
At the bottom type the following raspberry
Save and exit.
Open a browser and type: http://raspberry or any other program that you use to connect to the pi (putty, etc)
Just use raspberry instead of a local ip.

On your android device use a program like ES File Explorer
The hosts file is located at /etc/system

As said above I considered this thread as solved. I do not know how to set this flag.
I applied the workaround above.
However, I think my main issue probably is that my router does not work as DNS server. In order to have a private network with local address name, a router with DNS/DHCP server is necessary that resolve names.
When raspberry starts up it should send its name to router that assigned a whatever ip to it.
Whenever a client requires “raspberry.local” the ip is solved by router, for external names the resolution should be delegated to external ISP. This is how I expect a local DNS should works.

Thanks everyone for help.