System Administration Guide: IP Services

Chapter 12 DHCP Files and Commands (Reference)

This chapter explains the relationships between files and the commands that use the files, but does not explain how to use the commands.

The chapter contains the following information:

DHCP Commands

The following table lists the commands you might find useful in managing DHCP on your network.

Table 12–1 Commands Used in DHCP

Command 

Description 

dhtadm

Used to make changes to the options and macros in the dhcptab. This command is most useful in scripts that you create to automate changes you need to make to your DHCP information. Use dhtadm with the -P option and pipe it through the grep command for a quick way to search for particular option values in the dhcptab.

pntadmUsed to make changes to the DHCP network tables that map client IDs to IP addresses and optionally associate configuration information with IP addresses.
dhcpconfigUsed to configure and unconfigure DHCP servers and BOOTP relay agents, convert to a different data store, and import/export DHCP configuration data.
in.dhcpdThe DHCP server daemon. System scripts use this command to start and stop DHCP service. You can start in.dhcpd with non-default options, such as -d for debugging.
dhcpmgrThe DHCP Manager, a graphical tool used to configure and manage the DHCP service. DHCP Manager is the recommended Solaris DHCP management tool.
ifconfigUsed at system boot to assign IP addresses to network interfaces, configure network interface parameters, or both. On a Solaris DHCP client, ifconfig starts DHCP to get the parameters (including the IP address) needed to configure a network interface.
dhcpinfoUsed by system startup scripts on Solaris client systems to obtain information (such as host name) from the DHCP client daemon (dhcpagent) . You can also use dhcpinfo in scripts or at the command line to obtain specified parameter values.
snoopUsed to capture and display the contents of packets being passed across the network. snoop is useful for troubleshooting problems with the DHCP service.
dhcpagentThe DHCP client daemon, which implements the client side of the DHCP protocol.

Running DHCP Commands in Scripts

The dhcpconfig, dhtadm, and pntadm commands are optimized for use in scripts. In particular, the pntadm command is useful for creating a large number of IP address entries in a DHCP network table. The following sample script uses pntadm in batch mode to create IP addresses.


Example 12–1 addclient.ksh Script with the pntadm Command

#! /usr/bin/ksh
#
# This script utilizes the pntadm batch facility to add client entries
# to a DHCP network table. It assumes that the user has the rights to
# run pntadm to add entries to DHCP network tables.

#
# Based on the nsswitch setting, query the netmasks table for a netmask.
# Accepts one argument, a dotted IP address.
#
get_netmask()
{
	MTMP=`getent netmasks ${1} | awk '{ print $2 }'`
	if [ ! -z "${MTMP}" ]
	then
		print - ${MTMP}
	fi
}

