1. DHCP技術部署
關於DHCP協議在《tcp/ip協議學習目錄》一欄中已經講過了,這裏就不再進行過多介紹了,現在開始學習DHCP的實戰部分——DHCP技術部署。
實驗環境要求:
- 還是基於三層交換技術的網絡拓撲和配置
- SW1交換機部署爲DHCP服務器,然後在PC主機上開啓DHCP協議,用於動態獲取ip地址
配置SW1交換機爲DHCP服務器,爲不同VLAN提供動態IP地址:
SW1#conf t
Enter configuration commands, one per line. End with CNTL/Z.
SW1(config)#ip dhcp pool VLAN10
SW1(dhcp-config)#network 192.168.10.0 255.255.255.0
SW1(dhcp-config)#default-router 192.168.10.254
SW1(dhcp-config)#dns-server 8.8.8.8 114.114.114.114
SW1(dhcp-config)#lease 7
SW1(dhcp-config)#
SW1(dhcp-config)#exit
SW1(config)#ip dhcp pool VLAN20
SW1(dhcp-config)#network 192.168.20.0 255.255.255.0
SW1(dhcp-config)#default-router 192.168.20.254
SW1(dhcp-config)#dns-server 8.8.8.8 114.114.114.114
SW1(dhcp-config)#lease 7
SW1(dhcp-config)#
部署DHCP技術命令說明:
ip dhcp pool VLAN10命令用於定義VLAN10的HDCP地址池,其實說白了就是定義VLAN10的網段
network 192.168.10.0 255.255.255.0命令用於定義VLAN10的網段爲192.168.10.0
default-router 192.168.10.254命令:定義VLAN10的默認網關地址
dns-server 8.8.8.8 114.114.114.114命令:指定dns服務器地址,可以指定多個,一般的話指定3個就可以了,其中第一個爲主dns地址
lease 7:代表ip地址的釋放時間,一般獲取ip地址都有一個租期時間,到期之後ip地址會自動歸還給DHCP服務器
在PC1上開啓DHCP協議以動態獲取ip地址,配置如下:
PC1(config)#int f0/0
PC1(config-if)#ip add
PC1(config-if)#ip address dh
PC1(config-if)#ip address dhcp
PC1(config-if)#exit
PC1#
//看到下面這條信息,就說明PC1動態獲取IP地址成功
*Mar 1 00:04:55.591: %DHCP-6-ADDRESS_ASSIGN: Interface FastEthernet0/0 assigned DHCP address 192.168.10.1, mask 255.255.255.0, hostname PC1
PC2同理:
PC2#conf t
PC2(config)#
PC2(config)#int f0/0
PC2(config-if)#ip address dhcp
PC2(config-if)#exit
PC2(config)#
//PC2動態獲取ip地址成功
*Mar 1 00:05:37.547: %DHCP-6-ADDRESS_ASSIGN: Interface FastEthernet0/0 assigned DHCP address 192.168.20.1, mask 255.255.255.0, hostname PC2
address assign:就是地址分配的意思。
查看PC1的接口信息:
PC1#show ip interface brief
Interface IP-Address OK? Method Status Protocol
FastEthernet0/0 192.168.10.1 YES DHCP up up
PC1#
我們可以看到PC1開啓了DHCP協議,並從DHCP服務器上獲取到了ip地址。
查看服務器的DHCP信息:
SW1#show ip dhcp pool
Pool VLAN10 :
Utilization mark (high/low) : 100 / 0
Subnet size (first/next) : 0 / 0
Total addresses : 254
Leased addresses : 1
Pending event : none
1 subnet is currently in the pool :
Current index IP address range Leased addresses
192.168.10.2 192.168.10.1 - 192.168.10.254 1
Pool VLAN20 :
Utilization mark (high/low) : 100 / 0
Subnet size (first/next) : 0 / 0
Total addresses : 254
Leased addresses : 1
Pending event : none
1 subnet is currently in the pool :
Current index IP address range Leased addresses
192.168.20.2 192.168.20.1 - 192.168.20.254 1
SW1#
重要的幾個字段:
Total addresses:總的ip地址個數
Leased addresses:代表已經分配給PC的ip地址個數
查看DHCP協議已經分配出去的ip地址信息:
SW1#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.10.1 0063.6973.636f.2d63. Mar 08 2002 12:04 AM Automatic
6330.372e.3266.3363.
2e30.3030.302d.4661.
302f.30
192.168.20.1 0063.6973.636f.2d63. Mar 08 2002 12:05 AM Automatic
6330.382e.3335.6430.
2e30.3030.302d.4661.
302f.30
SW1#
從上面給出的DHCP信息來看,192.168.10.1和192.168.20.1地址已經分配出去了。
一般網關地址都會提前分配出去並且地址是固定的,因此需要在DHCP服務器上排除掉已經分配出去的網關ip地址,配置如下:
SW1#conf t
Enter configuration commands, one per line. End with CNTL/Z.
SW1(config)#ip dhcp excluded-address 192.168.10.254
SW1(config)#ip dhcp excluded-address 192.168.20.254
SW1(config)#
因爲對於以上的兩個網關地址已經分配給VLAN10和VLAN20這兩個網段了,因此需要在DHCP服務器上排除掉。
部署DHCP技術可以方便主機,各種終端,手機平板等設備接入網絡,另外除了一般企業網絡外,例如地鐵,公交等公共場合也會部署DHCP接入技術,因此DHCP技術應用非常廣泛。
2. 端口安全
端口安全主要是用於在局域網下實現用戶安全的接入網絡,主要是基於交換機接口中綁定特定數量的MAC地址來實現安全接入網絡的一種安全策略技術。
默認情況下,交換機的一個接口是可以學習很多個mac地址的,因爲此時沒有對接口進行任何限制。在開啓端口安全後,就可以對交換機的接口進行限制,例如限制接口的mac地址個數,並且當有接入交換機接口的設備違反端口安全的規則時還可以定義懲罰模式。
當違反規則時,端口安全有三種懲罰模式:
- Protect(保護模式),丟棄違規流量。
- Restrict(限制模式),丟棄流量並報警到網管平臺。
- Shutdown(關閉模式),丟棄流量並關閉接口。
SW1交換機的f0/1接口部署端口安全技術:
Switch#
Switch#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#int f0/1
Switch(config-if)#
Switch(config-if)#switchport mode access
Switch(config-if)#switchport port-security
Switch(config-if)#switchport port-security mac-address sticky
Switch(config-if)#switchport port-security maximum 1
Switch(config-if)#switchport port-security violation shutdown
端口安全技術部署命令說明:
switchport mode access :因爲在這個實驗中,交換機的接口是要接入主機PC的,因此要設置接口爲主機模式。
switchport port-security :部署端口安全技術。
switchport port-security mac-address sticky :當學習mac地址後會進行存儲,並且下次重啓交換機後mac地址不會丟失。
switchport port-security maximum 1:設置交換機的接口接入mac地址的數量。
switchport port-security violation shutdown :定義交換機接口的懲罰模式,當有接入主機設備違反規則時就會啓動對應的懲罰,這裏我們設置爲關閉接口。
show running-config命令查看交換機學習到的mac地址信息:
Switch#show running-config
Building configuration...
Current configuration : 1127 bytes
!
version 12.1
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname Switch
!
!
spanning-tree mode pvst
!
interface FastEthernet0/1
switchport mode access
switchport port-security
switchport port-security mac-address sticky
//交換機設備進行地址學習
switchport port-security mac-address sticky 0009.7C32.7E16
!
interface FastEthernet0/2
!
--More--
部署了端口安全技術後,交換機的f0/1學習到了MAC地址爲0009.7C32.7E16的設備,當下次交換機收到數據包的源MAC地址不是0009.7C32.7E16的話,那麼就會啓動端口安全的懲罰模式,把該接口關閉掉。
此時我們接入一個新的主機,即PC1,然後發送一個ping數據包:
查看交換機的接口狀態:
Switch#show interfaces f0/1
FastEthernet0/1 is down, line protocol is down (err-disabled)
Hardware is Lance, address is 0060.70b9.0801 (bia 0060.70b9.0801)
由於PC1是新接入的設備,違反了端口安全的規則(新接入的PC1的mac地址不是交換機f0/1接口綁定的mac地址),因此交換機啓動了懲罰模式直接把f0/1接口關閉(down)了。
交換機顯示的狀態信息:
%LINK-5-CHANGED: Interface FastEthernet0/1, changed state to administratively down
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to down
一般當交換機的端口由於違反規則而關閉時,可以通過“手工啓動”方式來啓動接口,但是對於管理上是不方便的,一般我們可以在交換機的接口上部署自動恢復來啓動接口。
自動恢復部署配置如下:
errdisable recovery cause psecure-violation
errdisable recovery interval 30
以上命令表示當接口由於端口安全違反規則進入errdisable狀態後, 等待30秒可以自動恢復啓動接口。