# Use DHCP for dynamic IPs and need hostname to resolve

## neil_leathers

My machines are behind a NAT box and have dynamic IPs served by DHCP for the internal network. I don't have DNS setup for the internal network (non-authoritative, not needed) so I need to set the hostname to resolve to the provided IP. What configuration options do I use to make my DHPC client do this? (For the moment, in order to compile dev-lang/python I have to put an entry into /etc/hosts.)

I have seen various posts in the forums almost on the subject but I didn't see one on this configuration (though I may have missed it).

I have a hostname set in /etc/conf.d/hostname (but can delete it if necessary)

I use net-misc/dhcpcd-4.0.15 to get an IP (it seems the least broken of the DHCP clients I have tried)

The DHCP server does not put the assigned IP into a DNS (and probably should not)

The IP address received must be dynamic (since the network is dynamic)

The host names must resolve locally

----------

## eccerr0r

I've used net-dns/dnsmasq with some luck.   This does pretty much everything - DHCP and DNS, keeps a local table of DHCP addresses with symbolic names that resolves with its own local DNS cache.  DD-WRT uses this to do local-only DNS lookups of "locally static" IPs.  Might want to check this out if you have your roll-your-own router/DNS/DHCP.

Or if you are using DD-WRT - use it to its full potential!

----------

## neil_leathers

 *eccerr0r wrote:*   

> I've used net-dns/dnsmasq with some luck.   This does pretty much everything - DHCP and DNS, keeps a local table of DHCP addresses with symbolic names that resolves with its own local DNS cache.  DD-WRT uses this to do local-only DNS lookups of "locally static" IPs.  Might want to check this out if you have your roll-your-own router/DNS/DHCP.

 

I'll consider it for the future since I've been thinking about moving to a roll-your-own router setup. Unfortunately I currently don't and am therefore looking at fixing this on the client end.

----------

## eccerr0r

Not exactly sure what you want to do here now...   If you have no local DNS, it will never resolve to anything anyway (unless you want to select something in your hosts file? but why?), might well just leave it as a default name?

You get a lease from DHCP, your IP address gets configured onto your ethernet, so now you can use the network...  I'm not sure why you need to set your hostname now?  It should work without hostname set, unless there's something I'm missing?

----------

## cyrillic

If you are looking for local DNS without a DNS server, multicast DNS is the next best thing.

Try net-dns/avahi with sys-auth/nss-mdns,

or net-misc/mDNSResponder.

... then have fun reading the instructions   :Smile: 

----------

