CCNA课程实验-04-DHCP

04-DHCP实验

实验背景

网络拓朴图

在这里插入图片描述

需求

  1. MSW1和SW2之间的线路需配置为Trunk,采用Dot1q封装协议
  2. MSW1和SW2上创建VLAN 10、20,MSW1 配置SVI 10的IP为192.168.10.254,SVI 20的IP为 192.168.20.254,作为PC1和PC2的网关,SW2将接口E0/1划分到VLAN 10,E0/2划分到VLAN 20
  3. 在MSW1上配置两个DHCP地址池,地址池名Produce,分发地址范围192.168.10.0/24,网关为192.168.10.254,DNS地址为114.114.114.114,要求下发IP地址时不允许下发192.168.10.254;地址池名Office,分发地址范围192.168.20.0/24,网关为192.168.20.254,DNS地址为114.114.114.114,要求下发IP地址时不允许下发192.168.20.254

配置实现

1

MSW1和SW2之间的线路需配置为Trunk,采用Dot1q封装协议
MSW1

MSW1(config)# interface ethernet 0/0
MSW1(config-if)# switchport trunk encapsulation dot1q
MSW1(config-if)# switchport mode trunk

SW2

SW2(config)# interface ethernet 0/0
SW2(config-if)# switchport trunk encapsulation dot1q
SW2(config-if)# switchport mode trunk

2

MSW1和SW2上创建VLAN 10、20,MSW1 配置SVI 10的IP为192.168.10.254,SVI 20的IP为 192.168.20.254,作为PC1和PC2的网关,SW2将接口E0/1划分到VLAN 10,E0/2划分到VLAN 20

MSW1

MSW1(config)# vlan 10, 20
MSW1(config-vlan)# exit
MSW1(config)# interface vlan 10
MSW1(config-if)# ip address 192.168.10.254 255.255.255.0
MSW1(config-if)# no shutdown
MSW1(config)# interface vlan 20
MSW1(config-if)# ip address 192.168.20.254 255.255.255.0
MSW1(config-if)# no shutdown

SW2

SW2(config)# vlan 10, 20
SW2(config-vlan)# exit
SW2(config)# interface e0/1
SW2(config-if)# switchport mode access
SW2(config-if)# switchport access vlan 10
SW2(config)# interface e0/2
SW2(config-if)# switchport mode access
SW2(config-if)# switchport access vlan 20

3

在MSW1上配置两个DHCP地址池,地址池名Produce,分发地址范围192.168.10.0/24,网关为192.168.10.254,DNS地址为114.114.114.114,要求下发IP地址时不允许下发192.168.10.254;地址池名Office,分发地址范围192.168.20.0/24,网关为192.168.20.254,DNS地址为114.114.114.114,要求下发IP地址时不允许下发192.168.20.254
MSW1

MSW1(config)# ip dhcp pool Produce
MSW1(dhcp-config)# network 192.168.10.0 255.255.255.0
MSW1(dhcp-config)# dns-server 114.114.114.114
MSW1(dhcp-config)# default-router 192.168.10.254
MSW1(dhcp-config)# ip dhcp pool Office
MSW1(dhcp-config)# network 192.168.20.0 255.255.255.0
MSW1(dhcp-config)# dns-server 114.114.114.114
MSW1(dhcp-config)# default-router 192.168.20.254
MSW1(dhcp-config)# exit
MSW1(config)# ip dhcp excluded-address 192.168.10.254 #这个ip不分配给客户机
MSW1(config)# ip dhcp excluded-address 192.168.20.254


#表示【192.168.10.254192.168.20.254】这个区间的IP都不分配给客户机
MSW1(config)# ip dhcp excluded-address 192.168.10.254 192.168.20.254

4

客户端IP获取
PC1

#用路由器模拟的PC,所以要执行关闭路由命令
PC1(config)# no ip routing
PC1(config)# intface e0/1
PC1(config-if)# ip address dhcp
PC1(config)# no shutdown   # 路由器默认是关闭端口的,所以要no shutdown

PC2

#用路由器模拟的PC,所以要执行关闭路由命令
PC2(config)# no ip routing
PC2(config)# intface e0/1
PC2(config-if)# ip address dhcp
PC2(config)# no shutdown   # 路由器默认是关闭端口的,所以要no shutdown

