1、 DHCP的概述
dynamic host configuration protocol 動態主機配置協議
1、DHCP服務的做用
減少管理員的工做量
減少輸入錯誤的可能
避免IP衝突
當網絡更改IP地址段時,不須要從新配置每臺計算機的IP
計算機移動沒必要從新配置IP
2、DHCP的原理
dhcp discover (客戶端請求ip地址)
dhcp offer (服務器響應請求)
dhcp request (客戶機選擇ip地址)
dhcp ack (服務器確認ip地址租約 客戶機得到ip地址)
3、租約
50% --- dhcp request
87.5% --- dhcp discover
4、端口
udp 67 server
udp 68 client
5、提供參數
Ip netmask gataway dns broadcast
配置DHCP中繼
實驗步驟:
1、 實驗需求 :經過DHCP中繼能夠爲不一樣網段分配ip
2、 實驗拓撲
3、實驗配置
DHCP服務器的配置
修改主配置文件 /etc/dhcpd.conf
[root@localhost ~]# vim /etc/dhcpd.conf
1 ddns-update-style none;
2 option subnet-mask 255.255.255.0;
3 option domain-name "domain.org";
4 option domain-name-servers 202.106.0.20;
5 option time-offset -18000; # Eastern Standard Time
6 default-lease-time 21600;
7 max-lease-time 43200;
8 subnet 192.168.1.0 netmask 255.255.255.0 {
9 option routers 192.168.1.1;
10 range 192.168.1.10 192.168.1.20;
11 }
12 subnet 192.168.2.0 netmask 255.255.255.0 {
13 option routers 192.168.2.1;
14 range 192.168.2.10 192.168.2.20;
15 }
16 subnet 192.168.3.0 netmask 255.255.255.0 {
17 option routers 192.168.3.1;
18 range 192.168.3.10 192.168.3.20;
19 }
|
#service dhcpd restart (重啓服務)
注意:DHCP服務器 網關需指向DHCP中繼服務器的IP
前面數字爲行號
DHCP中繼服務器的配置
①開啓路由轉發功能
[root@localhost ~]# vim /etc/sysctl.conf
[root@localhost ~]# sysctl -p
net.ipv4.ip_forward =1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 4294967295
kernel.shmall = 268435456
|
net.ipv4.ip_forward = 0改成1
sysctl -p (讓剛纔修改的內容當即生效)
②設置中繼接口及DHCP服務器的地址
[root@localhost ~]# vim /etc/sysconfig/dhcrelay
INTERFACES="eth0 eth1 eth2"
DHCPSERVERS="192.168.1.1"
[root@localhost ~]# service dhcrelay start
|
INTERFACES="eth0 eth1 eth2" (指定偵聽服務的網卡名稱)
DHCPSERVERS="192.168.1.2" (指定dhcp服務器的ip)
啓動dhcrelay中繼服務程序
#Server dhcrelay start
4、測試
用一個客戶端來作測試;用vmnet2,vmnet3,vmnet4來模擬不一樣的網段。
查看租約狀況
[root@localhost ~]# tail /var/lib/dhcpd/dhcpd.leases
lease 192.168.1.20 {
starts 5 2011/04/15 18:14:30;
ends 6 2011/04/16 00:14:30;
binding state active;
next binding state free;
hardware ethernet 00:0c:29:24:0a:c2;
uid "\001\000\014)$\012\302";
client-hostname "xp2";
} |