03路由器工作原理和配置

一、路由

  • 路由是指报文转发的路径信息,通过路由可以确定转发IP报文的路径。
  • 路由设备是根据路由转发报文到目的网段的网络设备,最常见的路由设备:路由器。
  • 路由设备维护着一张路由表,保存着路由信息。

涉及到不同网段之间的通信

  1. 直连路由
  2. 去往外网的,默认路由
  3. 给内网主机回包的,明细静态路由

网关

当数据包去往不同网段,都需要先经过网关才能到达

直连路由通信实例(同网段直连)

跟之前交换机上节一样的配置

在这里插入图片描述

修改ip设置
pc1  192.168.10.2 255.255.255.0 192.168.10.1
pc2  192.168.10.3 255.255.255.0 192.168.10.1
pc3  192.168.20.3 255.255.255.0 192.168.20.1
pc3  192.168.20.4 255.255.255.0 192.168.20.1
核心交换机上配置网关(LSW2)
[Huawei]interface vlan 10  //进入vlan10
[Huawei-Vlanif10]ip address 192.168.10.1 255.255.255.0  //配置网关
[Huawei]interface vlan 20  //进入vlan20
[Huawei-Vlanif10]ip address 192.168.20.1 255.255.255.0  //配置网关
测试192.168.10.1 ping 192.168.20.3
PC>ping 192.168.20.3

Ping 192.168.20.3: 32 data bytes, Press Ctrl_C to break
From 192.168.20.3: bytes=32 seq=1 ttl=127 time=63 ms
From 192.168.20.3: bytes=32 seq=2 ttl=127 time=62 ms
From 192.168.20.3: bytes=32 seq=3 ttl=127 time=63 ms
From 192.168.20.3: bytes=32 seq=4 ttl=127 time=63 ms
From 192.168.20.3: bytes=32 seq=5 ttl=127 time=78 ms

--- 192.168.20.3 ping statistics ---
  5 packet(s) transmitted
  5 packet(s) received
  0.00% packet loss
  round-trip min/avg/max = 62/65/78 ms

直连路由通信实例(不同网段直连)

在原来的基础上,添加一个路由器

在这里插入图片描述

用路由器来ping PC1电脑

静态路由

是指写一条路径,让ip知道怎么走

配置路由器ip
[Huawei]int g0/0/0
[Huawei-GigabitEthernet0/0/0]ip address  172.168.1.1 255.255.255.0
配置交换机LWS2ip
[Huawei]int g0/0/4
[Huawei-GigabitEthernet0/0/4]ip address 172.168.1.2 255.255.255.0
                                ^
Error: Unrecognized command found at '^' position.
//报错不支持端口直接配置ip,配置到vlan上
[Huawei]vlan 100
[Huawei]interface vlan 100
[Huawei-Vlanif100]ip address 172.168.1.2 255.255.255.0
[Huawei]int g0/0/4
[Huawei-GigabitEthernet0/0/4]port link-type ac
[Huawei-GigabitEthernet0/0/4]port default vlan 100
测试连通性

用交换机LWS2 172.168.1.2 ping 路由器172.168.1.1,用路由器172.168.1.1 ping 交换机LWS2 172.168.1.2

[Huawei]ping 172.168.1.1
  PING 172.168.1.1: 56  data bytes, press CTRL_C to break
    Reply from 172.168.1.1: bytes=56 Sequence=1 ttl=255 time=50 ms
    Reply from 172.168.1.1: bytes=56 Sequence=2 ttl=255 time=50 ms
    Reply from 172.168.1.1: bytes=56 Sequence=3 ttl=255 time=50 ms
    Reply from 172.168.1.1: bytes=56 Sequence=4 ttl=255 time=40 ms
    Reply from 172.168.1.1: bytes=56 Sequence=5 ttl=255 time=20 ms

  --- 172.168.1.1 ping statistics ---
    5 packet(s) transmitted
    5 packet(s) received
    0.00% packet loss
    round-trip min/avg/max = 20/42/50 ms
