Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am trying to set up a DHCP relay agent that would relay DHCP requests for both IPv4 and IPv6. I am using CentOS 6.2 and I am using the dhcrelay from the ISC DHCP implementation. I would like to set it up as a service, but the man page for dhcrelay states:

-6   Run dhcrelay as a DHCPv6 relay agent.  Incompatible with the -4 option.

-4   Run  dhcrelay as a DHCPv4/BOOTP relay agent.  This is the default mode of operation, so the argu-
     ment is not necessary, but may be specified for clarity.  Incompatible with -6.

It seems that the -6 and -4 options are incompatible. How would I still make it work for both protocols without rolling my own service wrapper for both cases?

This is the service script (/etc/init.d/dhcrelay):

#!/bin/sh
#
### BEGIN INIT INFO
# Provides: dhcrelay
# Default-Start:
# Default-Stop:
# Should-Start:
# Required-Start: $network
# Required-Stop:
# Short-Description: Start and stop the DHCP relay server
# Description: dhcrelay provides the Dynamic Host Configuration Protocol (DHCP)
#              relay server.  This is required when your DHCP server is on
#              another network segment from the clients.
### END INIT INFO
#
# The fields below are left around for legacy tools (will remove later).
#
# chkconfig: - 65 35
# description: dhcrelay provides a relay for Dynamic Host Control Protocol.
# processname: dhcrelay
# # pidfile: /var/run/dhcrelay.pid

. /etc/rc.d/init.d/functions

RETVAL=0

prog=dhcrelay
exec=/usr/sbin/dhcrelay
lockfile=/var/lock/subsys/dhcrelay
pidfile=/var/run/dhcrelay.pid
config=/etc/sysconfig/dhcrelay

# The dhcrelay daemon uses the sysconfig file for configuration information.
# There is no native configuration file for this program and you must specify
# its settings on the command line.
[ -f /etc/sysconfig/dhcrelay ] && . /etc/sysconfig/dhcrelay

configtest() {
    [ -x $exec ] || exit 5
    [ -f $config ] || exit 6
    [ -z "$DHCPSERVERS" ] && exit 6
    return 0
}

rh_status() {
    status $exec
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}

start() {
    [ `id -u` -eq 0 ] || exit 4
    [ -x $exec ] || exit 5
    [ -f $config ] || exit 6

    rh_status_q && return 0

    echo -n $"Starting $prog: "
    daemon $exec $DHCRELAYARGS $([ -n "$INTERFACES" ] && for int in $INTERFACES ; do echo -n " -i $int" ; done) $DHCPSERVERS 2>/dev/null
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch $lockfile
    return $RETVAL
}

stop() {
    [ `id -u` -eq 0 ] || exit 4

    rh_status_q || return 0

    echo -n $"Shutting down $prog: "
    killproc $prog
    RETVAL=$?

    echo
    [ $RETVAL -eq 0 ] && rm -f $lockfile
    return $RETVAL
}

usage() {
    echo $"Usage: $0 {start|stop|restart|force-reload|condrestart|try-restart|configtest|status}"
}

if [ $# -gt 1 ]; then
    exit 2
fi

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart|force-reload)
        stop ; start
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
        stop ; start
        ;;
    reload)
        usage
        # unimplemented feature
        exit 3
        ;;
    configtest)
        configtest
        ;;
    status)
        rh_status
        ;;
    *)
        usage
        exit 2
        ;;
esac

exit $?

And the etc/sysconfig/dhcrelay:

DHCRELAYARGS="-4 153.5.240.2"
# DHCPv4 only
INTERFACES=""
# DHCPv4 only
DHCPSERVERS=""
share|improve this question
    
Can't you just start a DHCPv4 AND a DHCPv6 relay? They shouldn't conflict as they serve different IP protocolls. I haven't tried that but it's my first guess –  Christopher Perrin Jul 5 '12 at 10:36
    
Yes, I can, but I would like to use the CentOS services for ease of administration. From what I've gathered, two daemons will have to be active due to limitations of dhcrelay but I would like to know if there is a simple way to still have this wrapped as a CentOS service instead of rolling my own wrappers. –  Tibor Jul 5 '12 at 10:40
    
I'd have to d/l CentOS and look into the service script to answer that one :D –  Christopher Perrin Jul 5 '12 at 10:42
    
could you add /etc/sysconfig/dhcrelay aswell? –  Christopher Perrin Jul 5 '12 at 10:58
    
