dhcp

DHCP:

先有client端發出discovery message

D:255.255.255.255

S:0.0.0.0  代表未知IP或默認路由


SERVER發送OFFER message 廣播報文


client發送request message 該報文應用於有多個sever的情況下

該報文有兩個作用:

1、當做ack

2、讓另一個server回收地址


acknowledgment message是server端的確認報文

l2+ip+udp+bootstrap+dhcp+fcs  dhcp只用在以太網環境


wKiom1L0mMbDEGLPAABPjwPyL1M627.jpg

按上圖做一個DHCP實驗:

R1:

interface f0/0

ip address 192.168.1.1 255.255.255.0

no shut

!

service dhcp

ip dhcp pool ip_pool

network 192.168.1.0 /24

default-router 192.168.1.1

dns-server 61.147.37.1 61.177.7.1

lease 1

!

ip dhcp excluded-address 192.168.1.1

ip dhcp excluded-address 192.168.1.254


R2:

interface f0/1

no shut

no ip address

ip address dhcp


R2獲取地址是地址池裏最小的開始分配


如果你想查看R1的dhcp池的分配情況,可以用這個命令:show ip dhcp binding

R1#show ip dhcp binding

Bindings from all pools not associated with VRF:

IP address          Client-ID/              Lease expiration        Type

                   Hardware address/

                   User name

192.168.1.2         0063.6973.636f.2d63.    Mar 02 2002 12:10 AM    Automatic

                   3030.312e.3133.6663.

                   2e30.3030.312d.4661.

                   302f.31

我們查看下抓包結果吧

1、就是discovery message

wKiom1L0nNrju5QSAAQcxqzUs-M423.jpg

2、offer message

wKioL1L0nSyxWW0VAAQ8esHckKo516.jpg

3、request message

wKiom1L0nh-yFJ9LAAMK4bT2idk349.jpg

4、ack message

wKioL1L0nl7B68zuAARmHK2lsUc626.jpg

ip dhcp excluded-address low_ip  hight_ip 定義一個例外地址範圍

R2上可以獲取默認路由的show ip route

R2#show ip route

Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP

      D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area

      N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2

      E1 - OSPF external type 1, E2 - OSPF external type 2

      i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2

      ia - IS-IS inter area, * - candidate default, U - per-user static route

      o - ODR, P - periodic downloaded static route


Gateway of last resort is 192.168.1.1 to network 0.0.0.0


C    192.168.1.0/24 is directly connected, FastEthernet0/1

S*   0.0.0.0/0 [254/0] via 192.168.1.1


helper-address client和server不在同一個子網的情況下,需要help address

過程如下:

當設備接收到一個廣播報文,如果配置了help address 就把該報文的目的地址改爲help address

變成單播報文,發送到指定IP地址


DHCP擴展應用helper-address

wKioL1L0prHD2Be8AACcBe867_g850.jpg

R1和R2之間鏈路的配置不變

R2:

interface f0/0

ip address 192.168.2.2 255.255.255.0

ip helper-address 192.168.1.1

no shut

R3:

interface f0/1

no shutdown

ip address dhcp

R1:

ip dhcp excluded-address 192.168.2.1 192.168.2.2

ip dhcp excluded-address 192.168.2.254

ip dhcp pool wolf

network 192.168.2.0 /24

default-router 192.168.2.1

dns-server 8.8.8.8

lease 1


在R3上show ip interface brief,我們發現沒有IP地址被獲取哦!

爲什麼呢?可能是路由問題嗎?

在R1上show ip route 只有直連路由

手動寫一條靜態路由ip route 192.168.2.0 255.255.255.0 f0/0

過一會兒,我們發現R3獲取IP地址了

我們抓包看看問題出在哪裏

wKiom1L0qUKCysjgAAETTzcxjYw333.jpg

知道問題了吧,discovery offer request ack 報文都變成了單播報文了

而R1沒有到192.168.2.0 的路由條目,所以報文送不到R3



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章