iptables KVM prerouting SMTP

我有一个主机,必须pipe理端口25上的stream量,然后路由到KVM机器上的端口25,作为postfix deamon,如下所示:

WAN --> (25) HOST_MACHINE --> (25) KVM_VM_WITH_POSTFIX_DOVECOT 

我已经打开了端口25(和其他),并将此规则添加到iptables

 iptables -t nat -A PREROUTING -p TCP --dport 25 -j DNAT --to-destination 192.168.122.201:25 

现在我的笔记本电脑可以连接到postfix服务器并发送电子邮件,但KVM机器无法连接到其他邮件服务器(连接超时)。

所以我试着用KVM连接到另一台邮件服务器:

 telnet mail.example.com 25 

上面的iptables规则启用,我无法连接。 但是,如果我从链中禁用它,我可以连接到外部服务器。

我错在哪里?

您的DNAT规则会将您的KVM主机在端口25上接收到的所有TCP通信路由到KVM来宾,无论是接口还是目的地。 您应该在该DNAT添加接口或目标IP(或两者):

 iptables -t nat -A PREROUTING -i your_pub_if -p TCP --dport 25 -j DNAT --to-destination 192.168.122.201:25 

要么

 iptables -t nat -A PREROUTING -d your_pub_IP/32 -p TCP --dport 25 -j DNAT --to-destination 192.168.122.201:25 

要么

 iptables -t nat -A PREROUTING -i your_pub_if -d your_pub_IP/32 -p TCP --dport 25 -j DNAT --to-destination 192.168.122.201:25