2014-10-31 80 views
0

本机有两个接口eth0eth1。有上eth0默认网关:将特定网络接口上的流量转发到特定主机

Destination  Gateway   Genmask   Flags Metric Ref Use Iface 
default   10.0.2.1  0.0.0.0   UG 0  0  0 eth0 
10.0.2.0  *    255.255.255.0 U  0  0  0 eth0 
10.0.2.0  *    255.255.255.0 U  0  0  0 eth1 

我需要eth1iptables设置规则来代理所有传入流量10.0.1.1

请注意,eth0与静态IP地址10.0.2.2相关联,而eth1是动态的。

有一个port forwarding with netfilter指南,解释了如何在一个稍微简单的设置中做到这一点,但我无法弄清楚如何从他们的例子到我的。您提供的在the link

+2

不是编程问题。相反,更适合[ubuntu.se]或[su]。 – 2014-10-31 14:33:03

回答

0

大厦,与using the conntrack module rather than the state module除外:

# Activate forwarding 
echo 1 > /proc/sys/net/ipv4/ip_forward 
# Forward packets coming in from the outside 
iptables -t nat -A PREROUTING -p tcp -i eth1 -j DNAT --to-destination 10.0.1.1 
# Make responses on the internal network go through the firewall 
iptables -t nat -A POSTROUTING -p tcp -d 10.0.1.1 -j SNAT --to-source 10.0.2.2 
# Allow forwarded packets 
iptables  -A FORWARD  -p tcp -d 10.0.1.1 -j ACCEPT -m conntrack --ctstate NEW,ESTABLISHED,RELATED 

为了在内核中禁用reverse path filtering,后面的步骤所述here。我认为在你的情况下,通过sysctlnet.ipv4.conf.eth1.rp_filter的值修改为0就足够了。
请注意,此解决方法有点安全漏洞。更好的方法是改变网络结构本身。

+0

我不能让这个工作(没有流量永远离开机器;我得到“火星人来源”日志消息),但我认为在我的特殊用例中,我可以简化我的设置并删除“eth1” 。 – malthe 2014-11-01 08:23:35

+0

什么是您获得完整的确切的日志消息?另外,你是否有意在路由表中为'10.0.2.0'创建一个双重入口?两个接口是否实际连接到相同的内部网络?你能解释一下这里的大局:你究竟想要达到什么样的目标,以及你希望你的设置看起来如何? – Yoel 2014-11-01 08:59:49

+0

路由表条目适用于不同的接口(只有一个可以看到来自Internet的流量)。但我意识到我可以很容易地匹配''! 10.0.0.0/16“,只需在单个界面上接收所有流量(这是一个虚拟环境)。换句话说,我不确定我的问题有多大意义。 – malthe 2014-11-03 10:41:48

相关问题