搭建DHCP Server(原创)

以前一直使用静态ip建网,但是如果来人,现分配ip毕竟很麻烦,决定建立一个DHCP Server。
操作系统:CentOS 5
DHCP:DHCP 4.1.0a2  (http://ftp.isc.org/isc/dhcp/dhcp-4.1.0a2.tar.gz

安装DHCP Server:
#wget http://ftp.isc.org/isc/dhcp/dhcp-4.1.0a2.tar.gz
#tar zxvf dhcp-4.1.0a2.tar.gz
#cd dhcp-4.1.0a2
#./configure --prefix=/usr/local/dhcp --disable-dhcpv6
#make
#make install

配置DHCP Server:
#cd /usr/local/dhcp/etc
#ln -s /usr/local/dhcp/etc/dhcpd.conf /etc/dhcpd.conf
#vi dhcpd.conf

option domain-name-servers 219.146.0.130, 219.150.32.132;

default-lease-time 86400;
max-lease-time 86400;
option time-offset -18000;
log-facility local7;
subnet 192.168.0.0 netmask 255.255.255.0 {
  range 192.168.0.100 192.168.0.130;
  option routers 192.168.0.1;
  option broadcast-address 192.168.0.255;
  option time-offset -18000;
}


呵呵,是不是很简单?

创建启动脚本:
#vi /etc/init.d/dhcpd

#!/bin/sh
#
#
# chkconfig: 2345 07 93
#
# description: DHCPD
#
# Script Author:  Qu WenQing 
 
state=$1
PREFIX=/usr/local/dhcp
DHCPDARGS="eth0"
PIDF=/var/run/dhcpd.pid
CONFIG=/etc/dhcpd.conf
LEASE=/var/db/dhcpd.leases


START ()
{
        if [ ! -f ${LEASE} ]; then
                touch ${LEASE}
        fi
        if [ -f ${PREFIX}/sbin/dhcpd ]; then
                echo "Starting the ISC DHCP server"
                ${PREFIX}/sbin/dhcpd -cf ${CONFIG} -lf ${LEASE} ${DHCPDARGS}
        fi
}
STOP ()
{
        if [ -f ${PIDF} ]; then
                PID=`cat ${PIDF}`
                if [ -d /proc/$PID ]; then
                        echo "Stopping the ISC DHCP server"
                        kill $PID
                fi
        fi
}


case $state in
start)
        START
        ;;
stop)
        STOP
        ;;
restart)
        STOP
        START
        ;;
esac

exit 0



保存,设置为可执行
#service dhcpd start

Starting the ISC DHCP server
Internet Systems Consortium DHCP Server 4.1.0a2
Copyright 2004-2008 Internet Systems Consortium.
All rights reserved.
For info, please visit http://www.isc.org/sw/dhcp/
Wrote 2 leases to leases file.
Listening on LPF/eth0/00:10:dc:71:d0:c5/192.168.0.0/24
Sending on   LPF/eth0/00:10:dc:71:d0:c5/192.168.0.0/24
Sending on   Socket/fallback/fallback-net


OK,启动成功。

标签: 原创 DHCP
评论: 0 | 引用: 0 | 阅读: 5997