一:实验环境
1.1: 华为ensp软件
1.2: PC机和路由器及交换机
初始化状态的PC机和初始化状态的路由器,交换机
二.实验需求,实现全网互通且DHCP中继在R4上
三:实验历程
3.1:设置装备
在ensp中,将PC机和路由器及交换机准备好,并启动。

3.2设置思绪
设置R1
1)设置接口

Int g0/0/0 ; ip add 12.0.0.1 24 ;un sh
Int g0/0/2 ; ip add 14.0.0.1 24 ;un sh

2)设置单臂路由及中继

dhcp enable    #系统视图下下令
int g0/0/1.10 ;
ip add 192.168.10.1;
d t v 10 ;
a b e;
dhcp select relay;    #设置中继模式
dhcp relay server-ip 14.0.0.2; #设置中继地址
un sh
int g0/0/1.20 ;
ip add 192.168.20.1;
d t v 20 ;a b e;dhcp select relay;
dhcp relay server-ip 14.0.0.2;
un sh

3)设置静态/默认路由
ip route-static 0.0.0.0 0.0.0.0 12.0.0.2
设置R2
1) 设置接口

int g0/0/0
ip add 12.0.0.2 24
un sh
int g0/0/1
ip add 15.0.0.1 24
un sh;q

2)设置开启中继模式

dhcp enable
dhcp select relay 
dhcp relay server-ip 14.0.0.2 ##指定中继地址

3)设置静态/默认路由(运营商端)

ip route-static 14.0.0.0 24 12.0.0.1
ip route-static 192.168.10.0 24 12.0.0.1
ip route-static 192.168.20.0 24 12.0.0.1

设置R4,提供中继服务
1)设置路由接口

Int g0/0/0 
Ip add 14.0.0.2 24
un sh

2)设置DHCP中继服务

dhcp enable
int g0/0/0
ip add 14.0.0.2 24
dhcp select global  #在接口上声明去全局模式找设置的DHCP服务
undo sh
设置中继池子,一个网段设置一个
ip pool DHCP15  #进DHCP15,设置PC5 15网段的池子
network 15.0.0.0 mask 24
gateway-list 15.0.0.1
dns-list 8.8.8.8 2.2.2.2
excluded-ip-address 15.0.0.100 15.0.0.254
static-bind ip-address 15.0.0.88 mac-address 5489-98C3-6B6F
ip pool DHCPvlan10 #进DHCPvlan10设置10.0网段池子
network 192.168.10.0 mask 24
gateway-list 192.168.10.1
dns-list 8.8.8.8 2.2.2.2
ip pool DHCPvlan20 #进DHCPvlan20设置20.0网段池子
network 192.168.20.0 mask 24
gateway-list 192.168.20.1
dns-list 8.8.8.8 2.2.2.2

3)设置路由
ip route-static 0.0.0.0 0.0.0.0 14.0.0.1
3.3 设置SW1交换机

[SW1] vlan batch 10 20
[SW1] interface Ethernet0/0/1
[SW1-Ethernet0/0/1]port link-type access
[SW1-Ethernet0/0/1]port default vlan 10
[SW1-Ethernet0/0/1]un sh
[SW1]interface Ethernet0/0/2
[SW1-Ethernet0/0/2]port link-type access
[SW1-Ethernet0/0/2]port default vlan 20
[SW1-Ethernet0/0/2]un sh
[SW1] interface Ethernet0/0/3
[SW1-Ethernet0/0/3]port link-type access
[SW1-Ethernet0/0/3]port default vlan 10
[SW1-Ethernet0/0/3]un sh
[SW1]interface Ethernet0/0/4
[SW1-Ethernet0/0/4]port link-type access
[SW1-Ethernet0/0/4]port default vlan 20
[SW1-Ethernet0/0/4]un sh
[SW1-Ethernet0/0/4]int g0/0/1
[SW1-GigabitEthernet0/0/1]p l t
[SW1-GigabitEthernet0/0/1]p t a v a
[SW1-GigabitEthernet0/0/1]un sh

3.4设置R1路由器
3.4.1 设置单臂路由

[R1]int g0/0/2
[R1-GigabitEthernet0/0/2]ip add 14.0.0.1 24
[R1-GigabitEthernet0/0/2]un sh
[R1-GigabitEthernet0/0/2]int g0/0/0
[R1-GigabitEthernet0/0/0]ip add 12.0.0.1 24
[R1-GigabitEthernet0/0/0]un sh
[R1]dhcp enable
[R1]int GigabitEthernet 0/0/1.10
[R1-GigabitEthernet0/0/1.10]d t v 10
[R1-GigabitEthernet0/0/1.10]ip address 192.168.10.1 24
[R1-GigabitEthernet0/0/1.10]a b e
[R1-GigabitEthernet0/0/1.10]un sh
[R1-GigabitEthernet0/0/1.10]int GigabitEthernet 0/0/1.20
[R1-GigabitEthernet0/0/1.20]d t v 20
[R1-GigabitEthernet0/0/1.20]ip address 192.168.20.1 24
[R1-GigabitEthernet0/0/1.20]a b e
[R1-GigabitEthernet0/0/1.20]un sh

