一、静态路由
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地址。