代碼示例:IP dhcp snooping配置
前面的文章中我們也講解過dhcp snooping的有關(guān)知識(shí),對(duì)于它的理解,配置以及相關(guān)的調(diào)制,應(yīng)用我們都介紹過了。這里我們?cè)賮韺?duì)IP dhcp snooping的具體配置以及案例分析進(jìn)行一下介紹,希望對(duì)大家能夠有所幫助。
1、3750配置DHCP服務(wù),配置DHCP snooping
- 如下:(無用的部分已經(jīng)刪除了)
- clock timezone WST 8
- switch 1 provision ws-c3750g-48ts
- system mtu routing 1500
- ip subnet-zero
- ip dhcp excluded-address 192.168.1.1 (保留地址)
- !
- ip dhcp pool test (啟動(dòng)DHCP)
- network 192.168.1.0 255.255.255.0
- default-router 192.168.1.1
- dns-server 192.168.1.1
- !
- ip dhcp snooping vlan 1 (指定DHCP snooping防護(hù)的vlan)
- ip dhcp snooping information option allow-untrusted
- ip dhcp snooping database flash:snooping (指定數(shù)據(jù)庫路徑)
- ip dhcp snooping (啟動(dòng)DHCP snooping)
- !
- !
- interface GigabitEthernet1/0/1
- !
- interface GigabitEthernet1/0/31 (正常的端口)
- switchport mode access
- spanning-tree portfast
- !
- interface GigabitEthernet1/0/32
- !
- interface GigabitEthernet1/0/42
- !
- interface GigabitEthernet1/0/43 (啟用IP DHCP snooping端口)
- switchport mode access
- switchport port-security
- spanning-tree portfast
- ip verify source
(啟用IP地址效驗(yàn),此端口用戶不能自己設(shè)置地址,只能通過DHCP獲得,但沒有mac層安全控制。
測(cè)試發(fā)現(xiàn),假如g1/0/43口的用戶分得地址=192.168.1.2,g1/0/42用戶故意修改IP為192.168.1.2,也會(huì)影響 g1/0/43的用戶,雖然g1/0/42修改IP不能訪問網(wǎng)絡(luò),但g1/0/43會(huì)提示IP沖突,所以必須結(jié)合DAI才能保護(hù)mac層)
- !
- interface GigabitEthernet1/0/44
- !
- interface GigabitEthernet1/0/45
- switchport mode access
- switchport port-security
- switchport port-security violation restrict
- spanning-tree portfast
- ip verify source port-security
- (啟用后此端口無法DHCP注冊(cè)地址,分析原因由于port-security的安全限制無法注冊(cè)MAC)
- (ip verify source port-security是配合啟動(dòng)IP soure binding使用
- ip source binding 001b.a111.5e11 vlan 1 192.168.1.200 interface Gi1/0/45,注意ip source binding和動(dòng)態(tài)DHCP不能同時(shí)用)
- !
- interface GigabitEthernet1/0/46
- !
#p#2、靜態(tài)IP dhcp snooping和IP Source Guard
- clock timezone WST 8
- switch 1 provision ws-c3750g-48ts
- system mtu routing 1500
- ip subnet-zero
- !
- ip dhcp snooping vlan 1 (指定DHCP snooping防護(hù)的vlan)
- ip dhcp snooping information option allow-untrusted
- ip dhcp snooping database flash:snooping (指定數(shù)據(jù)庫路徑)
- ip dhcp snooping database write-delay 15
- ip dhcp snooping (啟動(dòng)DHCP snooping)
- !
- !
- !
- interface GigabitEthernet1/0/45 (啟動(dòng)IP Source Guard的端口)
- switchport mode access
- switchport port-security
- switchport port-security violation restrict
- spanning-tree portfast
- ip verify source port-security
- (ip verify source port-security是配合啟動(dòng)IP soure binding使用
- ip source binding 000A.E439.5F55 vlan 1 192.168.1.200 interface Gi1/0/45,說明ip source binding和動(dòng)態(tài)DHCP不能同時(shí)用)
- !
- !
- interface Vlan1
- ip address 192.168.1.1 255.255.255.0
- !
- ip classless
- ip http server
- ip http secure-server
- !
- !
- ip source binding 000A.E439.5F55 vlan 1 192.168.1.200 interface Gi1/0/45
- !
- control-plane
- !
- !
- 注意使用如下命令查看工作狀態(tài):
- Switch#sh ip ver source
- Switch#sh ip dhcp binding
- Switch#sh ip dhcp snooping binding
#p#3、啟動(dòng)dai
- ip subnet-zero
- ip dhcp excluded-address 192.168.1.1
- !
- ip dhcp pool test
- network 192.168.1.0 255.255.255.0
- default-router 192.168.1.1
- dns-server 192.168.1.1
- lease infinite
- !
- ip dhcp snooping vlan 1 (需要DHCP為基礎(chǔ))
- ip dhcp snooping information option allow-untrusted
- ip dhcp snooping database flash:snooping(指定snooping 數(shù)據(jù)保存位置)
- ip dhcp snooping (啟動(dòng)DHCP snooping)
- ip arp inspection vlan 1 (啟動(dòng)DAI)
- ip arp inspection validate src-mac dst-mac ip (檢測(cè)項(xiàng)目)
- !
- !
- !
- interface GigabitEthernet1/0/31
- switchport mode access
- ip arp inspection trust (如果設(shè)置trust可以改IP,設(shè)置untrust不可以改IP,因?yàn)镈AI檢測(cè))
- spanning-tree portfast
- !
- interface GigabitEthernet1/0/32
- !
- nterface GigabitEthernet1/0/44
- !
- interface GigabitEthernet1/0/45
- switchport mode access
- switchport port-security
- switchport port-security violation restrict
- spanning-tree portfast
- ip verify source port-security
- !
- !
- Switch#sh ip arp inspection
#p#4、DHCP設(shè)置,分配固定IP
有時(shí)我們需要控制IP分配,可以使用下面方法!
- system mtu routing 1500
- ip subnet-zero
- ip dhcp excluded-address 192.168.1.1
- !
- ip dhcp pool test
- host 192.168.1.18 255.255.255.0 (分給用戶的IP)
- client-identifier 0101.0bf5.395e.55(用戶端mac)
- client-name test
- !
- ip dhcp pool go
- network 192.168.1.0 255.255.255.0 (啟動(dòng)網(wǎng)內(nèi)DHCP)
- !
- Switch#sh ip dhcp binding
- IP address Client-ID/ Lease expiration Type
- Hardware address
- 192.168.1.18 0101.0bf5.395e.55 Infinite Manual
時(shí)間倉促,沒能進(jìn)行很好的測(cè)試,希望大家能夠討論,給與指正!