羅定福
DHCP中繼在路由交換網絡中的設計與應用
羅定福
路由交換網絡是當前流行的網絡架構,DHCP 是當前主流的獲得 IP 地址協議。在現有的網絡設備上利用 DHCP 中繼技術實現動態 IP 地址的分配,既節省網絡建設成本,又方便統一管理。在真實設備上實驗表明:方案運行穩定、效率較高、無需額外的DHCP服務器且易于實現。
路由交換網絡;DHCP中繼;網絡建設成本;統一管理
路由交換網絡是當前公司企業組網的主流架構,隨著網絡規模的日益擴大和人們對網絡的移動性的要求越來越高,網絡管理員經常會采用動態主機配置協議(Dynamic Host Configuration Protocol, DHCP)[1]對網絡里的主機進行動態IP 地址分配和管理。在當前以“虛擬局域網”(Virtual Local Area Network,VLAN)為主流技術的路由交換網絡里,跨物理網段如何實現DHCP成為了一項重要的課題。
DHCP 中繼(DHCP Relay),也稱 DHCP 中繼代理。如果 DHCP服務器與 DHCP 客戶機在同一個物理網段,則客戶機可以順利地獲得動態分配的 IP 地址。如果 DHCP 服務器與 DHCP 客戶機不在同一個物理網段,則需要 DHCP Relay Agent(中繼代理)。用 DHCP 中繼代理可以省去在每個物理的網段都要有 DHCP 服務器的麻煩,它可以實現DHCP 廣播傳遞到不在同一個物理子網的 DHCP 服務器,也可以將服務器的消息返回給不在同一個子網的 DHCP 客戶機。其工作原理[2]如下:
(1)當 DHCP client 啟動并進行 DHCP 初始化時,它會在本地網絡廣播配置請求報文。
(2)如果本地網絡存在 DHCP server,則可以直接進行DHCP 配置,不需要 DHCP relay。
(3)如果本地網絡沒有 DHCP server,則與本地網絡相連的具有 DHCP relay 功能的網絡設備收到該廣播報文后,將進行適當處理并轉發給指定的其它網絡上的 DHCP server。
(4)DHCP server 根據 DHCP client 提供的信息進行相應的配置,并通過 DHCP relay 將配置信息發送給 DHCP client,完成對 DHCP client 的動態配置。
從開始到最終完成配置,需要多個這樣的交互過程。DHCP relay 設備修改 DHCP 消息中的相應字段,把 DHCP的廣播包改成單播包,并負責在服務器與客戶機之間轉換。
2.1 實驗拓撲[3]
如圖1所示:

