1.常用命令
名称 | 作用 |
---|---|
en | 进入特权模式 |
conf t | 进入配置模式 |
no shutdown | 启用 |
interface g0/0 | 进入接口模式 |
ip address +参数 | 配置ip |
show ip route | 查看路由表 |
show ip interface brie | 只显示ip信息 |
ip route +参数 | 配置静态ip路由 |
hostname R1 | 修改路由器名字为R1 |
2.网络布局
3.网络拓步图
4.实现PC0能够ping通PC1
pc0 | ||
---|---|---|
255.255.255.0 | 192.168.1.1 | 192.168.1.254 |
pc1 | ||
255.255.255.0 | 192.168.4.1 | 192.168.4.254 |
思路:
要实现PC0到到PC1需要通过路由器进行配置,路由器的作用就是实现咋不同局域网之间进行通信。
配置acl访问列表:
接口配置:
4.1 R1路由配置接口
配置g0/0为1.0网段的网关
配置g0/1为2.1
R1>en 命令提示符 #>代表用户模式提示符 基本上什么都干不了,只能做一些简单的查看操作
R1#conf t #输入en后进入 特权模式 可以做一些稍微复杂的操作 可以进行系统配置查看
R1(config)# interface g0/0 #输入conf t进入 配置模式提示符 可以对主机做一些配置
R1(config-if)# #输入intface g0/0 接口模式
R1(config-if)#ip address 192.168.1.254 255.255.255.0 配置ip
R1(config-if)#no shutdown #激活
R1(config)# interface g0/1 #输入conf t进入 配置模式提示符 可以对主机做一些配置
R1(config-if)# #输入intface g0/0 接口模式
R1(config-if)#ip address 192.168.2.1 255.255.255.0 配置ip
R1(config-if)#no shutdown #激活
#在特权模式下查看路由表
R1#show ip interface brief
Interface IP-Address OK? Method Status Protocol
GigabitEthernet0/0 192.168.1.254 YES manual up up
GigabitEthernet0/1 192.168.2.1 YES manual up down
ps:
#ctrl +z 快速回到配置
#show interface g0/0 查看接口g0/0的ip
#show ip interface brief 只显示接口ip地址信息
4.2 R2路由配置接口
配置g0/0为2.2
配置g0/1为3.1
R2>en 命令提示符 #>代表用户模式提示符 基本上什么都干不了,只能做一些简单的查看操作
R2#conf t #输入en后进入 特权模式 可以做一些稍微复杂的操作 可以进行系统配置查看
R2(config)# interface g0/0 #输入conf t进入 配置模式提示符 可以对主机做一些配置
R2(config-if)# #输入intface g0/0 接口模式
R2(config-if)#ip address 192.168.2.2 255.255.255.0 配置ip
R2(config-if)#no shutdown #激活
R2(config)# interface g0/1 #输入conf t进入 配置模式提示符 可以对主机做一些配置
R2(config-if)# #输入intface g0/1 接口模式
R2r(config-if)#ip address 192.168.3.1 255.255.255.0 配置ip
R2r(config-if)#no shutdown #激活
R2#show ip route
C 192.168.2.0/24 is directly connected, GigabitEthernet0/0
L 192.168.2.2/32 is directly connected, GigabitEthernet0/0
192.168.3.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.3.0/24 is directly connected, GigabitEthernet0/1
L 192.168.3.1/32 is directly connected, GigabitEthernet0/1
4.3 R3路由配置
配置G0/0为3.2
配置G0/1为4.254
R3>en 命令提示符 #>代表用户模式提示符 基本上什么都干不了,只能做一些简单的查看操作
R3#conf t #输入en后进入 特权模式 可以做一些稍微复杂的操作 可以进行系统配置查看
R3(config)# interface g0/0 #输入conf t进入 配置模式提示符 可以对主机做一些配置
R3(config-if)# #输入intface g0/0 接口模式
R3(config-if)#ip address 192.168.3.2 255.255.255.0 配置ip
R3(config-if)#no shutdown #激活
R3(config)# interface g0/1 #输入conf t进入 配置模式提示符 可以对主机做一些配置
R3(config-if)# #输入intface g0/1 接口模式
R3(config-if)#ip address 192.168.4.254 255.255.255.0 配置ip
R3(config-if)#no shutdown #激活
R3#show ip route
C 192.168.3.0/24 is directly connected, GigabitEthernet0/0
L 192.168.3.2/32 is directly connected, GigabitEthernet0/0
192.168.4.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.4.0/24 is directly connected, GigabitEthernet0/1
L 192.168.4.254/32 is directly connected, GigabitEthernet0/1
配置完接口以后 我们还是ping不通 ,因为R1路由器上没有去4网段的信息
5.配置下一跳信息
5.1 R1路由配置去4.0
ip route 路由配置 去往网段信息 网络掩码 去往目标的下一跳接口地址
R1(config)# ip route 192.168.4.0 255.255.255.0 192.168.2.2
R1#show ip route
192.168.1.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.1.0/24 is directly connected, GigabitEthernet0/0
L 192.168.1.254/32 is directly connected, GigabitEthernet0/0
192.168.2.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.2.0/24 is directly connected, GigabitEthernet0/1
L 192.168.2.1/32 is directly connected, GigabitEthernet0/1
S 192.168.4.0/24 [1/0] via 192.168.2.2
5.2 R2配置路由配置去4.0
R2(config)# ip route 192.168.4.0 255.255.255.0 192.168.3.2
R2#show ip route
C 192.168.2.0/24 is directly connected, GigabitEthernet0/0
L 192.168.2.2/32 is directly connected, GigabitEthernet0/0
192.168.3.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.3.0/24 is directly connected, GigabitEthernet0/1
L 192.168.3.1/32 is directly connected, GigabitEthernet0/1
S 192.168.4.0/24 [1/0] via 192.168.3.2
现在去ping 还是不行 有来有回才可以ping通 接下来配置4.0网段到1.0网段的路由配置
查看r3路由表没有去往1.0网段的路由 所以导致不能通信
5.3 R2路由配置去1.0
R2(config)# ip route 192.168.1.0 255.255.255.0 192.168.2.1
R2#show ip route
S 192.168.1.0/24 [1/0] via 192.168.2.1
192.168.2.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.2.0/24 is directly connected, GigabitEthernet0/0
L 192.168.2.2/32 is directly connected, GigabitEthernet0/0
192.168.3.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.3.0/24 is directly connected, GigabitEthernet0/1
L 192.168.3.1/32 is directly connected, GigabitEthernet0/1
S 192.168.4.0/24 [1/0] via 192.168.3.2
5.4 R3路由配置去1.0
R3(config)# ip route 192.168.1.0 255.255.255.0 192.168.3.1
R3#show ip route
S 192.168.1.0/24 [1/0] via 192.168.3.1
192.168.3.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.3.0/24 is directly connected, GigabitEthernet0/0
L 192.168.3.2/32 is directly connected, GigabitEthernet0/0
192.168.4.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.4.0/24 is directly connected, GigabitEthernet0/1
L 192.168.4.254/32 is directly connected, GigabitEthernet0/1
这样就可以ping 通了
网关:一个主机想访问其他网关的必经之路
路由器的接口:网关接口