静态路由原理 及实验案例

静态路由

一、静态路由

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 
相关推荐
三维频道1 小时前
数字化质控:拍照式蓝光三维扫描如何破解路由器注塑件的形变难题?
智能路由器·质量控制·数字雕刻·工业数字化·3d扫描·xtop3d·注塑工艺
云安全助手3 小时前
弹性云服务器+高防IP:让DDoS攻击不再是业务“生死劫”
运维·网络·安全
Hello_Embed4 小时前
嵌入式上位机开发入门(二十六):将 MQTT 测试程序加入 APP 任务
网络·笔记·网络协议·tcp/ip·嵌入式
zjeweler6 小时前
万字长文解析:构建从域名发现到框架识别的信息收集
网络安全·渗透测试·信息收集
亚空间仓鼠6 小时前
网络学习实例:网络理论知识
网络·学习·智能路由器
上海合宙LuatOS6 小时前
LuatOS扩展库API——【libfota2】远程升级
网络·物联网·junit·luatos
pengyi8710156 小时前
动态IP池快速更换实操方案,5分钟完成IP替换
服务器·网络·tcp/ip
平升电子DATA867 小时前
地下管网(污水/雨水管网)流量怎么监测?
网络
被摘下的星星7 小时前
以太网技术
服务器·网络