SUSE Conversations


DHCP (Dynamic Host Configuration Protocol)



By: DamianMyerscough

June 27, 2008 1:55 pm

Reads:553

Comments:4

Rating:0

In this article we are going to look at setting up and configuring a DHCP (Dynamic Host Configuration Protocol) server using SUSE Linux Enterprise Server 10 SP1. We will also look at configuring DHCP to reserving IP (Internet Protocol) addresses for certain machines, set clients DNS (Domain Name System) details and view what machines have been assigned an IP address.

Preparation

In this section of the article we will need to install the DHCP server software this can be done by using the YaST utility. The YaST software management module can be started by using two different commands, the first command is yast sw_single which will start a curses based interface and the second command is yast2 sw_single which will start a GUI (Graphical User Interface). In this article we will be using the yast sw_single command to install the DHCP server.

Once you have started the YaST software management module you will need to search for the keyword “dhcp-server“. Once you have selected the “dhcp-server” package you can begin the installation and then exit once the installation has finished. The next step is to confirm that the “dhcp-server” package was installed successfully this can be done by issuing the rpm command followed by the -q qualifier as shown in Figure 1.1.

linux-mw4w:~ # rpm -q dhcp-server
dhcp-server-3.0.3-23.33

Figure 1.1: Querying the RPM database for the dhcp-server package.

Configuring DHCP Server

In this section of the article we will look at configuring the DHCP server for basic functionality e.g. distributing IP addresses to machines across your network. The DHCP configuration file is located within the /etc directory with the name of “dhcpd.conf“, you will notice that this file is populated with examples on how to configure your DHCP server. In this article we will write our DHCP configuration from scratch so we will need to create a backup of the current dhcp.conf configuration file and create an empty dhcp.conf configuration file as shown in Figure 2.1.

linux-mw4w:/etc # mv dhcpd.conf dhcpd.conf.bak
linux-mw4w:/etc # touch dhcpd.conf

Figure 2.1: Creating a backup of the dhcpd.conf file and create an empty configuration file.

The next step is decide what subnet you will serve to workstations on the network. In this article we will serving the 192.168.0.0/24 subnet. The dhcp.conf configuration file that we will be using is shown in Figure 2.2 we will be adding more options throughout this article to customize our DHCP server to suit our needs. Table 1 explains each line within the dhcp.conf configuration.

ddns-update-style none;
ddns-updates off; 

# If this DHCP server is the official DHCP server for the local network
authoritative; 

# Use this to send dhcp log messages to a different log file (you also 
# have to hack syslog.conf to complete the redirection). 
log-facility local7; 

# A slightly different configuration for an internal subnet. 
subnet 192.168.0.0  netmask 255.255.255.0 { 
  range 192.168.0.2 192.168.0.254; 
  option routers 192.168.0.1; 
  option broadcast-address 192.168.0.255; 
  default-lease-time 600; 
  max-lease-time 7200; 
}

Figure 2.2: dhcpd.conf configuration file.

Directive Description
ddns-update-style none; The style parameter must be one of ad-hoc, interim or none. The ddns-update-style statement is only meaningful in the outer scope – it is evaluated once after reading the dhcpd.conf file, rather than each time a client is assigned an IP address, so there is no way to use different DNS update styles for different clients.
ddns-updates off; This option should be set if this is the official DHCP server on the local network. This is so that if a naive user installs a DHCP server not fully understanding how to configure it, it does not send spurious DHCPNAK messages to clients that have obtained addresses from a legitimate DHCP server on the network.
authoritative; This option should be set if this is the official DHCP server on the local network. This is so that if a naive user installs a DHCP server not fully understanding how to configure it, it does not send spurious DHCPNAK messages to clients that have obtained addresses from a legitimate DHCP server on the network.
log-facility local7; This directive specifies the log level on which to send messages to.
subnet 192.168.0.0 netmask 255.255.255.0 { This line specifies the subnet mask and netmask, you also see a left curly brace ({) which begin the block statement.
range 192.168.0.2 192.168.0.254; This directive specifies the IP range in which the DHCP will server. The left IP address is the beginning and the right IP address is the end.
option routers 192.168.0.1; This directive specifies the router for the network, if you do not have a router on your network then you do not need to specify this directive.
option broadcast-address 192.168.0.255; This directive specifies the broadcast address, as you can see the broadcast address is just outside the IP range we supply.
default-lease-time 600; This directive specifies how long in seconds to lease the IP address out to a host on the network.
max-lease-time 7200; This directive specifies how long in second the IP address can be leased for.
} This line terminates the block statement.

Table 1: Figure 2.2 explained.

Once you have created your dhcp.conf configuration file you will need to modify the dhcpd configuration file located within the /etc/sysconfig. This configuration file allows you to specify which interface to listen on. In this article we will set our DHCP server to listen on eth0 interface which has access to our whole network. The directive that need to be modified is “DHCPD_INTERFACE” Figure 2.3 shows the configuration for the eth0 interface.

...
DHCPD_INTERFACE="eth0"
...

Figure 2.3: Specifies which interface to listen on.

Once modified the dhcpd configuration file you can start the DHCP server by issuing the service command followed by ‘dhcpd start’ as shown in Figure 2.4 or using the rcdhcpd command.

linux-mw4w:/etc/sysconfig # service dhcpd start
Starting DHCP server [chroot]                                         done

Figure 2.4: Starting the DHCP server.

Once you have started the DHCP server you can check to see if your DHCP server is assigning IP addresses by checking the dhcpd.leases file located within the /var/lib/dhcp/db directory. Figure 2.5 shows the contents of the dhcpd.leases file when it has assigned an IP address to a workstation on the network.

lease 192.168.0. 252 {
     starts 5 2008/04/25 14:40:38;
     ends 5 2008/04/25 16:40:38;
     binding state active;
     next binding state free;
     hardware ethernet 00:16:3e:6d:b6:23;
     uid "\001\000\026>m\266#";
     client-hostname "Server1";
}

Figure 2.5: dhcpd.leases file content when an IP address has been assigned.

Reserving IP Addresses

In this section of the article we will look at assigning a specific IP address to a specific workstation on the network. The first task is to find out the MAC address of the machine you would like to set a specific IP address for the reason you need the MAC address is because this address in unique and no other network card should be the same. In this article we have a workstation which has the MAC address of “00:16:3E:6D:b6:23″ and we will assign the IP address of 192.168.0.10 to this workstation.

Once you have the MAC address you need to make an entry in the dhcp.conf configuration file as shown in Figure 3.1. Table 2 explains each line.

host damian {
    hardware ethernet 00:16:3e:6d:b6:23;
    fixed-address 192.168.0.10;
}

Figure 3.1: Setting a fixed IP address.

Directive Description
host damian { This section defines the clients hostname.
hardware ethernet 00:16:3e:6d:b6:23; This section specifies the clients MAC address in which we will use to assign a static IP address.
fixed-address 192.168.0.10; This section specifies the IP address which the client will receive.
} Terminates the deceleration block.

Table 2: Figure 3.1 explained.

Once you have made the changes to the dhcpd.conf configuration file you will need to remove the DHCP lease files from the /var/lib/dhcp/db directory as shown in Figure 3.2. Once you have removed the DHCP lease files you will need to restart the DHCP server this can be using the service command as shown in Figure 3.3.

linux-mw4w:~ # rm -rf /var/lib/dhcp/db/*

Figure 3.2: Remove the DHCP lease files.

linux-mw4w:/etc/sysconfig # service dhcpd restart
Shutting down DHCP server                                            done
Starting DHCP server [chroot]                                         done

Figure 3.3: Restarting the DHCP server.

Once you have restarted the DHCP server you can restart the clients network connection by issuing the service command on the clients workstation as shown in Figure 3.4.

linux-client:~ # service network restart
Shutting down network interfaces:

    eth0      device: Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE] (rev 10)

    eth0      configuration: eth-id-00:0c:29:86:36:b9                 done

