一、背景需求:
在一些带机量大的场景中,为避免网络中的广播风暴影响网络质量,某公司希望将内网进行广播域隔离,划分3个VLAN,同时需要 VLAN10 和 VLAN20 实现内网间互访,VLAN30 和 其他两个隔离,网管员能够远程管理内网设备。
这里,我会用GNS3复原当时的情形。
现有设备如下:
H3C ER系列路由器一台,
cisco C3560交换机一台,
可选方案:
1、采用单臂路由模式,vlan在三层交换机上划分,网关,DHCP均由路由器完成。(不推荐使用)这里不做演示,如有需求可看我另一篇文档:
2、将网关、dhcp地址池,架设在三层,三层交换机和路由器之间采用静态路由转发数据。ACL实现VLAN间隔离。
这里采用第二种方案。将网关、dhcp均由核心交换机完成。采用默认路由将流量转发给路由器。
二、网络拓扑
网络地址规划:
VLAN10: 10.0.10.0 /24 ,网关: 10.0.10.254
PC1:10.0.10.1 /24
PC2:10.0.10.2 /24
VLAN20: 10.0.20.0 /24,网关: 10.0.20.254
PC3:10.0.20.1 /24
PC4:10.0.20.2 /24
VLAN30: 10.0.30.0 /24,网关: 10.0.30.254
PC5:10.0.30.1 /24
PC6:10.0.30.2 /24
路由器 f0/0:172.16.2.1 /24
交换机 f1/15:172.16.2.2 /24
三、配置过程
1、若是旧机器,需要清空交换机原有配置。(如是全新设备,可以跳过此步骤)
这里不做演示,需要过程请看我另一篇文档:如何将思科交换机恢复出产设置?
2、初始化机器之后,重启交换机。
在路由器和交换机第一次启动或者刚初始化后启动会直接进入到会话模式,按Ctrl+c 命令跳过会话模式进入手工配置模式(命令模式)。另一种就是在特权命令状态使用Setup 命令也可通过交互方式对网络设备进行问话式配置。
--- System Configuration Dialog ---
Enable secret warning
Would you like to enter the initial configuration dialog? [yes/no]: yes
At any point you may enter a question mark '?' for help. // 任何时候可以打?取得帮助
Use ctrl-c to abort configuration dialog at any prompt. // 按Ctrl-C 可以取消并退出
Default settings are in square brackets '[]'. // 默认参数在[] 中
Basic management setup configures only enough connectivity
for management of the system, extended setup will ask you
to configure each interface on the system
Would you like to enter basic management setup? [yes/no]: yes // 继续交互配置吗
Configuring global parameters:
Enter host name [Switch]: Cy10th3560 // 输入交换机名称
The enable secret is a password used to protect access to
privileged EXEC and configuration modes. This password, after
entered, becomes encrypted in the configuration.
Enter enable secret: test // 输入EXEC 模式密码
The enable password is used when you do not specify an
enable secret password, with some older software versions, and
some boot images.
Enter enable password: test // 输入enable 模式密码
The virtual terminal password is used to protect
access to the router over a network interface.
Enter virtual terminal password: test // 输入虚拟控制端登录密码
Configure SNMP Network Management? [no]: no // 是否配置SNMP 管理
Enter interface name used to connect to the management network from the above interface summary:vlan1
// 输入用户网络管理的接口
Configuring interface Vlan1:
Configure IP on this interface? [no]: yes // 是否为接口配置IP 地址
IP address for this interface: 172.16.1.1
Subnet mask for this interface [255.255.255.0] : 255.255.255.0
Class C network is 172.16.0.0, 24 subnet bits; mask is /24
Would you like to enable as a cluster command switch? [yes/no]: no //是使用集群模式
[0] Go to the IOS command prompt without saving this config.
[1] Return back to the setup without saving this config.
[2] Save this configuration to nvram and exit.
Enter your selection [2]: 2 // 保存配置
以上是设置了交换机对的管理VLAN1的管理VLAN:VLAN1的IP地址:172.16.1.1,没有上述步骤也可自行配置。如下:
C3560#conf t
C3560(config)#int vlan1
C3560(config-if)#ip add 172.16.1.1 255.255.255.0
C3560(config-if)#no shutdown
C3560(config)#line vty 0 4
C3560(config-line)#password test
C3560(config-line)#login
C3560(config)#enable password test
C3560(config)#line console 0
C3560(config-line)#password test
C3560(config)#ip default-gateway 172.16.1.254 \\设置交换机的默认网关(全局配置模式下)
二层交换机配置了管理IP地址后,在管理地址的同网段内,设备可通过管理IP地址来远程访问交换机。
但若要跨网段去登录连接到另一个网段的二层交换机,则必须给二层交换机配置指定默认网关,双方的二层交换机都要配置指定默认网关地址。
企业局域网中一般会用到多个VLAN和网段,一般不同地址段的路由都是在上层设备上做通了的,而一般二层交换机只要将网关指向汇聚/核心层的三层设备的网管IP就可以了。
3、下面正式开始配置:
R1:
R1#conf t
R1(config)#int f0/0
R1(config-if)#ip add 172.16.2.1 255.255.255.0
R1(config-if)#no shut
R1(config)#ip route 10.0.10.0 255.255.255.0 172.16.2.2 \\去往VLAN的默认路由
R1(config)#ip route 10.0.20.0 255.255.255.0 172.16.2.2
R1(config)#ip route 10.0.30.0 255.255.255.0 172.16.2.2
SW:
C3560#vlan database
C3560(vlan)#vlan 10 name \\vlan10_PC
C3560(vlan)#vlan 20 name \\vlan20_shebei
C3560(vlan)#vlan 30 name \\vlan30_AP
C3560(config)#int vlan 10
C3560(config-if)#ip add 10.0.10.254 255.255.255.0
C3560(config-if)#no shutdown
C3560(config-if)#int vlan 20
C3560(config-if)#ip add 10.0.20.254 255.255.255.0
C3560(config-if)#no shutdown
C3560(config-if)#int vlan 30
C3560(config-if)#ip add 10.0.30.254 255.255.255.0
C3560(config-if)#no shutdown
C3560(config-if)#int f1/15
C3560(config-if)#no switchport \\转换为3层接口
C3560(config-if)#ip add 172.16.2.2 255.255.255.0
C3560(config-if)#ip route 0.0.0.0 0.0.0.0 172.16.2.1 \\指向路由器的默认路由
C3560(config)#ip routing \\开启IPV4的路由功能
C3560(config)#int f1/1 //真机可以使用范围配置更快,模拟器好像不支持 int f1/1-2
C3560(config-if)#switchport access vlan 10
C3560(config-if)#int f1/2
C3560(config-if)#switchport access vlan 10
C3560(config-if)#int f1/3
C3560(config-if)#switchport access vlan 20
C3560(config-if)#int f1/4
C3560(config-if)#switchport access vlan 20
C3560(config-if)#int f1/5
C3560(config-if)#switchport access vlan 30
C3560(config-if)#int f1/
C3560(config-if)#switchport access vlan 30
C3560(config-if)#do show vlan-switch //查看vlan信息,真机中:do show vlan brief
可以看到,接口都以划入VLAN中了。
4、接下来配置DHCP地址池、网关、DNS、保留地址等。
SW:
C3560(dhcp-config)#ip dhcp pool vlan10
C3560(dhcp-config)#network 10.0.10.0 /24
C3560(dhcp-config)#default-router 10.0.10.254
C3560(dhcp-config)#dns-server 8.8.8.8
C3560(config)#ip dhcp excluded-address 10.0.10.200 10.0.10.254
C3560(dhcp-config)#ip dhcp pool vlan20
C3560(dhcp-config)#network 10.0.20.0 /24
C3560(dhcp-config)#default-router 10.0.20.254
C3560(dhcp-config)#dns-server 8.8.8.8
C3560(config)#ip dhcp excluded-address 10.0.20.200 10.0.20.254
C3560(dhcp-config)#ip dhcp pool vlan30
C3560(dhcp-config)#network 10.0.30.0 /24
C3560(dhcp-config)#default-router 10.0.30.254
C3560(dhcp-config)#dns-server 8.8.8.8
C3560(config)#ip dhcp excluded-address 10.0.30.200 10.0.30.254
5、因为是用路由器模拟的PC,所以每个PC都需要关闭路由功能。这里只演示PC1,其余自行完成。
PC1#conf t
PC1(config)#ip routing
PC2#
……
PC3#
……
6、设置PC在接口下,通过dhcp自动获取ip地址
PC1(config)#ip address
PC1(config)#int f0/0
PC1(config-if)#ip address dhcp
PC1(config-if)#no shutdown
PC2(config)#ip address
PC2(config)#int f0/0
PC2(config-if)#ip address dhcp
PC2(config-if)#no shutdown
………………
自行配置其余PC
检查PC是否获取到地址,发现接口状态已经up,且获得了dhcp分配的地址
测试VLAN下的所有主机能否正常通信。
7、最后就需要隔离VLAN30了,使其不能与VLAN10和VLAN20通信。
C3560(config)#access-list 100 deny ip 10.0.30.0 0.0.0.255 10.0.10.0 0.0.0.255
C3560(config)#access-list 100 deny ip 10.0.30.0 0.0.0.255 10.0.20.0 0.0.0.255
C3560(config)#access-list 100 permit ip any any
C3560(config)#int vlan 30
C3560(config-if)#ip access-group 100
C3560(config-if)#ip access-group 100 in
C3560(config)#access-list 101 deny ip 10.0.20.0 0.0.0.255 10.0.30.0 0.0.0.255
C3560(config)#access-list 101 permit ip any any
C3560(config)#int vlan 20
C3560(config-if)#ip access-group 101
C3560(config-if)#ip access-group 101 in
C3560(config)#access-list 102 deny ip 10.0.10.0 0.0.0.255 10.0.30.0 0.0.0.255
C3560(config)#access-list 102 permit ip any any
C3560(config)#int vlan 10
C3560(config-if)#ip access-group 102
C3560(config-if)#ip access-group 102 in
8、测试VLAN10与VLAN30的通信
可以看到vlan10与vlan30互相不能通信
9、下面测试VLAN20与VLAN30之间的通信
10、最后,查看VLAN10与VLAN20之间的通信。
结论:VLAN10与VALN20可以通信,与VLAN30不能通信!!
拓扑图下载:gns3安装包+路由器镜像+拓扑图
(使用GNS3打开,路由器为:镜像C3660路由器)