静态路由原理 及实验案例

静态路由

一、静态路由

1、回顾

  • 静态路由
    • 由管理员手动配置,并且是单向的
    • 缺乏灵活性
  • 默认路由(缺省路由)
    • 一种特殊的静态路由
    • 当路由器在路由表中找不到目标网络的路由条 目时,路由器把请求转发到默认路由接口
    • 默认路由一般应用于末节网络

2、静态路由配置

  • 在路由器上添加路由条目语法:

    复制代码
    Router(config)# ip route network mask {address | interface}
    #network:目标网段 mask:目标网段的子网掩码 address:下一跳地址(下一个路由器的接口的IP地址) interface:发往下一跳路由器的本地接口
    • 举例:

      复制代码
      Router(config)# ip route 192.168.2.0 255.255.255.0 192.168.7.2
      Router(config)# ip route 192.168.2.0 255.255.255.0 f0/1

3、默认路由配置

  • 在路由器上添加路由条目语法:

    复制代码
    Router(config)# ip route 0.0.0.0 0.0.0.0 {address | interface}
    #0.0.0.0 0.0.0.0 代表任意网络

    举例:

    复制代码
    Router(config)# ip route 0.0.0.0 0.0.0.0 192.168.7.2
    Router(config)# ip route 0.0.0.0 0.0.0.0 f0/1

4、查看路由条目

  • 命令:

    复制代码
    Router# show ip route 
    Codes: L - local, 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, 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
    
         10.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
    C       10.10.10.0/24 is directly connected, FastEthernet0/1
    L       10.10.10.10/32 is directly connected, FastEthernet0/1
         172.16.0.0/24 is subnetted, 1 subnets
    S       172.16.20.0/24 [1/0] via 10.10.10.100
         192.168.1.0/24 is variably subnetted, 2 subnets, 2 masks
    C       192.168.1.0/24 is directly connected, FastEthernet0/0
    L       192.168.1.254/32 is directly connected, FastEthernet0/0
    #(C代表直连路由,S代表静态路由)

5、路由器上配置DHCP

  • 命令:

    复制代码
    Router(config)#ip dhcp pool woniu
    #定义地址池
    
    Router(dhcp-config)#network 192.168.1.0 255.255.255.0 #定义客户端网段
    Router(dhcp-config)#default-router 192.168.1.254 #定义客户端网关
    Router(dhcp-config)#dns-server 114.114.114.114 #定义客户端获取的DNS
    Router(dhcp-config)#exit
    
    Router(config)#ip dhcp excluded-address 192.168.1.1-192.168.1.10 #定义排除地址

二、实验案例

1、静态路由配置案例

  • 实验拓扑

  • 实验要求

    • 配置 PC0 与 PC1 进行通信
  • 实验步骤

    • 根据图上标示,配置 PC 的 IP 地址及网关, 配置路由器接口地址
    • 在路由器0上添加静态路由条目
    • 在路由器1上添加静态路由条目
  • 实验脚本

    复制代码
    //Router0
    interface FastEthernet0/0
     ip address 192.168.1.254 255.255.255.0
    !
    interface FastEthernet0/1
     ip address 192.168.10.10 255.255.255.0
    !
    ip route 192.168.3.0 255.255.255.0 192.168.10.100 
    
    //Router1
    interface FastEthernet0/0
     ip address 192.168.3.254 255.255.255.0
    !
    interface FastEthernet0/1
     ip address 192.168.10.100 255.255.255.0
    !
    ip route 192.168.1.0 255.255.255.0 192.168.10.10 

2、默认路由配置案例

  • 实验拓扑

  • 实验要求

    • 根据图上标示,配置 PC 的 IP 地址及网关, 配置路由器接口地址
    • 在路由器0上添加默认路由条目
    • 在路由器1上添加默认路由条目
  • 实验脚本

    复制代码
    //Router0
    interface FastEthernet0/0
     ip address 192.168.1.254 255.255.255.0
    !
    interface FastEthernet0/1
     ip address 192.168.2.254 255.255.255.0
    !
    interface Ethernet1/0
     ip address 192.168.3.254 255.255.255.0
    !
    interface Ethernet1/1
     ip address 20.10.10.10 255.255.255.0
    !
    ip route 0.0.0.0 0.0.0.0 20.10.10.100 
    
    //Router1
    interface FastEthernet0/0
     ip address 172.16.10.254 255.255.255.0
    !
    interface FastEthernet0/1
     ip address 20.10.10.100 255.255.255.0
    !
    ip route 0.0.0.0 0.0.0.0 FastEthernet0/1 

