路由器的基本配置

  路由器(Router)又称网关设备(Gateway)是用于连接多个逻辑上分开的网络,用于指导IP报文转发的路径信息。路由和交换机之间的主要区别就是交换机发生在OSI参考模型第二层(数据链路层),而路由发生在第三层,即网络层。

路由功能

  路由器的核心作用是实现网络互连,数据转发:

  • 路由(寻径):路由表建立、刷新
  • 交换:在网络之间转发分组数据
  • 隔离广播,指定访问规则
  • 异种网络互连
  • 子网间速率匹配

路由工作原理

  路由器通过路由决定数据的转发 , 转发策略称为路由选择(routing),这也是路由器名称的由来(router,转发者)。路由器转发IP分组时,只根据IP分组目的IP地址的网络号部分选择合适的端口把IP分组送出去。也就是说路由器也要判定端口所接的是否是目的子网。如果是,就把分组通过端口送到网络上;否则,也要选择下一个路由器来传送分组 ;路由器也有它的默认网关,用来传送不知道往哪儿送的IP分组。这样,通过路由器把知道如何传送的IP分组正确转发出去,不知道的IP分组送给“默认网关”路由器,这样一级一级地传送,IP分组最终将送到目的地,送不到目的地的IP分组则被网络丢弃了。
  简单的说就是, 每个路由器都有一个 “路由表”(存在于路由器RAM中), 路由器的转发根据路由表决定 数据转发路径,当路由器检查到包的目的IP地址时,他就可以根据路由表的内容决定包应该转发到哪个下一跳的地址上去。

路由表结构

这里写图片描述

Name description
172.16.8.0 目的逻辑网络地址或子网地址
255.255.255.0 目的逻辑网络地址或子网地址的网络掩码
1.1.1.1 下一跳逻辑地址
Fei_0/1 学习到这条路由的接口和数据转发接口
Static 路由器学习到这条路由的方式
1 路由优先级
0 Metrix值

路由器的配置

1、常用命令列举
这里写图片描述
这里写图片描述
2、实例应用
这里写图片描述

配置上图所示网络拓扑图, 这里采用的是静态路由配置方法,代码如下:

----------------------------------------------第一台路由器----------------------------------------------
Router>enable
Router#configure terminal 
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#no ip domain-lookup 
Router(config)#hostname RA
RA(config)#interface f0/1
RA(config-if)#ip address 172.30.1.1 255.255.255.0
RA(config-if)#no shutd
RA(config-if)#no shutdown 

RA(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/1, changed state to up

RA(config-if)#end
RA#
%SYS-5-CONFIG_I: Configured from console by console

RA#config
RA#configure t
Enter configuration commands, one per line. End with CNTL/Z.
RA(config)#interface f 0/0
RA(config-if)#ip address 192.168.1.1 255.255.255.0
RA(config-if)#no shutd
RA(config-if)#no shutdown 
RA(config-if)#end
RA#
%SYS-5-CONFIG_I: Configured from console by console

RA#wr
Building configuration...
[OK]
RA#show ip conf
RA#show ip confi
RA#show ip interface brief
Interface IP-Address OK? Method Status Protocol 
FastEthernet0/0 192.168.1.1 YES manual up up 
FastEthernet0/1 172.30.1.1 YES manual up down 
Vlan1 unassigned YES unset administratively down down
RA#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up

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

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

----------------------------------------------第二台路由器----------------------------------------------
Router>en
Router#configure t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#hostname RB
RB(config)#interface f 0/0
RB(config-if)#ip address 192.168.2.1 255.255.255.0
RB(config-if)#no shutdown

RB(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up

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

RB(config-if)#exit
RB(config)#interface f 0/1
RB(config-if)#ip address 172.30.1.2 255.255.255.0
RB(config-if)#no shutd
RB(config-if)#no shutdown 

RB(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/1, changed state to up

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

RB(config-if)#end
RB#
%SYS-5-CONFIG_I: Configured from console by console

RB#wr
Building configuration...
[OK]
RB#
RB#show ip interface brief
Interface IP-Address OK? Method Status Protocol 
FastEthernet0/0 192.168.2.1 YES manual up up 
FastEthernet0/1 172.30.1.2 YES manual up up 
Vlan1 unassigned YES unset administratively down down
RB#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to down

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

----------------------------------------------设置路由器登录密码----------------------------------------------


RA>en
RA#conf t
Enter configuration commands, one per line. End with CNTL/Z.
RA(config)#line vty 0 4  # 配置进入特权模式的密码
RA(config-line)#passw vty
RA(config-line)#login
RA(config-line)#exit

RA(config)#enable secret able  # 远程登陆密码


----------------------------------------------静态路由设置----------------------------------------------

ip route 目的地址 下一跳地址

RB:
RB>en
RB#conf t
Enter configuration commands, one per line. End with CNTL/Z.
RB(config)#ip route 192.168.1.0 255.255.255.0 172.30.1.1
RB(config)#exit
RB#
%SYS-5-CONFIG_I: Configured from console by console

RB#sh ip rou
RB#sh ip route 
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

172.30.0.0/24 is subnetted, 1 subnets
C 172.30.1.0 is directly connected, FastEthernet0/1
S 192.168.1.0/24 [1/0] via 172.30.1.1
C 192.168.2.0/24 is directly connected, FastEthernet0/0


RA:


RA>en
Password: 
Password: 
RA#conf t
Enter configuration commands, one per line. End with CNTL/Z.
RA(config)#ip route 192.168.3.0 255.255.255.0 172.30.1.2
RA(config)#exit
RA#
%SYS-5-CONFIG_I: Configured from console by console

RA#sh ip route
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

172.30.0.0/24 is subnetted, 1 subnets
C 172.30.1.0 is directly connected, FastEthernet0/1
C 192.168.1.0/24 is directly connected, FastEthernet0/0
S 192.168.3.0/24 [1/0] via 172.30.1.2

猜你喜欢

转载自blog.csdn.net/jeffery0207/article/details/80155350