<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>服务器安全维护工作室 &#187; linux-如何同时访问阿里云RDS的内外网-ssh-tunnel/snat/dnat</title>
	<atom:link href="https://www.fuwuqiok.com/tag/linux-%e5%a6%82%e4%bd%95%e5%90%8c%e6%97%b6%e8%ae%bf%e9%97%ae%e9%98%bf%e9%87%8c%e4%ba%91rds%e7%9a%84%e5%86%85%e5%a4%96%e7%bd%91-ssh-tunnelsnatdnat/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.fuwuqiok.com</link>
	<description></description>
	<lastBuildDate>Sun, 01 Mar 2020 07:28:40 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.2.26</generator>
	<item>
		<title>linux-如何同时访问阿里云RDS的内外网-ssh-tunnel/snat/dnat</title>
		<link>https://www.fuwuqiok.com/linux-%e5%a6%82%e4%bd%95%e5%90%8c%e6%97%b6%e8%ae%bf%e9%97%ae%e9%98%bf%e9%87%8c%e4%ba%91rds%e7%9a%84%e5%86%85%e5%a4%96%e7%bd%91-ssh-tunnelsnatdnat/</link>
		<comments>https://www.fuwuqiok.com/linux-%e5%a6%82%e4%bd%95%e5%90%8c%e6%97%b6%e8%ae%bf%e9%97%ae%e9%98%bf%e9%87%8c%e4%ba%91rds%e7%9a%84%e5%86%85%e5%a4%96%e7%bd%91-ssh-tunnelsnatdnat/#comments</comments>
		<pubDate>Fri, 10 Mar 2017 14:23:24 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[aliyun服务器代维]]></category>
		<category><![CDATA[服务器维护]]></category>
		<category><![CDATA[linux-如何同时访问阿里云RDS的内外网-ssh-tunnel/snat/dnat]]></category>

		<guid isPermaLink="false">https://www.fuwuqiok.com/?p=3135</guid>
		<description><![CDATA[<p>需求一： 之前介绍了windows下如何通过公网IP代理访问内网的RDS数据库，本文将介绍linux下如果通过 [&#8230;]</p>
<p><a rel="nofollow" href="https://www.fuwuqiok.com/linux-%e5%a6%82%e4%bd%95%e5%90%8c%e6%97%b6%e8%ae%bf%e9%97%ae%e9%98%bf%e9%87%8c%e4%ba%91rds%e7%9a%84%e5%86%85%e5%a4%96%e7%bd%91-ssh-tunnelsnatdnat/">linux-如何同时访问阿里云RDS的内外网-ssh-tunnel/snat/dnat</a>，首发于<a rel="nofollow" href="https://www.fuwuqiok.com">服务器安全维护工作室</a>。</p>
]]></description>
				<content:encoded><![CDATA[<div>需求一： 之前介绍了windows下如何通过公网IP代理访问内网的RDS数据库，本文将介绍linux下如果通过公网IP来访问内网的RDS。</div>
<p>&nbsp;</p>
<div>需求二：也有客户内网服务器想通过公网服务器上外网的需求（SNAT/VPN/PROXY）</div>
<div></div>
<div><img class="lazy " title="更多..." src="http://www.cnhejia.cn/wp-content/plugins/jquery-image-lazy-loading/images/grey.gif" alt="" data-original="http://www.cnhejia.cn/wp-includes/js/tinymce/plugins/wordpress/img/trans.gif" /></div>
<div>这两个需求在普通网络环境下很容易实现，开启ipnet.ipv4.ip_forward 之后</div>
<div>
<p>需求一：</p>
<div>公网服务器执行iptables命令：iptables -t nat -I PREROUTING -p tcp –dport 3306  -j DNAT –to RDSIP:3306</div>
</div>
<div>
<div>即可实现访问公网IP的3306端口即可转发到RDSIP的3306端口。</div>
<div>需求二：</div>
<div>公网服务器执行iptables命令:iptables -t nat -I POSTROUTING -s LANIP -j SNAT –to WANIP</div>
<div>内网服务器网关设置为公网服务器的内网IP，即可将访问请求转换为WANIP访问出去。</div>
<div></div>
<div>————</div>
<div></div>
<div>由于阿里云的虚拟化网络有一些限制，所以以上的办法实现这两个需求有时候会不成功，所以这里分享一个应用层实现的肯定管用的转发利用ssh tunnel，如下：</div>
<div>需求一：</div>
<div>[root@test ~]# ssh -Nf -L 122.224.103.234:3433:192.168.131.51:1433192.168.131.219</div>
<div></div>
<div>或者配置sshd_config   GatewayPorts yes然后执行</div>
<div>ssh -Nf -R 122.224.103.234:3433:192.168.1.51:1433 192.168.1.219</div>
<div></div>
<div>即可实现访问103.234服务器的3433端口，会通过内网IP:1.219来跳转访问到内网服务器1.51的1433端口</div>
<div>内网IP：131.219可以公网VM自身的内网IP，也可以是公网VM和内网服务器都可以连接的一台跳板机</div>
<div>备注：</div>
<div>如果3433端口想在自身所有的IP（0.0.0.0）上监听需要配置sshd_config的gatewayports为yes</div>
<div>-N 告诉SSH客户端，这个连接不需要执行任何命令。仅仅做端口转发</div>
<div>-f 告诉SSH客户端在后台运行  （使用此命令后，ssh隧道会一直在后台监听，不会因终端推出而中断）</div>
<div></div>
<div>需求二</div>
<div>开启gatewayports后运行命令</div>
<div>[root@test ~]# ssh -Nf -D 0.0.0.0:1080 122.224.103.234</div>
<div>即可在1080端口上开启socket5 代理，内网服务器需要访问网络的程序只要支持socket5协议即可通过公网服务器代理访问跟公网</div>
</div>
<p><a rel="nofollow" href="https://www.fuwuqiok.com/linux-%e5%a6%82%e4%bd%95%e5%90%8c%e6%97%b6%e8%ae%bf%e9%97%ae%e9%98%bf%e9%87%8c%e4%ba%91rds%e7%9a%84%e5%86%85%e5%a4%96%e7%bd%91-ssh-tunnelsnatdnat/">linux-如何同时访问阿里云RDS的内外网-ssh-tunnel/snat/dnat</a>，首发于<a rel="nofollow" href="https://www.fuwuqiok.com">服务器安全维护工作室</a>。</p>
]]></content:encoded>
			<wfw:commentRss>https://www.fuwuqiok.com/linux-%e5%a6%82%e4%bd%95%e5%90%8c%e6%97%b6%e8%ae%bf%e9%97%ae%e9%98%bf%e9%87%8c%e4%ba%91rds%e7%9a%84%e5%86%85%e5%a4%96%e7%bd%91-ssh-tunnelsnatdnat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