3、路由交换综合配置案例

  • 实验拓扑

  • 实验要求

    • 根据图上标示,配置 PC 和交换机的 IP 地址 及网关,配置路由器接口地址
    • 在路由器0上添加静态路由
    • 在路由器1上添加默认路由
    • 在交换机0上配置telnet,使 PC2 可以 telnet 管理交换机0
    • 在路由器1上配置 SSH,使 PC0 和 PC1 可以 管理路由器1
    • 在路由器0上配置DHCP,使PC0和PC1可以 自动获取IP地址及网关及DNS
  • 实验脚本

    复制代码
    //Switch0
    interface Vlan1
     ip address 192.168.1.100 255.255.255.0
    !
    ip default-gateway 192.168.1.254
    !
    line vty 0 4
     login local
     transport input telnet
     
     //Router0
    ip dhcp pool 1
     network 192.168.1.0 255.255.255.0
     default-router 192.168.1.254
     dns-server 192.168.1.254
    !
    interface FastEthernet0/0
     ip address 192.168.1.254 255.255.255.0
    !
    interface FastEthernet0/1
     ip address 10.10.10.10 255.255.255.0
    !
    ip route 172.16.20.0 255.255.255.0 10.10.10.100 
    
    //Router1
    hostname R1
    !
    enable secret 5 $1$mERr$/Q/mbs3O9oHsKR7rNG4e81
    !
    username pc0 secret 5 $1$mERr$/Q/mbs3O9oHsKR7rNG4e81
    username pc1 secret 5 $1$mERr$H7PDxl7VYMqaD3id4jJVK/
    !
    ip domain-name pc0andpc1
    !
    interface FastEthernet0/0
     ip address 172.16.20.254 255.255.255.0
    !
    interface FastEthernet0/1
     ip address 10.10.10.100 255.255.255.0
    !
    ip route 0.0.0.0 0.0.0.0 10.10.10.10 
    !
    line vty 0 4
     login local
     transport input ssh

课后作业:

  • 配置静态路由,指定线路进行配 置
  • 自行规划 IP 地址,需要注意的是路由器连接 的是不同网段
  • PC0到PC1走路由器1→路由器0→路由器2
  • PC0到PC2走路由器1→路由器2
  • PC1和PC2到PC0走路由器2→路由器0→路由 器1
  • 在路由器1上配置默认路由

配置脚本

复制代码
//Router1 
interface FastEthernet0/0
 ip address 192.168.1.254 255.255.255.0
!
interface FastEthernet0/1
 ip address 10.10.20.10 255.255.255.0
!
interface FastEthernet1/0
 ip address 10.10.10.10 255.255.255.0
!
ip route 192.168.3.0 255.255.255.0 10.10.10.100 
ip route 192.168.2.0 255.255.255.0 10.10.20.100 

//Router0
interface FastEthernet0/0
 ip address 10.10.20.100 255.255.255.0
!
interface FastEthernet0/1
 ip address 10.10.30.10 255.255.255.0
!
ip route 192.168.1.0 255.255.255.0 10.10.20.10 
ip route 192.168.2.0 255.255.255.0 10.10.30.100 
!

//Router2
interface FastEthernet0/0
 ip address 192.168.2.254 255.255.255.0
!
interface FastEthernet0/1
 ip address 192.168.3.254 255.255.255.0
!
interface Ethernet1/0
 ip address 10.10.10.100 255.255.255.0
!
interface Ethernet1/1
 ip address 10.10.30.100 255.255.255.0
!
ip route 192.168.1.0 255.255.255.0 10.10.30.10 
相关推荐
Fu2067217 小时前
第一阶段项目
linux·服务器·网络
张张123y13 小时前
Cordis 插件模型:契约、提供者、插件、作用域、策略包五件套讲透
网络·人工智能·开源·后端开发·ai agent
kingx316 小时前
NSSCTF Matryoshka 千层压缩包套娃的脚本化解法
网络安全·misc·python脚本·压缩包套娃·密码还原·自动化解题
孙克旭_16 小时前
CSRF跨站请求伪造漏洞
网络安全·csrf
流浪00118 小时前
计算机网络篇25:应用层——HTTPS 协议原理:非对称加密协商密钥,CA 证书挡住中间人
网络协议·计算机网络·https·非对称加密·对称加密·ca证书
FlightYe18 小时前
音视频修炼之容器与协议(六):HTTP 协议
android·linux·网络·网络协议·算法·http·音视频
如夏倾城18 小时前
网络安全态势感知全解析:概念、架构、厂商与旁路/串联接入选型
大数据·运维·网络·web安全·架构·知识图谱
wWYy.20 小时前
FTP协议
网络
wdfk_prog20 小时前
LWIP教程 33:从 `https_ex_init()` 到 `http_recv()`——altcp、mbedTLS、TLS Handshake 与 HTTPS 数据通路
网络协议·http·https
艺杯羹21 小时前
11月23日AI前沿复盘:安全双警报、模型降价潮与工程防线
人工智能·网络安全·系统架构·大模型·ai agent