linux下DHCP配置

DHCP服务器软件,
http://www.isc.org       开发机构
ftp://ftp.isc.org/isc/dhcp 中可以下载到最新版本 目前为dhcp-4.0.0a3.tar.gz 2007.9.19发布

安装
[root@happyboy soft]# tar xvzf dhcp-4.0.0a3.tar.gz
[root@happyboy soft]# cd dhcp-4.0.0a3
[root@happyboy dhcp-4.0.0a3]# ./configure
[root@happyboy dhcp-4.0.0a3]# make
[root@happyboy dhcp-4.0.0a3]# make install
[root@happyboy dhcp-4.0.0a3]# vi /etc/dhcpd.conf                   //手动创建配置文件,很关键,具体参考# man dhcpd.conf
ddns-update-style none;                                //动态DNS的更新方式,必须添加,否则服务器无法启动
subnet 192.168.0.0 netmask 255.255.255.0 {        //定义网段的服务范围,与服务器所在IP段在同一范围
        option routers  192.168.0.1;            //默认网关
        option subnet-mask      255.255.255.0;        //子网掩码
        option domain-name      "happyboy.net.cn";    //域名
        option domain-name-servers 192.168.0.100;    //DNS服务器
        range 192.168.0.2 192.168.0.99;               //地址池范围,注意已经使用的固定地址要排除在外
        default-lease-time 21600;            //默认释放时间 1/4天
        max-lease-time 43200;                //最长释放时间
        host mail {
                hardware ethernet 00:03:FF:B6:9E:AB;    //这部分定义了静态地址,mac与IP绑定,该IP地址不要放在地址池中,每个静态地址要建一个host
                fixed-address 192.168.0.200;
                }
}
启动服务器时报
WARNING: Host declarations are global.  They are not limited to the scope you declared them in.
Can't open lease database /usr/local/var/db/dhcpd.leases: No such file or directory --
  check for failed database rewrite attempt!
[root@happyboy dhcp-4.0.0a3]# mkdir /usr/local/var
[root@happyboy dhcp-4.0.0a3]# mkdir /usr/local/var/db
[root@happyboy dhcp-4.0.0a3]# touch /usr/local/var/db/dhcpd.leases //建立记录地址分配信息的文件,记录了IP地址是否已经分配等信息,没有该文件,服务器无法启动
[root@happyboy dhcp-4.0.0a3]# dhcpd
dhcpd: Error opening '/proc/net/if_inet6' to list IPv6 interfaces; No such file or directory
[root@happyboy dhcp-4.0.0a3]# make uninstall     //猜测最新版本的bug,安装7月份发布的dhcp-4.0.0a2.tar.gz 步骤同上,直接成功启动

[root@happyboy dhcp-4.0.0a2]# dhcpd
Internet Systems Consortium DHCP Server 4.0.0a2
Copyright 2004-2007 Internet Systems Consortium.
All rights reserved.
For info, please visit  http://www.isc.org/sw/dhcp/
WARNING: Host declarations are global.  They are not limited to the scope you declared them in.
Wrote 0 deleted host decls to leases file.
Wrote 0 new dynamic host decls to leases file.
Wrote 0 leases to leases file.
Listening on LPF/eth0/00:03:ff:b6:9e:ab/192.168.0.0/24
Sending on   LPF/eth0/00:03:ff:b6:9e:ab/192.168.0.0/24
Sending on   Socket/fallback/fallback-net

[root@happyboy db]# pwd
/usr/local/var/db
[root@happyboy db]# ll                              //而且该库文件也是自动生存的,并且都有内容
总用量 8
-rw-r--r--    1 root     root          127 10月  1 18:15 dhcpd.leases
-rw-r--r--    1 root     root          127 10月  1 17:23 dhcpd.leases~
[root@happyboy db]# more dhcpd.leases
# The format of this file is documented in the dhcpd.leases(5) manual page.
# This lease file was written by isc-dhcp-4.0.0a2
[root@happyboy dhcp-4.0.0a2]# ps -aux |grep dhcpd
root      7969  0.0  0.8  4648 2400 ?        S    18:15   0:00 dhcpd
root      7973  0.0  0.2  4928  668 pts/2    S    18:18   0:00 grep dhcpd

windows客户端测试
C:/Documents and Settings/liuzhangcai>ipconfig /renew

Windows IP Configuration


Ethernet adapter 本地连接:

   Connection-specific DNS Suffix  . : happyboy.net.cn
   IP Address. . . . . . . . . . . . : 192.168.0.2
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.0.1

C:/Documents and Settings/liuzhangcai>ipconfig/all

Windows IP Configuration

   Host Name . . . . . . . . . . . . : MyServer
   Primary Dns Suffix  . . . . . . . :
   Node Type . . . . . . . . . . . . : Unknown
   IP Routing Enabled. . . . . . . . : Yes
   WINS Proxy Enabled. . . . . . . . : No
   DNS Suffix Search List. . . . . . : happyboy.net.cn

Ethernet adapter 本地连接:

   Connection-specific DNS Suffix  . : happyboy.net.cn
   Description . . . . . . . . . . . : Intel(R) PRO/1000 PL Network Connection
   Physical Address. . . . . . . . . : 00-15-F2-BD-9E-AB
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
   IP Address. . . . . . . . . . . . : 192.168.0.2
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.0.1
   DHCP Server . . . . . . . . . . . : 192.168.0.200
   DNS Servers . . . . . . . . . . . : 192.168.0.200
   Lease Obtained. . . . . . . . . . : 2007年10月1日星期一 努力18:32:37
   Lease Expires . . . . . . . . . . : 2007年10月2日星期二 努力0:32:37

[root@happyboy root]# more /usr/local/var/db/dhcpd.leases           //这里已经记录相关信息了
# The format of this file is documented in the dhcpd.leases(5) manual page.
# This lease file was written by isc-dhcp-4.0.0a2

lease 192.168.0.2 {
  starts 1 2007/10/01 10:22:19;
  ends 1 2007/10/01 16:22:19;
  cltt 1 2007/10/01 10:22:19;
  binding state active;
  next binding state free;
  hardware ethernet 00:15:f2:bd:9e:ab;
  uid "/001/000/025/362/275/236/253";
  client-hostname "MyServer";
}

也可以通过其他方式确认DHCP服务启动
[root@happyboy root]# grep bootp /etc/services 
bootps          67/tcp                          # BOOTP server
bootps          67/udp
bootpc          68/tcp                          # BOOTP client
bootpc          68/udp
[root@happyboy root]# ps -aux |grep dhcpd
root      7969  0.0  0.8  4656 2228 ?        S    18:15   0:00 dhcpd
root      8132  0.0  0.2  4916  672 pts/3    S    18:33   0:00 grep dhcpd
[root@happyboy root]# netstat -unl |grep 67
udp        0      0 0.0.0.0:67              0.0.0.0:* 
linux客户机配置
[root@happyboy root]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=dhcp         //设置为dhcp状态即可
或者使用
[root@happyboy root]# netconfig           //设置为dhcp 自动获取,然后重新启动network服务
[root@happyboy root]# service network restart
服务器端调试:
[root@happyboy root]# tail -f /var/log/messages   //实时查看客户端请求分配信息
[root@happyboy root]# more /usr/local/var/db/dhcpd.leases    //查看库文件
客户端:
linxu/unix:dhclient eth0    //刷新客户端的dhcp信息,同windows的ipconfig/renew
windows: ipconifg /renew
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值