模拟DHCP
先将PC这台路由器的路由功能关闭掉
Router(config)#no ip routing
Router(config)#interface gigabitEthernet 0/0
Router(config-if)#ip address dhcp #开启DHCP模式
Router(config-if)#no shutdown
Router#show run interface gigabitEthernet 0/0
Building configuration...
!
interface GigabitEthernet0/0
ip address dhcp
no ip route-cache
duplex auto
speed auto
media-type rj45
end
Router#
WG(config)#interface gigabitEthernet 0/0
WG(config-if)#ip address 192.168.1.2 255.255.255.0
WG(config)#interface gigabitEthernet 0/1
WG(config-if)#ip address 192.168.2.1 255.255.255.0
WG(config-if)#no shutdown
DHCP(config)#interface gigabitEthernet 0/1
DHCP(config-if)#ip address 192.168.2.2 255.255.255.0
###l=====================================================
###l### 配置回去的路由,要不然PC的数据无法回去
DHCP(config)#ip route 192.168.1.0 255.255.255.0 192.168.2.1
DHCP(config)#ip dhcp pool PC
DHCP(dhcp-config)#network 192.168.1.0 255.255.255.0
DHCP(dhcp-config)#default-router 192.168.1.2
DHCP(dhcp-config)#dns-server 8.8.8.8
WG(config)#interface gigabitEthernet 0/0
WG(config-if)#ip helper-address 192.168.2.2 #在PC端相连的接口配置DHCP服务器的地址
###PC这时就获取到地址了
*Nov 16 12:41:47.245: %DHCP-6-ADDRESS_ASSIGN:
Interface GigabitEthernet0/0 assigned DHCP address 192.168.1.1, mask 255.255.255.0, hostname
PC(config)#interface gigabitEthernet 0/0
PC(config-if)#shutdown
PC(config-if)#no shutdown #在重启接口后就会获取到一个新的地址
PC(config)#
*Nov 16 12:50:15.694: %DHCP-6-ADDRESS_ASSIGN:
Interface GigabitEthernet0/0 assigned DHCP address 192.168.1.3, mask 255.255.255.0, hostname PC
PC#
*Nov 16 12:59:01.581: %DHCP-6-ADDRESS_ASSIGN:
Interface GigabitEthernet0/0 assigned DHCP address 192.168.1.1, mask 255.255.255.0, hostname PC
PC#sh ip interface brief
Interface IP-Address OK? Method Status Protocol
GigabitEthernet0/0 192.168.1.1 YES DHCP up up
GigabitEthernet0/1 unassigned YES unset administratively down down
GigabitEthernet0/2 unassigned YES unset administratively down down
GigabitEthernet0/3 unassigned YES unset administratively down down
PC#
=============================================
####DHCP服务器端已经显示一台设备上线了
DHCP(config)#do sh ip dhcp binding
Bindings from all pools not associated with VRF:
IP address Client-ID/ Lease expiration Type
Hardware address/
User name
192.168.1.1 0063.6973.636f.2d35. Nov 16 2022 01:04 PM Automatic
3037.302e.3466.3030.
2e63.3030.302d.4769.
302f.30
DHCP(config)#
DHCP静态绑定
###DHCP配置
DHCP(config)#ip dhcp pool static
DHCP(dhcp-config)#host 192.168.1.100 255.255.255.0 #分配的固定地址
#客户机的MAC地址,注意MAC前要加01+MAC
DHCP(dhcp-config)#client-identifier 015070.4f00.c000 #客户机的MAC地址,注意MAC前要加01+MAC
#客户机的MAC地址,注意MAC前要加01+MAC
DHCP(dhcp-config)#default-router 192.168.1.2
DHCP(dhcp-config)#dns-server 8.8.8.8
####PC要在接口下配置,让他用PC gigabitEthernet 0/0的MAC去请求DHCP
PC(config)#interface gigabitEthernet 0/0
PC(config-if)#ip address dhcp client-id gigabitEthernet 0/0
####再重启接口
PC(config-if)#shutdown
PC(config-if)#no shutdown
####DHCP绑定就生效了
PC#
*Nov 16 13:24:16.846: %DHCP-6-ADDRESS_ASSIGN:
Interface GigabitEthernet0/0 assigned DHCP address 192.168.1.100, mask 255.255.255.0, hostname PC
PC#
PC#sh ip interface brief
Interface IP-Address OK? Method Status Protocol
GigabitEthernet0/0 192.168.1.100 YES DHCP up up
GigabitEthernet0/1 unassigned YES unset administratively down down
GigabitEthernet0/2 unassigned YES unset administratively down down
GigabitEthernet0/3 unassigned YES unset administratively down down
PC#
网友评论