【问题标题】:iptables dnat mapping a private ip to public to specific ipiptables dnat 将私有 ip 映射到公共到特定 ip
【发布时间】:2014-12-24 14:59:12
【问题描述】:

我用两台机器构建了一个私网,它们都有两个网络接口 这是网络信息:

  • 机器1

    • eth0 10.0.0.11(私网)
    • eth1 10.82.80.208(校园网ip)
  • 机器2

    • eth0 10.0.0.21(私网)
    • eth2 10.82.80.207(校园网ip)

我想在我的机器(10.82.80.206)中访问校园网中的10.0.0.11,而不是通过iptablesdnat使用校园网IP地址。例如,我想将数据包的目的地从10.0.0.11更改为10.82.80.208

我正在尝试使用 iptables 命令,例如:

iptables -t nat -A PREROUTING -i eth0 -p tcp -d 10.0.0.11 -j DNAT --to-destination 10.82.80.208
iptables -t nat -A PREROUTING -i eth0 -p icmp -d 10.0.0.11 -j DNAT --to-destination 10.82.80.208
iptables -t nat -A PREROUTING -i eth0 -p udp -d 10.0.0.11 -j DNAT --to-destination 10.82.80.208

但是当我尝试 ping 10.0.0.11 时它似乎没用,主机仍然无法访问,我如何将我机器中的口袋目的地从 10.0.0.11 更改为 10.82.80.208

【问题讨论】:

  • 这个问题在这里似乎是题外话。您应该在serverfault.com 上询问。

标签: networking ip mapping iptables


【解决方案1】:

正如iptables's man page 报告的那样,-i 标志指定输入接口,而您需要-o 标志指定输出接口:

[!] -i, --in-interface name
Name of an interface via which a packet was received (only for packets entering the INPUT, FORWARD and PREROUTING chains). When the "!" argument is used before the interface name, the sense is inverted. If the interface name ends in a "+", then any interface which begins with this name will match. If this option is omitted, any interface name will match.
[!] -o, --out-interface name
Name of an interface via which a packet is going to be sent (for packets entering the FORWARD, OUTPUT and POSTROUTING chains). When the "!" argument is used before the interface name, the sense is inverted. If the interface name ends in a "+", then any interface which begins with this name will match. If this option is omitted, any interface name will match.

但是,我认为在您的情况下不需要指定接口或协议。我建议使用以下命令:

iptables -t nat -A PREROUTING -d 10.0.0.11 -j DNAT --to-destination 10.82.80.208

【讨论】:

    猜你喜欢
    • 2017-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多