实现内网主机通过DHCP获取IP地址
2023-12-22 11:46:58
实现内网主机通过DHCP获取IP地址
拓扑
需求:
- 每个VLAN的IP地址为192.168.xx.0,xx为vlan ID;
- DHCP服务器地址为192.168.66.1,网关为192.168.66.254,网关部署在SW6上,实现终端获取IP地址
配置步骤:
1) 接入层交换机连创建vlan,连接PC的接口配置接口为access,并且加入指定vlan
2) 交换机和交换机互联的接口配置trunk 允许所有vlan通过
3)在核心交换机SW6中配置vlanif的管理IP
SW10-要创建vlan,配置trunk 配置access
4)配置DHCP服务器,创建地址池
5)SW6核心交换机通过vlanif66和dhcp互通
6)dhcp配置回程的默认路由到DHCP中继(SW6)
7) 在SW6中配置DHCP中继
配置命令:
第一步:接入层交换机的基础配置: SW1的配置: sysname SW1 # vlan batch 10 20 30 40 66 # interface GigabitEthernet0/0/1 port link-type access port default vlan 10 # interface GigabitEthernet0/0/2 port link-type access port default vlan 20 # interface GigabitEthernet0/0/12 port link-type trunk port trunk allow-pass vlan 2 to 4094 SW2的配置: sysname SW2 # vlan batch 10 20 30 40 66 # interface GigabitEthernet0/0/3 port link-type access port default vlan 10 # interface GigabitEthernet0/0/4 port link-type access port default vlan 30 # interface GigabitEthernet0/0/12 port link-type trunk port trunk allow-pass vlan 2 to 4094 SW3的配置: sysname SW3 # vlan batch 10 20 30 40 66 # interface GigabitEthernet0/0/5 port link-type access port default vlan 20 # interface GigabitEthernet0/0/6 port link-type access port default vlan 40 # interface GigabitEthernet0/0/12 port link-type trunk port trunk allow-pass vlan 2 to 4094 SW4的配置: sysname SW4 # vlan batch 10 20 30 40 66 # interface GigabitEthernet0/0/7 port link-type access port default vlan 40 # interface GigabitEthernet0/0/8 port link-type access port default vlan 30 # interface GigabitEthernet0/0/12 port link-type trunk port trunk allow-pass vlan 2 to 4094 # interface GigabitEthernet0/0/23 port link-type trunk port trunk allow-pass vlan 2 to 4094 第二步:配置DHCP服务器,配置IP地址池 DHCP服务器配置: [R6-DHCP]dhcp enable [R6-DHCP]int g0/0/0 [R6-DHCP-GigabitEthernet0/0/0]ip add 192.168.66.1 24 [R6-DHCP-GigabitEthernet0/0/0]dhcp select global [R6-DHCP-GigabitEthernet0/0/0]quit [R6-DHCP]ip pool vlan10 [R6-DHCP-ip-pool-vlan10]network 192.168.10.0 mask 24 [R6-DHCP-ip-pool-vlan10]gateway-list 192.168.10.254 [R6-DHCP-ip-pool-vlan10]dns-list 8.8.8.8 [R6-DHCP-ip-pool-vlan10]ip pool vlan20 [R6-DHCP-ip-pool-vlan20]network 192.168.20.0 mask 24 [R6-DHCP-ip-pool-vlan20]gateway-list 192.168.20.254 [R6-DHCP-ip-pool-vlan20]dns-list 8.8.8.8 [R6-DHCP]ip pool vlan30 [R6-DHCP-ip-pool-vlan30]network 192.168.30.0 mask 24 [R6-DHCP-ip-pool-vlan30]gateway-list 192.168.30.254 [R6-DHCP-ip-pool-vlan30]dns-list 8.8.8.8 [R6-DHCP-ip-pool-vlan30]ip pool vlan40 [R6-DHCP-ip-pool-vlan40]network 192.168.40.0 mask 24 [R6-DHCP-ip-pool-vlan40]gateway-list 192.168.40.254 [R6-DHCP-ip-pool-vlan40]dns-list 8.8.8.8 第三步:配置核心交换机SW6, 配置DHCP中继 [Huawei]sys SW6 [SW6]vlan batch 10 20 30 40 66 [SW6]dhcp enable [SW6]port-group group-member g0/0/1 to g0/0/4 g0/0/24 [SW6-port-group]port link-type trunk [SW6-port-group]port trunk allow-pass vlan all [SW6]int vlan 10 [SW6-Vlanif10]ip add 192.168.10.252 24 [SW6-Vlanif10]dhcp select relay [SW6-Vlanif10]dhcp relay server-ip 192.168.66.1 [SW6-Vlanif10]int vlan 20 [SW6-Vlanif20]ip add 192.168.20.252 24 [SW6-Vlanif20]dhcp select relay [SW6-Vlanif20]dhcp relay server-ip 192.168.66.1 [SW6-Vlanif20]int vlan 30 [SW6-Vlanif30]ip add 192.168.30.252 24 [SW6-Vlanif30]dhcp select relay [SW6-Vlanif30]dhcp relay server-ip 192.168.66.1 [SW6-Vlanif30]int vlan 40 [SW6-Vlanif40]ip add 192.168.40.252 24 [SW6-Vlanif40]dhcp select relay [SW6-Vlanif40]dhcp relay server-ip 192.168.66.1 第四步:SW10交换机的基础配置 [SW10]vlan batch 10 20 30 40 66 [SW10]port-group group-member g0/0/23 g0/0/24 [SW10-port-group]port link-type trunk [SW10-port-group]port trunk allow-pass vlan all [SW10-port-group]quit [SW10]int g0/0/6 [SW10-G0/0/6]port link-type access [SW10-G0/0/6]port default vlan 66 第五步:排除常见错误: 备注:现在我们配置完dhcp服务器和dhcp中继,主机能够获取IP地址吗? 如果不能获取IP地址,为什么? 原因是什么? 怎么排错? 解决主机无法获取IP地址的问题? 1) 用SW6中继设备去pingDHCP服务器,看DHCP中继和DHCP服务器是否互通 [sw6] ping 192.168.66.1 经过验证发现不通: 无法发包,为什么? [sw6] display ip routing-table 192.168.66.1 发现: SW6没有去往 192.168.66.1 的路由 2) 在SW6中给vlanif 66 配置管理IP地址 [SW6]int vlan 66 [SW6-Vlanif66]ip add 192.168.66.254 24 再次验证: [sw6] display ip routing-table 192.168.66.1 发现: SW6有去往 192.168.66.1 的直连路由 3) 在DHCP中,配置去往中继地址的回程的默认路由 [R6-DHCP]ip route-static 0.0.0.0 0.0.0.0 192.168.66.254 备注:能获取IP地址了,但是每个vlan中只有1个PC能获取到IP地址,第2台pc无法获取IP地址 原因:地址冲突: 192.168.XX.252 和vlanif管理IP地址,冲突 解决方案: 1)把所有PC的dhcp功能都关闭 2)重置DHCP地址池 <R6-DHCP>reset ip pool name vlan10 all <R6-DHCP>reset ip pool name vlan20 all <R6-DHCP>reset ip pool name vlan30 all <R6-DHCP>reset ip pool name vlan40 all 3)在dhcp中做ping探测 备注:每次dhcp发IP地址的时候,都先ping 一下,如果能ping通 就证明这个IP地址有人再用,跳过这个IP地址,发下一个IP地址 [R6-DHCP]dhcp server ping packet 4 //地址探测 [R6-DHCP]dhcp server ping timeout 100 第六步:再次验证 发现PC可以正常获取IP地址
文章来源:https://blog.csdn.net/weixin_72194028/article/details/135144954
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!