#
# Based on the network specification, determine whether or not network is 
# subnetted or supernetted.
# Given a dotted IP network number, convert it to the default class
# network.(used to detect subnetting). Requires one argument, the
# network number. (e.g. 10.0.0.0) Echos the default network and default
# mask for success, null if error.
#
get_default_class()
{
	NN01=${1%%.*}
	tmp=${1#*.}
	NN02=${tmp%%.*}
	tmp=${tmp#*.}
	NN03=${tmp%%.*}
	tmp=${tmp#*.}
	NN04=${tmp%%.*}
	RETNET=""
	RETMASK=""

	typeset -i16 ONE=10#${1%%.*}
	typeset -i10 X=$((${ONE}&16#f0))
	if [ ${X} -eq 224 ]
	then
		# Multicast
		typeset -i10 TMP=$((${ONE}&16#f0))
		RETNET="${TMP}.0.0.0"
		RETMASK="240.0.0.0"
	fi
	typeset -i10 X=$((${ONE}&16#80))
	if [ -z "${RETNET}" -a ${X} -eq 0 ]
	then
		# Class A
		RETNET="${NN01}.0.0.0"
		RETMASK="255.0.0.0"
	fi
	typeset -i10 X=$((${ONE}&16#c0))
	if [ -z "${RETNET}" -a ${X} -eq 128 ]
	then
		# Class B
		RETNET="${NN01}.${NN02}.0.0"
		RETMASK="255.255.0.0"
	fi
	typeset -i10 X=$((${ONE}&16#e0))
	if [ -z "${RETNET}" -a ${X} -eq 192 ]
	then
		# Class C
		RETNET="${NN01}.${NN02}.${NN03}.0"
		RETMASK="255.255.255.0"
	fi
	print - ${RETNET} ${RETMASK}
	unset NNO1 NNO2 NNO3 NNO4 RETNET RETMASK X ONE
}

#
# Given a dotted form of an IP address, convert it to its hex equivalent.
#
convert_dotted_to_hex()
{
	typeset -i10 one=${1%%.*}
	typeset -i16 one=${one}
	typeset -Z2 one=${one}
	tmp=${1#*.}

	typeset -i10 two=${tmp%%.*}
	typeset -i16 two=${two}
	typeset -Z2 two=${two}
	tmp=${tmp#*.}

	typeset -i10 three=${tmp%%.*}
	typeset -i16 three=${three}
	typeset -Z2 three=${three}
	tmp=${tmp#*.}

	typeset -i10 four=${tmp%%.*}
	typeset -i16 four=${four}
	typeset -Z2 four=${four}

	 hex=`print - ${one}${two}${three}${four} | sed -e 's/#/0/g'`
	 print - 16#${hex}
	 unset one two three four tmp
}

#
# Generate an IP address given the network address, mask, increment.
# 
get_addr()
{
	typeset -i16 net=`convert_dotted_to_hex ${1}`
	typeset -i16 mask=`convert_dotted_to_hex ${2}`
	typeset -i16 incr=10#${3}

	# Maximum legal value - invert the mask, add to net.
	typeset -i16 mhosts=~${mask}
	typeset -i16 maxnet=${net}+${mhosts}

	# Add the incr value.
	let net=${net}+${incr}

	if [ $((${net} < ${maxnet})) -eq 1 ]
	then
		typeset -i16 a=${net}\&16#ff000000
		typeset -i10 a="${a}>>24"

		typeset -i16 b=${net}\&16#ff0000
		typeset -i10 b="${b}>>16"

		typeset -i16 c=${net}\&16#ff00
		typeset -i10 c="${c}>>8"

		typeset -i10 d=${net}\&16#ff
		print - "${a}.${b}.${c}.${d}"
	fi
	unset net mask incr mhosts maxnet a b c d
}

# Given a network address and client address, return the index.
client_index()
{
	typeset -i NNO1=${1%%.*}
	tmp=${1#*.}
	typeset -i NNO2=${tmp%%.*}
	tmp=${tmp#*.}
	typeset -i NNO3=${tmp%%.*}
	tmp=${tmp#*.}
	typeset -i NNO4=${tmp%%.*}

	typeset -i16 NNF1
	let NNF1=${NNO1}
	typeset -i16 NNF2
	let NNF2=${NNO2}
	typeset -i16 NNF3
	let NNF3=${NNO3}
	typeset -i16 NNF4
	let NNF4=${NNO4}
	typeset +i16 NNF1
	typeset +i16 NNF2
	typeset +i16 NNF3
	typeset +i16 NNF4
	NNF1=${NNF1#16\#}
	NNF2=${NNF2#16\#}
	NNF3=${NNF3#16\#}
	NNF4=${NNF4#16\#}
	if [ ${#NNF1} -eq 1 ]
	then
		NNF1="0${NNF1}"
	fi
	if [ ${#NNF2} -eq 1 ]
	then
		NNF2="0${NNF2}"
	fi
	if [ ${#NNF3} -eq 1 ]
	then
		NNF3="0${NNF3}"
	fi
	if [ ${#NNF4} -eq 1 ]
	then
		NNF4="0${NNF4}"
	fi
	typeset -i16 NN
	let NN=16#${NNF1}${NNF2}${NNF3}${NNF4}
	unset NNF1 NNF2 NNF3 NNF4

	typeset -i NNO1=${2%%.*}
	tmp=${2#*.}
	typeset -i NNO2=${tmp%%.*}
	tmp=${tmp#*.}
	typeset -i NNO3=${tmp%%.*}
	tmp=${tmp#*.}
	typeset -i NNO4=${tmp%%.*}
	typeset -i16 NNF1
	let NNF1=${NNO1}
	typeset -i16 NNF2
	let NNF2=${NNO2}
	typeset -i16 NNF3
	let NNF3=${NNO3}
	typeset -i16 NNF4
	let NNF4=${NNO4}
	typeset +i16 NNF1
	typeset +i16 NNF2
	typeset +i16 NNF3
	typeset +i16 NNF4
	NNF1=${NNF1#16\#}
	NNF2=${NNF2#16\#}
	NNF3=${NNF3#16\#}
	NNF4=${NNF4#16\#}
	if [ ${#NNF1} -eq 1 ]
	then
		NNF1="0${NNF1}"
	fi
	if [ ${#NNF2} -eq 1 ]
	then
		NNF2="0${NNF2}"
	fi
	if [ ${#NNF3} -eq 1 ]
	then
		NNF3="0${NNF3}"
	fi
	if [ ${#NNF4} -eq 1 ]
	then
		NNF4="0${NNF4}"
	fi
	typeset -i16 NC
	let NC=16#${NNF1}${NNF2}${NNF3}${NNF4}
	typeset -i10 ANS
	let ANS=${NC}-${NN}
	print - $ANS
}

#
# Check usage.
#
if [ "$#" != 3 ]
then
	print "This script is used to add client entries to a DHCP network"
	print "table by utilizing the pntadm batch facilty.\n"
	print "usage: $0 network start_ip entries\n"
	print "where: network is the IP address of the network"
        print "       start_ip is the starting IP address \n"
        print "       entries is the number of the entries to add\n"
	print "example: $0 10.148.174.0 10.148.174.1 254\n"
	return
fi

#
# Use input arguments to set script variables.
#
NETWORK=$1
START_IP=$2
typeset -i STRTNUM=`client_index ${NETWORK} ${START_IP}`
let ENDNUM=${STRTNUM}+$3
let ENTRYNUM=${STRTNUM}
BATCHFILE=/tmp/batchfile.$$
MACRO=`uname -n`

#
# Check if mask in netmasks table. First try
# for network address as given, in case VLSM
# is in use.
#
NETMASK=`get_netmask ${NETWORK}`
if [ -z "${NETMASK}" ]
then
	get_default_class ${NETWORK} | read DEFNET DEFMASK
	# use the default.
	if [ "${DEFNET}" != "${NETWORK}" ]
	then
		# likely subnetted/supernetted.
		print - "\n\n###\tWarning\t###\n"
		print - "Network ${NETWORK} is netmasked, but no entry was found  \n
              in the 'netmasks' table; please update the 'netmasks'  \n
              table in the appropriate nameservice before continuing. \n 
              (See /etc/nsswitch.conf.) \n" >&2
		return 1
	else
		# use the default.
		NETMASK="${DEFMASK}"
	fi
fi

#
# Create a batch file.
#
print -n "Creating batch file "
while [ ${ENTRYNUM} -lt ${ENDNUM} ]
do
	if [ $((${ENTRYNUM}-${STRTNUM}))%50 -eq 0 ]
	then
		print -n "."
	fi

	CLIENTIP=`get_addr ${NETWORK} ${NETMASK} ${ENTRYNUM}`
	print "pntadm -A ${CLIENTIP} -m ${MACRO} ${NETWORK}" >> ${BATCHFILE}
	let ENTRYNUM=${ENTRYNUM}+1
done
print " done.\n"

#
# Run pntadm in batch mode and redirect output to a temporary file.
# Progress can be monitored by using the output file.
#
print "Batch processing output redirected to ${BATCHFILE}"
print "Batch processing started."

pntadm -B ${BATCHFILE} -v > /tmp/batch.out 2 >&1

print "Batch processing completed."

DHCP Files

The following table lists files associated with Solaris DHCP.

Table 12–2 Files and Tables Used by DHCP Daemons and Commands

File/Table 

Description 

dhcptab

A generic term for the table of DHCP configuration information recorded as options with assigned values, which are then grouped into macros. The name of the dhcptab table and its location is determined by the data store you use for DHCP information.

DHCP network table 

Maps IP addresses to client IDs and configuration options. DHCP network tables are named according to the IP address of the network, such as 10.21.32.0. There is no file called dhcp_network. The name and location of DHCP network tables is determined by the data store you use for DHCP information.

dhcpsvc.conf

Records DHCP daemon startup options and the data store resource and location of the dhcptab and network tables. The file is located in the /etc/inet directory.

nsswitch.conf

Specifies the location of name service databases and the order in which to search them for various kinds of information. The nsswitch.conf file is consulted when you configure a DHCP server in order to obtain accurate configuration information. The file is located in the /etc directory.

resolv.conf

Contains information used by the DNS resolver. During DHCP server configuration, this file is consulted for information about the DNS domain and DNS server. The file is located in the /etc directory.

dhcp.interface

Indicates that DHCP is to be used on the client's network interface specified in the file name, such as dhcp.qe0. The dhcp.interface file might contain commands that are passed as options to the ifconfig interface dhcp start option command used to start DHCP on the client. The file is located in the /etc directory on Solaris DHCP client systems.

interface.dhc

Contains the configuration parameters obtained from DHCP for the given network interface. The client caches the current configuration information in /etc/dhcp/interface.dhc when the interface's IP address lease is dropped. The next time DHCP starts on the interface, the client requests to use the cached configuration if the lease has not expired. If the DHCP server denies the request, the client begins the standard DHCP lease negotiation process.

dhcpagent

Sets parameter values for the dhcpagent client daemon. The path to the file is /etc/default/dhcpagent. See the file itself or the dhcpagent(1M) man page for information about the parameters.

DHCP inittab

Defines aspects of DHCP option codes, such as the data type, and assigns mnemonic labels. See the dhcp_inittab man page for more information about the file syntax.

On the client, the information in the /etc/dhcp/inittab file is used by dhcpinfo to provide more meaningful information to human readers of the information. This file replaces the /etc/dhcp/dhcptags file. DHCP Option Information provides more information about this replacement. On the DHCP server system, this file is used by the DHCP daemon and management tools to obtain DHCP option information.

DHCP Option Information

Historically, DHCP option information has been stored in several places in Solaris DHCP, including the server's dhcptab table, the client's dhcptags file, and internal tables of in.dhcpd, snoop, dhcpinfo, and dhcpmgr. In an effort to consolidate option information, the Solaris 8 DHCP product introduced the /etc/dhcp/inittab file. See the dhcp_inittab man page for detailed information about the file.

The Solaris DHCP client uses the DHCP inittab file as a replacement for the dhcptags file to obtain information about option codes received in its DHCP packet. The in.dhcpd, snoop, and dhcpmgr programs on the DHCP server use the inittab file as well.


Note –

Most sites that use Solaris DHCP are not affected by this change. Your site is affected only if you plan to upgrade to Solaris 8, you previously created new DHCP options and modified the /etc/dhcp/dhcptags file, and you want to retain the changes. When you upgrade, the upgrade log notifies you that your dhcptags file had been modified and that you should make changes to the DHCP inittab file.


Differences Between dhcptags and inittab

The inittab file contains more information than the dhcptags file and it uses a different syntax.

A sample dhcptags entry is:

33 StaticRt - IPList Static_Routes

where 33 is the numeric code that is passed in the DHCP packet, StaticRt is the option name, IPList indicates the expected data is a list of IP addresses, and Static_Routes is a more descriptive name.

The inittab file consists of one-line records that describe each option. The format is similar to the format that defines symbols in dhcptab. The following table describes the syntax of the inittab.

Table 12–3 DHCP inittab File Syntax

Option 

Description 

option-name

Name of the option. The option name must be unique within its option category, and not overlap with other option names in the Standard, Site, and Vendor categories. For example, you cannot have two Site options with the same name, and you should not create a Site option with the same name as a Standard option.  

category

Identifies the namespace in which the option belongs. Must be one of Standard, Site, Vendor, Field, or Internal. 

code

Identifies the option when it is sent over the network. In most cases, the code uniquely identifies the option, without a category. However, in the case of internal categories like Field or Internal, a code might be used for other purposes and thus might not be globally unique. The code should be unique within the option's category, and not overlap with codes in the Standard and Site fields.  

type

Describes the data associated with this option. Valid types are IP, Ascii, Octet, Boolean, Unumber8, Unumber16, Unumber32, Unumber64, Snumber8, Snumber16, Snumber32, and Snumber64. For numbers, an initial U or S indicates that the number is unsigned or signed, and the digits at the end indicate the amount of bits in the number. The type is not case sensitive. 

granularity

Describes how many units of data make up a whole value for this option.  

maximum

Describes how many whole values are allowed for this option. 0 indicates an infinite number. 

consumers

Describes which programs can use this information. This should be set to sdmi, where:

    s – snoop


    d – in.dhcpd


    m – dhcpmgr


    i – dhcpinfo


A sample inittab entry is:

StaticRt Standard, 33, IP, 2, 0, sdmi

This entry describes an option named StaticRt, which is in the Standard category and is option code 33. The expected data is a potentially infinite number of pairs of IP addresses because the type is IP, granularity is 2, and maximum is infinite (0). The consumers of this option are sdmi: snoop, in.dhcpd, dhcpmgr, and dhcpinfo.

Converting dhcptags Entries to inittab Entries

If you previously added entries to your dhcptags file, you must add corresponding entries to the new inittab file. The following example shows how a sample dhcptags entry might be expressed in inittab format.

Suppose you had added the following dhcptags entry for fax machines connected to the network:

128 FaxMchn - IP Fax_Machine

The code 128 means that it must be in the site category, the option name is FaxMchn, the data type is IP.

The corresponding inittab entry might be:

FaxMchn SITE, 128, IP, 1, 1, sdmi

The granularity of 1 and maximum of 1 indicate that one IP address is expected for this option.