配置設(shè)備作為DHCP服務(wù)器示例(基于接口地址池),建議收藏!
DHCP服務(wù)器簡介
通常用戶希望網(wǎng)絡(luò)中的每臺終端能夠動態(tài)獲取IP地址、DNS服務(wù)器的IP地址、路由信息、網(wǎng)關(guān)信息等網(wǎng)絡(luò)參數(shù),不需要手動配置終端的IP地址等網(wǎng)絡(luò)參數(shù);另外,針對一些移動終端(手機、ipad、辦公筆記本等)希望能夠即插即用,不需要每次修改終端的IP等網(wǎng)絡(luò)參數(shù)。如果用戶網(wǎng)絡(luò)中有這些需求,就可以在匯聚層的用戶網(wǎng)關(guān)設(shè)備或核心層設(shè)備上配置DHCP服務(wù)器功能,來給終端分配IP地址等網(wǎng)絡(luò)參數(shù)。
動態(tài)主機配置協(xié)議DHCP(Dynamic Host Configuration Protocol)采用客戶端/服務(wù)器模式對用戶的網(wǎng)絡(luò)參數(shù)進行動態(tài)配置和集中管理。其中,DHCP服務(wù)器通過地址池為用戶分配IP地址等網(wǎng)絡(luò)參數(shù)。地址池分為接口地址池和全局地址池兩種。
接口地址池配置方式簡單,只能用于用戶與DHCP服務(wù)器在同一個網(wǎng)段的場景,并且只能給對應(yīng)接口下的用戶分配IP地址等網(wǎng)絡(luò)參數(shù);適用于設(shè)備數(shù)量有限、配置以及維護量可控的小型網(wǎng)絡(luò)。在用戶網(wǎng)關(guān)設(shè)備上配置基于接口地址池的DHCP服務(wù)器功能之后,對應(yīng)接口下的固定主機、移動終端等都可以自動獲取IP地址等網(wǎng)絡(luò)參數(shù),不需要用戶手動配置修改。
與接口地址池相比,全局地址池可應(yīng)用于大型網(wǎng)絡(luò),推薦在核心層設(shè)備上配置基于全局地址池的DHCP服務(wù)器功能或在服務(wù)器區(qū)域搭建一臺專門的DHCP服務(wù)器統(tǒng)一分配IP地址等網(wǎng)絡(luò)參數(shù),而用戶網(wǎng)關(guān)設(shè)備上只需要啟用簡單的DHCP中繼功能即可。
配置注意事項
本舉例適用的產(chǎn)品包括:
V200R005C00SPC300及后續(xù)版本的S2350-EI、S5300-LI
S2320-EI、S3300-SI、S3300-EI、S3300-HI
S5300-SI、S5300-EI、S5300-HI、S5310-EI、S5320-LI、S5320-SI、S5320-EI、S5320-HI、S5330-SI、S5330-HI、S5331-H、S5332-H、S5335-L1、S5335-L、S5335-S、S5336-S
S6300-EI、S6320-SI、S6320-EI、S6320-HI、S6330-H
S9303、S9306、S9312、S9310、S9310X、S9300X-4、S9300X-8、S9300X-12、S9303E、S9306E、S9312E
本舉例中產(chǎn)品的默認(rèn)適用版本請參見“案例適用的產(chǎn)品和版本說明”中的表1-1。

如需了解交換機軟件配套詳細(xì)信息,請點擊Info-Finder,在選擇產(chǎn)品系列或產(chǎn)品型號后,在“硬件中心”進行查詢。
組網(wǎng)需求
如圖7-3所示,某企業(yè)為辦公終端規(guī)劃了兩個網(wǎng)段,網(wǎng)段10.1.1.0/24內(nèi)PC為員工固定辦公終端,網(wǎng)段10.1.2.0/24供企業(yè)出差人員臨時接入網(wǎng)絡(luò)。企業(yè)希望通過DHCP方式為員工固定辦公終端和企業(yè)出差人員分配IP地址。其中,企業(yè)管理者的辦公PC(Client_1)由于業(yè)務(wù)需要,希望使用固定IP地址為10.1.1.100/24。

配置思路
基于接口地址池的DHCP服務(wù)器的配置思路如下:
通過在網(wǎng)關(guān)設(shè)備Switch上配置DHCP服務(wù)器,實現(xiàn)為企業(yè)兩個網(wǎng)段內(nèi)的終端動態(tài)分配IP地址。其中,網(wǎng)段10.1.1.0/24內(nèi)的PC為員工固定辦公終端,IP地址租期配置為30天;網(wǎng)段10.1.2.0/24供企業(yè)出差人員臨時接入網(wǎng)絡(luò),IP地址租期配置為1天。

