我有我的应用程序(WordPress)和数据库(MySQL)在不同的服务器上; 他们连接在由主机服务提供商提供的专用networking上, 为了安全 ,我已经采取了所有的初步步骤 (我知道的) 。
通常,我遵循这些IPTables规则:
*filter # Allow all loopback (lo0) traffic and drop all traffic to 127/8 that doesn't use lo0 -A INPUT -i lo -j ACCEPT -A INPUT -d 127.0.0.0/8 -j REJECT # Accept all established inbound connections -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT # Allow all outbound traffic - you can modify this to only allow certain traffic -A OUTPUT -j ACCEPT # Allow HTTP and HTTPS connections from anywhere (the normal ports for websites and SSL). -A INPUT -p tcp --dport 80 -j ACCEPT -A INPUT -p tcp --dport 443 -j ACCEPT # Allow SSH connections # # The -dport number should be the same port number you set in sshd_config # -A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT # Allow ping -A INPUT -p icmp -j ACCEPT # Log iptables denied calls -A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7 # Drop all other inbound - default deny unless explicitly allowed policy -A INPUT -j DROP -A FORWARD -j DROP COMMIT
但是对于我的独立(MySQL)数据库服务器,我发现规则需要一些更改。 例如,我需要打开MySQL的端口3306,这将是如此简单:
-A INPUT -p tcp --dport 443 -j ACCEPT
除了,我不知道如何修改它,只有应用程序服务器能够连接到数据库(即,使其支持远程连接)。 那么,我该怎么做呢?
所以你需要
-A INPUT -p tcp -s $INTERNAL_WEB_SERVER_IP --dport 3306 -j ACCEPT
只允许您的Web服务器与MySQL交谈。 正如dmourati提到的,允许pingstream量是一个好主意。 恕我直言,它有助于解决比它提出的安全问题更多的问题。
iptables -A INPUT -p icmp --icmp-type 8 -s 0/0 -d $SERVER_IP -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT iptables -A OUTPUT -p icmp --icmp-type 0 -s $SERVER_IP -d 0/0 -m state --state ESTABLISHED,RELATED -j ACCEPT
你提到的出站规则意味着你的数据库服务器可以build立任何传出的连接。 本质上来说,任何和所有源自数据库服务器的stream量都将被允许。