将本地接口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. leetcode:Path Sum (路径之和) 【面试算法题】

    题目: Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up ...

  2. Ehcache详细解读

    [http://raychase.iteye.com/blog/1545906]   Ehcache 是现在最流行的纯Java开源缓存框架. [通过编程方式使用EhCache ]   //从class ...

  3. Python常用网页字符串处理技巧

    首先一些Python字符串处理的简易常用的用法.其他的以后用到再补充. 1.去掉重复空格 s = "hello hello hello" s = ' '.join(s.split( ...

  4. 推荐系统之基于二部图的个性化推荐系统原理及C++实现

    1.引言 许多网站都喜欢让用户点击“喜欢/不喜欢”,“顶/反对”,也正是这种很简单的信息也可以利用起来对用户进行推荐!这里介绍一种基于网络结构的推荐系统! 由于推荐系统深深植根于互联网,用户与用户之间 ...

  5. HDU 5578 Friendship of Frog 水题

    Friendship of Frog Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.ph ...

  6. C#中Thread类中Join方法的理解(转载)

    指在一线程里面调用另一线程join方法时,表示将本线程阻塞直至另一线程终止时再执行      比如 using System; namespace TestThreadJoin { class Pro ...

  7. Android 中View的绘制机制源代码分析 三

    到眼下为止,measure过程已经解说完了,今天開始我们就来学习layout过程.只是在学习layout过程之前.大家有没有发现我换了编辑器,哈哈.最终下定决心从Html编辑器切换为markdown编 ...

  8. CircleWaveProgressBar

    https://github.com/eltld/CircleWaveProgressBar

  9. Microsoft Robotics Developer Studio 4

    Microsoft Robotics Developer Studio 4       Share   Language: English   Download Microsoft® Robotics ...

  10. centos 服务器配置(二) 之ftp配置

    Centos配置vsftpd服务器 1.通过yum来安装vsftpd [root@localhost ~]# yum -y install vsftpd 加-y是因为出现提示默认直接按Y.这里yum安 ...