在现实环境中,有时候不一定将网关启用在路由器上,有时候实现单臂路由功能不一定必须接在路由器上接口上,可以使用三层交换机实现,因为交换机本身具有丰富的接口这样灵活的使用,在实际工作中很常见。读者可以对比上一篇文章《单臂路由实验(子接口的使用)》,从中感悟其中的奥妙。
具体的操作如下:
背景描述:在switch1-2950T-24上需要两个vlan(vlan 501/406),vlan 501使用前10个端口,vlan406使用0/11-0/20端口,vlan 501使用10.63.201.0/24网段;vlan 406使用10.63.206.0/25网段;网关使用最后一个可用地址;管理地址vlan 1使用10.63.207.128/25.
1、网络拓扑结构图
2、在核心交换机(C3560-24PS)上的操作
Switch>en
Switch#conf
Switch#configure
Configuring from terminal, memory, or network [terminal]?
Enter configuration commands, one per line. End with CNTL/Z.
(1)此处没有命名设备,启用telnet用户口令
Switch(config)#line vty
Switch(config)#line vty 0 4
Switch(config-line)#login
% Login disabled on line 66, until 'password' is set
% Login disabled on line 67, until 'password' is set
% Login disabled on line 68, until 'password' is set
% Login disabled on line 69, until 'password' is set
% Login disabled on line 70, until 'password' is set
Switch(config-line)#pas
Switch(config-line)#password 123123
Switch(config-line)#exi
(2)创建vlan
Switch(config)#vlan 501
Switch(config-vlan)#ex
Switch(config)#vlan 406
Switch(config-vlan)#ex
(3)指定接口网关地址
Switch(config)#inter
Switch(config)#interface vla
Switch(config)#interface vlan 501
%LINK-5-CHANGED: Interface Vlan501, changed state to up
Switch(config-if)#ip ad
Switch(config-if)#ip address 10.63.201.254 255.255.255.0
Switch(config-if)#exi
Switch(config)#inter
Switch(config)#interface vlan 406
%LINK-5-CHANGED: Interface Vlan406, changed state to up
Switch(config-if)#ip address 10.63.206.126 255.255.255.128
Switch(config-if)#ex
(4)添加对应vlan的地址池
Switch(config)#ip dhcp pool vlan501
Switch(dhcp-config)#net
Switch(dhcp-config)#network 10.63.201.0 255.255.255.0
Switch(dhcp-config)#default-router 10.63.201.254
Switch(dhcp-config)#dns-server 10.10.2.1
Switch(dhcp-config)#ex
Switch(config)#ip dhcp po
Switch(config)#ip dhcp pool vlan406
Switch(dhcp-config)#network 10.63.206.0 255.255.255.128
Switch(dhcp-config)#default-router 10.63.206.126
Switch(dhcp-config)#dns-server 10.10.2.1
Switch(dhcp-config)#ex
Switch(config)#
(5)启用trunk模式
Switch(config)#interface f
Switch(config)#interface fastEthernet 0/1
Switch(config-if)#sw
Switch(config-if)#switchport mode trunk
Command rejected: An interface whose trunk encapsulation is "Auto" can not be configured to "trunk" mode.
Switch(config-if)#exi
Switch(config)#ex
%SYS-5-CONFIG_I: Configured from console by console
Switch#write // 保存一下
3、在汇聚交换机上的操作
Switch>
Switch>en
Switch#conf
Configuring from terminal, memory, or network [terminal]?
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#
(1)添加telnet用户口令
Switch(config)#line vty
Switch(config)#line vty 0 4
Switch(config-line)#login
% Login disabled on line 66, until 'password' is set
% Login disabled on line 67, until 'password' is set
% Login disabled on line 68, until 'password' is set
% Login disabled on line 69, until 'password' is set
% Login disabled on line 70, until 'password' is set
Switch(config-line)#pas
Switch(config-line)#password 123123
Switch(config-line)#exi
(2)添加vlan
Switch(config)#vlan 501
Switch(config-vlan)#ex
Switch(config)#vlan 406
Switch(config-vlan)#ex
(3)对应的接口启用trunk模式
Switch(config)#inter
Switch(config)#interface gigabitEthernet 1/1
Switch(config-if)#no shutdown
Switch(config-if)#sw
Switch(config-if)#switchport m
Switch(config-if)#switchport mode trunk
%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet1/1, changed state to down
%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet1/1, changed state to up
Switch(config-if)#ex
Switch(config)#inter
Switch(config)#interface f
Switch(config)#interface fastEthernet 0/1
Switch(config-if)#sw
Switch(config-if)#sw
itchport mode t
Switch(config-if)#switchport mode trunk
%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)#no shutdown
Switch(config-if)#ex
Switch(config)#
(4)添加管理地址
Switch(config)#inter
Switch(config)#interface vlan 1
Switch(config-if)#no shutdown
%LINK-5-CHANGED: Interface Vlan1, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan1, changed state to up
Switch(config-if)#ip address 10.63.207.129 255.255.255.128
Switch(config-if)#ex
Switch(config)#ip default-gateway 10.63.207.254
Switch(config)#ex
%SYS-5-CONFIG_I: Configured from console by console
Switch#
4、在接入交换机上的操作
Switch>en
Switch#conf
Configuring from terminal, memory, or network [terminal]?
Enter configuration commands, one per line. End with CNTL/Z.
(1)添加telnet用户口令
Switch(config)#line vty
Switch(config)#line vty 0 4
Switch(config-line)#login
% Login disabled on line 66, until 'password' is set
% Login disabled on line 67, until 'password' is set
% Login disabled on line 68, until 'password' is set
% Login disabled on line 69, until 'password' is set
% Login disabled on line 70, until 'password' is set
Switch(config-line)#pas
Switch(config-line)#password 123123
Switch(config-line)#exi
(2)添加vlan
Switch(config)#vlan 501
Switch(config-vlan)#ex
Switch(config)#vla
Switch(config)#vlan 406
Switch(config-vlan)#ex
(3)启用trunk模式
Switch(config)#inter
Switch(config)#interface g
Switch(config)#interface gigabitEthernet 1/1
Switch(config-if)#no shutdown
Switch(config-if)#sw
Switch(config-if)#switchport mode trunk
Switch(config-if)#ex
(4)将对应的接口划入对应vlan
Switch(config)#inter
Switch(config)#interface range f
Switch(config)#interface range fastEthernet 0/1-10
Switch(config-if-range)#no shutdown
Switch(config-if-range)#sw
Switch(config-if-range)#switchport access vlan 501
Switch(config-if-range)#ex
Switch(config)#inter
Switch(config)#interface r
Switch(config)#interface range f
Switch(config)#interface range fastEthernet 0/11-20
Switch(config-if-range)#no shutdown
Switch(config-if-range)#switchport ac
Switch(config-if-range)#switchport access vla
Switch(config-if-range)#switchport access vlan 406
Switch(config-if-range)#ex
(5)添加管理vlan的管理地址
Switch(config)#inter
Switch(config)#interface vlan 1
Switch(config-if)#ip ad
Switch(config-if)#ip address 10.63.207.130 255.255.255.128
Switch(config-if)#exi
Switch(config)#ip default-gateway 10.63.207.254
Switch(config)#ex
Switch#write //保存一下
Switch#
5、检验一下,看看能否自动获取ip地址
6、ping一下,试试
7、本次试验已经完成,如果读者有什么疑问欢迎留言交流。
本文出自 “刘飞的博客空间” 博客