二層交換機LSW_1和LSW_2上,需要配置接口的鏈路類型和加入的VLAN,實現(xiàn)二層互通。
操作步驟
使能DHCP服務(wù),缺省未使能
<Quidway> system-view[Quidway] sysname Switch
[Switch] dhcp enable
配置接口加入VLAN
# 配置GE0/0/1接口加入VLAN10。
[Switch] vlan batch 10 to 11[Switch] interface gigabitethernet 0/0/1
[Switch-GigabitEthernet0/0/1] port link-type access
[Switch-GigabitEthernet0/0/1] port default vlan 10
[Switch-GigabitEthernet0/0/1] quit
# 配置GE0/0/2加接口入VLAN11。
[Switch] interface gigabitethernet 0/0/2?[Switch-GigabitEthernet0/0/2] port link-type access?
[Switch-GigabitEthernet0/0/2] port default vlan 11?
[Switch-GigabitEthernet0/0/2] quit
3、配置VLANIF接口IP地址
# 配置VLANIF10接口地址。
[Switch] interface vlanif 10?
[Switch-Vlanif10] ip address 10.1.1.1 24 ?//企業(yè)為固定辦公終端的網(wǎng)段?
[Switch-Vlanif10] quit
# 配置VLANIF11接口地址。
[Switch] interface vlanif 11?
[Switch-Vlanif11] ip address 10.1.2.1 24 ?//企業(yè)為出差人員分配的網(wǎng)段?
[Switch-Vlanif11] quit
4、配置接口地址池
# 配置VLANIF10接口下的終端從接口地址池中獲取IP地址。
[Switch] interface vlanif 10?
[Switch-Vlanif10] dhcp select interface ?//使能接口采用接口地址池的DHCP服務(wù)器功能,缺省未使能?
[Switch-Vlanif10] dhcp server lease day 30 ?//租期的缺省值為1天,修改租期為30天?
[Switch-Vlanif10] dhcp server static-bind ip-address 10.1.1.100 mac-address 00e0-fc12-3456 ?//為Client_1分配固定的IP地址?
[Switch-Vlanif10] quit
# 配置VLANIF11接口下的終端從接口地址池中獲取IP地址。租期采用缺省值1天(不需配置)。
[Switch] interface vlanif 11?
[Switch-Vlanif11] dhcp select interface ?//使能接口采用接口地址池的DHCP服務(wù)器功能,缺省未使能?
[Switch-Vlanif11] quit
5、配置DHCP數(shù)據(jù)保存功能,設(shè)備發(fā)生故障時,可以在系統(tǒng)重啟后,執(zhí)行命令dhcp server database recover,從存儲設(shè)備文件恢復(fù)DHCP數(shù)據(jù)。
6、配置各終端自動獲取IP地址(以操作系統(tǒng)為Windows 7的PC為例)
右擊桌面“網(wǎng)絡(luò)”,單擊“屬性”,進入“網(wǎng)絡(luò)和共享中心”窗口。
單擊“本地連接”,進入“本地連接 狀態(tài)”窗口。
單擊“屬性”,進入“本地鏈接 屬性”窗口。
選擇“Internet 協(xié)議版本 4(TCP/IPv4)”,點擊“屬性”,進入“Internet 協(xié)議版本4(TCP/IPv4)屬性”窗口,選擇“自動獲得 IP 地址”,單擊“確定”。
在Switch上執(zhí)行命令display ip pool查看接口地址池VLANIF10和VLANIF11的配置信息。假設(shè)企業(yè)員工固定辦公終端有100個,出差人員接入3個。
[Switch] display ip pool interface vlanif10 ?Pool-name ? ? ? ?: Vlanif10??
Pool-No ? ? ? ? ?: 0 ?
Lease ? ? ? ? ? ?: 30 Days 0 Hours 0 Minutes ?
Domain-name ? ? ?: - ?
DNS-server0 ? ? ?: - ?
NBNS-server0 ? ? : - ?
Netbios-type ? ? : - ?
Position ? ? ? ? : Interface ? ? ? Status ? ? ? ? ? ? : Unlocked ?
Gateway-0 ? ? ? ?: 10.1.1.1 ?
Network ? ? ? ? ?: 10.1.1.0 ?
Mask ? ? ? ? ? ? : 255.255.255.0 ?
VPN instance ? ? : -- ?
Logging ? ? ? ? ?: Disable ?
Conflicted address recycle interval: - ?
Address Statistic: Total ? ? ? :253 ? ? ? Used ? ? ? ?:100 ? ? ? ? ? ? ? ? ? ? ?Idle ? ? ? ?:153 ? ? ? Expired ? ? :0 ? ? ? ? ? ? ? ? ? ? ?Conflict ? ?:0 ? ? ? ? Disable ? ? :0 ?------------------------------------------------------------------------------- ?
Network section ? ? ? ? ?Start ? ? ? ? ? End ? ? ? Total ? ?Used Idle(Expired) Conflict Disabled ?------------------------------------------------------------------------------- ? ? ? ? 10.1.1.1 ? ? ?10.1.1.254 ? ? 253 ? ? 100 ? ? ? ?153(0) ? ? ? 0 ? ? 0 ?-------------------------------------------------------------------------------
[Switch] display ip pool interface vlanif11 ?
Pool-name ? ? ? ?: Vlanif11 ?
Pool-No ? ? ? ? ?: 1 ?
Lease ? ? ? ? ? ?: 1 Days 0 Hours 0 Minutes ?
Domain-name ? ? ?: - ?
DNS-server0 ? ? ?: - ?
NBNS-server0 ? ? : - ?
Netbios-type ? ? : - ?
Position ? ? ? ? : Interface ? ? ? Status ? ? ? ? ? ? : Unlocked? ?、
Gateway-0 ? ? ? ?: 10.1.2.1 ?
Network ? ? ? ? ?: 10.1.2.0 ?
Mask ? ? ? ? ? ? : 255.255.255.0 ?
VPN instance ? ? : -- ?
Logging ? ? ? ? ?: Disable ?
Conflicted address recycle interval: - ?
Address Statistic: Total ? ? ? :253 ? ? ? Used ? ? ? ?:3 ? ? ? ? ? ? ? ? ? ? ?Idle ? ? ? ?:250 ? ? ? Expired ? ? :0 ? ? ? ? ? ? ? ? ? ? ?Conflict ? ?:0 ? ? ? ? Disable ? ? :0 ?------------------------------------------------------------------------------- ? Network section ? ? ? ? ?
Start ? ? ? ? ? End ? ? ? Total ? ?Used Idle(Expired) Conflict Disabled ?------------------------------------------------------------------------------- ? ? ? ?
10.1.2.1 ? ? ?10.1.2.254 ? ? 253 ? ? 3 ? ? ? ? ?250(0) ? ? ? 0 ? ? 0 ?-------------------------------------------------------------------------------
7、驗證配置結(jié)果
在Client_1(操作系統(tǒng)以Windows 7為例)上查看IP地址信息,可以看到Client_1已經(jīng)獲取到IP地址10.1.1.100/24。
C:\Documents and Settings\Administrator>ipconfig?Windows IP Configuration?
Ethernet adapter Local Area Connection 2: ? ?
Connection-specific DNS Suffix ?. : ? ?
IPv4 Address. . . . . . . . . . . : 10.1.1.100 ? ?
Subnet Mask . . . . . . . . . . . : 255.255.254.0 ? ?
Default Gateway . . . . . . . . . : 10.1.1.1
在其他DHCP客戶端(以10.1.1.0/24網(wǎng)段中操作系統(tǒng)為Windows 7的某終端為例)上查看IP地址信息,可以看到已經(jīng)成功獲取到IP地址。
C:\Documents and Settings\Administrator>ipconfig?Windows IP Configuration?
Ethernet adapter Local Area Connection 2: ? ?
Connection-specific DNS Suffix ?. : ? ?
IPv4 Address. . . . . . . . . . . : 10.1.1.51 ? ?
Subnet Mask . . . . . . . . . . . : 255.255.254.0 ? ?
Default Gateway . . . . . . . . . : 10.1.1.1
配置文件
Switch的配置文件
#
sysname Switch?
#?
vlan batch 10 to 11?
#?
dhcp enable?
#?
dhcp server database enable?
#?
interface Vlanif10?
?ip address 10.1.1.1 255.255.255.0 ?
dhcp select interface ?
dhcp server static-bind ip-address 10.1.1.100 mac-address 00e0-fc12-3456 ?
dhcp server lease day 30 hour 0 minute 0?
#?
interface Vlanif11 ?
ip address 10.1.2.1 255.255.255.0 ?
dhcp select interface?
#
interface GigabitEthernet0/0/1 ?
port link-type access ?
port default vlan 10
#
interface GigabitEthernet0/0/2 ?
port link-type access ?
port default vlan 11?
#
return