第二步 安装dhcp服务器

1 服务器环境
root@ubuntu:/# uname -a
Linux ubuntu 2.6.22-14-generic #1 SMP Sun Oct 14 23:05:12 GMT 2007 i686 GNU/Linux
root@ubuntu:/#

2 安装命令
root@ubuntu:/# apt-get install dhcp3-server
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
Reading state information... 完成
dhcp3-server 已经是最新的版本了。
共升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 0 个软件未被升级。

3 设置dhcpd工作接口
root@ubuntu:~# nano /etc/default/dhcp3-server
# Defaults for dhcp initscript
# sourced by /etc/init.d/dhcp
# installed at /etc/default/dhcp3-server by the maintainer scripts
#
# This is a POSIX shell fragment
# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
# Separate multiple interfaces with spaces, e.g. "eth0 eth1".

# 下面这句用来定义工作接口,如果是多个就中间空格
# 比如INTERFACES="eth0 eth1 eth2"
INTERFACES="eth0"
注*上面一行指明服务器端通过哪一块网卡提供dhcp服务)

4 主要设置
root@ubuntu:~# nano /etc/dhcp3/dhcpd.conf
# Sample configuration file for ISC dhcpd for Debian
#
# $Id: dhcpd.conf,v 1.1.1.1 2002/05/21 00:07:44 peloy Exp $ 

# The ddns-updates-style parameter controls whether or not the server will
# attempt to do a DNS update when a lease is confirmed. We default to the
# behavior of the version 2 packages ('none', since DHCP v2 didn't
# have support for DDNS.)
ddns-update-style none;

#下面是全局设置,这里定义的信息全dhcp服务器生效
#我一般注释掉了,下面可以分不同的子网进行设置
# option definitions common to all supported networks...
#option domain-name "apt-get.cn";
#option domain-name-servers 202.103.0.117, 202.103.24.68;
#default-lease-time 600;
#max-lease-time 7200;

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#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;

# No service will be given on this subnet, but declaring it helps the
# DHCP server to understand the network topology.

#subnet 10.152.187.0 netmask 255.255.255.0 {
#}

# This is a very basic subnet declaration.

#subnet 10.254.239.0 netmask 255.255.255.224 {
# range 10.254.239.10 10.254.239.20;
# option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org;
#}

# This declaration allows BOOTP clients to get dynamic addresses,
# which we don't really recommend.

#subnet 10.254.239.32 netmask 255.255.255.224 {
# range dynamic-bootp 10.254.239.40 10.254.239.60;
# option broadcast-address 10.254.239.31;
# option routers rtr-239-32-1.example.org;
#}

# A slightly different configuration for an internal subnet.
#subnet设置一个子网192.168.1.0/24
#range定义可以分配出去的地址为1.50到1.70
#option domain-name-servers定义dns为202.103.0.117等三个,这里注意每个之间要有个逗号
#option domain-name定义域名称
#option routers定义网关地址
#broadcast-address定义广播地址
#default-lease-time默认租约时间
#max-lease-time 最大租约时间
注*下面这一段是生效部分,请按照实际情况修改)
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.50 192.168.1.70;
注*上行的动态IP范围请不要与系统中已有的dhcp服务器冲突,比如无线路由器上自带的dhcp,但是也不需要把原有的关掉,只要范围不冲突就可以了,因为客户端在启动时会自动使用服务器端的dhcp所分配的地址、而不使用无线路由器上分配的)
option domain-name-servers 202.103.0.117,202.103.24.68,202.103.150.44;
option domain-name "apt-get.cn";
注*上行的domain-name在联网系统里会起作用,所以请选择一个你肯定不会去访问的名字、即使你并不知道它是否被注册成为域名)
option routers 192.168.1.1;
option broadcast-address 192.168.1.255;
default-lease-time 864000;
max-lease-time 86400000;
filename "pxelinux.0";
注*上面这一行是要手工加的很关键的信息,实际就是启动无盘工作站网卡的方式,而其中的pxelinux.0其实是一个文件名,下文将谈到这个文件如何生成)
}

# Hosts which require special configuration options can be listed in
# host statements. If no address is specified, the address will be
# allocated dynamically (if possible), but the host-specific information
# will still come from the host declaration.

#host passacaglia {
# hardware ethernet 0:0:c0:5d:bd:95;
# filename "vmunix.passacaglia";
# server-name "toccata.fugue.com";
#}

# Fixed IP addresses can also be specified for hosts. These addresses
# should not also be listed as being available for dynamic assignment.
# Hosts for which fixed IP addresses have been specified can boot using
# BOOTP or DHCP. Hosts for which no fixed address is specified can only
# be booted with DHCP, unless there is an address range on the subnet
# to which a BOOTP client is connected which has the dynamic-bootp flag
# set.
#host fantasia {
# hardware ethernet 08:00:07:26:c0:a5;
# fixed-address fantasia.fugue.com;
#}

# You can declare a class of clients and then do address allocation
# based on that. The example below shows a case where all clients
# in a certain class get addresses on the 10.17.224/24 subnet, and all
# other clients get addresses on the 10.0.29/24 subnet.

#class "foo" {
# match if substring (option vendor-class-identifier, 0, 4) = "SUNW";
#}

#shared-network 224-29 {
# subnet 10.17.224.0 netmask 255.255.255.0 {
# option routers rtr-224.example.org;
# }
# subnet 10.0.29.0 netmask 255.255.255.0 {
# option routers rtr-29.example.org;
# }
# pool {
# allow members of "foo";
# range 10.17.224.10 10.17.224.250;
# }
# pool {
# deny members of "foo";
# range 10.0.29.10 10.0.29.230;
# }
#}

5 启动服务器
root@ubuntu:/# /etc/init.d/dhcp3-server start
* Starting DHCP server dhcpd3 [ OK ]
root@ubuntu:/#

6 查看服务是否已经正常监听
root@ubuntu:/# netstat -aunp|grep dhcp
udp 0 0 0.0.0.0:67 0.0.0.0:* 23011/dhcpd3
已经在67号udp口上开始监听了


相关内容