我有一个新的 Linux 服务器(Debian 6.0)和一个数据库(MySQL),像往常一样通过端口 3306 访问。
现在由于某些用户的端口问题(因为3306端口经常被网络防火墙屏蔽),我想通过80或者443端口访问数据库,所以必须从80
端口重定向> 到 3306
以保持数据库正常工作。
我试过以下命令:
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3306
但是我得到了以下错误:
iptables: No chain/target/match by that name.
谁能帮我解决这个问题? NAT 表为空(PREROUTING
、POSTROUTING
、OUTPUT
没有条目)(使用 iptables -t nat -n -L 检查
)
最佳答案
在 NAT 功能所需的 iptables 内核模块中:
运行以下命令在内核中加载模块:
# modprobe iptable_nat
# modprobe ipt_REDIRECT
确保你在内核中编译了以上模块:
[root@instructor tmp]# grep REDIRECT /boot/config-$( uname -r )
CONFIG_IP_NF_TARGET_REDIRECT=m
CONFIG_BRIDGE_EBT_REDIRECT=m
在 VPS 服务器中:
使用modprobe
命令在主机服务器上启用模块
从主机服务器执行以下命令以启用 VPS
vzctl set VEID --iptables iptable_nat --iptables ipt_REDIRECT
在文件 /etc/vz/conf/veid.conf 中添加规则
IPTABLES="iptable_nat ipt_REDIRECT"
关于database - 端口重定向不起作用 (80->3306),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14695164/