2

我有两个 Centos 虚拟机。VM_1 上的 IP 地址是10.99.0.10,而 VM_2 是10.99.0.12。Apache 和 PHP 在 VM_1 中,而 MySQL 在 VM_2 中。两者都有 IPTables 规则。VM_2 可以正常使用规则。现在我正在从 VM_1 进行测试。

首先,我禁用了 VM_1 IPTables 并连接到 VM_2 MySQL(连接成功)。

[root@foster ~]# service IPTables  stop
IPTables : Applying firewall rules:                         [  OK  ]
[root@foster ~]# mysql -h 10.99.0.12 -u root -p
Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 5.6.21 MySQL Community Server (GPL)

接下来,我启用了 VM_1 IPTables 并连接到 VM_2 MySQL(它也不会在几个小时内响应)。

[root@foster ~]# service IPTables  start
IPTables : Applying firewall rules:                         [  OK  ]
[root@foster ~]# mysql -h 10.99.0.12 -u root -p
Enter password:

我的 IPTables 规则有什么问题?我的规则在Pastebin中。

4

1 回答 1

1

问题在于您启用MySQL流量的方法:

# Allow MySQL private Networking
sudo iptables -A INPUT -i eth1 -p tcp -s 10.99.0.12 --dport 3306 -m state --state NEW,ESTABLISHED -j ACCEPT
sudo iptables -A OUTPUT -o eth1 -p tcp --sport 3306 -m state --state ESTABLISHED -j ACCEPT

这些规则有两个问题:

  1. 只有当连接首先从( )发起时,它们才允许传出MySQL流量。VM_1VM_210.99.0.12
  2. 他们将端口指定3306为客户端的 ( VM_1) 端口,而不是服务器的 ( VM_2) 端口。

更合适的规则集如下:

# Allow MySQL private Networking
sudo iptables -A OUTPUT -o eth1 -p tcp --dport 3306 -m state --state NEW, ESTABLISHED -j ACCEPT
sudo iptables -A INPUT -i eth1 -p tcp -s 10.99.0.12 --sport 3306 -m state --state ESTABLISHED -j ACCEPT
于 2014-10-23T15:30:40.667 回答