Maintaining `/etc/hosts` for hosts on DHCP

dhcphosts

On my local DHCP network I have different PC's that I need to access remotely. Problem is that their IP's change. Sometimes I plug my laptop and netbook into other people's DHCP networks.

My current solution is to update the /etc/hosts file every time the target IP's change.

My /etc/hosts file looks like this:

# <ip-address>   <hostname.domain.org>    <hostname>
127.0.0.1        localhost.localdomain    localhost laptop    
192.168.1.14     desktop.localdomain      desktop
192.168.1.12     netbook.localdomain      netbook

Is there a way to bypass all that manual administration?

For example, could my computers broadcast their IPs on the LAN, or something like that? Windows does something like that, which allows you to reference a computer on the network with "\\COMPUTER_NAME"

Best Answer

It depends on what is doing the DHCP?

Most home routers use dnsmasq and you can use that as your local DNS server. You just need to set dnsmasq to return itself as the DNS server. Next, you need to make sure that your PCs broadcast a hostname during the DHCP request.

Then, voila, you should be able to resolve all your local machines through the DNS/DHCP server.

Related Question