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 ...
随机推荐
- jquery 选择器中含有空格注意
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- TextView 实现复制文本功能
Android api 11 以后可以直接设置 android:textIsSelectable="true" <TextView android:layout_width= ...
- Windows Self Signed Driver
In particular, Microsoft® instituted a device driver certification process for its Windows® desktop ...
- Lazy Loading Images
Use a blank.gif as the src of images, and include the width and height of the final image. HTML: < ...
- 【转】python代码风格-PEP8
转载自http://www.douban.com/note/134971609/ Python 的代码风格由 PEP 8 描述.这个文档描述了 Python 编程风格的方方面面.在遵守这个文档的条件下 ...
- IOS 7 Study - Displaying an Image on a Navigation Bar
ProblemYou want to display an image instead of text as the title of the current view controlleron th ...
- UVALive 4221 Walk in the Park 扫描线
Walk in the Park 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemi ...
- SQL自增长的数据插入
--子增长的插入 /*创建表*/ create table teacher ( id int identity(1,1) primary key not null, name varchar(20) ...
- TP常用函数
英文字符可用形如 {$vo.title|substr=0,5} 如果是中文字符thinkphp提供了msubstr如下 function msubstr($str, $start=0, $length ...
- HDU 4876 ZCC loves cards(暴力剪枝)
HDU 4876 ZCC loves cards 题目链接 题意:给定一些卡片,每一个卡片上有数字,如今选k个卡片,绕成一个环,每次能够再这个环上连续选1 - k张卡片,得到他们的异或和的数,给定一个 ...