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 ...
随机推荐
- android: Incorrect line ending: found carriage return (\r) without corresponding newline (\n)
当报这种错误的时候:Incorrect line ending: found carriage return (\r) without corresponding newline (\n) 解决方法: ...
- IL学习资料
读懂IL代码就这么简单 由浅入深CIL系列 .net IL 指令速查
- MFC 构建、消亡 顺序 (一)--单文档 (SDI)
MFC 构建.消亡 顺序 (一)--单文档 (SDI) by:http://www.cnblogs.com/vranger/ (一)SDI 生成顺序 (二)打开文档-“Open” (三)新建文档-“N ...
- Using Eclipse With CloudStack
As part of switching to Apache Maven for building CloudStack, the .classpath and .project files used ...
- C#操作Excel(2)-- 打开-读取Excel文档
由于要为某软件实现导出Excel功能,故有此文. 本文的开发环境是Visual Studio 2010 ,C#, Excel 2007. 新建C#工程后打开Solution Explorer,可以看到 ...
- 使用贝赛尔曲线画扇形、圆形、弧线、多边形,实现App下载时的动画效果demo
// // MyView.swift // TestUIBezierPath // // Created by iCodeWoods on 16/5/8. // Copyright © 2016年 i ...
- GXPT(一)——UI设计
通过长时间的积淀.TGB再次開始GXPT模式,JAVA版..NET版两条线同一时候进行. 纯面向对象的底层架构的搭建:easyUI+MVC的界面设计:工作流的再次雄起.云平台的构想:Confluenc ...
- 如何恢复 Linux 上删除的文件,第 1 部分
来源:http://www.ibm.com/developerworks/cn/linux/l-cn-filesrc/ 原理及普通文件的恢复 要想恢复误删除的文件,必须清楚数据在磁盘上究竟是如何存储的 ...
- 淘宝Refrash_token签名错误的解决办法
最近在做淘宝相关应用,想要通过Refrash_token来延长SessionKey的授权时间,但是总是报406 sign error. 经过多次尝试和多方询问,方才知道原来淘宝给的.net SDK里面 ...
- 功能分解——Android下画分时图与k线图有感
最近工作极度繁忙,已经好久没有更新博客了,总感觉要是再不抽空总结总结点东西,分分钟就会被懒惰的状态给打到了.同时也希望同学们谨记,如果你已经决定要坚持某些正确的东西,比如背完某章单词,看一完本书抑或是 ...