1.測(cè)試環(huán)境:Centos 6.9
虛擬主機(jī)中安裝
軟件版本:dhcp-4.1.1-53.P1.el6.centos.x86_64
工作原理:
2.安裝軟件:
yum list installed|grep dhcp
查看是否安裝
yum install -y dhcp
安裝dhcp(自動(dòng)安裝版本為4.1.1)
也可以使用rpm -qa|grep dhcp
查看安裝的情況
Whereis dhcp
查看安裝的文件在哪里 /etc/dhcp里面有我們需要的配置文件渤昌。
在/etc/rc.d/init.d/下面的dhcp的腳本 dhcp6 是針對(duì)于IPv6
3.配置文件
查看配置文件如下圖,發(fā)現(xiàn)默認(rèn)里面什么都沒有走搁,可以參考dhcpd.conf.sample
dhcpd.conf
# Sample configuration file for ISC dhcpd
# option definitions common to all supported networks...
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;
default-lease-time 600; #默認(rèn)租約時(shí)間
max-lease-time 7200;#最大租約時(shí)間
# Use this to enble / disable dynamic dns updates globally.
#ddns-update-style none; # 動(dòng)態(tài)DNS
# 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 {
}#subnet定義子網(wǎng)
# 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; # 提供動(dòng)態(tài)IP地址范圍
option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org; #默認(rèn)網(wǎng)關(guān)
}
# 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 10.5.5.0 netmask 255.255.255.224 {
range 10.5.5.26 10.5.5.30;
option domain-name-servers ns1.internal.example.org; #域名服務(wù)器
option domain-name "internal.example.org";#域名選項(xiàng)
option routers 10.5.5.1;#默認(rèn)網(wǎng)關(guān)
option broadcast-address 10.5.5.31;#廣播地址選項(xiàng)
default-lease-time 600;
max-lease-time 7200;
}
# 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 { #為客戶端指定主機(jī)名稱
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 {#把多個(gè)子網(wǎng)定義在一個(gè)超級(jí)作用域內(nèi)
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 {#已知的客戶端從下面的地址池選擇IP
deny members of "foo";
range 10.0.29.10 10.0.29.230;
}#
}
特別說明
參考的配置文件是不能直接使用的独柑,需要根據(jù)需要修改里面的IP地址,否則直接運(yùn)行文件私植,dhcp服務(wù)是會(huì)報(bào)錯(cuò)的忌栅。具體配置文件的使用,需要根據(jù)手冊(cè)曲稼,幫助文件來進(jìn)行設(shè)置索绪。
4.DDNS功能
動(dòng)態(tài)域名服務(wù):將用戶的動(dòng)態(tài)的IP地址映射到一個(gè)固定IP地址的域名解析服務(wù)上。現(xiàn)在有些路由器支持DDNS功能可以用來在自己家庭網(wǎng)絡(luò)構(gòu)建網(wǎng)站躯肌,而不用租用專用的網(wǎng)絡(luò)空間商和IP地址
5.客戶端租約數(shù)據(jù)庫(kù)文件
dhcpd.lease里面存儲(chǔ)是已經(jīng)分發(fā)的IP地址
可以使用配置文件中的lease-file-name語(yǔ)句改變dhcpd.leases文件的位置和名稱
格式:lease IP地址{statements......}
6.DHCP中繼代理
使用命令dhcrelay 實(shí)現(xiàn)中繼代理的功能者春,具體命令格式
Server0 設(shè)置的是代理要訪問到的DHCP服務(wù)器破衔。
配置DHCP中繼代理
vi /etc/sysconfig/dhcrealy
在里面輸入:
INTERFACES="eth1" DHCPSERVERS="192.168.1.251"
(IP地址根據(jù)自己的配置填寫)
開啟DHCP中繼代理服務(wù)器的IPV4轉(zhuǎn)發(fā):
可以在兩個(gè)地方開啟:
① vi /etc/sysctl.conf
將“net.ipv4.ip_forward = 0”改成“net.ipv4.ip_forward = 1”
執(zhí)行sysctl –p命令使剛開啟的IPV4轉(zhuǎn)發(fā)功能生效清女。
② echo 1 > /proc/sys/net/ipv4/ip_forward
啟動(dòng)DHCP中繼代理服務(wù)
dhcrelay 192.168.1.251
service dhcrelay start chkconfig --level 35 dhcrelay on
說明:dhcp的配置文件如果沒有配置好是無法啟動(dòng)服務(wù)的,因此應(yīng)該首先寫配置文件晰筛,然后在啟動(dòng)服務(wù)