交换机与路由技术-14-三层交换机配置

三层交换机配置

场景一:三层交换机的接口属于不同VLAN

创建VLAN 10并将接口加入到VLAN10

Switch#conf t

Enter configuration commands, one per line.  End with CNTL/Z.

Switch(config)#vlan 10

Switch(config-vlan)#exit

Switch(config)#int range f0/1-14

Switch(config-if-range)#sw mode acc

Switch(config-if-range)#sw acc vlan 10

Switch(config-if-range)#exit

配置虚接口IP,配置DHCP

Switch(config)#int vlan 10

Switch(config-if)#ip add 192.168.10.254 255.255.255.0

Switch(config-if)#no shutdown

Switch(config-if)#ip dhcp pool vlan10

Switch(dhcp-config)#network 192.168.10.0 255.255.255.0

Switch(dhcp-config)#default-router 192.168.10.254

Switch(dhcp-config)#dns-server 114.114.114.114

Switch(dhcp-config)#exit

Switch(config)#ip dhcp excluded-address 192.168.10.254

Switch(config)#

创建VLAN 20 并将接口加入到VLAN 20

Switch(config)#vlan 20

Switch(config-vlan)#exit

Switch(config)#int range f0/15-24

Switch(config-if-range)#sw mode acc

Switch(config-if-range)#sw acc vlan 20

Switch(config-if-range)#exit

Switch(config)#

配置虚接口IP 和DHCP

Switch(config)#int vlan 20

Switch(config-if)#

%LINK-5-CHANGED: Interface Vlan20, changed state to up

Switch(config-if)#ip add 192.168.20.254 255.255.255.0

Switch(config-if)#no shutdown

Switch(config-if)#ip dhcp pool vlan20

Switch(dhcp-config)#network 192.168.20.0 255.255.255.0

Switch(dhcp-config)#default-router 192.168.20.254

Switch(dhcp-config)#dns-server 114.114.114.114

Switch(dhcp-config)#exit

Switch(config)#ip dhcp excluded-address 192.168.20.254

Switch(config)#

开启路由功能

Switch(config)#ip routing

Switch(config)#

思科设备默认情况下,三层交换机是没有开启路由功能的。需要手动开启

场景二:三层交换机所有接口都属于Trunk模式

问题:交换机sw0上是否创建vlan 20

           交换机sw1上是否创建vlan 10

答案:否

我的理解:

Pc4发送数据到pc5 到达sw0 打上vlan 10标签,发现是不同网段的,将数据发往三层交换机,到达三层交换机,查看目的IP,发现是发往vlan 20的数据,会将标签转换为vlan 20 重新进行二层封装,后通过对应接口转发给sw1 sw1收到数据后通过对应接口转发给pc5

SW0配置

创建VLAN 10并将接口加入到VLAN 10

Switch>en

Switch#conf t

Enter configuration commands, one per line.  End with CNTL/Z.

Switch(config)#vlan 10

Switch(config-vlan)#exit

Switch(config)#int range f0/2-3

Switch(config-if-range)#sw mode acc

Switch(config-if-range)#sw acc vlan 10

Switch(config-if-range)#exit

Switch(config)#

/* 与三层交换机相连的接口配置为trunk口 */

Switch(config)#int f0/1

Switch(config-if)#sw mode trunk

Switch(config-if)#

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to down

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up

Switch(config-if)#

SW1配置

创建VLAN 20并将接口加入到VLAN 20

Switch>en

Switch#conf t

Enter configuration commands, one per line. End with CNTL/Z.

Switch(config)#vlan 20

Switch(config-vlan)#exit

Switch(config)#int range f0/2-3

Switch(config-if-range)#sw mode acc

Switch(config-if-range)#sw acc vlan 20

Switch(config-if-range)#exit

/* 与三层交换机相连的接口配置为trunk口 */

Switch(config)#int f0/1

Switch(config-if)#sw mode trunk

Switch(config-if)#

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to down

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up

Switch(config-if)#

三层交换机配置

创建所有VLAN(VLAN 10、VLAN 20)

将对应接口加入到VLAN,将所有接口设置为Trunk

需要将接口封装成dot1q标准帧格式才能trunk

为虚接口配置IP,mask,作为每个vlan的默认网关

为虚接口配置DHCP,使得主机自动获取TCP/IP参数

开启IP routing 路由功能

Switch>en

Switch#conf t

Enter configuration commands, one per line. End with CNTL/Z.

Switch(config)#vlan 10

Switch(config-vlan)#exit

Switch(config)#vlan 20

Switch(config-vlan)#exit

Switch(config)#

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/2, changed state to down

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/2, changed state to up

Switch(config)#int range f0/1-2

/* 强制封装成标准帧格式 */

Switch(config-if-range)#switchport trunk encapsulation dot1q

Switch(config-if)#sw mode trunk

Switch(config-if)#exit

Switch(config)#int vlan 10

Switch(config-if)#

%LINK-5-CHANGED: Interface Vlan10, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan10, changed state to up

Switch(config-if)#ip add 192.168.10.254 255.255.255.0

Switch(config-if)#no shutdown

Switch(config-if)#ip dhcp pool vlan10

Switch(dhcp-config)#network 192.168.10.0 255.255.255.0

Switch(dhcp-config)#default-router 192.168.10.254

Switch(dhcp-config)#dns-server 114.114.114.114

Switch(dhcp-config)#exit

Switch(config)#ip dhcp excluded-address 192.168.10.254

Switch(config)#int vlan 20

Switch(config-if)#

%LINK-5-CHANGED: Interface Vlan20, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan20, changed state to up

Switch(config-if)#ip add 192.168.20.254 255.255.255.0

Switch(config-if)#no shutdown

Switch(config-if)#ip dhcp pool vlan20

Switch(dhcp-config)#network 192.168.20.0 255.255.255.0

Switch(dhcp-config)#default-router 192.168.20.254

Switch(dhcp-config)#dns-server 114.114.114.114

Switch(dhcp-config)#exit

Switch(config)#ip dhcp excluded 192.168.20.254

Switch(config)#ip routing

Switch(config)#

实验结果

查看配置的DHCP信息

Show ip dhcp pool

 

  • 4
    点赞
  • 35
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

w辣条小王子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值