admin 管理员组

文章数量: 1184232

基础知识

ip地址是网络层中使用的地址,网络层依靠IP地址和路由协议将数据报送到目的IP主机。

路由器是互联网的核心设备,它在IP网络间转发数据报,这使得路由器的每个接口都连接一个或多个网络,而两个接口却不可以代表一个网络,路由器的一个配置了IP地址的接口所在的网络就是路由器的直连网络,路由器不需要额外的配置路由,当接口被激活后,路由器就会自动将直连网络加入到路由表中。

常用命令

命令格式 含义
ip address IP地址 子网掩码 在接口模式下配置当前接口的IP地址
show ip route 特权模式下查看路由器的路由表
do show ip route 非特权模式下查看路由表
no shutdown 接口模式下激活该接口

实验流程

1.设计拓扑

2.配置路由器IP地址

Router>enable
Router#configure terminal
Enter configuration commands, one per line.End with CNTL/Z.
Router(config)#interface g0/0
Router(config-if)#ip address 192.168.1.1 255.255.255.0
Router(config-if)#exit
Router(config)#interface g0/1
Router(config-if)#ip address 192.168.2.1 255.255.255.0
Router(config-if)#end
Router#%SYS-5-CONFIG_I: Configured from console by console
Router#

3.查看路由表

Router#show ip route
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
       i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
       *- candidate default, U - per-user static route, o - ODR
       P - periodic downloaded static route
Gateway of last resort is not set

4.激活端口

Router#configure terminal
Enter configuration commands, one per line.End with CNTL/Z.
Router(config)#interface g0/0
Router(config-if)#no shutdown
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)#exit
Router(config)#interface g0/1
Router(config-if)#no shutdown
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)#

5.查看路由表

Router#show ip route
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
       i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
       *- candidate default, U - per-user static route, o - ODR
       P - periodic downloaded static route
Gateway of last resort is not set
     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.1/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

6.验证主机连通

这里验证p0和p2的连通性,打开主机p0终端

C:\>ping 192.168.2.11
Pinging 192.168.2.11 with 32 bytes of data:
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Ping statistics for 192.168.2.11:
    Packets: Sent = 4, Received = 0, Lost = 4 (100% loss)
C:\>

等等,忘记配置每个主机的IP,子网掩码,网关了

再来

C:\>ping 192.168.2.11
Pinging 192.168.2.11 with 32 bytes of data:
Request timed out.
Reply from 192.168.2.11: bytes=32 time<1ms TTL=127
Reply from 192.168.2.11: bytes=32 time<1ms TTL=127
Reply from 192.168.2.11: bytes=32 time=1ms TTL=127
Ping statistics for 192.168.2.11:
    Packets: Sent = 4, Received = 3, Lost = 1 (25% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 1ms, Average = 0ms
C:\>

已经可以证明两者可以互相通信了,其它的同样也可以就不做验证了。

此时再看一下拓扑图

绿色:代表连通
红色:代表未连接
黄色:代表阻塞

注意:路由器端口所连接的不能是同一个网络,否者会出现端口重叠的现象。

本文标签: 地址 路由器的 编程