Linux 中搭建DHCP服务器实例

下面的Linux 中搭建DHCP服务器流程实例中,DHCP服务分配的IP地址段为192.168.1.128~192.168.1.133

㈠ 首先查看dhcp服务是否安装

[root@localhost ~]# rpm -qa | grep dhcp 
dhcp-3.0.5-31.el5 
dhcpv6-client-1.0.10-20.el5 
sblim-cmpi-dhcp-devel-1.0-49.el5 
sblim-cmpi-dhcp-1.0-49.el5 

㈡ 编辑/etc/dhcpd.conf

[root@localhost ~]# cat /etc/dhcpd.conf 

# DHCP Server Configuration file. 
#  see /usr/share/doc/dhcp*/dhcpd.conf.sample 
 
[root@localhost ~]# cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf 
cp:是否覆盖“/etc/dhcpd.conf”? yes 
 
[root@localhost ~]# cat /etc/dhcpd.conf 
 
ddns-update-style interim;  #DDNS更新方式,这里的设定值有3种:ad-hoc、interim和none 
ignore client-updates;  #忽略客户端更新 
 
subnet 192.168.1.0 netmask 255.255.255.0 { 
 
        option routers                  192.168.1.1;  #网关地址设定 
        option subnet-mask              255.255.255.0; #子网掩码设定 
        option domain-name              "localdomain"; #主机域名 
        option domain-name-servers      192.168.1.110; #设定DNS服务器地址 
        range dynamic-bootp 192.168.1.128 192.168.1.136; #动态分配的IP地址范围 

㈢ 对网卡绑定DHCP服务

[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 
# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE] 
DEVICE=eth0 
BOOTPROTO=dhcp 
ONBOOT=yes 

㈣ 重新启动DHCP服务

DHCP服务使用UDP的67端口,但Iptables不能过滤DHCP服务使用的原始套接字(Raw Socket)

所以在服务设定好之后,无须再设定Iptables

service dhcpd start

service network restart

如果在虚拟机内搭建,记得把网卡模式改成NAT

㈤ 验证

[root@localhost ~]# ifconfig eth0 
eth0      Link encap:Ethernet  HWaddr 00:0C:29:F9:B7:FA   
          inet addr:192.168.227.131  Bcast:192.168.227.255  Mask:255.255.255.0 
          inet6 addr: fe80::20c:29ff:fef9:b7fa/64 Scope:Link 

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/24066c88e16c2e2bda6d899254ccee42.html