小岑博客

  • 首页
  • VMware
  • 实验室
  • 培训&认证
  • 关于我
  • 分类目录
    • Citrix
    • Linux
    • Windows
    • 互联网
    • 存储
    • 虚拟化
    • 超融合
  1. 首页
  2. Linux
  3. 正文

linux下的DHCP配置

2011年6月2日 2904点热度 0人点赞 2条评论

今天来学习配置Linux下的DHCP服务!

DHCP服务器软件,http://www.isc.org 开发机构
ftp://ftp.isc.org/isc/dhcp 中可以下载到最新版本 目前为 dhcp-4.2.1-P1.tar.gz 安装http://ftp.isc.org/isc/dhcp/dhcp-4.2.1-P1.tar.gz
下面进行安装
[root@tony soft]# tar xvzf dhcp-4.2.1-P1.tar.gz
[root@tony soft]# cd dhcp-4.2.1-P1.tar.gz
[root@tony dhcp-4.2.1]# ./configure
[root@tony dhcp-4.2.1]# make
[root@tony dhcp-4.2.1]# make install
[root@tony dhcp-4.2.1]# 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 "crazycen.com"; //域名
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@tony dhcp-4.2.1]# mkdir /usr/local/var
[root@tony dhcp-4.2.1]# mkdir /usr/local/var/db
[root@tony dhcp-4.2.1]# touch /usr/local/var/db/dhcpd.leases //建立记录地址分配信息的文件,记录了IP地址是否已经分配等信息,没有该文件,服务器无法启动
[root@tony dhcp-4.2.1]# dhcpd
dhcpd: Error opening '/proc/net/if_inet6' to list IPv6 interfaces; No such file or directory
[root@tony dhcp-4.2.1]# make uninstall //猜测最新版本的bug,安装5月份发布的dhcp-4.2.1-P1.tar.gz 步骤同上,直接成功启动

[root@tony dhcp-4.2.1]# dhcpd
Internet Systems Consortium DHCP Server 4.2.1
Copyright 2004-2011Internet 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 5月 25 8:15 dhcpd.leases
-rw-r--r-- 1 root root 127 5月 257:23 dhcpd.leases~
[root@tony 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@dhcp-4.2.1]# 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

[root@tony 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.2.1
lease 192.168.0.2 {
starts 1 2011/05/25 10:22:19;
ends 1 2011/05/25 16:22:19;
cltt 1 2011/05/25 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@tonyroot]# grep bootp /etc/services
bootps 67/tcp # BOOTP server
bootps 67/udp
bootpc 68/tcp # BOOTP client
bootpc 68/udp
[root@tony 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@tony root]# netstat -unl |grep 67
udp 0 0 0.0.0.0:67 0.0.0.0:*
linux客户机配置
[root@tony root]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=dhcp //设置为dhcp状态即可
或者使用
[root@tony root]# netconfig //设置为dhcp 自动获取,然后重新启动network服务
[root@tony root]# service network restart
服务器端调试:
[root@happyboy root]# tail -f /var/log/messages //实时查看客户端请求分配信息
[root@tony root]# more /usr/local/var/db/dhcpd.leases //查看库文件

客户端:
linxu/unix:dhclient eth0 //刷新客户端的dhcp信息,同windows的ipconfig/renew
windows: ipconifg /renew

本作品采用 知识共享署名-非商业性使用 4.0 国际许可协议 进行许可
标签: DHCP linux 配置
最后更新:2011年6月2日

小岑

我是小岑,欢迎来到我的博客,青年人,爱捣鼓些东西,对世界充满着好奇,热爱旅游。 这里随便写写,记录些文字,大抵和技术相关。 VMware vExpert | VCIX | VCAP | VCP

点赞
< 上一篇
下一篇 >

文章评论

  • 小说排行榜

    我是沙发么

    2011年6月3日
    回复
    • tony

      @小说排行榜 绝对的沙发,不过来看看,也是可以的!

      2011年6月3日
      回复
  • 取消回复

    小岑

    我是小岑,欢迎来到我的博客,青年人,爱捣鼓些东西,对世界充满着好奇,热爱旅游。 这里随便写写,记录些文字,大抵和技术相关。 VMware vExpert | VCIX | VCAP | VCP


    COPYRIGHT © 2022 crazycen.com. ALL RIGHTS RESERVED.

    Theme Kratos Made By Seaton Jiang

    鄂ICP备16016796号-1