Shutting down service network  .  .  .  .  .  .  .  .  .  .  .  .  .  done

Hint: you may set mandatory devices in /etc/sysconfig/network/config

Setting up network interfaces:

    lo

    lo        IP address: 127.0.0.1/8

Checking for network time protocol daemon (NTPD):                     doneed

    eth0      device: Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE] (rev 10)

    eth0      configuration: eth-id-00:0c:29:86:36:b9

    eth0      (DHCP) . IP/Netmask: 192.168.0.10 / 255.255.255.0       done

Setting up service network  .  .  .  .  .  .  .  .  .  .  .  .  .  .  done

SuSEfirewall2: Warning: ip6tables does not support state matching. Extended IPv6 support disabled.

SuSEfirewall2: Another SuSEfirewall2 with PID 7462 found, waiting ...

SuSEfirewall2: Setting up rules from /etc/sysconfig/SuSEfirewall2 ...

SuSEfirewall2: batch committing...

SuSEfirewall2: Firewall rules successfully set

Figure 3.4: Restarting the clients network.

As you can see in Figure 3.4 the IP address 192.168.0.10 was assigned successfully.

Distributing Name servers

In this section of the article we will look at distributing two DNS server to our clients on the network. The DHCP directive that allows you to specify the DNS server is “domain-name-servers” followed by the DNS servers separated by commas (,). The first task that we need to do is modify the dhcp.conf configuration file, we will need to add the “domain-name-servers” directive in between subnet declaration as shown in Figure 4.1.

subnet 192.168.0.0  netmask 255.255.255.0 { 
  range 192.168.0.2 192.168.0.254; 
  option routers 192.168.0.1; 
  option broadcast-address 192.168.0.255; 
  default-lease-time 600; 
  max-lease-time 7200; 
  option domain-name-servers 192.168.0.1, 192.168.0.2;
}

Figure 4.1: Setting domain name servers.

The “domain-name-servers” option in Figure 4.1 will set two DNS servers (192.168.0.1 and 192.168.0.2) you will notice these two entries on the clients workstation within the /etc/resolv.conf configuration file.

Final Thoughts

In this article we looked at setting up and configuring a DHCP server. This article only touched some of the basics that the DHCP server can offer. I strongly recommend you visit the ISC DHCP website [1] to read about all the available features. It is also possible to followe the development of the DHCP server and see what’s intended for the next release.

Reference

[1] http://www.isc.org/index.pl?/sw/dhcp/

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)

Tags: ,
Categories: SUSE Linux Enterprise Server, Technical Solutions

Disclaimer: As with everything else at SUSE Conversations, this content is definitely not supported by SUSE (so don't even think of calling Support if you try something and it blows up).  It was contributed by a community member and is published "as is." It seems to have worked for at least one person, and might work for you. But please be sure to test, test, test before you do anything drastic with it.

4 Comments

  1. By:ericgearhart

    Sorry to be a grammer/spelling Nazi, but RFC 2131 says it’s “Dynamic Host Configuration Protocol”…

    http://tools.ietf.org/html/rfc2131

  2. By:DamianMyerscough

    Thanks for the correction, I have rectified the error.

  3. By:anonymous

    Good article – gives the basics. Just a minor error – under the heading “Configuring DHCP Server” the name of the config file is dhcpd.conf, not dhcp.conf.

    Cheers.

  4. By:DamianMyerscough

    Thanks for the feedback the error has been corrected.

Comment

RSS