一、使用静态路由的优缺点 静态路由的缺点是不能动态反映网络拓扑,当网络拓扑发生变化时,管理员就必须手工改变路由表;然而静态路不会占用路由器太多的CPU 和RAM 资源,也不占用线路的带宽。如果出于安全的考虑想隐藏网络的某些部分或者管理员想控制数据转发路径,也会使用静态路由。在一个小而简单的网络中,也常使用静态路由,因为配置静态路由会更为简捷。
. H( D2 }. b6 m& S/ s& I2 |; n, X [4 { 二、配置静态路由的命令
( j% I5 n$ ` r( ~6 a" \5 o. m ip route 目的网络 掩码 { 网关地址 | 接口 }
$ F5 |/ d y! X. _. k 例子:ip route 192.168.1.0 255.255.255.0 s0/0
+ c0 f4 ]# q# x6 ?. Q; x" ~ 例子:ip route 192.168.1.0 255.255.255.0 12.12.12.2
2 C9 i' d4 I, ^. h& y 在写静态路由时,如果链路是点到点的链路(例如PPP 封装的链路),采用网关地址和9 c& N% _. k" h( s2 z& A' y6 w: o
接口都是可以的;然而如果链路是多路访问的链路(例如以太网),则只能采用网关地址,
" f, j( I$ ? v4 P e9 m9 X 即不能:ip route 192.168.1.0 255.255.255.0 f0/0 。
/ `4 d. v# M" {8 b; }8 a4 M0 s 三、静态路由实验# R& N ?! h; c, u0 T
网络拓扑图:
" V$ Y. ?* ? ~$ D" [9 o* G
! y, w) F" S' J- a1 r% N0 ?/ f) e+ K* p 4 ]3 s. j+ D; i5 P! X
具体配置命令:' [, v' p" H( h5 S
Route A配置:
+ o+ o; F5 |$ O! o0 t Router>enable- C) z. Q7 |" x1 r7 P' f$ Z5 F
Router#config terminal$ `9 v& M, l; I2 ?. r+ L5 A8 h
Router(config)#hostname RouteA //修改路由器名称
; _5 x) C# |/ R4 Z* ] RouteA(config)#int f0/1 //进入FO/1接口模式
% M) F3 Q/ ]4 E! c" n RouteA(config-if)#ip address 1.1.1.2 255.255.255.0 //配置ip0 r( ?) y9 J! C
RouteA(config-if)#no shutdown //开启端口5 Z% |" c" j# k' x
RouteA(config-if)#int s0/0
1 p6 K: r- L4 O2 d2 ^4 j RouteA(config-if)#ip address 192.168.12.1 255.255.255.0/ d; w; M0 A! f$ V* c, {0 z
RouteA(config-if)#no shut
) ]8 {8 c$ a" v3 W! p RouteA(config-if)#exit
* Q1 j5 F m! K [ I/ q' Z0 | RouteA(config)#exit
, I* {% }/ D% ]; Y# Z4 E- } RouteA#copy run start //保存当前配置
; v% f- X6 a' Z; E' I' Z Destination filename [startup-config]?
7 \* T8 s! n# J" t Building configuration...
}# i5 g, i, D [OK]
/ C. z& ?% ^, d, B+ Y Route B配置:" {: u- q( |7 o R* K7 Q
Router>enable! L7 x' N& J5 E7 k9 a: }9 ~
Router#config terminal0 a- m3 b \6 O- o
RouterB(config)#hostname RouterB
9 d! [! [3 {* H ^( } RouterB(config)#int f0/1, X2 }7 ^4 m) Y1 s9 B
RouterB(config-if)#ip address 2.2.2.1 255.255.255.0
% t" c9 |7 v" w, [$ S8 W8 ] RouterB(config-if)#no shut3 L$ \6 W3 C5 o3 M* R
RouterB(config-if)#int s0/01 j K3 g8 G& F! n1 E2 w
RouterB(config-if)#ip address 192.168.12.2 255.255.255.03 g" o% t4 w2 K' b* Q$ e1 g
RouterB(config-if)#clock rate 128000 //配置时钟
' y! _. X. X: h RouterB(config-if)#no shut, Y+ A* `( ?2 ^, y C1 J
RouterB(config)#in s0/1( ?" f+ @4 X6 L% ~
RouterB(config-if)#ip address 192.168.23.1 255.255.255.0
" d2 `3 ]5 }6 X6 v5 A, d RouterB(config-if)#clock rate 128000' y$ t" m. H, E7 A
RouterB(config-if)#no shut
: m* b( D2 d! d) f) s( @ RouterB(config-if)#
) G- \7 C* g3 z# A9 L4 i RouterB(config-if)#exit
" ^, H4 a5 A4 w' y[NextPage]# |/ I- x; h1 A
Route C配置:
" x; `& e' G& m. x Router>enable/ Q/ E3 P' {5 n% Y
Router#config terminal
2 y* i& M$ u3 W; _9 S1 R; D Router#hostname RouterC: l: f' w. |( ?( B
RouterC(config)#int s0/0
7 h- @3 e& O: E/ D! Z1 w$ Y" l4 G RouterC(config-if)#ip address 192.168.23.2 255.255.255.0
) N+ k* k, M& Y RouterC(config-if)#no shut
& ~; ^7 B2 M$ P( K& D+ L, W6 y RouterC(config-if)#int f0/1
w# N0 e# ?6 U9 ? RouterC(config-if)#ip address 3.3.3.1 255.255.255.0
! b8 }8 D/ H+ T4 X2 z3 V8 p' V RouterC(config-if)#no shut! K( o- ~9 o& }* U5 [' h1 P
RouterC(config-if)#exit0 I8 ~" ~1 n# `" `) |# a
RouterC(config)#exit
1 `2 F8 w$ j6 N" O RouterC#copy run start; k( ]4 t1 q+ c, `
Destination filename [startup-config]?
" J& z! d4 u- L+ v4 i Building configuration...
9 S% B0 f( ?1 |7 z( K; a6 y, F; b) s [OK]
. [. G/ P* N1 K. G& e Router>enable6 @2 O/ t* C3 p* L3 C4 |+ Q& X
Router#config terminal
& N; G/ H/ K. a: M u, v* _4 V Router(config)#hostname RouteA //修改路由器名称
% l' B3 f& r' z1 c( [ RouteA(config)#int f0/1 //进入FO/1接口模式
( f! g( j7 {9 M1 N: C/ j# L RouteA(config-if)#ip address 1.1.1.2 255.255.255.0 //配置ip, H2 T; ~2 @' F
RouteA(config-if)#no shutdown //开启端口
3 J6 E8 w* R8 }6 @! B RouteA(config-if)#int s0/0& d4 L, a4 w4 R$ H& z
RouteA(config-if)#ip address 192.168.12.1 255.255.255.0
/ R( D. }- }/ q& q RouteA(config-if)#no shut
$ r9 W- L% E* q6 U RouteA(config-if)#exit1 C4 g( b' J5 a3 f- a+ z
RouteA(config)#exit
- P! k# f. Q( u6 N, b( ] RouteA#copy run start //保存当前配置
6 L: A; ^8 U& z' g6 j1 \# _8 K/ ~ Destination filename [startup-config]?
( @; L, k4 F, N1 Z$ L6 i Building configuration...9 ?0 ~0 V9 d2 U5 d% }( ]$ F$ T
[OK]* z, B Q P0 z# W
Router>enable
; i$ \7 A6 }. u K9 q9 u, O$ M7 z+ n7 d& M$ u Router#config terminal; D6 n# A- x% l; m& X
RouterB(config)#hostname RouterB
4 j; x+ A- V0 l6 b RouterB(config)#int f0/1* s$ a9 N. Z* y1 d" S
RouterB(config-if)#ip address 2.2.2.1 255.255.255.05 o1 s ^! D/ ]" s0 F! C3 }
RouterB(config-if)#no shut
: ?- l. @1 l1 w1 Q9 k* P. m RouterB(config-if)#int s0/08 e1 ]4 ~0 b& k s% j8 q# J
RouterB(config-if)#ip address 192.168.12.2 255.255.255.05 f/ ^) `! K2 x- Z- T
RouterB(config-if)#clock rate 128000 //配置时钟
' i2 F8 \4 M( z1 \4 a% c- _0 r RouterB(config-if)#no shut
* ~- [$ \( T! ^% I. M' n& M RouterB(config)#in s0/1- x4 X @ S! W; O
RouterB(config-if)#ip address 192.168.23.1 255.255.255.0
% A7 ?5 f ~4 V; [# u* I RouterB(config-if)#clock rate 128000
( D% `4 \1 _& p7 a& g RouterB(config-if)#no shut# e6 j8 ?8 A. V; E
RouterB(config-if)#
) b& ^% R+ D/ }/ ^! y! E# i RouterB(config-if)#exit: z0 |3 q/ G4 F% S5 H
Router>enable. u& T' B1 o2 {+ @& |
Router#config terminal
6 C% t* P# P' ^; t( }+ ~) t3 p Router#hostname RouterC
# J Q! R* S# c2 \- q6 j RouterC(config)#int s0/0, f% l% d u* m
2 z) P. c9 \, k2 Y1 J j6 c( G RouterC(config-if)#ip address 192.168.23.2 255.255.255.0 |