
在DHCPsnooping環(huán)境中(部署在交換機上),我們將端口視為trust或untrust兩種安全級別,也就是信任或非信任接口。在交換機上,將連接合法DHCP服務器的接口配置為trust。只有trust接口上收到的來自DHCPserver的報文(如DHCPOFFER,DHCPACK, DHCPNAK,或者DHCPLEASEQUERY)才會被放行,相反,在untrust接口上收到的來自DHCPserver的報文將被過濾掉,這樣一來就可以防止非法的DHCPserver接入。同時在部署了DHCPSnooping了交換機本地,還能維護一張DHCPsnooping的綁定數(shù)據(jù)庫(bindingdatabase),用于保存?zhèn)陕牭降腄HCP交互的表項,信息包括(針對untrust接口的):MAC地址、IP地址(DHCP分配的)、租期、綁定類型、VLAN號、接口編號(DHCP客戶端也就是連接客戶端PC的untrust接口)。這個DHCPsnooping bandingdatabse除了可以做一些基本的安全接入控制,還能夠用于DAI等防ARP欺騙的解決方案。 一臺支持DHCPsnooping的交換機,如果在其untrust接口上,收到來自下游交換機發(fā)送的、且?guī)в衞ption82的DHCP報文,則默認的動作是丟棄這些報文。如果該交換機開啟了DHCPsnooping并且?guī)в衞ption82的DHCP報文是在trusted接口上收到的,則交換機接收這些報文,但是不會根據(jù)報文中包含的相關信息建立DHCPbingding databse表項。
如果交換機確實通過一個untrust接口連接了下游交換機,并且希望放行該接口收到的、下游交換機發(fā)送出來的帶有option82的DHCP報文,則可使用全局命令:ipdhcp snooping information optionallow-untrusted,同時由于是通過untust接口收到的DHCP報文,因此會根據(jù)偵聽的結果創(chuàng)建DHCP snoopingbinding database表項。
二、Option82 DHCP option82又稱為DHCP中繼代理信息選項(Relay Agent InformationOption),是DHCP報文中的一個選項,其編號為82 CISCO注釋:The DHCPoption-82 feature is supported only when DHCP snooping is globallyenabled and on the VLANs to which subscriber devices using thisfeature are assigned.
基本的交互過程如下(下面描述的過程與上面的配圖無關):
- DHCP client廣播DHCP request
- 交換機收到DHCPrequest,它在報文中插入option82信息(當然,要你先做了相應的配置后),在插入的信息中,remote-IDsuboption是該交換機的MAC;circuit-ID suboption是收到DHCP request報文的接口ID。
- 如果交換機上還部署了DHCP relay,那么交換機將中繼地址也添加進DHCP報文中
- 交換機將攜帶了option82信息的DHCP報文轉發(fā)給DHCP服務器
- DHCP服務器接收到了DHCP報文,如果這臺服務器是能夠識別option82的,那么它將根據(jù)option82中攜帶的信息,來為客戶端分配IP地址,以及選擇相應的策略。然后服務器回應一個DHCP包,其中也包含option82信息。
- 交換機收到該DHCP報文后,發(fā)現(xiàn)報文的option82信息正是從本地始發(fā),交換機將option82信息移除后,將DHCP報文轉發(fā)給DHCPclient。
在上述事件的發(fā)生過程中,下面字段的內容不會發(fā)生改變: –Suboption type –Length of the suboption type –Circuit-ID type –Length of the circuit-ID type –Suboption type –Length of the suboption type –Remote-ID type –Length of the remote-ID type
In the port field of thecircuit-ID suboption, the port numbers start at3.也就是說這個字段中,端口號是從3開似乎的,第一個端口號就是3,依次類推。例如,一個帶了SFP插槽的24口交換機,port3是fastx/0/1,port4是fast x/0/2,以此類推,port 27就是sfq模塊的x/0/1口。其中x為堆疊成員編號。
Option報文結構:DHCP option 82又稱為DHCP中繼代理信息選項(Relay Agent InformationOption),是DHCP報文中的一個選項,其編號為82。rfc3046定義了option 82,選項位置在option255之前而在其它option之后。
CODE:82LEN:Agent Information field的字節(jié)數(shù),不包含code及l(fā)en字段的長度Option82可包含多個suboption,rfc3046定義了如下兩個:
Subopt:子選項編號,如果是circuit ID則值為1,remote ID則值為2Len:Sub-option Value的字節(jié)個數(shù),不包括SubOpt和Len字段的兩個字節(jié)
option82子選項1:即CircuitID,它表示接收到的DHCP請求報文來自的電路標識,這個標識只在中繼代理節(jié)點內部有意義,在服務器端不可以解析其含義,只作為一個不具含義的標識使用。一般情況下,默認是接收到DHCP請求報文的接入交換機VlanID加接入二層端口名稱,如Vlan2+Ethernet0/0/10,也可以由用戶指定自己的代理電路ID。通常子選項1與子選項2要共同使用來標識DHCP客戶端的信息。
option82子選項2:即 RemoteID,一般情況下為插入該option82信息的接入層交換機的MAC。
CISCO注釋:If the DHCP relay agent is enabled but DHCP snoopingis disabled, the DHCP option-82 data insertion feature is notsupported.
三、DHCP Snooping BindingDatabase
在交換機上激活DHCPsnooping后,交換機會使用在untrust接口上“偵聽到的“DHCP交互內容形成一個表:dhcp snoopingbinding database。如下:SW1#show ip dhcp snoopingbindingMacAddress ipAddress Lease(sec)Type VLAN Interface------- ----------- ---------- ------------- ------------------------00:B0:64:04:09:99 192.168.10.1 86025 dhcp-snooping 10 FastEthernet0/1Total number of bindings: 1
默認情況下,這個數(shù)據(jù)庫是動態(tài)的,也就是說當交換機重啟,數(shù)據(jù)庫內的表項全部丟失。這個事情的結果可能會造成網絡的中斷。因此我們可以將這個數(shù)據(jù)庫以文件的形式存儲起來,這個就是DHCPsnooping database agent。
配置命令非常簡單,全局命令:SW2(config)#ip dhcp snooping database ? flash: Database agent URL ftp: Database agent URL http: Database agent URL https: Database agent URL rcp: Database agent URL scp: Database agent URL tftp: Database agent URL timeout Configure abort timeoutinterval write-delay Configuredelay timer for writes to URL由于flash空間非常有限,因此建議將文件存儲在TFTP服務器上。當部署在TFTP服務器上時,注意先創(chuàng)建一個空的文件以對應配置命令中的URL,這個文件用于dhcpsnooping bingding database的寫入(視具體設備而定)。
形成的文件的格式如下:TYPE DHCP-SNOOPINGVERSION 1BEGIN......END
下面是一個例子:2bb4c2a1TYPE DHCP-SNOOPINGVERSION 1BEGIN192.1.168.1 3 0003.47d8.c91f 2BB6488E interface-id21ae5fbb192.1.168.3 3 0003.44d6.c52f 2BB648EB interface-id1bdb223f192.1.168.2 3 0003.47d9.c8f1 2BB648AB interface-id584a38f0END
四、配置示例1.實驗1:基礎實驗PC屬于VLAN10,網關在SW2上。DHCPserver屬于VLAN100,網關在SW2上。SW1為接入層交換機,部署DHCP snooping,將Fa0/24定義為trust接口。SW2為核心層交換機,部署DHCP relay
DHCPserver的配置如下:no ip routingip default-gateway 192.168.100.254Interface fast0/0 ip address 192.168.100.1255.255.255.0 no shutdown exitService dhcpIp dhcp pool vlan10 network 192.168.10.0 /24 default-router 192.168.10.254
SW1的配置如下:vlan 10!ip dhcp snooping !! 全局開啟DHCPsnoopingip dhcp snooping vlan 10 !!vlan10激活DHCP snoopingno ip dhcp snooping informationoption !!不寫入option82!Interface fast0/1 switchport access vlan 10interface fast0/24 switchport trunk encapsulation dot1q switchport mode trunk ip dhcp snoopingtrust
SW2的配置如下:vlan 10vlan 100 name Server!Interface fast0/1 switchport access vlan 100interface fast0/24 switchport trunk encapsulation dot1q switchport mode trunkInterface vlan 10 ip address 192.168.10.254255.255.255.0 ip helper-address 192.168.100.1Interface vlan 100 ip address 192.168.100.254255.255.255.0
實驗結果:PC獲取到了地址,在SW1上查看dhcp snooping bingding databsae:SW1#show ip dhcp snoopingbindingMacAddress ipAddress Lease(sec)Type VLAN Interface------ --------------- ---------- ---------- -----------------------00:B0:64:04:09:99 192.168.10.1 86025 dhcp-snooping 10 FastEthernet0/1Total number of bindings: 1
2.實驗2:接入交換機插入option82,核心交換機做中繼在SW1上開啟DHCP snooping,同時不去no ip dhcp snooping informationoption,也就是插入option82。其他設備配置與上一個實驗相同,發(fā)現(xiàn)PC機無法獲取地址,通過在網關設備上,也即是SW2上debug會發(fā)現(xiàn)報錯:relayinformation option exists, but giaddr iszero。giaddr字段意思為該報文做經過的第一個DHCP中繼代理的IP地址。在SW2上增加配置:(全局配置模式)ip dhcp relay information trust-all或:Interface vlan 10 ip dhcp relay information trusted上述命令,將使交換機接受攜帶option82信息,同時giaddr為0的dhcp報文,然后做中繼。如此一來即可成功獲取地址。
SW1的配置如下:vlan 10!ip dhcp snoopingip dhcp snooping vlan10Interface fast0/1 switchport access vlan 10interface fast0/24 switchport trunk encapsulation dot1q switchport mo————de trunk ip dhcp snoopingtrust
SW2的配置如下:vlan 10vlan 100 name Server!ip dhcp relay informationtrust-allInterface fast0/1 switchport access vlan 100interface fast0/24 switchport trunk encapsulation dot1q switchport mode trunkInterface vlan 10 ip address 192.168.10.254255.255.255.0 ip helper-address 192.168.100.1Interface vlan 100 ip address 192.168.100.254255.255.255.0
3.實驗3:接入層交換機插入option82,上游核心交換機也開啟dhcp snooping接入層交換機SW1開啟dhcp snooping,插入option82;核心層交換機SW2也開啟dhcpsnooping,默認所有端口都是untrust的,這時如果SW2的fast0/24口收到攜帶了option82的dhcp報文,則丟棄。解決辦法之一,是將SW2的fast0/24口配置為trust接口,但是這么一來通過該trust接口收到的dhcp報文,是不會創(chuàng)建dhcpsnooping binding表項的。另一個方法是,使用命令:ip dhcp snooping information optionallow-untrusted。這條命令放行攜帶了option82的DHCP報文,同時會在本地創(chuàng)建dhcp snoopingbinding表項。
SW1的配置如下:vlan 10!ip dhcp snoopingip dhcp snooping vlan 10Interface fast0/1 switchport access vlan 10interface fast0/24 switchport trunk encapsulation dot1q switchport mode trunk ip dhcp snooping trust
SW2的配置如下:vlan 10vlan 100 name Server!ip dhcp snooping information optionallow-untrustedip dhcp relay information trust-all !!注意區(qū)分上述兩條命令Interface fast0/1 switchport access vlan 100interface fast0/24 switchport trunk encapsulation dot1q switchport mode trunkInterface vlan 10 ip address 192.168.10.254255.255.255.0 ip helper-address 192.168.100.1Interface vlan 100 ip address 192.168.100.254255.255.255.0
4.無DHCP中繼環(huán)境中,option82及相關問題
這個環(huán)境比較簡單,PC與DHCP服務器同處一個VLAN,我主要想證實一下普通交換機對攜帶了option82的DHCP包的處理情況。SW1仍然開啟dhcp snooping,同時插入option82SW2將服務器劃入與PC相同的VLAN,相當于純做透傳。其中SW1的配置如下:vlan 10!ip dhcp snoopingip dhcp snooping vlan 10Interface fast0/1 switchport access vlan 10interface fast0/24 switchport trunk encapsulation dot1q switchport mode trunk ip dhcp snooping trust
SW2的配置如下:vlan 10!Interface fast0/1 switchport access vlan 10interface fast0/24 switchport trunk encapsulation dot1q switchport mode trunkInterface vlan 10 ip address 192.168.10.254255.255.255.0DHCP server的配置就是常規(guī)配置,這里不再贅述。
實驗的結果是,PC無法獲取地址。我們分析一下,SW1將PC發(fā)出來的DHCP請求消息插入option82,隨后發(fā)給SW2。通過SW2上的debug信息我們發(fā)現(xiàn):*Mar 16 17:09:21.858: DHCPD: inconsistent relayinformation.*Mar 16 17:09:21.858: DHCPD: relay information option exists,but giaddr is zero.SW2意識到,DHCP報文中有中繼信息選項,也就是option82,但是giaddr是全0。SW2雖然意識到了這個問題,但還是乖乖將這個數(shù)據(jù)交給了DHCPserver,通過在DHCPserver上的debug信息:*Mar 4 07:02:23.473: DHCPD: inconsistentrelay information.*Mar 4 07:02:23.473: DHCPD: relayinformation option exists, but giaddr is zero.顯然,DHCP服務器也意識到了上面的問題,它采取的動作是,忽略這個DHCP請求。因此PC無法獲取地址。
解決的辦法之一,是SW1不插入opiton82,另一個方法,是在DHCPserver上,使用配置:(全局配置模式)ip dhcp relay information trust-all或:Interface fast0/0 ip dhcp relay information trusted思路和實驗2一樣。這樣一來SW2會接受這些DHCP報文并進行處理,PC就能夠獲取到地址了。
5.其他配置ip dhcp snooping limit rate rate注意,在交換機開啟了DHCPsnooping后,由于對dhcp報文都要進行窺探,因此當網絡中存在DHCP攻擊行為,將會嚴重消耗交換機的性能,因此,可以通過該命令限制接口上允許收到的DHCP報文數(shù)量。Configurethe number of DHCP packets per second that an interface canreceive. The range is 1 to 2048. By default, no rate limit isconfigured.
ip dhcp snooping verify mac-addressConfigure the switch to verify that the source MAC address ina DHCP packet received on untrusted ports matches the clienthardware address in the packet. The default is to verify that thesource MAC address matches the client hardware address in thepacket.
ip dhcp snooping binding mac-address vlan vlan-idip-address interface interface-id expiry seconds靜態(tài)配置一條dhcp snooping bingding dabase表項,該命令是在特權模式下配置。
紅茶三杯網絡工程 | 項目管理 | IT服務管理 | CCIE培訓學習 沉淀 成長 分享微博:http://weibo.com/vinsoney博客:http://blog.sina.com.cn/vinsoney站點:http://ccietea.com
愛華網



