iptables进行端口转发

需求外网访问内网的WEB服务器

我的测试环境:VMware workstation + 2台 Ubuntu 12.04.5 LTS 版本的。
转发外网服务器2个网卡一个192.168.31.206,一个10.10.100.52 )
内网服务器:10.10.100.51

转发服务器配置

iptables -t nat -A PREROUTING -d 192.168.31.206 -p tcp --dport 80 -j DNAT --to-destination 10.10.100.51:80
iptables -t nat -A OUTPUT -d 192.168.31.206 -p tcp --dport 80 -j DNAT --to-destination 10.10.100.51:80//本机访问需要添加OUTPUT 

iptables -t nat -A POSTROUTING -j MASQUERADE
//查看规则
root@ubuntu:/home/hu# iptables -t nat --list --lin
Chain PREROUTING (policy ACCEPT)
num  target     prot opt source               destination         
1    DNAT       tcp  --  anywhere             192.168.31.206       tcp dpt:http to:10.10.100.51:80

Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination          
1    DNAT       tcp  --  anywhere             192.168.31.206       tcp dpt:http to:10.10.100.51:80     

Chain POSTROUTING (policy ACCEPT)
num  target     prot opt source               destination         
1    MASQUERADE all  --  anywhere             anywhere             
//删除规则
iptables -t nat -D PREROUTING 1   //序号从1 开始,后边以此+1.
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值