echo 1 > /proc/sys/net/ipv4/ip_forward

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

修改完成后运行以下命令使参数生效:
/sbin/sysctl -p

将本地接口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    这样允许iptalbes FORWARD。

2、 service iptables stop  关闭防火墙

3、 重新配置规则

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 -j SNAT --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 -j SNAT --to-source 61.144.14.72
~

----------------------------------------------------------------
TCP
iptables -t nat -A PREROUTING --dst 61.144.14.87 -p tcp --dport 9304 -j DNAT --to-destination 10.94.143.204:9304
iptables -t nat -A POSTROUTING --dst 10.94.143.204 -p tcp --dport 9304 -j SNAT --to-source 61.144.14.87
UDP
iptables -t nat -A PREROUTING --dst 61.144.14.87 -p udp --dport 9305 -j DNAT --to-destination 10.94.143.204:9305
iptables -t nat -A POSTROUTING --dst 10.94.143.204 -p udp --dport 9305 -j SNAT --to-source 61.144.14.87

CentOS系统中使用iptables设置端口转发的更多相关文章

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

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

  2. iptables设置端口转发

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

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

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

  4. 如何在CentOS系统中安装配置SNMP服务

    CentOS(Community Enterprise Operating System,中文意思是:社区企业操作系统)是Linux发行版之一,现在有一大部分服务器在使用此操作系统:SNMP(简单网络 ...

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

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

  6. linux设置端口转发(一键设置)

    linux设置端口转发 #下载rinetd程序并进入文件夹 wget http://www.boutell.com/rinetd/http/rinetd.tar.gz&&tar -xv ...

  7. 在Centos系统中基于PowerDNS和Poweradmin自建域名解析服务器替代DnsPod

    本文讲述了我在Centos 7系统(其他版本的Centos未尝试)中基于PowerDNS和poweradmin自建域名解析服务器替代DnsPod的过程.通过本文所述方法,可以建立权威域名解析服务器的m ...

  8. CentOS系统中last命令的作用

    CentOS系统中last命令的作用是显示近期用户或终端的登录情况,它的使用权限是所有用户.通过last命令查看该程序的log,管理员可以获知谁曾经或企图连接系统. 格式 last [—R] [—n] ...

  9. 在CentOS 7 上为docker配置端口转发以兼容firewall

    在CentOS 7上当我们以类似下列命令将主机端口与容器端口映射时可能遇到无法访问容器服务的问题 docker run --name web_a -p 192.168.1.250:803:80 -d ...

随机推荐

  1. java动态数组笔记

    动态数组: 在java.lang.reflect包下提供了Array类,包括一系列static方法,通过这些方法可动态的创建数组.给元素赋值.取出元素值等等 //理解数组引用——下面定义的objs数组 ...

  2. ubuntu replace system openjdk

    一些ubuntu自带jdk的.但是有时候会确实我们所要的文件.下面介绍如何replace jdk 1. 卸载现有jdk sudo apt-get purge openjdk-\* 2. 下载jdk. ...

  3. Hibernate通过自编写sql查询

    public List<InterProductMsg> selectIsHaveProductid(String productId) { String sql="SELECT ...

  4. DataFrame的数据类型转换

    dfxxx['username']=pd.to_numeric(dfxxx['username'],errors='coerce')#将不能转换数据类型的值强制转换成NaN dfxxx['userna ...

  5. MQTT学习之一

    一MQTT特性: 基于C/S,发布订阅(发布者服务器->云平台代理->订阅客户端)一对多结构,适用于低带宽高延时,基于TCP/IP之上.

  6. Java反射机制分析指南

    一.JAVA是动态语言吗? 一般而言,说到动态言,都是指在程序运行时允许改变程序结构或者变量类型,从这个观点看,JAVA和C++一样,都不是动态语言. 但JAVA它却有着一个非常突出的动态相关机制:反 ...

  7. MVC视图之间调用方法总结

    调用视图方式有两种: 一:直接调用(不通过controller) <body> @Html.Partial("../Shared/Error"); </body& ...

  8. HDU 4357——String change——————【规律题】

    String change Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  9. 接口调试,HttpWebRequest和HttpWebResponse使用,接口回调处理

    public void queryIdCardSelects { string url=“jiekoudizhi.html”; string param="jiekoucanshu" ...

  10. Oracle数据库分割字符串function方法

    下面我直接上传一串代码源码, create or replace function strsplit(p_value varchar2, p_split varchar2 := ',') --usag ...