-   Linux - Networking (
-   -   setup hostname from DNS/DHCP dynamically (

nicolasdiogo 12-27-2012 02:46 AM

setup hostname from DNS/DHCP dynamically

i have a small setup with a few VMs that i use for testing stuff. And i would like to set these up so that i can have them getting their hostnames from the DNS/DHCP setup.

my VMs are either ubuntu or debian - so i would think they would require the same, or very similar, configurations.

but i have no idea what needs doing.

i am finding difficulty to find any valid information as the keywords that i have used for searching are not really helpful. i have tried searching for:
'hostname dynamic dns dhcp'

if somebody could be so kind to provide me with some idea of the configuration, it would be most appreciated.


business_kid 12-27-2012 03:41 AM

No, most people leave the hostname alone. This box is RoseViolet wherever she goes.
A handy way of hacking this for yourself is to hack init scripts or the dhclient script to change hostname. Why do you need a different hostname?

nicolasdiogo 12-27-2012 12:50 PM

i have a template of ubuntu and another for debian Virtual Machine.

so when i create/copy a new VM - i have to edit its hostname as the default will not do; TEMPLUBU, TEMPLDEB

I understand that tools such as Puppet would do this - but would be like just over the top for my requirements.

just to be clearer - there is no off-the-shelve solution for this in Linux?


business_kid 12-27-2012 01:52 PM

If I'm right, the dhcp can give hostnames after a fashion.

The usual info is dns, and IP. You can grok a dhcp license file to see if there's a spot for hostnames. When it comes to hostname, the server can link an ip to a hostname by simply having a dns entry, and then the outside world makes that link. The dhcp server can link an ip to a mac address. But that's all server side. You can change your hostname by a command like

echo "ShyTalk" > /etc/hostname.

but nobody listens to that normally. Nobody interrogates it normally. If someone is listening, perhaps you should explain to us who and why.

nicolasdiogo 12-27-2012 01:59 PM

so your suggestion would be to have a script that

after booting, collects the IP of host
nslookup - to collect the hostname for that IP, from the DNS
write that hostname into /etc/hostname

then reboot

is that what you are suggesting?


business_kid 12-27-2012 03:12 PM

I'm not sure what you are trying to do and I'm not suggesting. I was pointing out that the most important thing is what the outside world thinks your hostname is, not what your box thinks it is.

nicolasdiogo 12-27-2012 03:52 PM


i am back where i started.


All times are GMT -5. The time now is 09:00 PM.