[Huawei]ping 172.168.1.2
  PING 172.168.1.2: 56  data bytes, press CTRL_C to break
    Reply from 172.168.1.2: bytes=56 Sequence=1 ttl=255 time=70 ms
    Reply from 172.168.1.2: bytes=56 Sequence=2 ttl=255 time=30 ms
    Reply from 172.168.1.2: bytes=56 Sequence=3 ttl=255 time=20 ms
    Reply from 172.168.1.2: bytes=56 Sequence=4 ttl=255 time=30 ms
    Reply from 172.168.1.2: bytes=56 Sequence=5 ttl=255 time=20 ms

  --- 172.168.1.2 ping statistics ---
    5 packet(s) transmitted
    5 packet(s) received
    0.00% packet loss
    round-trip min/avg/max = 20/34/70 ms

都是正常通信,但是路由器172.168.1.1去ping PC1 192.168.10.2,不能正常通信

[Huawei]ping 192.168.10.2
  PING 192.168.10.2: 56  data bytes, press CTRL_C to break
    Request time out
    Request time out
    Request time out
    Request time out
    Request time out

  --- 192.168.10.2 ping statistics ---
    5 packet(s) transmitted
    0 packet(s) received
    100.00% packet loss

是因为路由器不知道怎么给192.168发包,指导路由器发包的表叫路由表,路由器查看通往192.168.10.2的路由,发现什么都没有,不知道怎么给192.168.10.发包,我们就需要告诉它怎么发包

[Huawei]dis ip routing-table 192.168.10.2
增加一条静态路由
命令解析:
[Huawei]ip route-static 192.168.3.0 255.255.255.0(目标网段及掩码) 192.168.2.2(下一跳IP地址)
实际操作命令
[Huawei]ip route-static 192.168.10.0 24 172.168.1.2  //添加静态路由
[Huawei]dis ip routing-table 192.168.10.2  //再次查看就会有发包路径
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Table : Public
Summary Count : 1
Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

   192.168.10.0/24  Static  60   0          RD   172.168.1.2     GigabitEthernet
0/0/0

再次测试路由器 172.168.1.1 ping PC1 192.168.10.2

[Huawei]ping 192.168.10.2
  PING 192.168.10.2: 56  data bytes, press CTRL_C to break
    Reply from 192.168.10.2: bytes=56 Sequence=1 ttl=127 time=120 ms
    Reply from 192.168.10.2: bytes=56 Sequence=2 ttl=127 time=60 ms
    Reply from 192.168.10.2: bytes=56 Sequence=3 ttl=127 time=40 ms
    Reply from 192.168.10.2: bytes=56 Sequence=4 ttl=127 time=70 ms
    Reply from 192.168.10.2: bytes=56 Sequence=5 ttl=127 time=60 ms

  --- 192.168.10.2 ping statistics ---
    5 packet(s) transmitted
    5 packet(s) received
    0.00% packet loss
    round-trip min/avg/max = 40/70/120 ms

路由器连接外网

连接图上面的不变,添加电信宽带AR2和外网Server1

在这里插入图片描述

怎么设置让PC1访问互联网

设置LSW2静态路由去往互联网

现在配置去往AR1的静态路由
ip route-static 0.0.0.0 0.0.0.0 172.168.1.1
AR1配置去往电信宽带AR2的路由
int g0/0/1
ip address 1.1.1.1 255.255.255.0
ip route-static 0.0.0.0 0.0.0.0 1.1.1.2

W2静态路由去往互联网

现在配置去往AR1的静态路由
ip route-static 0.0.0.0 0.0.0.0 172.168.1.1
AR1配置去往电信宽带AR2的路由
int g0/0/1
ip address 1.1.1.1 255.255.255.0
ip route-static 0.0.0.0 0.0.0.0 1.1.1.2
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值