Iptables

iptables/firewall-cmd DROP rules set last block ip rule set before

  • December 29, 2021

以下是我擁有的 iptables 規則列表:

# firewall-cmd --direct --get-all-rules
ipv4 filter INPUT 0 -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
...
...
ipv4 filter INPUT 1 -d 127.0.0.1 -p tcp -m tcp --dport 4118 -j ACCEPT
ipv4 filter INPUT 2 -i lo -j DROP
ipv4 filter FORWARD 0 -j DROP
ipv4 filter OUTPUT 0 -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
...
...
ipv4 filter OUTPUT 1 -d 127.0.0.1 -p tcp -m tcp --dport 4118 -j ACCEPT
ipv4 filter OUTPUT 2 -o lo -j DROP

當我啟動我的 dsa 命令時,我收到以下錯誤消息:

dsa_control
couldn't connect to 127.0.0.1:4118 (-1: Socket reset)

ss -ntl給出:

State            Recv-Q           Send-Q                      Local Address:Port                       Peer Address:Port
LISTEN           0                128                               0.0.0.0:111                             0.0.0.0:*
LISTEN           0                128                               0.0.0.0:22                              0.0.0.0:*
LISTEN           0                128                                  [::]:111                                [::]:*
LISTEN           0                5                                       *:4118                                  *:*
LISTEN           0                128                                  [::]:22                                 [::]:*

當我刪除 DROP 輸入和輸出規則時,一切正常。知道這些 DROP 規則如何仍然阻止 ip 127.0.0.1 嗎?

確實缺少一條規則。除了 –sport 之外,我還必須添加選項 –dport 才能根據需要打開埠。

引用自:https://unix.stackexchange.com/questions/681595