Linux运用iptables端口转发
来源:互联网 发布:org.apache.axis2 jar 编辑:程序博客网 时间:2024/04/29 23:39
启用网卡转发功能
#echo 1 > /proc/sys/net/ipv4/ip_forward
举例:从192.168.0.132:21521(新端口)访问192.168.0.211:1521端口
a.同一端口转发192.168.0.132上开通1521端口访问
iptables -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 1521 -j ACCEPT
iptables -t nat -I PREROUTING -p tcp --dport 1521 -j DNAT --to 192.168.0.211
iptables -t nat -I POSTROUTING -p tcp --dport 1521 -j MASQUERADE
b.不同端口转发192.168.0.132上开通21521端口访问
iptables -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 21521 -j ACCEPT
iptables -t nat -A PREROUTING -p tcp -m tcp --dport 21521 -j DNAT --to-destination 192.168.0.211:1521
iptables -t nat -A POSTROUTING -s 192.168.0.0/16 -d 192.168.0.211 -p tcp -m tcp --dport 1521 -j SNAT --to-source 192.168.0.132
以上两条等价配置(更简单[指定网卡]):
iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 31521 -j DNAT --to 192.168.0.211:1521
iptables -t nat -A POSTROUTING -j MASQUERADE
保存iptables
#service iptables save
#service iptables restart
二 用iptables做本机端口转发
代码如下:
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8080
估计适当增加其它的参数也可以做不同IP的端口转发。
如果需要本机也可以访问,则需要配置OUTPUT链
(********特别注意:本机访问外网的端口会转发到本地,导致访不到外网,如访问yown.com,实际上是访问到本地,建议不做80端口的转发或者指定目的 -d localhost):
iptables -t nat -A OUTPUT -d localhost -p tcp --dport 80 -j REDIRECT --to-ports 8080
原因:
外网访问需要经过PREROUTING链,但是localhost不经过该链,因此需要用OUTPUT。
/sbin/iptables -t nat -A PREROUTING -p tcp -m tcp --dport 20022 -j REDIRECT --to-ports 22
端口转发
IP端口转发
/sbin/iptables -t nat -A PREROUTING -p tcp -m tcp --dport 881 -j DNAT --to-destination 10.10.2.200:881
/sbin/iptables -t nat -A POSTROUTING -s 10.10.0.0/16 -d 10.10.2.200 -p tcp -m tcp --dport 881 -j SNAT --to-source
/sbin/iptables –A INPUT –p tcp –dport 881 –i ppp0 –j ACCEPT
IP端口转发
/sbin/iptables -t nat -A PREROUTING -p tcp -m tcp --dport 800 -j DNAT --to-destination 10.10.2.101:800
/sbin/iptables -t nat -A POSTROUTING -s 10.10.0.0/16 -d 10.10.2.101 -p tcp -m tcp --dport 800 -j SNAT --to-source
/sbin/iptables –A INPUT –p tcp –dport 800 –i ppp0 –j ACCEPT
IP端口转发
/sbin/iptables -t nat -A PREROUTING -p tcp -d --dport 80 -J DNAT --to-destination :8080
/sbin/iptables -t nat -A POSTROUTING -p tcp -s --sport 8080 -J SNAT --to-source
- Linux运用iptables端口转发
- linux 利用iptables 端口转发
- Linux采用iptables端口转发的配置
- iptables设置端口转发
- iptables 端口转发实例
- iptables 实现端口转发
- iptables进行端口转发
- iptables 做端口转发
- iptables 端口转发
- iptables 做端口转发
- iptables 配置端口转发
- iptables 实现端口转发
- iptables端口转发
- linux下用iptables做本机端口转发方法
- iptables例:本地端口转发
- iptables学习 03 端口转发
- centos iptables 端口转发命令
- 配置iptables实现端口转发
- ava RMI 框架(远程方法调用)
- WPF中的页面跳转
- mybatis不执行子查询collection和association
- 关于listView空值的有好提示以及notifyDataSetChange
- WebStorm快捷键
- Linux运用iptables端口转发
- HDU 1150 Machine Schedule 二分图最小覆盖点
- Android:自定义Dialog上面的黑框或者说是Title怎么去掉
- 关于Socket理解
- 第一次拿到一台肉鸡 -- sql注入和内网端口转发登陆内网服务器
- js实现checkbox复选框全选/全不选
- 关于视频相关的播放、转换技术总结
- CFormView 在改变大小时,控件闪烁的问题
- composer php生态环境中用来管理依赖关系的工具