06.计算机网络--- 网络层/ICMP协议/三层交换机

目录

一.ICMP协议

 二.路由实验

三.三层交换机


一.ICMP协议

ping命令是基于icmp协议的,ICMP协议借助ip协议

Internet Control Message Protocol 互联网控制报文协议。它是TCP/IP协议簇的一个子协议,用于在IP主机、路由器之间传递控制消息。控制消息是指网络通不通、主机是否可达、路由是否可用等网络本身的消息。这些控制消息虽然并不传输用户数据,但是对于用户数据的传递起着重要的作用

ICMP是一个“错误侦测与回馈机制”,是通过IP数据包封装的,用来发送错误和控制信息 ---》用来探测网络是否通畅的

ICMP协议的封装:(ICMP头部没有源和目的地址,所以将自己当成一个数据,再封装一个IP头部,用了两个网络层协议)

ICMP头部(ICMP头部封装占8个字节 ):

类型(type,请求包或者响应包)、回显数据(这个数据没有价值,是随机产生的,用来投石问路,可大可小)

ICMP协议数据包的类型:

        echo request 请求包 type=8

        echo reply 响应包 type=0

### 指定ping命令发送的数据包大小为100,但是可以发现ping命令实际携带了108个字节,因为ping命令使用了ICMP协议,需要携带ICMP头部,刚好就是8个字节
[root@xieshan ~]# ping -s 100 www.baidu.com
PING www.a.shifen.com (14.215.177.39) 100(128) bytes of data.
108 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=1 ttl=53 time=25.7 ms		#多的8个字节是ICMP头部
108 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=2 ttl=53 time=25.2 ms
108 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=3 ttl=53 time=25.3 ms


ping之死:利用了icmp协议,必须要回复对方,而且对方给你发多少数据多少个包,你就要回复多少数据多少个包(目前这个攻击方式的漏洞已经被内核修复了,当你频繁的ping,或者携带的数据量很大时,会不理你,丢弃数据包)

[root@xieshan ~]# ping www.baidu.com			#正常情况,会回应
PING www.a.shifen.com (14.215.177.39) 56(84) bytes of data.
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=1 ttl=53 time=25.7 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=2 ttl=53 time=25.6 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=3 ttl=53 time=25.1 ms
[root@xieshan ~]# ping -s 10000 www.baidu.com		#携带的数据过大,不会回应了
PING www.a.shifen.com (14.215.177.39) 10000(10028) bytes of data.

可以通过防火墙设置让别人ping不了自己,或者指定的IP地址可以ping通自己:

[root@xieshan ~]# iptables -A INPUT icmp --icmp-type 8 -j DROP		#iptables是一个防火墙工具,8是请求包
[root@xieshan ~]# iptables -I INPUT-s 192.168.2.237 -p icmp --icmp-type 8 -j ACCEPT #指定某个Ip地址可以ping过来
[root@xieshan ~]# iptables -L		#查看设置的规则	
[root@xieshan ~]# iptables -F		#清除规则

关于ICMP协议的更多知识,可以查看这位博主的这篇文章:https://blog.csdn.net/qq_25687271/article/details/123392725?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522165803634816782248588821%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=165803634816782248588821&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~top_click~default-3-123392725-null-null.142

 二.路由实验

设置一个局域网,包含四台PC机,四台交换机,五台路由器,让局域网中的不同网段的PC机可以任意ping通局域网内的任何一台PC机。

步骤:

        1.规划网络拓扑

        2.规划IP地址和网段

        3.配置好pc机和路由器接口的IP地址

        4.添加静态路由

        5.ping测试

        6.故障排除 --- troubleshooting

三.三层交换机

VLAN之间的通信需要路由器来完成,VLAN增加导致数据量增大,路由器与交换机之间路径成为整个网络的瓶颈 。

使用三层交换技术实现vlan间通信,三层交换=二层交换+三层转发(一次路由,多次交换,第一次查路由表,走路由器,之后都直接走交换机,速度更快,不用每次都查路由表,比路由器聪明)

三层交换机里的接口是虚接口

三层交换机实验:

步骤:

思科设备中的一些命令:

开启路由功能

Switch#en

Switch#conf t

Enter configuration commands, one per line. End with CNTL/Z.

Switch(config)#ip rout

Switch(config)#ip routing

Switch(config)#

让交换机的接口成为路由接口

Switch#en

Switch#conf t

Enter configuration commands, one per line. End with CNTL/Z.

Switch(config)#int

Switch(config)#interface f0/1

Switch(config-if)#no switchport

Switch(config-if)#

给vlan配置ip地址

Switch(config)#interface vlan 1

Switch(config-if)#ip add 192.168.1.254 255.255.255.0

Switch(config-if)#no shutdown

Switch(config-if)#exit

Switch(config)#interface vlan 2

Switch(config-if)#

%LINK-5-CHANGED: Interface Vlan2, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan2, changed state to up

Switch(config-if)#ip add 192.168.2.254 255.255.255.0

Switch(config-if)#exit

Switch(config)#interface vlan 3

Switch(config-if)#

查看路由表

Switch#show ip route

Codes: C - connected, S - static, I - IGRP, 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

C 192.168.1.0/24 is directly connected, Vlan1

C 192.168.2.0/24 is directly connected, Vlan2

C 192.168.3.0/24 is directly connected, Vlan3

C 192.168.6.0/24 is directly connected, FastEthernet0/1

Switch#

在三层交换机上添加1条静态路由

Switch(config)#ip route 192.168.5.0 255.255.255.0 192.168.6.2

Switch(config)#end

Switch#

%SYS-5-CONFIG_I: Configured from console by console

Switch#

Switch#

Switch#show ip route

Codes: C - connected, S - static, I - IGRP, 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

C 192.168.1.0/24 is directly connected, Vlan1

C 192.168.2.0/24 is directly connected, Vlan2

C 192.168.3.0/24 is directly connected, Vlan3

S 192.168.5.0/24 [1/0] via 192.168.6.2

C 192.168.6.0/24 is directly connected, FastEthernet0/1

Switch#

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值