Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have an Ubuntu 11.04 server virtual machine. I would like to request a specific hostname from the DHCP server at the office. Since I don't run it often, the IP changes nearly every time that I boot it. Obviously, referencing it by a hostname is the preferred option.

I know that my DHCP server respects DHCP client hostname requests. On my windows 7 machine, I can rename the computer, reboot, query the DHCP server, and see the new name in the ANSWER SECTION. The query command that I use is:

dig @192.168.225.5 -x 192.168.235.XXX

and each time it will respond with the new computer hostname. I can also now ping and ssh from other machines using that new hostname.

I have no such luck on the Ubuntu VM. I modified /etc/dhcp/dhclient.conf to include a line:

send host-name "MYRQUESTEDHOSTNAME";

and then run

sudo /etc/init.d/networking restart

but querying with dig using the VM's IP address yields no ANSWER SECTION.

What am I missing?

share|improve this question

3 Answers 3

You need to check whether the hostname is actually sent. If it is, the problem lies with the dhcp server not updating the DNS records.

send specifies the options to send to the DHCP server. You're assuming that send host-name "foo.bar" means send foo.bar as the hostname. Yet it means send the hostname and the string "foo.bar" to the dhcp server. You need two lines: option host-name "foo.bar"; send host-name;

share|improve this answer
    
This does not seem to work and appears to contradict what's in the conf file by default (and other references that I found via google). lucidtips.com/2008/11/17/… Unfortunately, that does not seem to work either. –  Keith Bentrup May 13 '11 at 17:18
    
Ack, you're right. I read request syntax, not send. –  Mel May 13 '11 at 17:26
    
It appears the hostname is sent - at least I can find the unique value in packets identified by Wireshark as "DHCP Discover" and "DHCP Request" packets. I'm not sure what would be different for the win7 machine and the Ubuntu VM. –  Keith Bentrup May 13 '11 at 19:17
up vote 1 down vote accepted

I found a solution that works for my network, but your mileage may vary. I'm not sure why it does not happen automatically. Anyway, here's the simple shell script that should update the right nameserver on the right network interface with the right IP (will work for VPN connections, too) and should work on OSX/BSD & Linux.

#!/bin/bash

# the host information to send
DOMAIN=$(awk '/^search/ {print $2}' /etc/resolv.conf | head -1)
HOST=$(hostname -s)

# nameserver to update
NAMESERVER=$(awk '/nameserver/ {print $2}' /etc/resolv.conf | head -1)

# linux version to find interace that routes to nameserver 
if [[ -e /sbin/ip ]]; then
    INTERFACE=$(ip -o route get ${NAMESERVER} | awk '{print $5}')
else # osx / bsd version
    INTERFACE=$(route get ${NAMESERVER} | awk '/interface/ {print $2}')
fi

# ip of the interface
IP=$(ifconfig ${INTERFACE} | perl -ne 'print "$1" if /inet.*?(\d+\.\d+\.\d+\.\d+)/')


nsupdate -d <(

echo server ${NAMESERVER} 53
echo update add ${HOST}.${DOMAIN} 86400 A ${IP}
echo show
echo send

)
share|improve this answer

What the answer above gets at is that your Windows computer is manually updating the nameserver on your network with its hostname, which is completely separate from the DHCP process.

Ideally, your DHCP Server itself would be doing this task -- so the answer is not so much to do with the DHCP request than it is configuration of the DHCP/DNS server itself. See this article for proper configuration on Debian.

share|improve this answer
    
Ubuntu is debian-based, but this user is using Ubuntu server, not Debian stable. Are you sure the method you link to will work for this user? Might there be a better (perhaps, more distro-specific) tutorial you could link to? –  HalosGhost May 29 at 18:35
1  
I have successfully used that tutorial on Ubuntu 14.04. The DNS and DHCP packages are largely identical between the two. –  Nicholas Andre Aug 6 at 21:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.