本地流量出站 2023-07-29

2023-07-28  本文已影响0人  9_SooHyun

本地流量出站链路

问题:目前需要ping google.com,从命令下发到icmp 请求完成出站的过程中,dns,防火墙和本地路由表分别起到了什么作用,它们在链路中的顺序是怎样的

出站链路顺序是:DNS解析 -> 防火墙检查 -> 本地路由表查找 -> 请求出站

数据包在经过 iptables 的各个链(如 PREROUTING、INPUT、FORWARD、OUTPUT 和 POSTROUTING)的处理后,只有通过了相应的规则(没有被丢弃或拒绝),才会进入路由表进行路由选择。

在这个过程中,iptables 可以根据配置的规则对数据包进行过滤、修改或其他操作。只有满足规则的数据包才能继续向下传递,最终进入路由表进行路由选择。如果在 iptables 的某个链中,数据包被丢弃或拒绝,那么它将不会进入路由表,也不会到达目标地址。

本机网络不通,一般和【iptables或路由】的设置有关

本机网络不通排查实战

本机ping不通30.160.241.214,请排查

[root@VM-100-149-centos ~]# ping 30.160.241.214
PING 30.160.241.214 (30.160.241.214) 56(84) bytes of data.
ping: sendmsg: Operation not permitted
ping: sendmsg: Operation not permitted
^C
--- 30.160.241.214 ping statistics ---
5 packets transmitted, 0 received, 100% packet loss, time 4086ms

查看iptables:

[root@VM-100-149-centos ~]# #【iptables DROP了目的地是30.160.241.214的icmp请求】
[root@VM-100-149-centos ~]# iptables -t filter -L OUTPUT --line-numbers -v -n | grep 30.160.241.214
4        5   420 DROP       icmp --  *      *       0.0.0.0/0            30.160.241.214       icmptype 8
[root@VM-100-149-centos ~]# iptables -t filter -D OUTPUT 4
[root@VM-100-149-centos ~]#

查看路由表:

[root@VM-100-149-centos ~]# # 【路由表将 30.160.241.0/24的目标网络,应通过本地环回接口(loopback interface)进行路由,下一跳网关为127.0.0.1,ICMP请求实际上将在本地计算机上进行处理,而不是发送到外部网络】
[root@VM-100-149-centos ~]# route -en | grep 30.160.   
30.160.241.0    127.0.0.1       255.255.255.0   UG        0 0          0 lo
[root@VM-100-149-centos ~]# ip route list table main | grep 30.160.241  # or ip route show | grep 30.160.241.214
30.160.241.0/24 via 127.0.0.1 dev lo scope link   
[root@VM-100-149-centos ~]# ip route del 30.160.241.0/24 via 127.0.0.1 dev lo scope link
[root@VM-100-149-centos ~]#

ping通:

[root@VM-100-149-centos ~]# ping 30.160.241.214
PING 30.160.241.214 (30.160.241.214) 56(84) bytes of data.
64 bytes from 30.160.241.214: icmp_seq=1 ttl=64 time=1.65 ms
64 bytes from 30.160.241.214: icmp_seq=2 ttl=64 time=1.59 ms
64 bytes from 30.160.241.214: icmp_seq=3 ttl=64 time=1.62 ms
^C
--- 30.160.241.214 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 1.591/1.626/1.658/0.027 ms
[root@VM-100-149-centos ~]# 

解析:

注:发往 localhost(即 127.0.0.1)的数据包会经过防火墙,但是它们不会通过物理网络接口,而是经过本地回环接口(lo,一个虚拟的网络接口)。

packets to 127.0.0.1 aren't allowed "outside" the computer. But they still go out of the firewall and are sent to lo

上一篇 下一篇

猜你喜欢

热点阅读