当前位置: 首页 > news >正文

路由器02_静态路由DHCP

一、静态路由

1、静态路由特点

由管理员手工配置,是单向的,缺乏灵活性

2、默认路由

默认路由是一种比较特殊静态路由,一般用于末节(末梢)网络,直接指定目标为任何地方

二、静态路由配置

1、静态路由

ip route 目标网络(目标的网段 目标的网络地址) 目标的子网掩码 下一跳地址(下一个路由器的接口的IP地址)或者发往下一个路由器的本地接口

ip route 192.168.1.0 255.255.255.0 192.168.10.0
ip route 192.168.1.0 255.255.255.0 f0/1

2、默认路由

ip route 0.0.0.0 255.255.255.0 192.168.10.0
ip route 0.0.0.0 255.255.255.0 f0/1

3、查看路由条目

show ip route

 三、静态路由实验

1、实验要求

实验设备:两台主机PC0和PC1、三台路由器R0、R1、R2

实验环境:PC1直连R0,PC2直连R1,R0与R1相接,且R0、R1各有一条链路连接R2,网络拓扑如下:

注:画网络通信拓扑图一定要把IP标识清楚!!!

实验要求
PC0到PC1走R0 R2 R1
PC1到PC0走R1 R0路由器

首先配置PC的IP地址,其次给路由器配置端口IP,最后配置静态路由或默认路由

路由器接口IP配置
 

