本文共 3170 字,大约阅读时间需要 10 分钟。
1.实验拓扑图:
环境准备:
2.实验步骤:
1)配置SW1:SW1#conf tSW1(config)#vlan 10 ##创建VLAN10SW1(config-vlan)#exitSW1(config)#vlan 20 ##创建VLAN20SW1(config-vlan)#exitSW1(config)#int range f0/1-2SW1(config-if-range)#switchport mode access SW1(config-if-range)#switchport access vlan 10 ##加入VLAN10SW1(config-if-range)#int range f0/3-4SW1(config-if-range)#switchport mode access SW1(config-if-range)#switchport access vlan 20 ##加入VLAN20SW1(config-if-range)#exitSW1(config)#int f0/24SW1(config-if)#switchport mode trunk ##设置链路类型为trunkSW1(config-if)#endSW1#sh vlan bVLAN Name Status Ports
1 default active Fa0/5, Fa0/6, Fa0/7, Fa0/8
Fa0/9, Fa0/10, Fa0/11, Fa0/12Fa0/13, Fa0/14, Fa0/15, Fa0/16Fa0/17, Fa0/18, Fa0/19, Fa0/20Fa0/21, Fa0/22, Fa0/23, Fa0/24Gig1/1, Gig1/210 VLAN0010 active Fa0/1, Fa0/220 VLAN0020 active Fa0/3, Fa0/4SW1#sh int f0/24 sw
Name: Fa0/24Switchport: EnabledAdministrative Mode: trunkOperational Mode: downAdministrative Trunking Encapsulation: dot1qOperational Trunking Encapsulation: dot1qNegotiation of Trunking: OnAccess Mode VLAN: 1 (default)Trunking Native Mode VLAN: 1 (default)2)配置路由器:单臂路由实现不同VLAN间通信
R1>enR1#conf tR1(config)#int f0/0R1(config-if)#no sh ##开启物理接口R1(config-if)#int f0/0.1 ##进入子接口f0/0.1R1(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.2R1(config-subif)#encapsulation dot1Q 20 ##设置封装VLAN类型,将子接口和VLAN20进行绑定R1(config-subif)#ip addr 192.168.20.1 255.255.255.0R1(config-subif)#endR1#sh ip int bInterface IP-Address OK? Method Status ProtocolFastEthernet0/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.34)配置DHCP实现自动分配IP地址:R1
R1#conf tR1(config)#ip dhcp pool vlan10 ##配置vlan10的DHCP地址池R1(dhcp-config)#? ##显示可以配置的参数default-router Default routersdns-server Set name serverexit Exit from DHCP pool configuration modenetwork Network number and maskno Negate a command or set its defaultsoption Raw DHCP optionsR1(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.0R1(dhcp-config)#default-router 192.168.20.1R1(dhcp-config)#dns-server 202.106.0.20R1(dhcp-config)#endR1#sh run
hostname R1。。。。。。省略部分信息。。。。。。。ip dhcp pool vlan10network 192.168.10.0 255.255.255.0default-router 192.168.10.1dns-server 202.106.0.20ip dhcp pool vlan20network 192.168.20.0 255.255.255.0default-router 192.168.20.1dns-server 202.106.0.20。。。。。。省略部分信息。。。。。。。interface FastEthernet0/0no ip addressduplex autospeed auto!interface FastEthernet0/0.1encapsulation dot1Q 10ip address 192.168.10.1 255.255.255.0!interface FastEthernet0/0.2encapsulation dot1Q 20ip address 192.168.20.1 255.255.255.0!R1#5)验证DHCP:
PC1:PC2:
总结:Dhcp可以自动给客户机分配IP地址、子网掩码、默认网关、DNS服务器。
转载于:https://blog.51cto.com/14386465/2406582