I want Ubuntu to get hostname and DNS name from DHCP client. Default installation of 11.10 does not do that.
Update: same question asked and Unsolved
There is a way to do it with a little script for a dhcp hook as described here.
Create a new file:
and paste the following code:
Make sure it is readable...
That's all. On the next dhcp response your hostname will update automatically.
You can get your hostname from your DHCP server - it is part of the DHCP specification.
"This option specifies the name of the client"
You don't get your hostname from the DHCP server.
You can send your hostname to the server, which may change the IP you're assigned. You can change what name is sent either by editing your Network Manager connection (the field is called DHCP Client ID) or you can edit (as root)
... and change
By default Ubuntu will get its DNS settings from the router (if it sends them) but I suspect you're talking about local DNS/mDNS where you can access other computers by their hostname. This is called Ahavi or Zeroconf in Ubuntu and it's installed by default.
You should be able to access your computer by
d_inevitable's answer almost solved my problem, but not completely. The problem was that although:
The client was not getting a new hostname (easily verified by typing
in terminal and getting the old hostname, or no hostname if I had deleted the contents/file). As a result, the proposed solution by d_inevitable was only copying an empty string.
To solve that, I applied a crud solution, that generally should not be followed unless you are desperate to make it work, like I was.
First, open with edit capability the DHCP client control script:
There, you will have to locate the function
Just use the search and it should come right up. Now, at least on my computer, this function has three if-then-else conditions, encapsulated to each other:
Now, what you need is to force the assignment of the new hostname to your host, no matter what. Therefore you want to comment out the two encapsulated if-then-else. The result should look something like:
Now the d_inevitable's or this should work as expected. Hope that helps if you are in a similar desperate frustration as I was.
The answer depends on whether or not you are using static leases on your DHCP server. If you are, it is unnecessary to get the hostname from DNS. You can change this line in d_inevitable's solution
But this should happen automatically if your hostname is originally set to localhost.localdomain, so you don't have to write a script. However, if you want to set the hostname to the FQDN, you'll need to change d_inevitable's script to
Again, all this only works if you're using static leases.
Don't have enough reputation to comment, but I'd like to piggy-back on the previous answer as it almost solved the problem for me using a dhclient hook.
I've found that using the standard ISC DHCP Server for some reason, the aforementioned hook outputs a host name with a '.' period character at the end of the hostname for some reason.
So, in the previous answer you might need "cut out" the extraneous period with a sed: