Configuring ISC DHCPv6 Server

本文介绍如何安装和配置ISC DHCPv6服务器。包括状态化和非状态化配置模式的选择,软件下载步骤,示例配置文件等内容。适用于希望了解DHCPv6服务器配置细节的技术人员。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Configuring ISC DHCPv6 Server

Contents

[hide]


Preface

This article should give you a short overview how to install a DHCPv6 Server and configure it.

With DHCPv6 you can decide in which mode you want to use your dhcp server. You can use a 'stateless' or 'stateful mode'. Both are described in this article below


Stateless Configuration

In stateless configuration mode the dhcp server interacts together with an other IPv6 address assignment mechanism (e.g. a radvd router). The client first gets its prefix (and generates his own IPv6 address - SLAAC) and receives some more informations (like DNS server IPs, NTP server) as second part from your DHCPv6 server.

In this mode the DHCPv6 Server provides the following informations to clients:

 DNS serveraddresses
 Domain Name
 NTP Server
 SIP Server (RFC 3319)
... see http://www.iana.org/assignments/dhcpv6-parameters/dhcpv6-parameters.xml


Stateful Configuration

In this mode the DHCPv6 server provides their addresses without any other address assigning mechanism.


Installation

Softwaredownload

You can download the current production release of ISC DHCP Server from http://www.isc.org/software/dhcp. Single steps for installation are listed in file README. If you want to see my steps, look below:

 wget http://ftp.isc.org/isc/dhcp/dhcp-4.2.1-P1.tar.gz
 tar -zxfv dhcp-4.2.1-P1.tar.gz
 cd dhcp-4.2.1-P1
 ./configure

 make && make install

Sampleconfigurations

The folder "dhcp-4.2.1-P1/docs/examples" provides some sampleconfigs, who are documented very well.


Serverconfiguration

Preconfigurationsteps

A possible configuration could look like this:

1.) prefix '2001:ed8:77b5' (here you can use your sixxs prefix)
2.) To indicate the dhcp server in ipv6 choose an 'easy to read' ipv4-in-ipv6 address: 2001:ed8:77b5::10:123:105:122 (ipv4: 10.123.105.122/24)
3.) the dhcp range starts from 2001:ed8:77b5::1 to 2001:ed8:77b5::ffff:ffff (many addresses...)


 Client Server
HW MAC 00:22:68:11:62:cd 60:eb:69:4e:2b:8b
Link local Address fe80::222:68ff:fe:11:62cd fe80::62eb:69ff:fe4e:2b8b
IP range 2001:ed8:77b5::1 2001:ed8:77b5::ffff:ffff 2001:ed8:77b5::10:123:105:122/64
SIXXs range <YOUR-PREFIX>::1 <YOUR-PREFIX>::ffff:ffff <YOUR-PREFIX>::10:123:105:122/64


Adding the Serverinterface to your Subnet

To become the server work properly, the listening interface has to be configured with a ip address in the provided subnet - otherwise the server will not start. (With this address the server knows, which interface he should use.)

There exists two methodes to configure your interface with IPv6 addresses:


ifconfig

ifconfig <INTERFACE> inet6 {add|del} <IPV6-ADDRESS>/<PREFIX-LENGTH>

example (for adding a address):
ifconfig eth0 inet6 add 2001:ed8:77b5::10:123:105:122/64


ip

 ip -6 addr {add|del} <IPV6-ADDRESS>/<PREFIX-LENGTH> dev <INTERFACE>

 example
ip -6 addr add  2001:ed8:77b5::10:123:105:122/64 dev eth0 


The Expected IP Flow

Keep in mind, that the IPv6 DHCP client communicates always with the 'all multicast node' (ff02::1:1,ff02::1:2) as destination address. The server always communicates with his local link address (fe80::) as source address.

At first look it's a little bit confusing, but the IP flow looks like this:
(taken from whireshark's ip flow view)


     Client                                                     DHCP Server
fe80::222:68ff:fe11:62cd                                 fe80::62eb:69ff:fe4e:2b8b
	|				                           |
	|                      (all nodes address)                 |
	|                          ff02::1:2                       |
	|                             |                            |                   
	|                             |                            |
	|    Solicit XID: 0x28d6      |                            | DHCPv6: Solicit XID: 0x28d6e4 CID: 0001000115ad822e0022681162cd 
	|---------------------------->|                            |
	|                             |                            |
	|                             |                            |
	|   Advertise XID: 0x28       |                            | DHCPv6: Advertise XID: 0x28d6e4 IAA: 2001:ed8:77b5::8758:1493 CID: 0001000115ad822e0022681162cd 
	|<---------------------------------------------------------|
	|                             |                            |
	|                             |                            |
	|    Request XID: 0x35a2      |                            | DHCPv6: Request XID: 0x35a211 CID: 0001000115ad822e0022681162cd IAA: 2001:ed8:77b5::8758:1493 
	| --------------------------->|                            |
	|                             |                            |
	|                             |                            |
	|   Reply XID: 0x35a211       |                            | DHCPv6: Reply XID: 0x35a211 IAA: 2001:ed8:77b5::8758:1493 CID: 0001000115ad822e0022681162cd 
	|<---------------------------------------------------------|


DHCP Server Configfiles (Create a Range)

stateful configuration

default-lease-time 2592000;
preferred-lifetime 604800;
option dhcp-renewal-time 3600;
option dhcp-rebinding-time 7200;

# Enable RFC 5007 support (same than for DHCPv4)
allow leasequery;

# Global definitions for name server address(es) and domain search list
#
# 
option dhcp6.name-servers 3ffe:501:ffff:100:200:ff:fe00:3f3e;
option dhcp6.domain-search "test.example.com","example.com";

option dhcp6.info-refresh-time 21600;


# The subnet where the server is attached
subnet6 2001:ed8:77b5::/64 {
	range6 2001:ed8:77b5::1 2001:ed8:77b5::ffff:ffff;
}


Starting the Server

Manually

You can start the server with the following command:

  dhcpd -6 -cf <PATH-to-configfile> -ls <PATH-to-leasefile>


Automatically with /etc/init.d/

Here you can see my script to start the dhcpv6 server automatically at boottime. I use ubuntu, feel free to adopt this script for your purpose.

 #!/bin/sh
#
# $Id: isc dhcp server.init.d,v 4.2.1-P1 2011/04/05 /usr/local/sbin/dhcpd$
#

### BEGIN INIT INFO
# Provides:          dhcpd-server
# Required-Start:    $remote_fs $network $syslog
# Required-Stop:     $remote_fs $network $syslog
# Should-Start:      $local_fs slapd
# Should-Stop:       $local_fs slapd
# Default-Start:     2 3 4 5
# Default-Stop:      1
# Short-Description: DHCP server
# Description:       Dynamic Host Configuration Protocol Server
### END INIT INFO

PATH=/sbin:/bin:/usr/sbin:/usr/bin

# config file
NAME=dhcpdv6
DESC="DHCP IPv6 server"
INTERFACES="eth0"

SERVER=/usr/local/sbin/dhcpd
SERVERARGS="-6"
CONFIGFILE=/etc/dhcpdv6/dhcpv6.conf
LIBFOLDER=/var/lib/dhcpv6
LEASEFILE="${LIBFOLDER}/dhcpdv6.leases"
RUNFOLDER=/var/run/dhcpv6
DHCPDPID="${RUNFOLDER}/dhcpdv6.pid"


# check filetypes/values
test -f "${SERVER}" || exit 0

# include all init functions
. /lib/lsb/init-functions

test_config()
{
	# 1.) check config
	if [ ! "${SERVER}" "${SERVERARGS}" -t -q -cf "${CONFIGFILE}" > /dev/null 2>&1 ]; then
		echo "${NAME} self-test failed. Please fix the config file."
		echo "The error was: "
		"${SERVER}" "${SERVERARGS}" -t -cf "${CONFIGFILE}"
		exit 1
	fi

	# 2.) test_config will started if someone wants to start the server
	# test if the server is currently running
	if [ "${1}" = "start" ]; then
		if [ -e "${DHCPDPID}" ]; then
		  stop_server "Currently running instance of ${DESC} found (PID: `cat ${DHCPDPID}`) - will now stop this instance"
		fi
	fi
}

stop_server(){
	if [ "${1}" != "" ]; then
	 log_daemon_msg "${1}"
	fi

	if [ -e "${DHCPDPID}" ]; then
	  log_daemon_msg "Stopping ${DESC} ${NAME} [`cat ${DHCPDPID}`]"
	  start-stop-daemon --stop --quiet --pidfile "${DHCPDPID}"
	  log_end_msg $?
	  rm -f "${DHCPDPID}"
	else
	  log_daemon_msg "Stopping ${DESC} ${NAME}: nothing do do, no pidfile found"	
	fi
}

# single arg is -v for messages, -q for none
check_status(){
  if [ ! -r "$DHCPDPID" ]; then
    test "$1" != -v || echo "$NAME is not running."
    return 3
  fi
  
  if read pid < "$DHCPDPID" && ps -p "$pid" > /dev/null 2>&1; then
    test "$1" != -v || echo "$NAME is running."
    return 0
  else
    test "$1" != -v || echo "$NAME is not running but $DHCPDPID exists."
    return 1
  fi
}

case "$1" in
	start)
	  test_config ${1}
		log_daemon_msg "Starting ${DESC} ${NAME}"

		# allow dhcp server to write lease and pid file
		if [ ! -e "${RUNFOLDER}" ]; then
		  # create run folder
		  mkdir -p "${RUNFOLDER}"
		  chown dhcpd:dhcpd "${RUNFOLDER}"
		  
		  # create pid file
		  touch "${DHCPDPID}"
		  chown dhcpd:dhcpd "${DHCPDPID}"
		else
		   # create pid file
		  touch "${DHCPDPID}"
		  chown dhcpd:dhcpd "${DHCPDPID}"
		fi

		if [ ! -e "${LIBFOLDER}" ]; then
		  # create run folder
		  mkdir -p "${LIBFOLDER}"
		  chown dhcpd:dhcpd "${LIBFOLDER}"
		  
		  # create lease file
		  touch "${LEASEFILE}"
		  chown dhcpd:dhcpd "${LEASEFILE}"
		else
		   # create pid file
		  touch "${LEASEFILE}"
		  chown dhcpd:dhcpd "${LEASEFILE}"
		fi
		
		start-stop-daemon --start --quiet --pidfile "${DHCPDPID}" --exec "${SERVER}" -- "${SERVERARGS}" -q -pf "${DHCPDPID}" -cf "${CONFIGFILE}"  -lf "${LEASEFILE}" "${INTERFACES}"
		sleep 2
				

		if check_status -q; then
		  log_end_msg 0
		else
			log_failure_msg "check syslog for diagnostics."
			log_end_msg 1
			exit 1
		fi
		;;
	stop)
		# stop dhcp server
		stop_server
		;;
		
	restart | force-reload)
		test_config
		$0 stop
		sleep 2
		$0 start
		if [ "$?" != "0" ]; then
			exit 1
		fi
		;;
	status)
		echo -n "Status of $DESC: "
		check_status -v
		exit "$?"
		;;
	*)
		echo "Usage: $0 {start|stop|restart|force-reload|status}"
		exit 1 
