IP路由原理
一.什么是路由
路由是指导IP报文发送的路径信息。
二.路由表的构成
路由表是路由器转发报文的判断依据
三.路由器单跳操作
四.路由表查找规则
1.选择度量值小的进行转发
2.永远将下一跳地址指向直连路由
3.如果路由表中没有相匹配的主机路由去匹配就会丢弃,但是如果存在默认路由的话,会默认从默认路由转发。
五.路由的来源
1.直连路由
开销小,配置简单,无需人工维护。只能发现本接口所属网段的路由
2.手工配置的静态路由
无开销,配置简单,需人工维护,适合简单拓扑结构的网络
3.路由协议发现的动态路由
开销大,配置复杂,无需人工维护,适合复杂拓扑结构的网络
六.路由度量值(Metric)
1.路由度量值表示到达折条路由所指目的地址的代价。
2.通常影响路由度量值的因素:
线路演示,带宽,线路使用率,线路可信度,跳数,最大传输单元
3.不同路由协议参考的因素不同
七.路由优先级
如果到相同目的地址有多个路由来源,则:
a>.以Preference(优先级)确定不同类型优先级;
b>.Preference越小,优先级越高;
c>.优先级最高的路由被添加进路由表
八.各类路由默认优先级
九.路由环路
环路产生的原因:配置错误或协议缺陷
十.实验:
1.单臂路由的配置不同VLAN互通。
以上是一个简单“单臂路由”拓扑图:
a.实现思路:1>.在22层交换机上划分不同的vlan,并将相应的端口加入不同的 VLAN中;
2>.在路由器上配置子接口IP位各个部门员工的网关IP;
3>.不同的VLAN只要经过三层设备就能成功的访问到其他不同的VLAN了;
b.配置过程如下:
注意:为了操作方便我将“22层核心交换机”更名为core,将“网关出口”更名为gw
22层核心交换机配置如下:
22层核心交换机配置
[Huawei]sysname core
[core]interface GigabitEthernet 0/0/1
[core-GigabitEthernet0/0/1]port link-type access #将改口配置为access口
[core-GigabitEthernet0/0/1]quit
[core]interface GigabitEthernet 0/0/2
[core-GigabitEthernet0/0/2]port link-type access
[core-GigabitEthernet0/0/2]quit
[core]interface GigabitEthernet 0/0/3
[core-GigabitEthernet0/0/3]port link-type access
[core-GigabitEthernet0/0/3]quit
[core]interface GigabitEthernet 0/0/4
[core-GigabitEthernet0/0/4]port link-type access
[core-GigabitEthernet0/0/4]quit
[core]interface GigabitEthernet 0/0/5
[core-GigabitEthernet0/0/5]port link-type access
[core-GigabitEthernet0/0/5]quit
[core]interface GigabitEthernet 0/0/10
[core-GigabitEthernet0/0/10]port link-type trunk #将改口配置为trunk口
[core-GigabitEthernet0/0/10]port trunk allow-pass vlan all
[core-GigabitEthernet0/0/10]undo shutdown
[core-GigabitEthernet0/0/10]quit
[core]vlan 10
[core-vlan10]port GigabitEthernet 0/0/1 #将端口加入该VLAN10中
[core-vlan10]vlan 20
[core-vlan20]port GigabitEthernet 0/0/2
[core-vlan20]vlan 30
[core-vlan30]port GigabitEthernet 0/0/3
[core-vlan30]vlan 40
[core-vlan40]port GigabitEthernet 0/0/4
[core-vlan40]vlan 50
[core-vlan50]port GigabitEthernet 0/0/5
[core-vlan50]quit
[core]dis vlan 10 to 50 #查看10到50所有连续的VLAN信息
--------------------------------------------------------------------------------
U: Up; D: Down; TG: Tagged; UT: Untagged;
MP: Vlan-mapping; ST: Vlan-stacking;
#: ProtocolTransparent-vlan; *: Management-vlan;
-------------------------------------------------------------------------------- VID Type Ports
--------------------------------------------------------------------------------
10 common UT:GE0/0/1(U)
20 common UT:GE0/0/2(U)
30 common UT:GE0/0/3(U)
40 common UT:GE0/0/4(U)
50 common UT:GE0/0/5(U) VID Status Property MAC-LRN Statistics Description
--------------------------------------------------------------------------------
10 enable default enable disable VLAN 0010
20 enable default enable disable VLAN 0020
30 enable default enable disable VLAN 0030
40 enable default enable disable VLAN 0040
50 enable default enable disable VLAN 0050
[core]
网关出口配置过程如下:
出口网关配置
[Huawei]sysname gw
[gw]interface Ethernet 0/0/0
[gw-Ethernet0/0/0]undo shutdown #将物理接口配置成不关闭状态
[gw-Ethernet0/0/0]quit
[gw]interface Ethernet 0/0/0.1
[gw-Ethernet0/0/0.1]vlan-type dot1q 10 #将该子接口172封装成trunk,允许VLAN透传。
[gw-Ethernet0/0/0.1]ip address 172.30.1.254 255.255.255.0 #给该虚接口配置一个地址,也是 172.30.1.0/24的网管地址
[gw-Ethernet0/0/0.1]undo shutdow #该接口不启状态
[gw-Ethernet0/0/0.1]quit
[gw]interface Ethernet 0/0/0.2
[gw-Ethernet0/0/0.2]vlan-type dot1q 20
[gw-Ethernet0/0/0.2]ip address 172.30.2.254
[gw-Ethernet0/0/0.2]undo shutdown
[gw-Ethernet0/0/0.2]quit
[gw]interface Ethernet 0/0/0.3
[gw-Ethernet0/0/0.3]vlan-type dot1q 30
[gw-Ethernet0/0/0.3]ip address 172.30.3.254 24
[gw-Ethernet0/0/0.3]undo shutdown
[gw-Ethernet0/0/0.3]quit
[gw]interface Ethernet 0/0/0.4
[gw-Ethernet0/0/0.4]vlan-type dot1q 40
[gw-Ethernet0/0/0.4]ip address 172.30.4.254 24
[gw-Ethernet0/0/0.4]undo shutdown
[gw-Ethernet0/0/0.4]quit
[gw]interface Ethernet 0/0/0.5
[gw-Ethernet0/0/0.5]vlan-type dot1q 50
[gw-Ethernet0/0/0.5]ip address 172.30.5.254 24
[gw-Ethernet0/0/0.5]undo shutdown
[gw-Ethernet0/0/0.5]quit
[gw]
运维部门电脑测试结果如下:
PC>
PC>ipconfig Link local IPv6 address...........: fe80::5689:98ff:fea7:2066
IPv6 address......................: :: / 128
IPv6 gateway......................: ::
IPv4 address......................: 172.30.3.1
Subnet mask.......................: 255.255.255.0
Gateway...........................: 172.30.3.254
Physical address..................: 54-89-98-A7-20-66
DNS server........................: PC>ping 172.30.1.1 Ping 172.30.1.1: 32 data bytes, Press Ctrl_C to break
From 172.30.1.1: bytes=32 seq=1 ttl=127 time=78 ms
From 172.30.1.1: bytes=32 seq=2 ttl=127 time=47 ms
From 172.30.1.1: bytes=32 seq=3 ttl=127 time=62 ms
From 172.30.1.1: bytes=32 seq=4 ttl=127 time=62 ms
From 172.30.1.1: bytes=32 seq=5 ttl=127 time=62 ms --- 172.30.1.1 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 47/62/78 ms PC>ping 172.30.2.1 Ping 172.30.2.1: 32 data bytes, Press Ctrl_C to break
From 172.30.2.1: bytes=32 seq=1 ttl=127 time=47 ms
From 172.30.2.1: bytes=32 seq=2 ttl=127 time=62 ms
From 172.30.2.1: bytes=32 seq=3 ttl=127 time=47 ms
From 172.30.2.1: bytes=32 seq=4 ttl=127 time=62 ms
From 172.30.2.1: bytes=32 seq=5 ttl=127 time=47 ms --- 172.30.2.1 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 47/53/62 ms PC>ping 172.30.3.1 Ping 172.30.3.1: 32 data bytes, Press Ctrl_C to break
From 172.30.3.1: bytes=32 seq=1 ttl=128 time<1 ms
From 172.30.3.1: bytes=32 seq=2 ttl=128 time<1 ms
From 172.30.3.1: bytes=32 seq=3 ttl=128 time<1 ms
From 172.30.3.1: bytes=32 seq=4 ttl=128 time<1 ms
From 172.30.3.1: bytes=32 seq=5 ttl=128 time<1 ms --- 172.30.3.1 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 0/0/0 ms PC>ping 172.30.4.1 Ping 172.30.4.1: 32 data bytes, Press Ctrl_C to break
From 172.30.4.1: bytes=32 seq=1 ttl=127 time=63 ms
From 172.30.4.1: bytes=32 seq=2 ttl=127 time=46 ms
From 172.30.4.1: bytes=32 seq=3 ttl=127 time=63 ms
From 172.30.4.1: bytes=32 seq=4 ttl=127 time=62 ms
From 172.30.4.1: bytes=32 seq=5 ttl=127 time=47 ms --- 172.30.4.1 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 46/56/63 ms PC>ping 172.30.5.1 Ping 172.30.5.1: 32 data bytes, Press Ctrl_C to break
From 172.30.5.1: bytes=32 seq=1 ttl=127 time=63 ms
From 172.30.5.1: bytes=32 seq=2 ttl=127 time=62 ms
From 172.30.5.1: bytes=32 seq=3 ttl=127 time=47 ms
From 172.30.5.1: bytes=32 seq=4 ttl=127 time=62 ms
From 172.30.5.1: bytes=32 seq=5 ttl=127 time=93 ms --- 172.30.5.1 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 47/65/93 ms PC>
c.总结单臂路由的优缺点:
优点:
1>实现了不同VLAN的互通。
2>.只需要一个物理接口能给多个VLAN配置网关,通过子接口的技术,子接口必须封装802.1Q的trunk协议。
缺点:
1>.不同VLAN的数据每次访问都要通过路由器进行路由查找,效率比较低;
2>.购买一个路由器设备比购买一个三层交换机要贵的多,性价比低!
2.三层交换配置不同VLAN互通。
a.三层交换机以内置的三层路由转发引擎执行VLAN间路由功能
b.配置过程如下:
三层核心交换机配置如下:
[Huawei]sysname core
[core]interface GigabitEthernet 0/0/1
[core-GigabitEthernet0/0/1]port link-type access #将改口配置为access口
[core-GigabitEthernet0/0/1]quit
[core]interface GigabitEthernet 0/0/2
[core-GigabitEthernet0/0/2]port link-type access
[core-GigabitEthernet0/0/2]quit
[core]interface GigabitEthernet 0/0/3
[core-GigabitEthernet0/0/3]port link-type access
[core-GigabitEthernet0/0/3]quit
[core]interface GigabitEthernet 0/0/4
[core-GigabitEthernet0/0/4]port link-type access
[core-GigabitEthernet0/0/4]quit
[core]interface GigabitEthernet 0/0/5
[core-GigabitEthernet0/0/5]port link-type access
[core-GigabitEthernet0/0/5]quit
[core]interface GigabitEthernet 0/0/10
[core-GigabitEthernet0/0/10]port link-type trunk #将改口配置为trunk口
[core-GigabitEthernet0/0/10]port trunk allow-pass vlan all
[core-GigabitEthernet0/0/10]undo shutdown
[core-GigabitEthernet0/0/10]quit
[core]vlan 10
[core-vlan10]port GigabitEthernet 0/0/1 #将端口加入该VLAN10中
[core-vlan10]vlan 20
[core-vlan20]port GigabitEthernet 0/0/2
[core-vlan20]vlan 30
[core-vlan30]port GigabitEthernet 0/0/3
[core-vlan30]vlan 40
[core-vlan40]port GigabitEthernet 0/0/4
[core-vlan40]vlan 50
[core-vlan50]port GigabitEthernet 0/0/5
[core-vlan50]quit
[core]dis vlan 10 to 50 #查看10到50所有连续的VLAN信息
--------------------------------------------------------------------------------
U: Up; D: Down; TG: Tagged; UT: Untagged;
MP: Vlan-mapping; ST: Vlan-stacking;
#: ProtocolTransparent-vlan; *: Management-vlan;
-------------------------------------------------------------------------------- VID Type Ports
--------------------------------------------------------------------------------
10 common UT:GE0/0/1(U)
20 common UT:GE0/0/2(U)
30 common UT:GE0/0/3(U)
40 common UT:GE0/0/4(U)
50 common UT:GE0/0/5(U) VID Status Property MAC-LRN Statistics Description
--------------------------------------------------------------------------------
10 enable default enable disable VLAN 0010
20 enable default enable disable VLAN 0020
30 enable default enable disable VLAN 0030
40 enable default enable disable VLAN 0040
50 enable default enable disable VLAN 0050
[core]
[core]interface Vlanif 10 #创建SVI
[core-Vlanif10]ip address 172.30.1.254 24 #给当前VLAN10配置一个管理地址。
[core-Vlanif10]undo shutdown
[core-Vlanif10]quit
[core]interface Vlanif 20
[core-Vlanif20]ip address 172.30.2.254 24
[core-Vlanif20]undo shutdown
[core-Vlanif20]quit
[core]interface Vlanif 30
[core-Vlanif30]ip address 172.30.3.254 24
[core-Vlanif30]undo shutdown
[core-Vlanif30]quit
[core]interface Vlanif 40
[core-Vlanif40]ip address 172.30.4.254 24
[core-Vlanif40]undo shutdown
[core-Vlanif40]quit
[core]interface Vlanif 50
[core-Vlanif50]ip address 172.30.5.254 24
[core-Vlanif50]undo shutdown
[core-Vlanif50]quit
运维部门电脑测试结果如下:
PC>ipconfig Link local IPv6 address...........: fe80::5689:98ff:fea7:2066
IPv6 address......................: :: / 128
IPv6 gateway......................: ::
IPv4 address......................: 172.30.3.1
Subnet mask.......................: 255.255.255.0
Gateway...........................: 172.30.3.254
Physical address..................: 54-89-98-A7-20-66
DNS server........................: PC>ping 172.30.1.1 Ping 172.30.1.1: 32 data bytes, Press Ctrl_C to break
From 172.30.1.1: bytes=32 seq=1 ttl=127 time=31 ms
From 172.30.1.1: bytes=32 seq=2 ttl=127 time=15 ms
From 172.30.1.1: bytes=32 seq=3 ttl=127 time<1 ms
From 172.30.1.1: bytes=32 seq=4 ttl=127 time=47 ms
From 172.30.1.1: bytes=32 seq=5 ttl=127 time=16 ms --- 172.30.1.1 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 0/21/47 ms PC>ping 172.30.2.1 Ping 172.30.2.1: 32 data bytes, Press Ctrl_C to break
From 172.30.2.1: bytes=32 seq=1 ttl=127 time=47 ms
From 172.30.2.1: bytes=32 seq=2 ttl=127 time<1 ms
From 172.30.2.1: bytes=32 seq=3 ttl=127 time<1 ms
From 172.30.2.1: bytes=32 seq=4 ttl=127 time=32 ms
From 172.30.2.1: bytes=32 seq=5 ttl=127 time=46 ms --- 172.30.2.1 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 0/25/47 ms PC>ping 172.30.3.1 Ping 172.30.3.1: 32 data bytes, Press Ctrl_C to break
From 172.30.3.1: bytes=32 seq=1 ttl=128 time<1 ms
From 172.30.3.1: bytes=32 seq=2 ttl=128 time<1 ms
From 172.30.3.1: bytes=32 seq=3 ttl=128 time<1 ms
From 172.30.3.1: bytes=32 seq=4 ttl=128 time<1 ms
From 172.30.3.1: bytes=32 seq=5 ttl=128 time<1 ms --- 172.30.3.1 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 0/0/0 ms PC>ping 172.30.4.1 Ping 172.30.4.1: 32 data bytes, Press Ctrl_C to break
From 172.30.4.1: bytes=32 seq=1 ttl=127 time=31 ms
From 172.30.4.1: bytes=32 seq=2 ttl=127 time=31 ms
From 172.30.4.1: bytes=32 seq=3 ttl=127 time=16 ms
From 172.30.4.1: bytes=32 seq=4 ttl=127 time=31 ms
From 172.30.4.1: bytes=32 seq=5 ttl=127 time=16 ms --- 172.30.4.1 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 16/25/31 ms PC>ping 172.30.5.1 Ping 172.30.5.1: 32 data bytes, Press Ctrl_C to break
From 172.30.5.1: bytes=32 seq=1 ttl=127 time=16 ms
From 172.30.5.1: bytes=32 seq=2 ttl=127 time=15 ms
From 172.30.5.1: bytes=32 seq=3 ttl=127 time=16 ms
From 172.30.5.1: bytes=32 seq=4 ttl=127 time<1 ms
From 172.30.5.1: bytes=32 seq=5 ttl=127 time=31 ms --- 172.30.5.1 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 0/15/31 ms PC>
c.三层交换机的优点
1>.不用路由器照样实现不同VLAN间的互通;
2>.性价比高,功能比普通二层交换机要多的多.