iptables 규칙이 ping localhost에 영향을 미치는 이유는 무엇입니까?

iptables 규칙이 ping localhost에 영향을 미치는 이유는 무엇입니까?

다음은 Centos 시스템에 있는 iptable 방화벽 규칙입니다. 이 시점에서는 localhost를 ping할 수 없습니다. ping localhost실패하고 있었어요.

그러나 규칙을 플러시하자마자 iptables -Flocalhost에 ping을 보낼 수 있었습니다. 질문은 왜?? 이 iptables 세트가 localhost(127.0.0.1) ping 기능에 어떤 영향을 미쳤습니까?

root@localhost:~# iptables -L -n
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0            udp dpt:53
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:53
ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0            udp dpt:67
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:67
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:6080
LPASS      udp  --  0.0.0.0/0            0.0.0.0/0            state NEW udp spt:68 dpt:67
LPASS      all  --  192.168.122.49       0.0.0.0/0
LPASS      tcp  --  192.168.122.0/24     0.0.0.0/0            tcp spt:21
LPASS      all  --  0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
LPASS      tcp  --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:21
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:22
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0            state NEW
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpts:8505:8506
LPASS      tcp  --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:80
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:443
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:6000
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpts:6001:6100
ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0            state NEW udp dpt:161
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:24
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:8081
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:2222
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
LDROP      all  --  0.0.0.0/0            0.0.0.0/0

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  0.0.0.0/0            192.168.122.0/24     ctstate RELATED,ESTABLISHED
ACCEPT     all  --  192.168.122.0/24     0.0.0.0/0
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0
REJECT     all  --  0.0.0.0/0            0.0.0.0/0            reject-with icmp-port-unreachable
REJECT     all  --  0.0.0.0/0            0.0.0.0/0            reject-with icmp-port-unreachable
ACCEPT     tcp  --  0.0.0.0/0            192.168.122.49       tcp dpt:3389
ACCEPT     all  --  192.168.122.49       0.0.0.0/0
DROP       all  --  192.168.122.0/24     0.0.0.0/0
LFDROP     all  --  0.0.0.0/0            0.0.0.0/0            PHYSDEV match --physdev-in vnet+ --physdev-out vnet+ --physdev-is-bridged
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0            state NEW
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0            udp dpt:68

Chain LDROP (1 references)
target     prot opt source               destination
DROP       all  --  0.0.0.0/0            0.0.0.0/0

Chain LFDROP (1 references)
target     prot opt source               destination
DROP       all  --  0.0.0.0/0            0.0.0.0/0

Chain LPASS (6 references)
target     prot opt source               destination
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0

ifconfig는 인터페이스가 작동 중임을 나타냅니다.

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 65922  bytes 5788036 (5.5 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 65922  bytes 5788036 (5.5 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

답변1

이 때문입니다모든 것인터페이스 밖으로 나가서 인터페이스로 들어오는 것은 iptables 또는 방화벽 규칙을 통해 구문 분석됩니다.

따라서 패킷이 ICMP, HTTP, FTP 또는 기타 프로토콜을 위해 인터페이스에서 자체적으로 나가야 하는 경우. 외부 IP의 경우와 동일한 과정을 거치게 됩니다. 예를 들어 HTTP의 경우 TCP 연결을 시작한 다음 로컬 호스트에 HTTP 요청을 보내고 모든 통신은 다음을 통해 이루어집니다.봐라상호 작용.

이제 예를 들어, 계속해서산출규칙은 다음과 같습니다.

ACCEPT     ICMP  --  127.0.0.1            127.0.0.1 

ICMP를 실행하려고 해도 여전히 실행되지 않습니다. 작동하려면 아래와 같은 입력 규칙도 필요합니다.

ACCEPT     ICMP  --  127.0.0.1            127.0.0.1 

관련 정보