单臂路由和DHCP
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了单臂路由和DHCP相关的知识,希望对你有一定的参考价值。
1.实验拓扑图:环境准备:
2.实验步骤:
1)配置SW1:
SW1#conf t
SW1(config)#vlan 10 ##创建VLAN10
SW1(config-vlan)#exit
SW1(config)#vlan 20 ##创建VLAN20
SW1(config-vlan)#exit
SW1(config)#int range f0/1-2
SW1(config-if-range)#switchport mode access
SW1(config-if-range)#switchport access vlan 10 ##加入VLAN10
SW1(config-if-range)#int range f0/3-4
SW1(config-if-range)#switchport mode access
SW1(config-if-range)#switchport access vlan 20 ##加入VLAN20
SW1(config-if-range)#exit
SW1(config)#int f0/24
SW1(config-if)#switchport mode trunk ##设置链路类型为trunk
SW1(config-if)#end
SW1#sh vlan b
VLAN Name Status Ports
1 default active Fa0/5, Fa0/6, Fa0/7, Fa0/8
Fa0/9, Fa0/10, Fa0/11, Fa0/12
Fa0/13, Fa0/14, Fa0/15, Fa0/16
Fa0/17, Fa0/18, Fa0/19, Fa0/20
Fa0/21, Fa0/22, Fa0/23, Fa0/24
Gig1/1, Gig1/2
10 VLAN0010 active Fa0/1, Fa0/2
20 VLAN0020 active Fa0/3, Fa0/4
SW1#sh int f0/24 sw
Name: Fa0/24
Switchport: Enabled
Administrative Mode: trunk
Operational Mode: down
Administrative Trunking Encapsulation: dot1q
Operational Trunking Encapsulation: dot1q
Negotiation of Trunking: On
Access Mode VLAN: 1 (default)
Trunking Native Mode VLAN: 1 (default)
2)配置路由器:单臂路由实现不同VLAN间通信
R1>en
R1#conf t
R1(config)#int f0/0
R1(config-if)#no sh ##开启物理接口
R1(config-if)#int f0/0.1 ##进入子接口f0/0.1
R1(config-subif)#encapsulation dot1Q 10 ##设置封装VLAN类型iee802.1q,将子接口和VLAN10进行绑定
R1(config-subif)#ip addr 192.168.10.1 255.255.255.0 ##设置子接口IP地址
R1(config-subif)#int f0/0.2 ##进入子接口f0/0.2
R1(config-subif)#encapsulation dot1Q 20 ##设置封装VLAN类型,将子接口和VLAN20进行绑定
R1(config-subif)#ip addr 192.168.20.1 255.255.255.0
R1(config-subif)#end
R1#sh ip int b
Interface IP-Address OK? Method Status Protocol
FastEthernet0/0 unassigned YES unset up up
FastEthernet0/0.1 192.168.10.1 YES manual up up
FastEthernet0/0.2 192.168.20.1 YES manual up up
3)验证:
PC0能ping通PC3:命令提示符ping 192.168.20.3
4)配置DHCP实现自动分配IP地址:R1
R1#conf t
R1(config)#ip dhcp pool vlan10 ##配置vlan10的DHCP地址池
R1(dhcp-config)#? ##显示可以配置的参数
default-router Default routers
dns-server Set name server
exit Exit from DHCP pool configuration mode
network Network number and mask
no Negate a command or set its defaults
option Raw DHCP options
R1(dhcp-config)#network 192.168.10.0 255.255.255.0 ##设置网段,客户机请求时自动从网段中分配IP地址和子网掩码
R1(dhcp-config)#default-router 192.168.10.1 ##设置默认网关
R1(dhcp-config)#dns-server 202.106.0.20 ##设置DNS服务器地址
R1(dhcp-config)#exit ##退出dhcp配置模式
R1(config)#ip dhcp pool vlan20 ##配置vlan20的DHCP地址池
R1(dhcp-config)#net 192.168.20.0 255.255.255.0
R1(dhcp-config)#default-router 192.168.20.1
R1(dhcp-config)#dns-server 202.106.0.20
R1(dhcp-config)#end
R1#sh run
hostname R1
。。。。。。省略部分信息。。。。。。。
ip dhcp pool vlan10
network 192.168.10.0 255.255.255.0
default-router 192.168.10.1
dns-server 202.106.0.20
ip dhcp pool vlan20
network 192.168.20.0 255.255.255.0
default-router 192.168.20.1
dns-server 202.106.0.20
。。。。。。省略部分信息。。。。。。。
interface FastEthernet0/0
no ip address
duplex auto
speed auto
!
interface FastEthernet0/0.1
encapsulation dot1Q 10
ip address 192.168.10.1 255.255.255.0
!
interface FastEthernet0/0.2
encapsulation dot1Q 20
ip address 192.168.20.1 255.255.255.0
!
R1#
5)验证DHCP:
PC1:
PC2:
总结:Dhcp可以自动给客户机分配IP地址、子网掩码、默认网关、DNS服务器。
以上是关于单臂路由和DHCP的主要内容,如果未能解决你的问题,请参考以下文章