其他分享
首页 > 其他分享> > 学习日记——(路由与交换技术)单臂路由

学习日记——(路由与交换技术)单臂路由

作者:互联网

一、相关知识

二、简单例子

1、拓扑结构

2、相关代码

 S1:

Switch>en

Switch#conf t

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

Switch(config)#host S1

VLAN 的划分

S1(config)#vlan 10

S1(config-vlan)#e

S1(config-vlan)#exit

S1(config)#vlan 20

S1(config-vlan)#e

S1(config-vlan)#exit

将接口划分到相应的VLAN

S1(config)#int f

S1(config)#int fastEthernet 0/1

S1(config-if)#sw

S1(config-if)#switchport mo

S1(config-if)#switchport mode acc

S1(config-if)#switchport mode access

S1(config-if)#sw

S1(config-if)#switchport ac

S1(config-if)#switchport access vlan 10

S1(config-if)#e

S1(config-if)#exit

S1(config)#int fastEthernet 0/2

S1(config-if)#switchport mode access

S1(config-if)#switchport access vlan 10

S1(config-if)#e

S1(config-if)#exit

配置trunk模式

S1(config)#int fastEthernet 0/3

S1(config-if)#switchport mode t

S1(config-if)#switchport mode trunk

S1(config-if)#

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

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

S1(config-if)#

%LINK-5-CHANGED: Interface FastEthernet0/4, changed state to up

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

S1(config-if)#exit

S1(config)#

%LINK-5-CHANGED: Interface FastEthernet0/4, changed state to up

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

跟路由器相连的链路也要配置trunk 模式

S1(config)#interface fastEthernet 0/4

S1(config-if)#sw

S1(config-if)#switchport mod

S1(config-if)#switchport mode tru

S1(config-if)#switchport mode trunk

S1(config-if)#

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

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

S1(config-if)#e

S1(config-if)#exit


S2:

Switch>en

Switch#conf t

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

Switch(config)#host S2

VLAN 的划分

S2(config)#vlan 10

S2(config-vlan)#e

S2(config-vlan)#exit

S2(config)#vlan 20

S2(config-vlan)#e

S2(config-vlan)#exit

将接口划分到相应的VLAN

S2(config)#int f

S2(config)#int fastEthernet 0/1

S2(config-if)#sw

S2(config-if)#switchport mod

S2(config-if)#switchport mode ac

S2(config-if)#switchport mode access

S2(config-if)#sw

S2(config-if)#switchport ac

S2(config-if)#switchport access vlan 10

S2(config-if)#e

S2(config-if)#exit

S2(config)#int fastEthernet 0/2

S2(config-if)#switchport mode access

S2(config-if)#switchport access vlan 20

S2(config-if)#e

S2(config-if)#exit

交换机1 F0/3口配置了trunk模式,交换机2与它同一条链路上的接口也自动设置成trunk模式

S2(config)#%SPANTREE-2-RECV_PVID_ERR: Received 802.1Q BPDU on non trunk FastEthernet0/3 VLAN1.

%SPANTREE-2-BLOCK_PVID_LOCAL: Blocking FastEthernet0/3 on VLAN0001. Inconsistent port type.

S2(config)#

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

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


R1:

Router>en

Router#conf t

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

Router(config)#host R1

R1(config)#int

R1(config)#interface g

开启物理接口

R1(config)#interface gigabitEthernet 0/0

R1(config-if)#no sh

R1(config-if)#no shutdown

设置物理接口下的逻辑接口 

R1(config-if)#

%LINK-5-CHANGED: Interface GigabitEthernet0/0, changed state to up

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

R1(config-if)#e

R1(config-if)#exit

R1(config)#interface gigabitEthernet 0/0.10

R1(config-subif)#

(提示信息)%LINK-5-CHANGED: Interface GigabitEthernet0/0.10, changed state to up

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

R1(config-subif)#en

R1(config-subif)#encapsulation ?

dot1Q IEEE 802.1Q Virtual LAN

R1(config-subif)#encapsulation d

R1(config-subif)#encapsulation dot1Q 10  

R1(config-subif)#ip address 192.168.10.254 255.255.255.0

R1(config-subif)#ex

R1(config-subif)#exit

R1(config)#interface gigabitEthernet 0/0.20

R1(config-subif)#

%LINK-5-CHANGED: Interface GigabitEthernet0/0.20, changed state to up

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

R1(config-subif)#en

R1(config-subif)#encapsulation d

R1(config-subif)#encapsulation dot1Q 20

R1(config-subif)#ip add

R1(config-subif)#ip address 192.168.20.254 255.255.255.0

R1(config-subif)#ex

R1(config-subif)#exit

R1(config)#do show ip route  (配置后的路由表)

Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP

D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area

N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2

E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP

i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area

* - candidate default, U - per-user static route, o - ODR

P - periodic downloaded static route

Gateway of last resort is not set

192.168.10.0/24 is variably subnetted, 2 subnets, 2 masks

C 192.168.10.0/24 is directly connected, GigabitEthernet0/0.10

L 192.168.10.254/32 is directly connected, GigabitEthernet0/0.10

192.168.20.0/24 is variably subnetted, 2 subnets, 2 masks

C 192.168.20.0/24 is directly connected, GigabitEthernet0/0.20

L 192.168.20.254/32 is directly connected, GigabitEthernet0/0.20

R1(config)#


结果:各个网段之间能互相ping 通


这篇文章就写到这里啦,有哪些不好的欢迎指出! 

标签:R1,switchport,S2,S1,Interface,config,日记,路由,单臂
来源: https://blog.csdn.net/weixin_54055099/article/details/121315041