查看GNU/Linux Tips的源代码
←
GNU/Linux Tips
跳转到:
导航
,
搜索
因为以下原因,你没有权限编辑本页:
您刚才请求的操作只有这个用户组中的用户才能使用:
用户
您可以查看并复制此页面的源代码:
=== 实例 === 网关端口映射到内网: <source lang=bash> $ iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 80 -j DNAT --to-destination 192.168.1.87:8080 </source> 共享网关公网地址入网: <source lang=bash> # static ip $ iptables -t nat -A POSTROUTING -o eth1 -j SNAT # dynamic IP $ iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE </source> If you have an HTTP proxy (such as Squid) configured to run as a transparent proxy on your firewall computer and listen on port 8888, you can add one rule to redirect outbound HTTP traffic to the HTTP proxy: <source lang=bash> $ iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8888 # iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 6666 </source> 将测试网段的端口的包转发到本机端口,其他网段则正常访问原端口: <source lang=bash> $ iptables -t nat -A PREROUTING -p tcp -s 192.168.10.0/24 --dport 1234 -j REDIRECT --to-ports 6666 </source> 端口转发,将源为 A 访问 B 的 1234 端口的包,转发到 C 的 6666 端口,其他的不管: <source lang=bash> $ iptables -t nat -A PREROUTING -s 192.168.10.2 -p tcp --dport 1234 -j DNAT --to-destination 192.168.10.6:6666 $ iptables -t nat -A POSTROUTING --dst 192.168.10.2 -p tcp --dport 6666 -j MASQUERADE # 将目的端口 82 的包,全部转发到 xx.xx.xx.xx:83 $ iptables -t nat -I PREROUTING -p tcp --dport 82 -j DNAT --to-destination xx.xx.xx.xx:83 $ iptables -t nat -I POSTROUTING -d xx.xx.xx.xx -p tcp --dport 83 -j MASQUERADE # 目标为 xx.xx.xx.xx:83 的 tcp 包,自动获取当前网卡的 IP 地址进行源地址转换 $ iptables -t nat -I POSTROUTING -j MASQUERADE # 自动获取当前网卡的 IP 地址进行源地址转换 </source> * -s [!] addr[/mask] <===> --src <===> --source * -d [!] addr[/mask] <===> --dst <===> --destination * DNAT 模式用来做目的网络地址转换,比如把某个目的端口包都转发到内网的地址端口,可以做某种类型的负载平衡。Destination NAT (DNAT) exposes specific services on an internal network to the outside world without linking the internal computers directly to the Internet. * SNAT 模式用于源网络地址转换,就是重写包的源 IP 地址。一般挂在 POSTROUTING chain of the nat table。Source NAT (SNAT) is used to share a single Internet connection among computers on a network。 保存规则: <source lang=bash> $ service iptables save </source> 关闭端口转发: <source lang=bash> $ service iptables stop </source> <br>
返回到
GNU/Linux Tips
。
个人工具
登录
名字空间
页面
讨论
变换
查看
阅读
查看源代码
查看历史
操作
搜索
导航
首页
社区专页
新闻动态
最近更改
随机页面
帮助
工具箱
链入页面
相关更改
特殊页面