esac

exit 0

Don't forget to configure your runlevels, to really start the server if your machine starts:

 update-rc.d <FILE-above> defaults


Lets Start the engine

Now you lets start your dhcp client and see the magic of dhcpv6. :-)

For example:
The network-manager-gnome supports dhcpv6 as client


<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
### DHCPv6 Type 3 Message Format and Usage In the context of Dynamic Host Configuration Protocol version 6 (DHCPv6), a Type 3 message is specifically known as an Advertise message. This message plays a crucial role during the process where clients seek IP address assignments or other configuration parameters from servers within IPv6 networks. The structure of this message includes several fields that are essential for its operation: - **Message Type**: Set to value 3, indicating it's an Advertise message. - **Transaction ID**: A unique identifier used by both client and server to match requests with responses. - **Options Field**: Contains various options such as Identity Association for Non-temporary Address (IA_NA)[^1], which specifies how long addresses can be used before needing renewal; DNS recursive name servers information, domain search list entries among others depending on what has been requested by the client through Solicit messages. When configuring network settings using DHCPv6, after sending out solicitations seeking available services, clients will receive one or more advertise messages containing offered configurations including but not limited to global unicast addresses along with associated lifetimes and additional service details like Domain Name System (DNS) server addresses. Upon receipt of these advertisements, based upon selection criteria defined either locally at each node or specified via policy mechanisms external to protocol operations themselves, nodes choose preferred offers leading towards subsequent steps involving request/response exchanges finalizing assignment processes. ```python # Example Python code snippet demonstrating handling of DHCPv6 ADVERTISE packet def handle_dhcpv6_advertise(packet): if packet['dhcp6.type'] == 'advertise': transaction_id = packet['dhcp6.transaction-id'] advertised_options = parse_options_field(packet['dhcp6.options']) # Process received IA_NA option ia_na_info = extract_ia_na(advertised_options) print(f"Received DHCPv6 Advertise with Transaction ID {transaction_id}") print("Included Options:", advertised_options) print("Identity Associations for Non-Temporary Addresses Info:", ia_na_info) ``` --related questions-- 1. What specific elements does the Options field contain in a DHCPv6 Advertise message? 2. How do clients select between multiple Advertise messages they might receive when requesting configuration data over DHCPv6? 3. Can you explain the difference between DHCPv6 Solicit and Advertise messages? 4. In what scenarios would a device send a DHCPv6 Solicit message rather than directly transmitting a Request message?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值