代碼示例:IP dhcp snooping配置
前面的文章中我們也講解過dhcp snooping的有關知識,對于它的理解,配置以及相關的調制,應用我們都介紹過了。這里我們再來對IP dhcp snooping的具體配置以及案例分析進行一下介紹,希望對大家能夠有所幫助。
1、3750配置DHCP服務,配置DHCP snooping
- 如下:(無用的部分已經刪除了)
- 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 (啟動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防護的vlan)
- ip dhcp snooping information option allow-untrusted
- ip dhcp snooping database flash:snooping (指定數據庫路徑)
- ip dhcp snooping (啟動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地址效驗,此端口用戶不能自己設置地址,只能通過DHCP獲得,但沒有mac層安全控制。
測試發現,假如g1/0/43口的用戶分得地址=192.168.1.2,g1/0/42用戶故意修改IP為192.168.1.2,也會影響 g1/0/43的用戶,雖然g1/0/42修改IP不能訪問網絡,但g1/0/43會提示IP沖突,所以必須結合DAI才能保護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注冊地址,分析原因由于port-security的安全限制無法注冊MAC)
- (ip verify source port-security是配合啟動IP soure binding使用
- ip source binding 001b.a111.5e11 vlan 1 192.168.1.200 interface Gi1/0/45,注意ip source binding和動態DHCP不能同時用)
- !
- interface GigabitEthernet1/0/46
- !
#p#2、靜態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防護的vlan)
- ip dhcp snooping information option allow-untrusted
- ip dhcp snooping database flash:snooping (指定數據庫路徑)
- ip dhcp snooping database write-delay 15
- ip dhcp snooping (啟動DHCP snooping)
- !
- !
- !
- interface GigabitEthernet1/0/45 (啟動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是配合啟動IP soure binding使用
- ip source binding 000A.E439.5F55 vlan 1 192.168.1.200 interface Gi1/0/45,說明ip source binding和動態DHCP不能同時用)
- !
- !
- 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
- !
- !
- 注意使用如下命令查看工作狀態:
- Switch#sh ip ver source
- Switch#sh ip dhcp binding
- Switch#sh ip dhcp snooping binding
#p#3、啟動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為基礎)
- ip dhcp snooping information option allow-untrusted
- ip dhcp snooping database flash:snooping(指定snooping 數據保存位置)
- ip dhcp snooping (啟動DHCP snooping)
- ip arp inspection vlan 1 (啟動DAI)
- ip arp inspection validate src-mac dst-mac ip (檢測項目)
- !
- !
- !
- interface GigabitEthernet1/0/31
- switchport mode access
- ip arp inspection trust (如果設置trust可以改IP,設置untrust不可以改IP,因為DAI檢測)
- 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設置,分配固定IP
有時我們需要控制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 (啟動網內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
時間倉促,沒能進行很好的測試,希望大家能夠討論,給與指正!