首先假設兩台思科路由器,R1(服務端)連接R2(客戶端),組成一個簡單的鏈式局域網,下面就來實現DHCP,配置的命令及其解釋如下:
1、R1 dhcp服務的配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
dhcp#configure terminal
//進入全局模式
dhcp(config)#service dhcp
//打開dhcp功能
dhcp(config)#no ip dhcp conflictlogging
//關閉dhcp日志記錄
dhcp(config)#ip dhcp pool cisco
//配置dhcp服務器的名稱為cisco
dhcp(dhcp-config)#network 192.168.1.0 255.255.255.0
//配置dhcp服務器要分配的網段
dhcp(dhcp-config)#
default
-router 192.168.1.1
//配置默認網關為192.168.1.1
dhcp(dhcp-config)#dns-server 192.168.1.1
//配置dns服務器為192.168.1.1
dhcp(dhcp-config)#lease 3
//地址租用期限: 3天
dhcp(dhcp-config)#exit
//退出dhcp配置模式
dhcp(config)#ip dhcp excluded-address 192.168.1.200 192.168.1.254
//配置dhcp不分配的地址
|
2、R2客戶端獲取IP地址
Client#configure terminal //進入全局模式
dhcp(config)#interface fastethernet0/0 //進入fastethernet0/0接口
dhcp(config-if)#ip address dhcp //從dhcp服務器獲取IP地址
實例
Cisco設備上設置DHCP實例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
一位客戶想把DHCP SERVER遷移到6509交換機的MSFC上,要求還挺復雜:
1.同時為多個VLAN的客戶機分配地址
2.VLAN內有部分地址采用手工分配的方式
3.為客戶指定網關、Wins服務器等
4.VLAN 2的地址租用有效期限為1天,其它為3天
5.按MAC地址為特定用戶分配指定的IP地址
最終配置如下:
ip dhcp excluded-address 10.1.1.1 10.1.1.19
//不用於動態地址分配的地址
ip dhcp excluded-address 10.1.1.240 10.1.1.254
ip dhcp excluded-address 10.1.2.1 10.1.2.19
!
ip dhcp pool global
//global是pool name, 由用戶指定
network 10.1.0.0 255.255.0.0
//動態分配的地址段
domain-name client.com
//為客戶機配置域后綴
dns-server 10.1.1.1 10.1.1.2
//為客戶機配置dns服務器
netbios-name-server 10.1.1.5 10.1.1.6
//為客戶機配置wins服務器
netbios-node-type h-node
//為客戶機配置節點模式(影響名稱解釋的順利,如h-node=先通過wins服務器解釋...)
lease 3
//地址租用期限: 3天
ip dhcp pool vlan1
network 10.1.1.0 255.255.255.0
//本pool是global的子pool, 將從global pool繼承domain-name等option
default
-router 10.1.1.100 10.1.1.101
//為客戶機配置默認網關
!
ip dhcp pool vlan2
//為另一VLAN配置的pool
network 10.1.2.0 255.255.255.0
default
-router 10.1.2.100 10.1.2.101
lease 1
!
ip dhcp pool vlan1_john
//總是為MAC地址為...的機器分配...地址
host 10.1.1.21 255.255.255.0
client-identifier 010050.bade.6384
//client-identifier=01加上客戶機網卡地址
!
ip dhcp pool vlan1_tom
host 10.1.1.50 255.255.255.0
client-identifier 010010.3ab1.eac8
相關的DHCP調試命令:
no service dhcp
//停止DHCP服務[默認為啟用DHCP服務]
sh ip dhcp binding
//顯示地址分配情況
show ip dhcp conflict
//顯示地址沖突情況
|
1
|
clear ip dhcp binding 192.168.1.2
//清理已經分配的IP
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
<em id=
"__mceDel"
> debug ip dhcp server {events | packets | linkage}
//觀察DHCP服務器工作情況
如果DHCP客戶機分配不到IP地址,常見的原因有兩個。第一種情況是沒有把連接客戶機的端口設置為Portfast方式。MS客戶機開機后檢查網卡連接正常,Link是UP的,就開始發送DHCPDISCOVER請求,而此時交換機端口正在經歷生成樹計算,一般需要30-50秒才能進入轉發狀態。MS客戶機沒有收到DHCP SERVER的響應就會給網卡設置一個169.169.X.X的IP地址。解決的方法是把交換機端口設置為Portfast方式:CatOS(4000/5000/6000):
set
spantree portfast mod_num/port_num enable; IOS(2900/3500):
interface
... ; spanning-tree portfast。
另外一種情況是DHCP服務器和DHCP工作站不在同一個VLAN,這時候通常通過設置ip helper-address來解決:
interface
vlan1
ip address 10.1.1.254 255.255.255.0
//假設DHCP服務器地址為10.1.1.8
interface
Vlan2
ip address 10.1.2.254 255.255.255.0
ip helper-address 10.1.1.8
//假設這是DHCP客戶機所在的VLAN
參考資料網頁:
DHCP Configuring
DHCP Commands
ip helper-address
portfast
</em>
|