@ChristopherPerrin I did. –  Tibor Jul 5 '12 at 11:02

2 Answers 2

up vote 1 down vote accepted

Youd have to make a new init script for an additional IPv6 relay. But it is not so hard.

Copy /etc/init.d/dhcrelay to /etc/init.d/dhcrelay6

Edit /etc/init.d/dhcrelay6 to

#!/bin/sh
#
### BEGIN INIT INFO
# Provides: dhcrelay6
# Default-Start:
# Default-Stop:
# Should-Start:
# Required-Start: $network
# Required-Stop:
# Short-Description: Start and stop the DHCP relay server
# Description: dhcrelay provides the Dynamic Host Configuration Protocol (DHCP)
#              relay server.  This is required when your DHCP server is on
#              another network segment from the clients.
### END INIT INFO
#
# The fields below are left around for legacy tools (will remove later).
#
# chkconfig: - 65 35
# description: dhcrelay provides a relay for Dynamic Host Control Protocol for IPv6.
# processname: dhcrelay6
# # pidfile: /var/run/dhcrelay6.pid

. /etc/rc.d/init.d/functions

RETVAL=0

prog=dhcrelay6
exec=/usr/sbin/dhcrelay6
lockfile=/var/lock/subsys/dhcrelay6
pidfile=/var/run/dhcrelay6.pid
config=/etc/sysconfig/dhcrelay6

# The dhcrelay daemon uses the sysconfig file for configuration information.
# There is no native configuration file for this program and you must specify
# its settings on the command line.
[ -f /etc/sysconfig/dhcrelay6 ] && . /etc/sysconfig/dhcrelay6

configtest() {
    [ -x $exec ] || exit 5
    [ -f $config ] || exit 6
    [ -z "$DHCPSERVERS" ] && exit 6
    return 0
}

rh_status() {
    status $exec
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}

start() {
    [ `id -u` -eq 0 ] || exit 4
    [ -x $exec ] || exit 5
    [ -f $config ] || exit 6

    rh_status_q && return 0

    echo -n $"Starting $prog: "
    daemon $exec -6 $DHCRELAYARGS $([ -n "$LOWER" ] && for int in $LOWER; do echo -n " -l $int" ; done) $([ -n "$UPPER " ] && for int in $UPPER ; do echo -n " -u $int" ; done) 2>/dev/null
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch $lockfile
    return $RETVAL
}

stop() {
    [ `id -u` -eq 0 ] || exit 4

    rh_status_q || return 0

    echo -n $"Shutting down $prog: "
    killproc $prog
    RETVAL=$?

    echo
    [ $RETVAL -eq 0 ] && rm -f $lockfile
    return $RETVAL
}

usage() {
    echo $"Usage: $0 {start|stop|restart|force-reload|condrestart|try-restart|configtest|status}"
}

if [ $# -gt 1 ]; then
    exit 2
fi

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart|force-reload)
        stop ; start
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
        stop ; start
        ;;
    reload)
        usage
        # unimplemented feature
        exit 3
        ;;
    configtest)
        configtest
        ;;
    status)
        rh_status
        ;;
    *)
        usage
        exit 2
        ;;
esac

exit $?

Copy /etc/sysconfig/dhcrelay to /etc/sysconfig/dhcrelay

Edit /etc/sysconfig/dhcrelay to

DHCRELAYARGS=""
# Downstream interfaces (Clients)
LOWER=""
# Upstream interfaces (Servers)
UPPER=""

Execute

ln -s /usr/sbin/dhcrelay /usr/sbin/dhcrelay6

This is necessary so the service can be stoped independent from the IPv4 relay because it doesn't use a PID-file and is stopped by basename.

This is not tested as I don't have CentOS installed but it SHOULD work. Contact me if it does not and we'll work it out.

share|improve this answer
    
Thank you! I hoped it was possible without creating a new service wrapper, but it seems this is impossible. This is a great solution though. –  Tibor Jul 5 '12 at 11:50

You don't need to do the binary linking. You say "it doesn't use a PID-file" - so why is the pid file specified in the init script then?

In actual fact, the dhcprelay daemon spawns a pid file for ipv4 mode, and a different pid file for ipv6 mode, so you just need to specify the correct pid file in each init script, and starting and stopping each instance of the daemon (ipv4 & ipv6) will work fine.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.