Dhcp中继ensp

拓扑图

Dhcp中继ensp_第1张图片

system-view

[Huawei]sysname SW1

[SW1]vlan batch 10 20

[SW1]int e0/0/1                                                         #配置access接口

[SW1-Ethernet0/0/1]port link-type access

[SW1-Ethernet0/0/1]port default vlan 10

[SW1-Ethernet0/0/1]undo shut

[SW1-Ethernet0/0/1]q

[SW1]int e0/0/2                                                                #配置access接口

[SW1-Ethernet0/0/2]port link-type access

[SW1-Ethernet0/0/2]port default vlan 20        

[SW1-Ethernet0/0/2]undo shutdown

[SW1-Ethernet0/0/2]int e0/0/3                                #配置access接口

[SW1-Ethernet0/0/3]port link-type access

[SW1-Ethernet0/0/3]port default vlan 10        

[SW1-Ethernet0/0/3]undo shutdown

[SW1-Ethernet0/0/3]q

[SW1]int e0/0/4                                                                #配置access接口

[SW1-Ethernet0/0/4]port link-type access

[SW1-Ethernet0/0/4]port default vlan 20        

[SW1-Ethernet0/0/4]undo shutdown

[SW1-Ethernet0/0/4]q

[SW1]int g0/0/1                                                                #配置trunk接口

[SW1-GigabitEthernet0/0/1]port link-type trunk

[SW1-GigabitEthernet0/0/1]port trunk allow-pass vlan all

[SW1-GigabitEthernet0/0/1]undo shutdown

system-view

[Huawei]sysname R1

#开启dhcp功能

[R1]dhcp enable                         

#配置第一个虚拟子接口1.1

[R1]int g0/0/1.1

#选择封装类型及vlan

[R1-GigabitEthernet0/0/1.1]dot1q termination vid 10        

#开启arp广播功能

[R1-GigabitEthernet0/0/1.1]arp broadcast enable

#配置IP地址

[R1-GigabitEthernet0/0/1.1]ip add 192.168.10.1 24

#指向DHCP服务器

[R1-GigabitEthernet0/0/1.1]dhcp select relay

[R1-GigabitEthernet0/0/1.1]dhcp relay server-ip 14.0.0.2

[R1-GigabitEthernet0/0/1.1]undo shutdown

[R1-GigabitEthernet0/0/1.1]q

#同理配置第二个虚拟接口1.2

[R1]int g0/0/1.2        

[R1-GigabitEthernet0/0/1.2]dot1q termination vid 20

[R1-GigabitEthernet0/0/1.2]arp broadcast enable

[R1-GigabitEthernet0/0/1.2]ip add 192.168.20.1 24        

[R1-GigabitEthernet0/0/1.2]dhcp select relay

[R1-GigabitEthernet0/0/1.2]dhcp relay server-ip 14.0.0.2

[R1-GigabitEthernet0/0/1.2]q

#配置IP地址即可

[R1]int g0/0/3

[R1-GigabitEthernet0/0/3]ip add 14.0.0.1 24        

[R1-GigabitEthernet0/0/3]undo shutdown

[R1-GigabitEthernet0/0/3]q

#配置IP地址即可

[R1]int g0/0/2

[R1-GigabitEthernet0/0/2]ip add 12.0.0.1 24

[R1-GigabitEthernet0/0/2]undo shutdown

[R1-GigabitEthernet0/0/2]q

#配置指向PC7的默认路由

[R1]ip route-static 0.0.0.0 0.0.0.0 12.0.0.2

system-view

[Huawei]sysname R2

#在全局模式下开启dhcp功能

[R2]dhcp enable

#配置IP地址

[R2]int g0/0/2

[R2-GigabitEthernet0/0/2]ip add 12.0.0.2 24

[R2-GigabitEthernet0/0/2]undo shutdown

[R2-GigabitEthernet0/0/2]q

#配置IP地址、指向DHCP服务器

[R2]int g0/0/0

[R2-GigabitEthernet0/0/0]ip add 15.0.0.1 24

sys        

[Huawei]sysname R3

#在全局模式下开启dhcp功能

[R3]dhcp enable

#配置IP地址、宣告DHCP地址池

[R3]interface g0/0/3

[R3-GigabitEthernet0/0/3]ip add 14.0.0.2 24

#选择全局的地址池给DHCP客户端使用,而“dhcp select interface”则是选择接口的地址池给DHCP客户端使用

[R3-GigabitEthernet0/0/3]dhcp select global         

[R3-GigabitEthernet0/0/3]undo shutdown

[R3-GigabitEthernet0/0/3]q

#配置主机PC7的地址池(名称:pc7)

[R3]ip pool dhcp-pc7

#设置IP地址网段

[R3-ip-pool-dhcp-pc7]network 15.0.0.0 mask 24

#设置网关

[R3-ip-pool-dhcp-pc7]gateway-list 15.0.0.1

#DNS服务器地址

[R3-ip-pool-dhcp-pc7]dns-list 8.8.8.8 114.114.114.114

[R3-ip-pool-dhcp-pc7]q

#配置VLAN10的IP地址池

[R3]ip pool dhcp-vlan10

[R3-ip-pool-dhcp-vlan10]network 192.168.10.0 mask 24

[R3-ip-pool-dhcp-vlan10]gateway-list 192.168.10.1        

[R3-ip-pool-dhcp-vlan10]dns-list 8.8.8.8 114.114.114.114

[R3-ip-pool-dhcp-vlan10]q

#配置VLAN20的IP地址池

[R3]ip pool dhcp-vlan20

[R3-ip-pool-dhcp-vlan20]network 192.168.20.0 mask 24

[R3-ip-pool-dhcp-vlan20]gateway-list 192.168.20.1

[R3-ip-pool-dhcp-vlan20]dns-list 8.8.8.8 114.114.114.114

[R3-ip-pool-dhcp-vlan20]q

#配置静态路由

[R3]ip route-static 192.168.10.0 24 14.0.0.1

[R3]ip route-static 192.168.20.0 24 14.0.0.1

[R3]ip route-static 15.0.0.0 24 14.0.0.1

#指向DHCP服务器

[R2-GigabitEthernet0/0/0]dhcp select relay

[R2-GigabitEthernet0/0/0]dhcp relay server-ip 14.0.0.2

[R2-GigabitEthernet0/0/0]undo shut

[R2-GigabitEthernet0/0/0]q

#配置向左流通的静态路由

[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

[R2]ip route-static 14.0.0.0 24 12.0.0.1

测试pc自动获得IP地址

你可能感兴趣的:(网络,网络)