配置PC的IP地址获取方式
在SW2(DHCP中继)上配置
创建VLAN,并为其配置IP地址(VLAN10、20配置网关),命令如下:
[SW2]vlan batch 10 20 100
[SW2]interface Vlanif 10
[SW2-Vlanif10]ip address 192.168.10.254 24
[SW2-Vlanif10]interface Vlanif 20
[SW2-Vlanif20]ip address 192.168.20.254 24
[SW2-Vlanif20]interface vlanif 100
[SW2-Vlanif100]ip address 10.10.10.1 30
设置接口类型,并加入对应的VLAN,命令如下:
[SW2]int g0/0/1
[SW2-GigabitEthernet0/0/1]port link-type access
[SW2-GigabitEthernet0/0/1]port default vlan 10
[SW2]int g0/0/2
[SW2-GigabitEthernet0/0/2]port link-type access
[SW2-GigabitEthernet0/0/2]port default vlan 20
[SW2]int g0/0/3
[SW2-GigabitEthernet0/0/3]port link-type access
[SW2-GigabitEthernet0/0/3]port default vlan 100
配置一条指向DHCP服务器的默认路由,以便把PC发出的DHCP广播报文中继给DHCP服务器,命令如下:
[SW2]ip route-static 0.0.0.0 0 10.10.10.2
开启DHCP并启用DHCP中继,命令如下:
[SW2]dhcp enable
[SW2]int v 10
[SW2-Vlanif10]dhcp select relay
[SW2-Vlanif10]dhcp relay server-ip 10.10.10.2
[SW2]int v 20
[SW2-Vlanif20]dhcp select relay
[SW2-Vlanif20]dhcp relay server-ip 10.10.10.2
在SW1(DHCP)上配置
创建VLAN,加入接口并配置IP地址
[dhcp]vlan batch 100
[dhcp]int g 0/0/1
[dhcp-GigabitEthernet0/0/1]port link-type access
[dhcp-GigabitEthernet0/0/1]port default vlan 100
[dhcp-GigabitEthernet0/0/1]int v 100
[dhcp-Vlanif100]ip address 10.10.10.2 30
配置到达VLAN10、20的静态路由,以便把DHCP报文发给DHCP中继,命令如下:
[dhcp]ip route-static 192.168.10.0 24 10.10.10.1
[dhcp]ip route-static 192.168.20.0 24 10.10.10.1
创建全局地址池,命令如下:
[dhcp]dhcp enable
[dhcp]int v 100
[dhcp-Vlanif100]dhcp select global
[dhcp]ip pool vlan10
[dhcp-ip-pool-vlan10]network 192.168.10.0 mask 24
[dhcp-ip-pool-vlan10]gateway-list 192.168.10.254
[dhcp]ip pool vlan20
[dhcp-ip-pool-vlan20]network 192.168.20.0 mask 24
[dhcp-ip-pool-vlan20]gateway-list 192.168.20.254
验证实验结果:
标签:中继,ip,配置,GigabitEthernet0,192.168,dhcp,DHCP,SW2 From: https://blog.csdn.net/2401_86336750/article/details/144446314