3.4.2设置DHCP中继服务(指定中继路由地址)

[R1-GigabitEthernet0/0/1.20]int GigabitEthernet 0/0/1.10
[R1-GigabitEthernet0/0/1.10]dhcp select relay  #选择中继模式
[R1-GigabitEthernet0/0/1.10]dhcp relay server-ip 14.0.0.2
[R1-GigabitEthernet0/0/1.10]un sh
[R1-GigabitEthernet0/0/1.10]int GigabitEthernet 0/0/1.20
[R1-GigabitEthernet0/0/1.20]dhcp select relay
[R1-GigabitEthernet0/0/1.20]dhcp relay server-ip 14.0.0.2
[R1-GigabitEthernet0/0/1.20]un sh

3.4.3设置静态路由
[R1]ip route-static 0.0.0.0 0.0.0.0 12.0.0.2
3.5 设置R2路由器
3.5.1设置接口

[R2]int g0/0/0
[R2-GigabitEthernet0/0/0]ip add 12.0.0.2 24
[R2-GigabitEthernet0/0/0]un sh
[R2-GigabitEthernet0/0/0]int g0/0/1
[R2-GigabitEthernet0/0/1]ip add 15.0.0.1 24
[R2-GigabitEthernet0/0/1]un sh

3.5.2设置中继服务

[R2]dhcp enable
[R2-GigabitEthernet0/0/1]dhcp select relay
[R2-GigabitEthernet0/0/1]dhcp relay server-ip 14.0.0.2
[R2-GigabitEthernet0/0/1]undo sh
[R2-GigabitEthernet0/0/1]q

3.5.3设置路由

[R2]ip route-static 14.0.0.0 24 12.0.0.1
[R2]ip route-static 192.168.10.0 24 12.0.0.1
[R2]ip route-static 192.168.20.0 24 12.0.0.1

3.6 设置R4路由器
3.6.1设置路由接口

Int g0/0/0 
Ip add 14.0.0.2 24
un sh

3.6.2设置DHCP中继服务

[R4]dhcp enable #系统模式声明启用DHCP
[R4]int g0/0/0
[R4-GigabitEthernet0/0/0]ip add 14.0.0.2 24
[R4-GigabitEthernet0/0/0]dhcp select global  #在接口上声明去全局模式找设置的DHCP

3.6.3设置的DHCP服务

[R4-GigabitEthernet0/0/0]undo sh
[R4-GigabitEthernet0/0/0]q
[R4]ip pool DHCP15
[R4-ip-pool-DHCP15]network 15.0.0.0 mask 24
[R4-ip-pool-DHCP15]gateway-list 15.0.0.1
[R4-ip-pool-DHCP15]dns-list 8.8.8.8 2.2.2.2
[R4-ip-pool-DHCP15]excluded-ip-address 15.0.0.100 15.0.0.254
[R4-ip-pool-DHCP15]static-bind ip-address 15.0.0.88 mac-address 5489-98C3-6B6F    #此处MAC地址配的是PC5的mac,且设置分配15.0.0.88地址
[R4-ip-pool-DHCP15]dis this
ip pool DHCP15
 gateway-list 15.0.0.1
 network 15.0.0.0 mask 255.255.255.0
 static-bind ip-address 15.0.0.88 mac-address 5489-98c3-6b6f
 excluded-ip-address 15.0.0.100 15.0.0.254
 dns-list 8.8.8.8 2.2.2.2
[R4-ip-pool-DHCP15]q
[R4]ip pool DHCPvlan10
[R4-ip-pool-DHCPvlan10]network 192.168.10.0 mask 24
[R4-ip-pool-DHCPvlan10]gateway-list 192.168.10.1
[R4-ip-pool-DHCPvlan10]dns-list 8.8.8.8 2.2.2.2
[R4-ip-pool-DHCPvlan10]ip pool DHCPvlan20
[R4-ip-pool-DHCPvlan20]network 192.168.20.0 mask 24
[R4-ip-pool-DHCPvlan20]gateway-list 192.168.20.1
[R4-ip-pool-DHCPvlan20]dns-list 8.8.8.8 2.2.2.2
[R4-ip-pool-DHCPvlan20]q
[R4]ip route-static 0.0.0.0 0.0.0.0 14.0.0.1

3.7 检查是否知足需求

PC5已经获取指定设置的IP