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 服务器.
来源: http://www.bubuko.com/infodetail-3087895.html