centos6.5 iptables实现端口转发
将本地接口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实现端口转发的更多相关文章
- centos7 && centos6.5部KVM使用NAT联网并为虚拟机配置firewalld && iptables防火墙端口转发
centos7 && centos6.5 部KVM使用NAT联网并为虚拟机配置firewalld && iptables防火墙端口转发 一.准备工作: 1: 检查kvm ...
- iptables 设置端口转发/映射
iptables 设置端口转发/映射 服务器A有两个网卡 内网ip:192.168.1.3 外网ip:10.138.108.103 本地回环:127.0.0.1 服务器B有网卡,8001提供服务 内网 ...
- Ubuntu环境下的iptables的端口转发配置实例
打开转发开关要让iptables的端口转发生效,首先需要打开转发开关方法一:临时打开,重启后失效$sudo su#echo 1 >/proc/sys/net/ipv4/ip_forward 方法 ...
- iptables设置端口转发
转自:https://blog.csdn.net/sigangjun/article/details/17412821 一 从一台机到另一台机端口转发 启用网卡转发功能 #echo 1 > /p ...
- iptables做端口转发
一.用iptables做本机端口转发 比如80端口转8080端口 代码如下: iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT ...
- CentOS系统中使用iptables设置端口转发
echo 1 > /proc/sys/net/ipv4/ip_forward 首先应该做的是/etc/sysctl.conf配置文件的 net.ipv4.ip_forward = 1 默认是0 ...
- 利用iptables做端口转发
需求背景: A与C不在同一网段无法直接访问,而A和B,C和B可以互通.现需要A借助B访问C的3306端口. 解决方案: 利用iptables配置规则,实现端口转发. 具体操作: 在B上开启端口转发功能 ...
- 使用iptables做端口转发
通过iptables可以做转发 #!/bin/sh IPT="/sbin/iptables" /bin/echo "1" > /proc/sys/net/ ...
- iptables实现端口转发实际案例
拓扑 client : 跳板机 外网:192.168.10.194 内网:10.1.1.1 内网mysql: 10.1.1.2 [root@test194 network-scripts]# cat ...
随机推荐
- 解决NDK开发中Eclipse报错“Unresolved inclusion jni.h”的最终方法
http://blog.csdn.net/zhubin215130/article/details/39347873
- css3 过度效果之物体向上冒出
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"/> <meta nam ...
- 在sphinx中应用复杂过滤条件
一.问题的引入 在sphinx应用中,需要对数据进行复杂的条件过滤,刷选出我们需要的数据.这个过程,等同于mysql查询中的where条件. 但sphinx本身的filter并不能支持复杂的逻 ...
- 推荐资料——最受网友力荐的30份HTML前端开发资料
w3cmark最近会新增一个栏目,专注于搜集前端资源的下载,包括和前端相关的电子书.文档PPT.手册.视频教程等等.而下载的媒介是用微博的微盘,至于为什么选择微盘的,那是因为和微博关联起来,通过微盘上 ...
- 【JavaScript】使用面向对象的技术创建高级 Web 应用程序
本文讨论: JavaScript 是基于原型的语言 用 JavaScript 进行面向对象的编程 JavaScript 编码技巧 JavaScript 的未来 本文使用了以下技术: JavaScrip ...
- [MEAN+ Webstrom] First API -- 2.Debug Node.js RESTful application
Using WebStrom can easily debug the Node applcation. For example, we have an Node+Express applicatio ...
- 各种ORM安装
1.EF安装 2.PetaPoco安装 Install-Package PetaPoco 3.
- Golang学习 - sync 包
------------------------------------------------------------ 临时对象池 Pool 用于存储临时对象,它将使用完毕的对象存入对象池中,在需要 ...
- Replace INTO与INSERT INTO的不同之处
Replace INTO和INSERT INTO的区别: REPLACE的运行与INSERT很相似.只有一点例外,假如表中的一个旧记录与一个用于PRIMARY KEY或一个UNIQUE索引的新记录具有 ...
- windows和linux中检查端口是否被占用
一.windows 1.查询端口占用情况 cmd > netstat -ano 2.查询8080端口是否被占用 cmd > netstat -ano|findstr 8080 3.查询哪个 ...