路由器02_静态路由&DHCP

一、静态路由

1、静态路由特点

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

2、默认路由

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

二、静态路由配置

1、静态路由

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

bash 复制代码
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、默认路由

bash 复制代码
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、查看路由条目

bash 复制代码
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配置

Go 复制代码
#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 shut

R2(config-if)#
%LINK-5-CHANGED: Interface GigabitEthernet0/0, changed state to up

R2(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 shut

R1(config-if)#
%LINK-5-CHANGED: Interface GigabitEthernet0/0, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/0, changed state to up

R1(config-if)#int g0/1
R1(config-if)#ip add 30.0.0.2 255.255.255.0
R1(config-if)#no shut

R1(config-if)#
%LINK-5-CHANGED: Interface GigabitEthernet0/1, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/1, changed state to up

R1(config-if)#int g0/2
R1(config-if)#ip add 20.0.0.2 255.255.255.0
R1(config-if)#no shut

R1(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 shut

Router(config-if)#
%LINK-5-CHANGED: Interface GigabitEthernet0/0, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/0, changed state to up

Router(config-if)#int g0/1
Router(config-if)#ip add 10.0.0.1 255.255.255.0
Router(config-if)#no shut

Router(config-if)#
%LINK-5-CHANGED: Interface GigabitEthernet0/1, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/1, changed state to up

Router(config-if)#int g0/2
Router(config-if)#ip add 30.0.0.1 255.255.255.0
Router(config-if)#no shut

Router(config-if)#
%LINK-5-CHANGED: Interface GigabitEthernet0/2, changed state to up

Router(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/2, changed state to up

Router(config-if)#exit
Router(config)#hostname R0
R0(config)#

查看路由表:

bash 复制代码
#R2路由表
Gateway of last resort is not set

     10.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/0
     20.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 set

     20.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/2
     30.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/1
     192.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 set

     10.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/1
     30.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/2
     192.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的静态路由

Go 复制代码
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服务器地址
Go 复制代码
#全局模式
#定义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地址。

相关推荐
爬树的小蚂蚁1 小时前
Linux 修改bond后网关不生效的问题
linux·运维·服务器
2501_915373882 小时前
Vue 3零基础入门:从环境搭建到第一个组件
前端·javascript·vue.js
lisw053 小时前
网络化:DevOps 工程的必要基础(Networking: The Essential Foundation for DevOps Engineering)
网络·devops
沙振宇5 小时前
【Web】使用Vue3开发鸿蒙的HelloWorld!
前端·华为·harmonyos
驱动小百科5 小时前
WiFi出现感叹号上不了网怎么办 轻松恢复网络
网络·智能路由器·wifi出现感叹号怎么解决·wifi无法上网·电脑wifi
好多知识都想学5 小时前
协议路由与路由协议
网络·智能路由器
爆农5 小时前
centos搭建dokcer和vulhub
linux·运维·centos
SZ1701102315 小时前
中继器的作用
服务器·网络·智能路由器
chenxy025 小时前
如何快速分享服务器上的文件
运维·服务器
运维@小兵6 小时前
vue开发用户注册功能
前端·javascript·vue.js