DHCP自动获取ip地址实验

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了DHCP自动获取ip地址实验相关的知识,希望对你有一定的参考价值。

一:实验环境
1.1: 华为ensp软件
1.2: PC机和路由器及交换机
初始化状态的PC机和初始化状态的路由器,交换机
二:实验过程
2.1:配置设备
在ensp中,将PC机和路由器及交换机按图示做成拓扑图。
技术图片
2.2 配置SW1交换机

[SW1]vlan batch 10 20
[SW1]int e0/0/1
[SW1-Ethernet0/0/1]p l a
[SW1-Ethernet0/0/1]p d v 10
[SW1-Ethernet0/0/1]un sh
[SW1-Ethernet0/0/1]int e0/0/2
[SW1-Ethernet0/0/2]p l a
[SW1-Ethernet0/0/2]p d v 20
[SW1-Ethernet0/0/2]un sh
[SW1-Ethernet0/0/2]int e0/0/3
[SW1-Ethernet0/0/3]p l a
[SW1-Ethernet0/0/3]p d v 10
[SW1-Ethernet0/0/3]un sh
[SW1-Ethernet0/0/4]int e0/0/4
[SW1-Ethernet0/0/4]p l a
[SW1-Ethernet0/0/4]p d v 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
[SW1]dis int b
Ethernet0/0/1               up    up          0%     0%          0          0
Ethernet0/0/2               up    up          0%     0%          0          0
Ethernet0/0/3               up    up          0%     0%          0          0
Ethernet0/0/4               up    up          0%     0%
[SW1]dis cu
interface Ethernet0/0/1
 port link-type access
 port default vlan 10
interface Ethernet0/0/2
 port link-type access
 port default vlan 20
interface Ethernet0/0/3
 port link-type access
 port default vlan 10
interface Ethernet0/0/4
 port link-type access
 port default vlan 20
interface GigabitEthernet0/0/1
 port link-type trunk
 port trunk allow-pass vlan 2 to 4094

2.3 配置R1路由器
先配置单臂路由

interface GigabitEthernet0/0/0
 ip address 12.0.0.1 255.255.255.0
[R1]int g0/0/1.10
[R1-GigabitEthernet0/0/1.10]ip add 192.168.10.1 24
[R1-GigabitEthernet0/0/1.10]d t v 10
[R1-GigabitEthernet0/0/1.10]a b e
[R1-GigabitEthernet0/0/1.10]un sh
[R1]int g0/0/1.20
[R1-GigabitEthernet0/0/1.20]ip add 192.168.20.1 24
[R1-GigabitEthernet0/0/1.20]dot1q termination vid 20
[R1-GigabitEthernet0/0/1.20]arp broadcast enable
[R1-GigabitEthernet0/0/1.20]un sh

再配置DNS

[R1]int g0/0/1.10
[R1-GigabitEthernet0/0/1.10]dhcp select interface
[R1-GigabitEthernet0/0/1.10]dhcp server dns-list 2.2.2.2 8.8.8.8
[R1-GigabitEthernet0/0/1.10]int g0/0/1.20
[R1-GigabitEthernet0/0/1.20]dhcp select interface
[R1-GigabitEthernet0/0/1.20]dhcp server dns-list 2.2.2.2 8.8.8.8
[R1-GigabitEthernet0/0/1.20]dis this
interface GigabitEthernet0/0/1.20
 dot1q termination vid 20
 ip address 192.168.20.1 255.255.255.0
 arp broadcast enable
 dhcp select interface
 dhcp server dns-list 2.2.2.2 8.8.8.8
[R1-GigabitEthernet0/0/1.20]int g0/0/1.10
[R1-GigabitEthernet0/0/1.10]dis this
interface GigabitEthernet0/0/1.10
 dot1q termination vid 10
 ip address 192.168.10.1 255.255.255.0
 arp broadcast enable
 dhcp select interface
 dhcp server dns-list 2.2.2.2 8.8.8.8

配置路由
[R1]ip route-static 0.0.0.0 0.0.0.0 12.0.0.2
2.4 配置R2路由器
先配置接口

[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

再配置DHCP

[R2]dhcp enable
[R2-GigabitEthernet0/0/1]dhcp select global
[R2-GigabitEthernet0/0/1]q
[R2]ip pool DHCP15
[R2-ip-pool-DHCP15]network 15.0.0.0 mask 24
[R2-ip-pool-DHCP15]gateway-list 15.0.0.1
[R2-ip-pool-DHCP15]dns-list 8.8.8.8 2.2.2.2
[R2-ip-pool-DHCP15]dis this
ip pool DHCP15
 gateway-list 15.0.0.1
 network 15.0.0.0 mask 255.255.255.0
 dns-list 8.8.8.8 2.2.2.2
[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

2.5 PC端测试
技术图片
把其余PC均设置DHCP 再应用并查看其他地址
Ipconfig /renew 重新获取ip地址
Ipconfig /release 释放IP地址
技术图片
再用其他PC ping 192.168.10.254,都能ping通
技术图片
2.4 抓包研究DHCP报文
技术图片
技术图片
技术图片

以上是关于DHCP自动获取ip地址实验的主要内容,如果未能解决你的问题,请参考以下文章

Linux网络服务之DHCP服务原理与自动获取实验

DHCP自动获取ip地址实验

DHCP自动获取ip地址实验

不同vlan通过配置DHCP中继自动获取IP且互通

DHCP自动获取IP地址服务

DHCP实验演示(Huawei交换机设备配置)