将本地接口IP 61.144.a.b 的3389端口 转发到 116.6.c.d的3389      (主要访问到61.144.a.b的3389端口,就会跳转到116.6.c.d的3389)

【步骤】
1、 首先应该做的是/etc/sysctl.conf配置文件的 net.ipv4.ip_forward = 1 默认是0    这样允许iptalbes FORWARD。
2、 service iptables stop  关闭防火墙
3、 重新配置规则

iptables -t nat -A PREROUTING --dst 61.144.a.b -p tcp --dport 3389 -j DNAT --to-destination 116.
6.c.d:3389

iptables -t nat -A POSTROUTING --dst 116.6.c.d -p tcp --dport 3389 -j SNAT --to-source 61.144.a.b

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.a.b -p tcp --dport 3389 -j DNAT --to-destination 116.6.c.d:3389
iptables -t nat -A POSTROUTING --dst 116.6.a.b -p tcp --dport 3389 -j SNAT --to-source 61.144.c.d
~
----------------------------------------------------------------
TCP

iptables -t nat -A PREROUTING --dst 61.144.a.b -p tcp --dport 9304 -j DNAT --to-destination 10.94.a.b:9304
iptables -t nat -A POSTROUTING --dst 10.94.a.b -p tcp --dport 9304 -j SNAT --to-source 61.144.a.b

UDP
iptables -t nat -A PREROUTING --dst 61.144.a.b -p udp --dport 9305 -j DNAT --to-destination 10.94.a.b:9305
iptables -t nat -A POSTROUTING --dst 10.94.a.b -p udp --dport 9305 -j SNAT --to-source 61.144.a.b

另:

iptables配置文件的位置:/etc/sysconfig/iptables 外网地址发变化在配置文件里修改就可以了。

centos6.5 iptables实现端口转发的更多相关文章

  1. centos7 && centos6.5部KVM使用NAT联网并为虚拟机配置firewalld && iptables防火墙端口转发

    centos7 && centos6.5 部KVM使用NAT联网并为虚拟机配置firewalld && iptables防火墙端口转发 一.准备工作: 1: 检查kvm ...

  2. iptables 设置端口转发/映射

    iptables 设置端口转发/映射 服务器A有两个网卡 内网ip:192.168.1.3 外网ip:10.138.108.103 本地回环:127.0.0.1 服务器B有网卡,8001提供服务 内网 ...

  3. Ubuntu环境下的iptables的端口转发配置实例

    打开转发开关要让iptables的端口转发生效,首先需要打开转发开关方法一:临时打开,重启后失效$sudo su#echo 1 >/proc/sys/net/ipv4/ip_forward 方法 ...

  4. iptables设置端口转发

    转自:https://blog.csdn.net/sigangjun/article/details/17412821 一 从一台机到另一台机端口转发 启用网卡转发功能 #echo 1 > /p ...

  5. iptables做端口转发

    一.用iptables做本机端口转发 比如80端口转8080端口 代码如下:   iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT ...

  6. CentOS系统中使用iptables设置端口转发

    echo 1 > /proc/sys/net/ipv4/ip_forward 首先应该做的是/etc/sysctl.conf配置文件的 net.ipv4.ip_forward = 1 默认是0  ...

  7. 利用iptables做端口转发

    需求背景: A与C不在同一网段无法直接访问,而A和B,C和B可以互通.现需要A借助B访问C的3306端口. 解决方案: 利用iptables配置规则,实现端口转发. 具体操作: 在B上开启端口转发功能 ...

  8. 使用iptables做端口转发

    通过iptables可以做转发 #!/bin/sh IPT="/sbin/iptables" /bin/echo "1" > /proc/sys/net/ ...

  9. iptables实现端口转发实际案例

    拓扑 client : 跳板机 外网:192.168.10.194 内网:10.1.1.1 内网mysql: 10.1.1.2 [root@test194 network-scripts]# cat ...

随机推荐

  1. as自定义菜单。

    与菜单相关的类一共有3个 ContextMenu类 ContextMenuBuiltInItems类 //与系统内置菜单相关的类 ContextMenuItem类 //与用户自定义菜单相关的类

  2. 16.ARC

    Swift 使用自动引用计数(ARC)机制来跟踪和管理应用程序的内存.通常情况下,Swift 内存管理机制会一直起作用,我们无须自己来考虑内存的管理.ARC 会在类的实例不再被使用时,自动释放其占用的 ...

  3. 毕业设计--天气预报App

    9月中旬,开始动手做我的毕业设计了,之前一直在纠结做啥,后来想想,既然是做毕业设计,那就大胆地做点自己没接触过的东西吧.然后网上查找资料得知做天气预报需要用到开放的API,而且要用那种现在还在维护的, ...

  4. MyEclipse 编写 ExtJS 卡死问题解决方法

    MyEclipse 8.6  在 jsp 中编写 ExtJS时,会出现卡死现象,让人甚是头疼.网上找了很多方法,折腾半天,还是不管用. 什么MyEclipse 优化,Validation 取消,MyE ...

  5. 在Assertion中获取Response的headers,获取headers中信息,获取body(content)

    // get the  headers of the requestdef content= messageExchange.getResponseContent()def headers = mes ...

  6. Delphi 设置WebBrowser 代理服务器 与 UserAgent

    uses UrlMon, WinInet; {----------------------------------------------------------------------------- ...

  7. Android自定义图形,图形的拼接、叠加、相容

    直接上Xfermode子类: AvoidXfermode  指定了一个颜色和容差,强制Paint避免在它上面绘图(或者只在它上面绘图). PixelXorXfermode  当覆盖已有的颜色时,应用一 ...

  8. C#如何通过NCO3.0来连接SAP并调用SAP中的RFC

    ,这是SAP针对.Net开发的专用组件,安装完成之后在C:\Program Files\SAP\SAP_DotNetConnector3_x86目录下面会有sapnco_utils.dll sapnc ...

  9. Android Checkbox Example

    1. Custom String 打开 “res/values/strings.xml” 文件, File : res/values/strings.xml <?xml version=&quo ...

  10. C语言待研究问题

    1.内存分配 变量的静态分配和静态变量的区别: 变量的静态分配和动态分配 2.堆和栈的区别 3.CPU的并发性 4.变量和参数的区别