圖1 DHCP 中繼網絡
模擬企業網絡拓撲,在現有路由器 RA 上配置 DCHP服務,充當 DHCP 服務器角色,在匯聚層交換機 S3 配置DHCP 中繼代理,跨網段為企業內部兩個部門 S2A、S2B 分配不同網段的 IP 地址。
2.2 實驗過程與關鍵代碼配置[4](以銳捷設備命令行為例)
步驟 1:在路由器 RA 上配置端口 IP 地址信息、路由以及DHCP服務。
RA(config)#interface fa 1/0
RA(config-if)#ip address 192.16.30.1 255.255.255.0
RA(config)#service DHCP
RA(DHCP-config)# ip DHCP pool vlan10
RA(DHCP-config)# network 192.168.10.0 255.255.255.0
RA(DHCP-config)# default-router 192.168.10.1
RA(DHCP-config)#ip DHCP excluded-address 192.168.10.1
RA(DHCP-config)# ip DHCP pool vlan20
RA(DHCP-config)# network 192.168.20.0 255.255.255.0
RA(DHCP-config))# default-router 192.168.20.1
RA(DHCP-config)#ip DHCP excluded-address 192.168.20.1
RA(config) #ip route 0.0.0.0 0.0.0.0 192.168.30.2
步驟 2:在三層交換機 S3 上配置路由以及 DHCP 中繼代理。
S3(config)#vlan 10
S3(config)#vlan 20
S3(config)#interface fa 0/1
S3(config-if)#no switchport
S3(config-if)#ip address 192.168.30.1 255.255.255.0
S3(config)#interface vlan 10
S3(config-if)#ip address 192.168.10.1 255.255.255.0
S3(config)#interface vlan 20
S3(config-if)#ip address 192.168.20.1 255.255.255.0
S3(config)#interface range fa 0/23,24
S3(config-if)#switchport mode trunk
S3(config)ip route 0.0.0.0 0.0.0.0 192.168.30.1
S3(config)#service DHCP
S3(config)#interface vlan 10
S3(config-if)#ip help-address 192.168.30.1
S3(config)#interface vlan 20
S3(config-if)#ip help-address 192.168.30.1
步驟 3:在二層交換機 S2A 和 S2B 上分別配置 VLAN。
Switch(config)#vlan 10
Switch(config)#vlan 20
Switch(config)#interface fa 0/1
Switch(config-if)#switchport access vlan 10
Switch(config)# interface fa 0/2
Switch(config-if)#switchport access vlan 20
Switch(config)# interface fa 0/24
Switch(config-if)#switchport mode trunk
步驟 3:客戶機設置自動獲取 IP 地址。
2.3 配置結果查看。
S3配置結果如下:
S3#show running-config
vlan 1
vlan 10
vlan 20
service DHCP
interface FastEthernet 0/1
no switchport
ip address 192.168.30.2 255.255.255.0
interface FastEthernet 0/2
......
interface FastEthernet 0/22
interface FastEthernet 0/23
switchport mode trunk
interface FastEthernet 0/24
switchport mode trunk interface VLAN 10
ip helper-address 192.168.30.1
ip address 192.168.10.1 255.255.255.0 interface VLAN 20
ip helper-address 192.168.30.1
ip address 192.168.20.1 255.255.255.0
ip route 0.0.0.0 0.0.0.0 192.168.30.1
RA配置結果如下:
RA#show running-config
hostname RA
service DHCP
ip DHCP excluded-address 192.168.10.1
ip DHCP excluded-address 192.168.20.1
ip DHCP pool vlan10
network 192.168.10.0 255.255.255.0
dns-server 192.168.30.1
default-router 192.168.10.1
ip DHCP pool vlan20
network 192.168.20.0 255.255.255.0
dns-server 192.168.30.1
default-router 192.168.20.1
interface serial 1/3
clock rate 64000
interface FastEthernet 1/0
ip address 192.168.30.1 255.255.255.0
interface FastEthernet 1/1
ip route 0.0.0.0 0.0.0.0 192.168.30.2
1、網絡設備應支持 DHCP 服務。
2、配置 DHCP 中繼時指向的服務器地址要正確。
3、網絡中的其它服務如 DNS 等,如果設備支持也能部署。
在以 VLAN 為主流的路由交換網絡里,利用 DHCP 中繼技術,充分利用現有的設備部署 DHCP 服務,能更有利于統一管理、降低成本、提升經濟效益。
[1] 張巧紅,安常青,李學農等.DHCP 技術在清華大學校園網 中 的 應 用 [J]. 計 算 機 工 程 與 應用 ,2001,37(10):50-52,72.DOI:10.3321/j.issn:1002-8331. 2001.10.017.
[2] 韓麗,崔建濤.DHCP 中繼代理在虛擬機上的實現[J].太原理工大學學報,2010,41(2):163-165.
[3] 羅定福,李艷.三層交換機與路由器連接的技術研究[J].佛山科學技術學院學報(自然科學版),2013,31(2):52-54.
[4] 高峽,鐘嘯劍,李永俊.網絡設備互連實驗指南[M].北京:科學出版社,2009:71-98
Design and Application of DHCP Relay in Routing and Switching Network
Luo Dingfu
(Department of Computers, Guangdong Songshan Polytechnic College, Shaoguan 512126, China)
The routing and switching network is a popular network architecture, and DHCP is the current main IP address access protocol. The allocation of dynamic IP addresses using DHCP relay technology in the existing network devices, can save the cost of network construction, and be convenient for unified management. The experiments on real devices tell us: the scheme is stable, high efficiency, no additional DHCP server and is easy to implement.
Routing and Switching Network; DHCP Relay; Network Construction Cost; Management
TP311
A
1007-757X(2014)02-0048-02
2014.01.09)
羅定福(1982-),男,廣東省興寧市人,廣東松山職業技術學院計算機系,講師,研究方向:計算機網絡技術,韶關,512126