通过代理路由smtp和pop3过去的iptables

以下设置:

客户端(Outlook)<—–> | eth1 PROXY eth0 | Interwebs

我如何设法做到这一点? 将所有筛选表的标准策略设置为ACCEPT并不会改变一件事情,那么是不是也在改变呢?

凯,凯

你可以使用一个SOCKS代理服务器或iptables和NAT来做到这一点。

我假设您的客户端主机位于本地networking中,并使用私有IP地址(例如10.0.0.0/8,172.28.0.0/12或192.168.0.0/16)。

前提条件:

  1. 你可以从你的Linux机器到你的客户端主机
  2. 你可以从你的Linux机器到达互联网

第一步是启用IP转发:

# set kernel flag to allow IP forwarding from one to another network device echo 1 > /proc/sys/net/ipv4/ip_forward 

下一步是使用iptables来激活NAT:

 # enable NAT for Internet device (here eth0) iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE # accept incoming Internet traffic, which is related to established outgoing connection iptables -A FORWARD -i eth0 -o eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT # enable forwarding from internal device eth1 to external device eth0 iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT 

这是一个非常简单的设置,我build议仔细研究一下iptables,为您的局域网提供安全保护,同时也可以访问局域网到互联网。

要限制只能访问某些协议(这里是SMTP,POP3,IMAP),可以使用以下设置:

 # enable NAT for Internet device (here eth0) iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE # accept incoming Internet traffic, which is related to established outgoing connection iptables -A FORWARD -i eth0 -o eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT # enable forwarding from internal device eth1 to external device eth0 iptables -A FORWARD -i eth1 --dport 25 -o eth0 -j ACCEPT iptables -A FORWARD -i eth1 --dport 110 -o eth0 -j ACCEPT iptables -A FORWARD -i eth1 --dport 143 -o eth0 -j ACCEPT