#R2路由器接口IP设置
Router#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#hostname R2
R2(config)#int g0/0
R2(config-if)#ip add 10.0.0.2 255.255.255.0
R2(config-if)#no shutR2(config-if)#
%LINK-5-CHANGED: Interface GigabitEthernet0/0, changed state to upR2(config-if)#int g0/1
R2(config-if)#ip add 20.0.0.1 255.255.255.0
R2(config-if)#no shut#R1路由器接口IP设置
Router>en 
Router#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#hostname R1
R1(config)#int g0/0 
R1(config-if)#ip add 192.168.20.254 255.255.255.0
R1(config-if)#no shutR1(config-if)#
%LINK-5-CHANGED: Interface GigabitEthernet0/0, changed state to up%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/0, changed state to upR1(config-if)#int g0/1
R1(config-if)#ip add 30.0.0.2 255.255.255.0
R1(config-if)#no shutR1(config-if)#
%LINK-5-CHANGED: Interface GigabitEthernet0/1, changed state to up%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/1, changed state to upR1(config-if)#int g0/2
R1(config-if)#ip add 20.0.0.2 255.255.255.0
R1(config-if)#no shutR1(config-if)#
%LINK-5-CHANGED: Interface GigabitEthernet0/2, changed state to up%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/2, changed state to up#R0接口IP配置
Router>en
Router#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#int g0/0
Router(config-if)#ip add 192.168.10.254
% Incomplete command.
Router(config-if)#ip add 192.168.10.254 255.255.255.0
Router(config-if)#no shutRouter(config-if)#
%LINK-5-CHANGED: Interface GigabitEthernet0/0, changed state to up%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/0, changed state to upRouter(config-if)#int g0/1
Router(config-if)#ip add 10.0.0.1 255.255.255.0
Router(config-if)#no shutRouter(config-if)#
%LINK-5-CHANGED: Interface GigabitEthernet0/1, changed state to up%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/1, changed state to upRouter(config-if)#int g0/2
Router(config-if)#ip add 30.0.0.1 255.255.255.0
Router(config-if)#no shutRouter(config-if)#
%LINK-5-CHANGED: Interface GigabitEthernet0/2, changed state to upRouter(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/2, changed state to upRouter(config-if)#exit
Router(config)#hostname R0
R0(config)#

查看路由表:

#R2路由表
Gateway of last resort is not set10.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C       10.0.0.0/24 is directly connected, GigabitEthernet0/0
L       10.0.0.2/32 is directly connected, GigabitEthernet0/020.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C       20.0.0.0/24 is directly connected, GigabitEthernet0/1
L       20.0.0.1/32 is directly connected, GigabitEthernet0/1#R1路由表
Gateway of last resort is not set20.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C       20.0.0.0/24 is directly connected, GigabitEthernet0/2
L       20.0.0.2/32 is directly connected, GigabitEthernet0/230.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C       30.0.0.0/24 is directly connected, GigabitEthernet0/1
L       30.0.0.2/32 is directly connected, GigabitEthernet0/1192.168.20.0/24 is variably subnetted, 2 subnets, 2 masks
C       192.168.20.0/24 is directly connected, GigabitEthernet0/0
L       192.168.20.254/32 is directly connected, GigabitEthernet0/0#R0路由表
Gateway of last resort is not set10.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C       10.0.0.0/24 is directly connected, GigabitEthernet0/1
L       10.0.0.1/32 is directly connected, GigabitEthernet0/130.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C       30.0.0.0/24 is directly connected, GigabitEthernet0/2
L       30.0.0.1/32 is directly connected, GigabitEthernet0/2192.168.10.0/24 is variably subnetted, 2 subnets, 2 masks
C       192.168.10.0/24 is directly connected, GigabitEthernet0/0
L       192.168.10.254/32 is directly connected, GigabitEthernet0/0

添加R0->R2、 R2->R1的静态路由

R2#
R2#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
R2(config)#ip route 192.168.20.0 255.255.255.0 20.0.0.2

 在R1上添加默认路由

仿真模式可以进行路由跟踪

四、路由器DHCP配置

DHCP:动态主机配置协议,主要是为客户机提供TCP/IP参数:IP地址、子网掩码、网关、DNS服务器地址,客户机可以通过路由器所提供的DHCP服务器IP地址。

  • 定义DHCP地址池
    • 池的名字
    • 指定分配的网络范围:网络地址和子网掩码
    • 指定默认网关
    • 指定DNS服务器地址
#全局模式
#定义IP地址池的名字ip dhcp pool woniu#指定分配的网络范围和子网掩码network 192.168.10.0 255.255.255.0#指定默认网关default-router 192.168.10.254#指定 DNS服务器地址dns-server 114.114.114.114

  • 指定保留地址(eNSP使用2911路由器)

最后在主机IP配置处选择DHCP即可动态获取IP地址。

http://www.lryc.cn/news/279878.html

相关文章:

  • Mysql 递归查询所有子节点,hutool树形结构封装
  • 【代码随想录04】24. 两两交换链表中的节点 19. 删除链表的倒数第 N 个结点 面试题 02.07. 链表相交 142. 环形链表 II
  • Pandas实战100例 | 案例 25: 计算相关系数
  • vue文本识别“\n“换行问题的解决方式
  • 【QT-UI】
  • MyBatisPlus逆向工程
  • 创建ESP32开源WiFi MAC(介质访问控制)层
  • LeetCode 2723. 两个 Promise 对象相加
  • Flutter--常用技术文档
  • 行分类问题
  • java常见面试题:如何使用Java进行XML解析和生成?
  • 【LabVIEW FPGA入门】LabVIEW FPGA实现I2S解码器
  • linux 安装sipp
  • c++最值查找
  • xtu-c语言考试复习-2
  • MySQL决战:MySQL数据导入导出
  • Unity 面试篇|(二)Unity基础篇 【全面总结 | 持续更新】
  • TIDB的忘了root用户密码和数据库密码解决办法
  • QT基础篇(4)QT5基本对话框
  • Springboot项目Nacos做配置中心
  • SpringSecurity入门demo(三)多用户身份认证
  • 【设计模式-02】Strategy策略模式及应用场景
  • ssh远程登陆
  • go如何终止多个for select循环嵌套
  • nginx(1.13.7)首次安装出现:【make: *** 没有规则可以创建“default”需要的目标“build” 问题】解决措施
  • 2024.1.8 关于 Redis 数据类型 Zset 集合命令、编码方式、应用场景
  • ffmpeg[学习(四)](代码实现) 实现音频数据解码并且用SDL播放
  • C++ 字符串哈希 || 字符串前缀哈希法
  • 【java】项目部署liunx服务器的简单步骤
  • 深度学习笔记(五)——网络优化(1):学习率自调整、激活函数、损失函数、正则化