路由器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 小时前
UNIX下C语言编程与实践58-UNIX TCP 连接处理:accept 函数与新套接字创建
c语言·网络·unix
IT成长日记4 小时前
【Nginx开荒攻略】Nginx虚拟主机配置:从域名、端口到IP的完整指南
linux·运维·服务器·nginx·虚拟主机
taxunjishu4 小时前
DeviceNet 转 Modbus TCP 协议转换在 S7-1200 PLC化工反应釜中的应用
运维·人工智能·物联网·自动化·区块链
光影少年4 小时前
angular生态及学习路线
前端·学习·angular.js
迎風吹頭髮5 小时前
Linux内核架构浅谈8-Linux内核与UNIX的传承:设计思想与特性差异
linux·运维·架构
猫头虎6 小时前
如何查看局域网内IP冲突问题?如何查看局域网IP环绕问题?arp -a命令如何使用?
网络·python·网络协议·tcp/ip·开源·pandas·pip
黑马金牌编程6 小时前
Linux 服务器常见的性能调优
linux·运维·服务器·性能优化
tianyuanwo6 小时前
Linux进程管理中的T状态问题分析与解决体系
linux·运维·进程管理·t状态
无尽夏_6 小时前
HTML5(前端基础)
前端·html·html5
Jagger_7 小时前
敏捷开发流程-精简版
前端·后端