
我在執行 Ubuntu 18.04 LTS 的 Hetzner-Cloud 中新設定的伺服器上遇到問題。
安裝 Iptables(-persistent) 並配置下列規則集後:
root@inetsec:/home/linus# iptables -L
Chain INPUT (policy DROP)
target prot opt source destination
ACCEPT tcp -- anywhere 1.2.3.4 tcp dpt:272
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
我仍然可以使用 Telnet 和其他幾個連接埠(110、143、25、993)成功進行 TCP 握手。
即便如此,負責此連接埠的應用程式(Dovecot 和 Postfix)甚至沒有運行,並netstat -tulpen
顯示:
Proto Recv-Q Send-Q Local Address Foreign Address State User Inode PID/Program name
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 112 20485 1198/mysqld
tcp 0 0 1.2.3.4:272 0.0.0.0:* LISTEN 0 18773 1047/sshd
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 101 19746 1113/systemd-resolv
tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN 111 19076 1004/named
udp 0 0 127.0.0.53:53 0.0.0.0:* 101 19745 1113/systemd-resolv
udp 0 0 127.0.0.1:53 0.0.0.0:* 111 19075 1004/named
udp 0 0 0.0.0.0:68 0.0.0.0:* 0 18955 1173/dhclient
udp 0 0 0.0.0.0:68 0.0.0.0:* 0 15042 816/dhclient
,我仍然使用 telnet 在上述連接埠上獲得 TCP 握手,而不是預期的逾時(由於 INPUT DROP 策略)或至少是ICMP-Destination Unreachable (3)
關閉連接埠的訊息。
我發現的一個問題是,如果我使用已儲存的 iptable 規則集 ( ) 重新啟動伺服器,iptables-save > /etc/iptables/rules.v4
伺服器會在狀態下掛起大約 5 分鐘
....
iscsi: registered transport (tcp)
iscsi: registered transport (user)
在啟用登入之前。
執行該命令大約需要 15 秒iptables -L