天天看点

单臂路由和交换机配置实验

单臂路由和交换机配置实验

实验:如上图

公司 划分了4个局域网、分别是1.0、 2.0、 3.0、 4.0网段,分别接到2个交换机,再连上路由器后上网,现需要4个网段能够互通。

首先把PC机IP 按图配好。然后配置SW2交换机,命令如下:

SW2>

enable

configure terminal

enable secret 163.com(设置密文密码163.com)

line vyt 0 4 设置虚拟端口0-4 用于远程telnet

password 163.com

login 设置生效

line console 0 配置接口

password 163.com

login

exit

vlan 10创建Vlan10

interface vlan 10进入vlan 10

ip address 192.168.1.100 255.255.255.0 配置IP

no shutdown 启用

vlan 20

interface vlan 20

ip address 192.168.2.100 255.255.255.0

no shutdown

interface fa0/1

switchport mode access 设置fa0/1端口为 access 模式

switchport access vlan 10把端口加入vlan 10

spanning-tree portfast 设置成快速端口

interface fa0/2

switchport mode access

switchport access vlan 20

spanning-tree portfast

interface range fa 0/11,fa 0/13,fa 0/16 - fa 0/20

switchport access vlan 10 把fa 0/11 13 16 17 18 19 20 端口加入Vlan10

单臂路由和交换机配置实验

interface fa 0/10

switchport trunk encapsulation dot1q 把端口封装成dot1q协议

switchport mode trunk 把 10端口设成trunk 模式,就是可以跑多个vlan

switchport trunk allowed vlan all (允许所有vlan通过此端口,可写可不写,一般情况下trunk本来就默认所有vlan通过)

no shutdown

interface fa 0/5

switchport mode trunk

switchport trunk encapsulation

no shutdown

到这里SW2交换机配置完毕,查看一下有没有配置错误:查看结果和上面配置无误

show vlan查 vlan

show ip interface brief查IP和端口状态

show ip running-config 查看所有配置

单臂路由和交换机配置实验
单臂路由和交换机配置实验

右边交换机SW3配置方法一样。

现在用PC 测试一下网络连通性、发现相同网段、相同vlan的可以互通,而不同网段不同vlan的不能通。

单臂路由和交换机配置实验

我再在SW2 交换机上加2台PC ,PC5 加入vlan 30 IP 192.168.3.2 ,PC6 加入vlan10 IP 192.168.3.3

再测试互通性,得出相同网段、相同vlan的可以互通,相同网段不同vlan也是不能互通的。

单臂路由和交换机配置实验
单臂路由和交换机配置实验

现在要在路由器R1上配置网关、使全网互通。

enable

configure terminal

interface fa 0/0

no shutdown

interface fa 0/0.10 创建.10子接口并进入

encapsulation dot1q 10 封装端口为dot1q 标记为10(这里要注意,标记号一定要和vlan号一致,不然有时候会导致网络不通)

ip address 192.168.1.254 255.255.255.0配置网关IP

no shutdown

interface fa0/0.20

encapsulation dot1q 20

ip address 192.168.2.254 255.255.255.0

no shutdown

interface fa 0/0.30

encapsulation dot1q 30

ip address 192.168.3.254 255.255.255.0

no shutdown

interface fa 0/0.40

encapsulation dot1q 40

ip address 192.168.4.254 255.255.255.0

no shutdown

end

单臂路由和交换机配置实验

查看一下配置情况,看看是否正确。

show ip interface brief

单臂路由和交换机配置实验

现在整个网络配置全部完成,测试一下整个网络的联通性。

发现整个网络通不了,原来是交换机SW2 的fa 0/10连路由器的端口没有设置为trunk 模式,确记,要跑多个vlan 的端口接口处,一定要改成trunk 模式。

再测试后,发现192.168.3.3 与其它的不通,因为在同一个网络里有一个192.168.3网段在VLAN 30 里,而3.3在VLAN 10里,所以不通. 其它的网络全是通的。