# DHCP Server

## WWJD

Hi, 

   I am trying to setup a DHCP server. So far I have emerge the the package "emerge -k dhcp" but from here on I do not follow. Is there a tutorial that will walk me through the rest of the setup? I am able to write out the configuration but I am having trouble setting it up.

Thanks!

----------

## dogghaus

Hi, here is a functional dhcpd.conf file, normally found in /etc.  Replace the x's with your correct ip addresses for your zones and dns servers, and your correct domain and server names.  Also, you can skip the server key, unless you want dhcp to update dns automatically (recommended!).  This is running on a redhat box, the config should be the same.  Then, start the service: /etc/init.d/dhcpd start.

Hope this helps!

authoritative;

option domain-name              "domain.com";

option domain-name-servers      192.168.x.x, x.x.x.x, x.x.x.x;

default-lease-time              600;

max-lease-time                  7200;

ddns-domainname "domain.com";

ddns-rev-domainname "in-addr.arpa";

ddns-update-style interim;

ignore client-updates;

key server.domain.com. {

        algorithm hmac-md5;

        secret "blahblahblah";

}

zone domain.com. {

primary 127.0.0.1;

key server.domain.com.;

}

zone 0.x.168.192.in-addr.arpa. {

primary 127.0.0.1;

key server.domain.com.;

}

subnet 192.168.x.0 netmask 255.255.255.0 {

        range 192.168.x.20 192.168.x.100;

        option broadcast-address        192.168.x.255;

        option routers                  192.168.x.1;

}

log-facility local7;

----------

## symbiote

Too many uneeded and confusing options.

Just use this:

```
option domain-name "localnetwork.net";

option domain-name-servers 192.168.0.1 192.168.0.254;

option routers 192.168.0.254;

default-lease-time 600;

max-lease-time 7200;

ddns-update-style interim;

ignore client-updates; 

subnet 192.168.0.0 netmask 255.255.255.0 {

range 192.168.0.20 192.168.0.250;

option broadcast-address 192.168.0.255;

} 
```

option domain-name-servers will contain your DNS servers.

option routers will be your gateway.

as for the subnet, just write the network address of your network and the appropriate netmask. then specify a range.

----------

## dogghaus

Actually, none of those settings are unnecessary.  If you want a dhcp client to automatically update your dns, those are the bare minimums.  Only distributing addresses may be fine for a home network, but I figured I might as well show him how to do it right.

----------

## axxackall

 *Quote:*   

> ddns-update-style interim; 

 

I saw many posts on mail-lists saying that interim does not work for win2k and winxp client. The advise to use ad-hoc

I use ad-hoc and in 95% it works fine.

----------

## dogghaus

I had originally used ad-hoc, and it didn't work very well for me.  I have a mix of clients: win2k, nt4, win98, linux.  I think it depends on the version of dhcpd you are using.  I run dhcp-3.x.  This is an excerpt from man dhcpd.conf:

THE AD-HOC DNS UPDATE SCHEME

       The ad-hoc Dynamic DNS update scheme is now  deprecated  and  does  not

       work.   In future releases of the ISC DHCP server, this scheme will not

       likely be available.  The interim scheme works,  allows  for  failover,

       and  should  now  be  used.  The following description is left here for

       informational purposes only.

I left out the lengthy explanation.  If yours works and updates well, no need to change it, but you may want to consider updating that for future releases.

----------

## jlancaster

Are there any BIND options that need to be set to receive DDNS updates?  DHCP server appears to be working fine, but nothing is showing up in BIND.

Here is my dhcpd.conf:

-------------------------------

ddns-update-style interim;

ignore client-updates;

default-lease-time 600;

max-lease-time 7200;

# Network services

group {

    ddns-updates off;

    # Gentoo Linux server

    host thisserver.domain.local {

        fixed-address 192.168.1.2;

        }

    }

# Home network

subnet 192.168.1.0 netmask 255.255.255.0 {

    option domain-name-servers 192.168.1.2, 151.164.1.8, 151.164.11.201;

    option domain-name "domain.local";

    option routers 192.168.1.1;

    option broadcast-address 192.168.1.255;

    ddns-updates on;

    range 192.168.1.17 192.168.1.21;

    }

authoritative;

----------

## UberLord

May I recommend dnsmasq as an alternative to DHCP and BIND as it does both and sticks dhcp addresses into dns as well

Much more lightweight (< 100 k) and easy configuration. Perfect for the LAN that just needs simple DNS + external resolving

----------

## dogghaus

In response to jlancaster:

The way my machine is configured requires the following files: 

dhcpd.conf

named.conf and assorted zone files

rndc.conf

rndc.key

The /etc/rndc.conf file is referenced by named; the /etc/rndc.key file holds the private key that also is included in the dhcpd.conf file (see my previous post, the section stating blahblahblah; that's my shorthand for an encrypted string)

Look for these files on your machine, chances are they are there minding their own business.

I'll keep an eye on this post if you need any more help.

----------

## jlancaster

Still not working, but I have to be close.  I made the appropriate changes to dhcp.conf as instructed, then added the following to the top of my named.conf (per: http://ops.ietf.org/dns/dynupd/secure-ddns-howto.html) Note the trailing '.' on the server's host name--I was just mimmicing the how-to.

key server.domain.com. {

    algorithm HMAC-MD5;

    secret "blahblahblah";

};

then modified my zone records as follows:

zone "domain.com" {

    type master;

    file "/var/bind/domain.com.hosts";

    allow-update {

        key server.domain.com.;

    };

};

zone "x.168.192.in-addr.arpa" {

    type master;

    file "/var/bind/192.168.x.rev";

};

I note in your previous post you refer to 'rndc.conf'.  I do not find that file on my system.  What is it?  How does it get there?

I used the how-to to create a TSIG key, using 'server.domain.com' as the key name as suggested.  However, I cannot find a file with the name 'K<keyname>+157+<keyid>.private' (or even *.private) anywhere on my system.  Did I do something wrong?  Is this step integral to everything else?

Thanks,

Jim

----------

## mattsk

Heyho.

I've gotten the dynamic DNS setup hapily working on my Gentoo Server. Unfortunately none of my Linux clients got their hostnames added to the dns. (Windows clients of all flavours worked a treat). 

I was going to ask if anyone knew how to change this. However i just worked it out for myself, so I'll post my findings in the hope that they help someone else.

It turns out that dhcpcd wasn't sending it's hostname to the dhcp server (it doesn't seem to by default, at least not on Gentoo).

To fix this you need to give dhcpcd the -h <hostname> option. For Gentoo, this seemed to be most easily achieved by editing /etc/conf.d/net

```
# For DHCP set iface_eth? to "dhcp"

# For passing options to dhcpcd use dhcpcd_eth?

#

iface_eth0="dhcp"

dhcpcd_eth0="-D -h `/bin/hostname`"

```

The important bit there is the dhcpcd_eth0= option. you only need the -h option. Calling /bin/hostname seemed better than just hard coding it, it means that if I do change my hostname, it should (I havne't tested this) reflect itself in the dns automatically. The -D option is an experiment on my part to get the domain name set based on what the DHCP server tells the client. I'm not sure if it's working or not yet.

Anyway, enough ramabling from me. I hope this helps someone.

----------

## jlancaster

You're a genius!  That was the missing link.

Jim

----------

