计算机网络实验

目录

VLAN&TRUNK

静态路由和动态路由

RIP协议路由配置


VLAN&TRUNK

VLAN(Virtual Local Area Network)即虚拟局域网,是将一个物理的LAN在逻辑上划分成多个广播域的通信技术。

每个VLAN是一个广播域,VLAN内的主机间可以直接通信,而VLAN间则不能直接互通。这样,广播报文就被限制在一个VLAN内。

Vlan中继(trunk)是以太网接口之间的点对点链路,负责在单个链路上传输多个VLAN流量。

 设置主机IP

 配置交换机SW0,SW1(只显示了SW0的,SW同样步骤)

###基本操作###
switch>en//进入特权模式
Switch#conf t//进入全局配置
Enter configuration commands, one per line.  End with CNTL/Z.

Switch(config)#in f0/1//接口模式
Switch(config-if)#end//退出到特权模式
Switch#
%SYS-5-CONFIG_I: Configured from console by console

Switch(config-if)#exit//后退

switch#sh vl br//查看vlan信息
VLAN Name                             Status    Ports
---- -------------------------------- --------- -------------------------------
1    default                          active    Fa0/1, Fa0/2, Fa0/3, Fa0/4
                                                Fa0/5, Fa0/6, Fa0/7, Fa0/8
                                                Fa0/9, Fa0/10, Fa0/11, Fa0/12
                                                Fa0/13, Fa0/14, Fa0/15, Fa0/16
                                                Fa0/17, Fa0/18, Fa0/19, Fa0/20
                                                Fa0/21, Fa0/22, Fa0/23, Fa0/24
2    VLAN0002                         active    
1002 fddi-default                     active    
1003 token-ring-default               active    
1004 fddinet-default                  active    
1005 trnet-default                    active  
  
Switch#vl da//在特权模式下创建vlan
% Warning: It is recommended to configure VLAN from config mode,
  as VLAN database mode is being deprecated. Please consult user
  documentation for configuring VTP/VLAN in config mode.
Switch(vlan)#vl 2//创建2个vl,vl1默认存在
VLAN 2 modified:
Switch(vlan)#vl 3
VLAN 3 modified:
Switch(vlan)#exit//vlan模式时用exit退出
APPLY completed.
Exiting....

###将vlan加到接口上
Switch#conf t//换到全局配置
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#in f0/2
Switch(config-if)#sw mo ac
Switch(config-if)#sw ac vl 2
Switch(config-if)#exit
Switch(config)#in f0/3
Switch(config-if)#sw mo ac
Switch(config-if)#sw ac vl 3
Switch(config-if)#exit
Switch(config)#exit
Switch#
%SYS-5-CONFIG_I: Configured from console by console
sh vl br//查看vlan

VLAN Name                             Status    Ports
---- -------------------------------- --------- -------------------------------
1    default                          active    Fa0/4, Fa0/5, Fa0/6, Fa0/7
                                                Fa0/8, Fa0/9, Fa0/10, Fa0/11
                                                Fa0/12, Fa0/13, Fa0/14, Fa0/15
                                                Fa0/16, Fa0/17, Fa0/18, Fa0/19
                                                Fa0/20, Fa0/21, Fa0/22, Fa0/23
2    VLAN0002                         active    Fa0/2
3    VLAN0003                         active    Fa0/3
1002 fddi-default                     active    
1003 token-ring-default               active    
1004 fddinet-default                  active    
1005 trnet-default                    active    
Switch#

###交换机之间接口trunk模式,AUTO自适应
Switch#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#in f0/24
Switch(config-if)#sw mo tr
Switch(config-if)#end
Switch#
%SYS-5-CONFIG_I: Configured from console by console

配置好后用PC1测试主机连接,只能访问同一个vlan下的主机。

静态路由和动态路由

网关(Gateway)又称网间连接器协议转换器。

情景:位于两个校区之间的主机通信

 配置主机ip

配置路由器R0,R1,R2(这里只展示了R0)

(1)配置两个接口的ip


Continue with configuration dialog? [yes/no]: n


Press RETURN to get started!


###进入特权模式配置路由器接口ip
Router>en
Router#conf t
Enter configuration commands, one per line.  End with CNTL/Z.

Router(config)#in f0/0
Router(config-if)#ip ad 192.168.2.1 255.255.255.0
Router(config-if)#no sh
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
Router(config-if)#exit

Router(config)#in f0/1
Router(config-if)#ip ad 192.168.1.1 255.255.255.0
Router(config-if)#no sh
%LINK-5-CHANGED: Interface FastEthernet0/1, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up

###查看路由器配置情况
Router(config-if)#end
Router#
%SYS-5-CONFIG_I: Configured from console by console
sh ru
Building configuration...

Current configuration : 476 bytes
!
version 12.4
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname Router
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
interface FastEthernet0/0
 ip address 192.168.2.1 255.255.255.0
 duplex auto
 speed auto
!
interface FastEthernet0/1
 ip address 192.168.1.1 255.255.255.0
 duplex auto
 speed auto
!
interface Vlan1
 no ip address
 shutdown
!
ip classless
!
!
!
!
!
!
!
line con 0
line vty 0 4
 login
!
!
!
end

(2)配置静态路由格式:目的ip 子网掩码 下一跳ip 

配置R0

Router>en 
Router#conf t
Enter configuration commands, one per line.  End with CNTL/Z.

Router(config)#ip route 0.0.0.0 0.0.0.0 192.168.2.2
Router(config)#end
Router#
%SYS-5-CONFIG_I: Configured from console by console

Router#sh ip ro
Codes: C - connected, S - static, I - IGRP, 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 192.168.2.2 to network 0.0.0.0

C    192.168.1.0/24 is directly connected, FastEthernet0/1
C    192.168.2.0/24 is directly connected, FastEthernet0/0
S*   0.0.0.0/0 [1/0] via 192.168.2.2
Router#

 配置R1

Router#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#ip route 192.168.1.0 255.255.255.0 192.168.2.1
Router(config)#ip route 192.168.4.0 255.255.255.0 192.168.3.2
Router(config)#end
Router#
%SYS-5-CONFIG_I: Configured from console by console

Router#sh ip ro
Codes: C - connected, S - static, I - IGRP, 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

S    192.168.1.0/24 [1/0] via 192.168.2.1
C    192.168.2.0/24 is directly connected, FastEthernet0/0
C    192.168.3.0/24 is directly connected, FastEthernet0/1
S    192.168.4.0/24 [1/0] via 192.168.3.2
Router#

测试PC之间的连接

RIP协议路由配置

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值