效果截图

PC1

PC1#show ip interface brief
Interface                  IP-Address      OK? Method Status                Protocol
Ethernet0/0                unassigned      YES unset  administratively down down    
Ethernet0/1                192.168.10.1    YES DHCP   up                    up      
Ethernet0/2                unassigned      YES unset  administratively down down    
Ethernet0/3                unassigned      YES unset  administratively down down    
PC1#show ip dns view
DNS View default parameters:
Logging is off
DNS Resolver settings:
  Domain lookup is enabled
  Default domain name: 
  Domain search list:
  Lookup timeout: 3 seconds
  Lookup retries: 2
  Domain name-servers:
    114.114.114.114
DNS Server settings:
  Forwarding of queries is enabled
  Forwarder timeout: 3 seconds
  Forwarder retries: 2
  Forwarder addresses:
PC1#show ip
*Oct 26 17:24:03.733: %SYS-5-CONFIG_I: Configured from console by console
PC1#show ip route
Default gateway is 192.168.10.254

Host               Gateway           Last Use    Total Uses  Interface
ICMP redirect cache is empty
PC1#

PC2

PC2#show ip interface brief
Interface                  IP-Address      OK? Method Status                Protocol
Ethernet0/0                unassigned      YES unset  administratively down down    
Ethernet0/1                unassigned      YES unset  administratively down down    
Ethernet0/2                192.168.20.1    YES DHCP   up                    up      
Ethernet0/3                unassigned      YES unset  administratively down down    
PC2#show ip dns view
DNS View default parameters:
Logging is off
DNS Resolver settings:
  Domain lookup is enabled
  Default domain name: 
  Domain search list:
  Lookup timeout: 3 seconds
  Lookup retries: 2
  Domain name-servers:
    114.114.114.114
DNS Server settings:
  Forwarding of queries is enabled
  Forwarder timeout: 3 seconds
  Forwarder retries: 2
  Forwarder addresses:


PC2#show ip route
Default gateway is 192.168.20.254

Host               Gateway           Last Use    Total Uses  Interface
ICMP redirect cache is empty
PC2#

MSW1

MSW1#show ip dhcp binding
Bindings from all pools not associated with VRF:
IP address      Client-ID/              Lease expiration        Type       State      Interface
                Hardware address/
                User name
192.168.10.1    0063.6973.636f.2d61.    Oct 27 2023 11:33 PM    Automatic  Active     Vlan10
                6162.622e.6363.3030.
                2e33.3031.302d.4574.
                302f.31
192.168.20.1    0063.6973.636f.2d61.    Oct 27 2023 11:33 PM    Automatic  Active     Vlan20
                6162.622e.6363.3030.
                2e34.3032.302d.4574.
                302f.32
MSW1#

主要命令汇总

配置DHCP

//关闭DHCP
SW(config)# no service dhcp
//配置地址池
SW(config)#  ip dhcp pool Produce
SW(dhcp-config)# network 网络id 子网掩码 //进入配置
SW(dhcp-config)# dns-server 1.1.1.1 //解析dns的服务器ip地址
SW(dhcp-config)# default-router 1.1.1.254 //默认的网关地址

//保留这个ip不分配给客户机
MSW1(config)# ip dhcp excluded-address 192.168.10.254
//表示【192.168.10.254,192.168.20.254】这个区间的IP都不分配给客户机
MSW1(config)# ip dhcp excluded-address 192.168.10.254 192.168.20.254

删除配置的地址池

SW(dhcp-config)# no ip dhcp pool Produce //删除

SW# clear ip dhcp pool Produce //删除
SW# clear ip dhcp binding	//删除
SW# clear ip dhcp subnet	//删除

查询DHCP状态

//查询客户机器ip绑定情况
MSW1#show ip dhcp binding
//显示地址池的状态,可带地址池名称,如果带只显示指定的地址池,
MSW1#show ip dhcp pool

客户端获取

//客户端获取ip命令
SW(config)# interface ethernet 0/0
SW(config-if)# ip address dhcp
SW(config-if)# no shutdown
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

烈火蜓蜻

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值