静态路由原理 及实验案例

静态路由

一、静态路由

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 
相关推荐
Suchadar2 小时前
NAT网络地址转换
linux·服务器·网络
1+2单片机电子设计2 小时前
基于 STM32 的人脸识别系统
网络·人工智能
bleach-3 小时前
应急响应之入侵检测排查——Windows篇—,Windows日志介绍分析
windows·安全·web安全·网络安全·系统安全
代码游侠3 小时前
复习——线程(pthread)
linux·运维·开发语言·网络·学习·算法
while(1){yan}3 小时前
数据链路层与物理层
java·网络·网络协议
aml258__3 小时前
一、Cisco( OSPF多区域与路由汇总技术实践:ABR优化网络路由表实验)251220
运维·网络·动态路由协议·网络优化·ospf多区域·abr·路由汇总
重生之我在番茄自学网安拯救世界3 小时前
网络安全中级阶段学习笔记(九):upload靶场实战(14-16关)-图片马制作与通过教学
笔记·学习·网络安全·文件上传漏洞·图片木马
池央3 小时前
IPIDEA赋能跨境电商:Amazon商品比价自动化采集实战
网络·自动化·php
Ms08067安全实验室4 小时前
网络勒索攻击 之 如何快速应急响应(上)
网络