靜態路由:由人,手動寫出的路由條目就叫靜態路由,永久有效,優先級最高,效率最高,
路由器是干啥的?
連接不同地址段的網路,屏蔽不同地址段的網路廣播,
路由器有多個介面,至少得有2個吧,一邊一個局域網,

-
查詢路由表里的路由條目
show ip routeR1#show ip route Codes: 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 i - IS-IS, su - IS-IS summary, 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 C 192.168.0.0/24 is directly connected, FastEthernet1/0C:代表直連的意思,就是說我使用介面1/0,可以連接192.168.0.0/24網路上的任意主機,
-
不退出全域模式,在全域模式下執行特權模式下的命令:在原來特權模式下的命令的前面加do
R2(config)#do show ip interface brief Interface IP-Address OK? Method Status Protocol FastEthernet0/0 192.168.0.2 YES manual up up FastEthernet1/0 unassigned YES unset administratively down down R2(config)# -
測驗2個點是否聯通:ping
R1#ping 192.168.0.2 Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 192.168.0.2, timeout is 2 seconds: .!!!! Success rate is 80 percent (4/5), round-trip min/avg/max = 60/61/64 ms R1#ping 192.168.0.2執行結果里的【.!!!!】的含義:!代表通了;.代表不通,只要有一個!,就說明通了,至于為什么有第一個點,是因為ARP的原因,
-
假設路由器有2個介面,介面f0/0的ip地址是:192.168.0.1/24,那么就不能把另一個介面f1/0的ip地址配置成和介面f0/0是同一個網段的ip地址了,會報出下面的錯誤:【% 192.168.0.0 overlaps with FastEthernet0/0】,
路由器就是為連接不同地址段網路而生的,2個介面設定成了相同的地址段,就變成交換機(swith)了,那就不如直接用交換機了,交換機比路由器便宜多了,
R2(config)#do show ip interface brief Interface IP-Address OK? Method Status Protocol FastEthernet0/0 192.168.0.2 YES manual up up FastEthernet1/0 unassigned YES unset administratively down down R2(config)#interface f1/0 R2(config-if)#ip addres 192.168.0.3 255.255.255.0 % 192.168.0.0 overlaps with FastEthernet0/0由此可見路由器是連接不同局域網的,并且隔離2個局域網的廣播,
-
ping使用的協議是ICMP,ICMP協議是網路層協議,
從一個路由器A的一個介面f0/0,ping另一個路由器B的一個非直連介面f1/0的地址的場景,這2個介面處于不同的網路段:
ping要使用ICMP協議,ICMP協議的報文里要求有源IP地址和目的IP地址,由于無法知道(路由器A里的路由表里沒有路由器B里f1/0網段的條目)從哪個介面出去,就無法知道源IP地址,所以ICMP協議的包就無法做成,當然就無法發送,所以ping不通,
ping,必須能去而且還能回來才能ping通,
添加路由條目
方法1,不指定出介面,也就是沒有指定源IP,需要路由器去遞回查詢一次,才能獲得出介面的源ip:ip route 192.168.1.0 255.255.255.0 192.168.0.2
192.168.1.0 255.255.255.0:是目標網路
192.168.0.2:是下一跳,
為了能夠訪問192.168.1.0 255.255.255.0網路,必須借助192.168.0.2,作為跳板,
R1(config)#ip route 192.168.1.0 255.255.255.0 192.168.0.2
R1(config)#do show ip route
Gateway of last resort is not set
C 192.168.0.0/24 is directly connected, FastEthernet1/0
S 192.168.1.0/24 [1/0] via 192.168.0.2
S:代表靜態路由的意思,
方法2,不指定下一跳,但是指定了出介面,沒下一跳,路由尋址慢:ip route 192.168.1.0 255.255.255.0 f1/0
R1(config)#ip route 192.168.1.0 255.255.255.0 f1/0
R1#show ip route
C 192.168.0.0/24 is directly connected, FastEthernet1/0
S 192.168.1.0/24 is directly connected, FastEthernet1/0
方法3,既指定出介面又指定下一跳:ip route 192.168.1.0 255.255.255.0 f1/0 192.168.0.2
R1(config)#ip route 192.168.1.0 255.255.255.0 f1/0 192.168.0.2
R1(config)#do show ip route
C 192.168.0.0/24 is directly connected, FastEthernet1/0
S 192.168.1.0/24 [1/0] via 192.168.0.2, FastEthernet1/0
這種方式最好
末梢網路:只通過一個下一跳去所有的網路,
比如公司,公司里面的主機都是私有ip,公司只有一個公網ip,所以需要把路由器的下一跳指定成這個公網ip,
S 0.0.0.0/0 [1/0] via 公網ip, FastEthernet1/0

負載均衡路由條目:
目的地是相同的,有很多通路都可以到達目的地,為了避免某幾條路由過于擁堵,就使用負載均衡路由條目,把請求平均分配到每條路由,
S 0.0.0.0/0 [1/0] via 192.168.0.2,192.168.1.2,192.168.2.2 ...
掩碼最長匹配原則
當有1個以上路由條目都可以到達目的地時,選用那條路由呢?
選用掩碼最長的,
例如:目的地是192.168.2.1,路由條目有2條,如下所示,這2條都可以到達,但選用的是S 192.168.2.1 /32,因為它的掩碼的長度是32,另一個是24.
S 192.168.2.1 /32 via ...
S 192.168.2.0 /24 via ...
例如:訪問12.2.0.0時,12.1.1.0/24和12.1.1.0/24都不匹配,只能匹配12.0.0.0/8
12.1.1.1/32
12.1.1.0/24
12.0.0.0/8
靜態路由的優缺點:


轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/142922.html
標籤:Linux
