展会信息港展会大全

CentOS系统中使用iptables设置端口转发
来源:互联网   发布日期:2016-01-28 13:09:36   浏览:1871次  

导读: 将本地接口IP 61.144.14.72 的3389端口 转发到 116.6.73.229的3389 (主要访问到61.144.14.72的3389端口,就会跳转到116.6.73.22...

将本地接口IP 61.144.14.72 的3389端口 转发到 116.6.73.229的3389

(主要访问到61.144.14.72的3389端口,就会跳转到116.6.73.229的3389)

【步骤】

1、 首先应该做的是/etc/sysctl.conf配置文件的 net.ipv4.ip_forward = 1 默认是0 这样允许iptalbesFORWARD。

2、 service iptables stop 关闭防火墙

3、 重新配置规则

iptables -t nat -A PREROUTING --dst 61.144.14.72 -p tcp --dport 3389 -jDNAT --to-destination 116.6.73.229:3389

iptables -t nat -A POSTROUTING --dst 116.6.73.229 -p tcp --dport 3389 -jSNAT --to-source 61.144.14.72

service iptables save

将当前规则保存到 /etc/sysconfig/iptables

若你对这个文件很熟悉直接修改这里的内容也等于命令行方式输入规则。

5、 启动iptables 服务, service iptables start

可以写进脚本,设备启动自动运行;

# vi /etc/rc.local

#!/bin/sh

#

# This script will be executed *after* all the other init scripts.

# You can put your own initialization stuff in here if you don't

# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local

sh /root/myshipin.log

---------------------------------------------------------------------

vi myshipin.log

#!/bin/sh

#

# This script will be executed *after* all the other init scripts.

# You can put your own initialization stuff in here if you don't

# want to do the full Sys V style init stuff.

iptables -F -t nat iptables -t nat -A PREROUTING --dst 61.144.14.72 -p tcp--dport 3389 -j DNAT --to-destination 116.6.73.229:3389

iptables -t nat -A POSTROUTING --dst 116.6.73.229 -p tcp --dport 3389 -jSNAT --to-source 61.144.14.72

~

----------------------------------------------------------------

TCP

iptables -t nat -A PREROUTING --dst 61.144.14.87 -p tcp --dport 9304 -jDNAT --to-destination 10.94.143.204:9304

iptables -t nat -A POSTROUTING --dst 10.94.143.204 -p tcp --dport 9304 -jSNAT --to-source 61.144.14.87

UDP

iptables -t nat -A PREROUTING --dst 61.144.14.87 -p udp --dport 9305 -jDNAT --to-destination 10.94.143.204:9305

iptables -t nat -A POSTROUTING --dst 10.94.143.204 -p udp --dport 9305 -jSNAT --to-source 61.144.14.87

赞助本站

人工智能实验室

相关热词: 开发 编程 android

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港