喜欢真诚 發表於 2020-9-10 01:36:00

Linux服务器所以Frp实现内网穿透(阿里云Ubuntu)

<div style="font-family: &quot;Helvetica Neue&quot;, Helvetica, Tahoma, Arial, &quot;Hiragino Sans GB&quot;, STHeiti, &quot;Microsoft YaHei&quot;, &quot;微软雅黑&quot;, &quot;WenQuanYi Micro Hei&quot;, STXihei, &quot;华文细黑&quot;, Heiti, &quot;黑体&quot;, SimSun, &quot;宋体&quot;, Song, sans-serif; font-size: 16px; line-height: 1.8; font-weight: normal; color: rgba(47, 47, 47, 1); word-wrap: break-word">
        <div class="preview html_preview xsj_public" style="max-width: 100%"><p class="xsj_paragraph xsj_paragraph_level_0" style="margin: 1.1em 0 1.6em"></p><div class="toc"><ul style="padding: 0; margin: 1.1em 0 1.1em 3em; list-style-type: none"><li>Linux服务器下Frp实现内网穿透(阿里云Ubuntu)<ul style="padding: 0; margin: 0 0 0 1em; list-style-type: none"><li><ul style="padding: 0; margin: 0 0 0 1em; list-style-type: none"><li>一、下载Frp项目</li><li>二、配置公网服务器</li><li>三、修改内网服务器</li><li>四、分别启动内网公网服务器FRP<ul style="padding: 0; margin: 0 0 0 1em; list-style-type: none"><li>1、在公网服务器中启动frps服务端:</li><li>2、在内网服务器中启动frpc客户端:</li></ul></li><li>五、ssh登录服务器</li><li>六、常见问题与解决方案<ul style="padding: 0; margin: 0 0 0 1em; list-style-type: none"><li>1、内网服务器无法连接frpc客户端:</li><li>2、ssh无法使用内网账号密码登录,只能使用公网密码登录</li><li>3、ssh无法登录到frp服务器,提示超时</li><li>4、tcp拨号提示超时</li></ul></li></ul></li><li>安全地暴露内网服务</li></ul></li></ul></div><p style="margin: 1.1em 0 1.6em"></p>
<h1 class="xsj_heading_hash xsj_heading xsj_heading_h1" id="linuxe69c8de58aa1e599a8e4b88bfrpe5ae9ee78eb0e58685e7bd91e7a9bfe9808fe998bfe9878ce4ba91ubuntu_1" style="font-weight: bold; text-rendering: optimizelegibility; font-size: 2rem; margin: 0.8em 0 0.6em"><div class="xiaoshujiang_element xsj_anchor" style="overflow: hidden; float: right">

</div>
<span class="xsj_heading_content">Linux服务器下Frp实现内网穿透(阿里云Ubuntu)</span></h1>
<p class="xsj_paragraph xsj_paragraph_level_0" style="margin: 1.1em 0 1.6em">有时候我们需要让内网的服务器允许访问,但是自己内网家庭常用带宽,我发直接访问IP,所以我们只能进行内网穿透,使用花生壳等软件是付费的,所以我们选择了<code style="background-color: rgba(240, 240, 240, 1); border-radius: 4px; padding: 2px 4px; margin: 0 0.225em; color: rgba(136, 0, 0, 1); border: 0; font-size: 0.9em">frp</code>作为内网穿透工具,配置如下,你需要的东西有:</p>
<ul class="markdown_ul" style="padding: 0; margin: 1.1em 0 1.1em 3em">
<li><span class="xsj_placeholder_span"></span>公网服务器,具有外网IP(如阿里云,腾讯云等服务器)</li>
<li><span class="xsj_placeholder_span"></span>内网服务器,能联网即可。</li>
</ul>
<h3 class="xsj_heading_hash xsj_heading xsj_heading_h3" id="e4b880e38081e4b88be8bdbdfrpe9a1b9e79bae_2" style="font-weight: bold; text-rendering: optimizelegibility; font-size: 1.6rem; margin: 0.6em 0 0.4em"><div class="xiaoshujiang_element xsj_anchor" style="overflow: hidden; float: right">

</div>
<span class="xsj_heading_content">一、下载Frp项目</span></h3>
<p class="xsj_paragraph xsj_paragraph_level_0" style="margin: 1.1em 0 1.6em">分别下载<code style="background-color: rgba(240, 240, 240, 1); border-radius: 4px; padding: 2px 4px; margin: 0 0.225em; color: rgba(136, 0, 0, 1); border: 0; font-size: 0.9em">frp</code>到公网服务器和内网服务器:</p>
<div class="xiaoshujiang_code_container" style="margin: 1em 0 2em; position: relative"><pre data-processed="true" style="line-height: initial !important; word-wrap: break-word; tab-size: 4; white-space: pre-wrap; font-family: monospace; margin: 0"><code class="language-powershell hljs" data-info="powershell" style="background: rgba(240, 240, 240, 1); border-radius: 4px; padding: 0.5em; margin: 0 0.225em; color: rgba(68, 68, 68, 1); border: 0; font-size: 0.9em; overflow: visible !important; display: block; overflow-x: auto">wget https://github.com/fatedier/frp/releases/download/v0.<span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">25.0</span>/frp_0.<span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">25.0</span>_linux_amd64.tar.gz</code></pre></div>
<p class="xsj_paragraph xsj_paragraph_level_0" style="margin: 1.1em 0 1.6em">然后解压并进入服务器,</p>
<div class="xiaoshujiang_code_container" style="margin: 1em 0 2em; position: relative"><pre data-processed="true" style="line-height: initial !important; word-wrap: break-word; tab-size: 4; white-space: pre-wrap; font-family: monospace; margin: 0"><code class="language-powershell hljs" data-info="powershell" style="background: rgba(240, 240, 240, 1); border-radius: 4px; padding: 0.5em; margin: 0 0.225em; color: rgba(68, 68, 68, 1); border: 0; font-size: 0.9em; overflow: visible !important; display: block; overflow-x: auto">tar zxvf ./frp_0.<span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">25.0</span>_linux_amd64.tar.gz
cd frp_0.<span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">25.0</span>_linux_amd64/

<span class="hljs-comment" style="overflow: visible !important; color: rgba(136, 136, 136, 1)"># 目录内容如下</span>
<span class="hljs-comment" style="overflow: visible !important; color: rgba(136, 136, 136, 1)"># LICENSEfrpcfrpc.inifrpc_full.inifrpsfrps.inifrps_full.ini</span></code></pre></div>
<h3 class="xsj_heading_hash xsj_heading xsj_heading_h3" id="e4ba8ce38081e9858de7bdaee585ace7bd91e69c8de58aa1e599a8_3" style="font-weight: bold; text-rendering: optimizelegibility; font-size: 1.6rem; margin: 0.6em 0 0.4em"><div class="xiaoshujiang_element xsj_anchor" style="overflow: hidden; float: right">

</div>
<span class="xsj_heading_content">二、配置公网服务器</span></h3>
<p class="xsj_paragraph xsj_paragraph_level_0" style="margin: 1.1em 0 1.6em">进入公网IP服务器中修改目录中的<code style="background-color: rgba(240, 240, 240, 1); border-radius: 4px; padding: 2px 4px; margin: 0 0.225em; color: rgba(136, 0, 0, 1); border: 0; font-size: 0.9em">frps.ini</code>配置文件, 将<code style="background-color: rgba(240, 240, 240, 1); border-radius: 4px; padding: 2px 4px; margin: 0 0.225em; color: rgba(136, 0, 0, 1); border: 0; font-size: 0.9em">bind_port</code>改为随意可用端口</p>
<div class="xiaoshujiang_code_container" style="margin: 1em 0 2em; position: relative"><pre data-processed="true" style="line-height: initial !important; word-wrap: break-word; tab-size: 4; white-space: pre-wrap; font-family: monospace; margin: 0"><code class="language-powershell hljs" data-info="powershell" style="background: rgba(240, 240, 240, 1); border-radius: 4px; padding: 0.5em; margin: 0 0.225em; color: rgba(68, 68, 68, 1); border: 0; font-size: 0.9em; overflow: visible !important; display: block; overflow-x: auto">
bind_port = <span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">7000</span></code></pre></div>
<h3 class="xsj_heading_hash xsj_heading xsj_heading_h3" id="e4b889e38081e4bfaee694b9e58685e7bd91e69c8de58aa1e599a8_4" style="font-weight: bold; text-rendering: optimizelegibility; font-size: 1.6rem; margin: 0.6em 0 0.4em"><div class="xiaoshujiang_element xsj_anchor" style="overflow: hidden; float: right">

</div>
<span class="xsj_heading_content">三、修改内网服务器</span></h3>
<p class="xsj_paragraph xsj_paragraph_level_0" style="margin: 1.1em 0 1.6em">在内网IP服务器中修改<code style="background-color: rgba(240, 240, 240, 1); border-radius: 4px; padding: 2px 4px; margin: 0 0.225em; color: rgba(136, 0, 0, 1); border: 0; font-size: 0.9em">frpc.ini</code>配置文件:</p>
<div class="xiaoshujiang_code_container" style="margin: 1em 0 2em; position: relative"><pre data-processed="true" style="line-height: initial !important; word-wrap: break-word; tab-size: 4; white-space: pre-wrap; font-family: monospace; margin: 0"><code class="language-powershell hljs" data-info="powershell" style="background: rgba(240, 240, 240, 1); border-radius: 4px; padding: 0.5em; margin: 0 0.225em; color: rgba(68, 68, 68, 1); border: 0; font-size: 0.9em; overflow: visible !important; display: block; overflow-x: auto">
server_addr = <span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">123.123</span>.<span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">123.123</span>
server_port = <span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">7000</span>


type = tcp
local_ip = <span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">127.0</span>.<span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">0.1</span>
local_port = <span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">22</span>
remote_port = <span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">6000</span></code></pre></div>
<p class="xsj_paragraph xsj_paragraph_level_0" style="margin: 1.1em 0 1.6em">其中解释如下:</p>
<ul class="markdown_ul" style="padding: 0; margin: 1.1em 0 1.1em 3em">
<li><span class="xsj_placeholder_span"></span>common表示基本配置
<ul class="markdown_ul" style="padding: 0; margin: 0 0 0 1em">
<li><span class="xsj_placeholder_span"></span>server_addr:公网服务器地址</li>
<li><span class="xsj_placeholder_span"></span>server_port:公网bind_port配置的端口</li>
</ul>
</li>
<li><span class="xsj_placeholder_span"></span>ssh表示使用ssh登录内网服务器
<ul class="markdown_ul" style="padding: 0; margin: 0 0 0 1em">
<li><span class="xsj_placeholder_span"></span>type:tcp即可</li>
<li><span class="xsj_placeholder_span"></span>local_ip:本地iP,127.0.0.1即可</li>
<li><span class="xsj_placeholder_span"></span>local_port: ssh端口</li>
<li><span class="xsj_placeholder_span"></span>remote_port:ssh链接端口</li>
</ul>
</li>
</ul>
<h3 class="xsj_heading_hash xsj_heading xsj_heading_h3" id="e59b9be38081e58886e588abe590afe58aa8e58685e7bd91e585ace7bd91e69c8de58aa1e599a8frp_5" style="font-weight: bold; text-rendering: optimizelegibility; font-size: 1.6rem; margin: 0.6em 0 0.4em"><div class="xiaoshujiang_element xsj_anchor" style="overflow: hidden; float: right">

</div>
<span class="xsj_heading_content">四、分别启动内网公网服务器FRP</span></h3>
<h4 class="xsj_heading_hash xsj_heading xsj_heading_h4" id="1e38081e59ca8e585ace7bd91e69c8de58aa1e599a8e4b8ade590afe58aa8frpse69c8de58aa1e7abafefbc9a_6" style="font-weight: bold; text-rendering: optimizelegibility; font-size: 1.5rem; margin: 0.5em 0 0.3em"><div class="xiaoshujiang_element xsj_anchor" style="overflow: hidden; float: right">

</div>
<span class="xsj_heading_content">1、在公网服务器中启动frps服务端:</span></h4>
<p class="xsj_paragraph xsj_paragraph_level_0" style="margin: 1.1em 0 1.6em">为了方便调试,我们先启动桌面版:</p>
<div class="xiaoshujiang_code_container" style="margin: 1em 0 2em; position: relative"><pre data-processed="true" style="line-height: initial !important; word-wrap: break-word; tab-size: 4; white-space: pre-wrap; font-family: monospace; margin: 0"><code class="language-powershell hljs" data-info="powershell" style="background: rgba(240, 240, 240, 1); border-radius: 4px; padding: 0.5em; margin: 0 0.225em; color: rgba(68, 68, 68, 1); border: 0; font-size: 0.9em; overflow: visible !important; display: block; overflow-x: auto">cd frp_0.<span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">25.0</span>_linux_amd64/
./frps -c ./frps.ini
nohup ./frps -c ./frps.ini &amp;

<span class="hljs-comment" style="overflow: visible !important; color: rgba(136, 136, 136, 1)"># 链接成功会出现如下内容</span>
<span class="hljs-comment" style="overflow: visible !important; color: rgba(136, 136, 136, 1)"># 2019/03/19 16:41:16 frps tcp listen on 0.0.0.0:7000</span>
<span class="hljs-comment" style="overflow: visible !important; color: rgba(136, 136, 136, 1)"># 2019/03/19 16:41:16 Start frps success</span>
<span class="hljs-comment" style="overflow: visible !important; color: rgba(136, 136, 136, 1)"># 2019/03/19 16:41:16 PrivilegeMode is enabled, you should pay more attention to security issues</span></code></pre></div>
<p class="xsj_paragraph xsj_paragraph_level_0" style="margin: 1.1em 0 1.6em">生产使用中可使用如下命令在后台运行:</p>
<div class="xiaoshujiang_code_container" style="margin: 1em 0 2em; position: relative"><pre data-processed="true" style="line-height: initial !important; word-wrap: break-word; tab-size: 4; white-space: pre-wrap; font-family: monospace; margin: 0"><code class="language-powershell hljs" data-info="powershell" style="background: rgba(240, 240, 240, 1); border-radius: 4px; padding: 0.5em; margin: 0 0.225em; color: rgba(68, 68, 68, 1); border: 0; font-size: 0.9em; overflow: visible !important; display: block; overflow-x: auto">nohup ./frps -c ./frps.ini &gt; /dev/null <span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">2</span>&gt;&amp;<span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">1</span> &amp;</code></pre></div>
<h4 class="xsj_heading_hash xsj_heading xsj_heading_h4" id="2e38081e59ca8e58685e7bd91e69c8de58aa1e599a8e4b8ade590afe58aa8frpce5aea2e688b7e7abafefbc9a_7" style="font-weight: bold; text-rendering: optimizelegibility; font-size: 1.5rem; margin: 0.5em 0 0.3em"><div class="xiaoshujiang_element xsj_anchor" style="overflow: hidden; float: right">

</div>
<span class="xsj_heading_content">2、在内网服务器中启动frpc客户端:</span></h4>
<p class="xsj_paragraph xsj_paragraph_level_0" style="margin: 1.1em 0 1.6em">公网服务器启动成功后,在内网服务器中启动<code style="background-color: rgba(240, 240, 240, 1); border-radius: 4px; padding: 2px 4px; margin: 0 0.225em; color: rgba(136, 0, 0, 1); border: 0; font-size: 0.9em">frpc</code>,为了方便调试,我们一样启动桌面版:</p>
<div class="xiaoshujiang_code_container" style="margin: 1em 0 2em; position: relative"><pre data-processed="true" style="line-height: initial !important; word-wrap: break-word; tab-size: 4; white-space: pre-wrap; font-family: monospace; margin: 0"><code class="language-powershell hljs" data-info="powershell" style="background: rgba(240, 240, 240, 1); border-radius: 4px; padding: 0.5em; margin: 0 0.225em; color: rgba(68, 68, 68, 1); border: 0; font-size: 0.9em; overflow: visible !important; display: block; overflow-x: auto">cd frp_0.<span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">25.0</span>_linux_amd64/
./frpc -c ./frpc.ini
nohup ./frpc -c ./frpc.ini &amp;

<span class="hljs-comment" style="overflow: visible !important; color: rgba(136, 136, 136, 1)"># 链接成功会出现如下内容</span>
<span class="hljs-comment" style="overflow: visible !important; color: rgba(136, 136, 136, 1)"># 2019/03/19 17:43:44 login to server success, get run id </span>
<span class="hljs-comment" style="overflow: visible !important; color: rgba(136, 136, 136, 1)"># 2019/03/19 17:43:44 start proxy success</span></code></pre></div>
<p class="xsj_paragraph xsj_paragraph_level_0" style="margin: 1.1em 0 1.6em">生产使用中可使用如下命令在后台运行:</p>
<div class="xiaoshujiang_code_container" style="margin: 1em 0 2em; position: relative"><pre data-processed="true" style="line-height: initial !important; word-wrap: break-word; tab-size: 4; white-space: pre-wrap; font-family: monospace; margin: 0"><code class="language-powershell hljs" data-info="powershell" style="background: rgba(240, 240, 240, 1); border-radius: 4px; padding: 0.5em; margin: 0 0.225em; color: rgba(68, 68, 68, 1); border: 0; font-size: 0.9em; overflow: visible !important; display: block; overflow-x: auto">nohup ./frpc -c ./frpc.ini &gt; /dev/null <span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">2</span>&gt;&amp;<span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">1</span> &amp;</code></pre></div>
<h3 class="xsj_heading_hash xsj_heading xsj_heading_h3" id="e4ba94e38081sshe799bbe5bd95e69c8de58aa1e599a8_8" style="font-weight: bold; text-rendering: optimizelegibility; font-size: 1.6rem; margin: 0.6em 0 0.4em"><div class="xiaoshujiang_element xsj_anchor" style="overflow: hidden; float: right">

</div>
<span class="xsj_heading_content">五、ssh登录服务器</span></h3>
<p class="xsj_paragraph xsj_paragraph_level_0" style="margin: 1.1em 0 1.6em">如果配置成功,在进入本地服务器就相对容易了,与以前的<code style="background-color: rgba(240, 240, 240, 1); border-radius: 4px; padding: 2px 4px; margin: 0 0.225em; color: rgba(136, 0, 0, 1); border: 0; font-size: 0.9em">ssh</code>一样:</p>
<div class="xiaoshujiang_code_container" style="margin: 1em 0 2em; position: relative"><pre data-processed="true" style="line-height: initial !important; word-wrap: break-word; tab-size: 4; white-space: pre-wrap; font-family: monospace; margin: 0"><code class="language-powershell hljs" data-info="powershell" style="background: rgba(240, 240, 240, 1); border-radius: 4px; padding: 0.5em; margin: 0 0.225em; color: rgba(68, 68, 68, 1); border: 0; font-size: 0.9em; overflow: visible !important; display: block; overflow-x: auto">ssh root@公网IP -p <span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">6000</span></code></pre></div>
<p class="xsj_paragraph xsj_paragraph_level_0" style="margin: 1.1em 0 1.6em">也可以使用</p>
<div class="xiaoshujiang_code_container" style="margin: 1em 0 2em; position: relative"><pre data-processed="true" style="line-height: initial !important; word-wrap: break-word; tab-size: 4; white-space: pre-wrap; font-family: monospace; margin: 0"><code class="language-powershell hljs" data-info="powershell" style="background: rgba(240, 240, 240, 1); border-radius: 4px; padding: 0.5em; margin: 0 0.225em; color: rgba(68, 68, 68, 1); border: 0; font-size: 0.9em; overflow: visible !important; display: block; overflow-x: auto">ssh -oPort=<span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">6000</span> test@公网IP</code></pre></div>
<h3 class="xsj_heading_hash xsj_heading xsj_heading_h3" id="e585ade38081e5b8b8e8a781e997aee9a298e4b88ee8a7a3e586b3e696b9e6a188_9" style="font-weight: bold; text-rendering: optimizelegibility; font-size: 1.6rem; margin: 0.6em 0 0.4em"><div class="xiaoshujiang_element xsj_anchor" style="overflow: hidden; float: right">

</div>
<span class="xsj_heading_content">六、常见问题与解决方案</span></h3>
<h4 class="xsj_heading_hash xsj_heading xsj_heading_h4" id="1e38081e58685e7bd91e69c8de58aa1e599a8e697a0e6b395e8bf9ee68ea5frpce5aea2e688b7e7abafefbc9a_10" style="font-weight: bold; text-rendering: optimizelegibility; font-size: 1.5rem; margin: 0.5em 0 0.3em"><div class="xiaoshujiang_element xsj_anchor" style="overflow: hidden; float: right">

</div>
<span class="xsj_heading_content">1、内网服务器无法连接frpc客户端:</span></h4>
<p class="xsj_paragraph xsj_paragraph_level_0" style="margin: 1.1em 0 1.6em">此问题一般情况是公网IP没有开放<code style="background-color: rgba(240, 240, 240, 1); border-radius: 4px; padding: 2px 4px; margin: 0 0.225em; color: rgba(136, 0, 0, 1); border: 0; font-size: 0.9em">bind_port</code>设置的<code style="background-color: rgba(240, 240, 240, 1); border-radius: 4px; padding: 2px 4px; margin: 0 0.225em; color: rgba(136, 0, 0, 1); border: 0; font-size: 0.9em">7000</code>端口,<strong class="markdown_strong_asterisk" style="font-weight: bold">此时可以检查防火墙是否允许以及查看服务器安全规则</strong>,如阿里云需要设置<strong class="markdown_strong_asterisk" style="font-weight: bold">安全组规则</strong>允许访问。</p>
<h4 class="xsj_heading_hash xsj_heading xsj_heading_h4" id="2e38081sshe697a0e6b395e4bdbfe794a8e58685e7bd91e8b4a6e58fb7e5af86e7a081e799bbe5bd95efbc8ce58faae883bde4bdbfe794a8e585ace7bd91e5af86e7a081e799bbe5bd95_11" style="font-weight: bold; text-rendering: optimizelegibility; font-size: 1.5rem; margin: 0.5em 0 0.3em"><div class="xiaoshujiang_element xsj_anchor" style="overflow: hidden; float: right">

</div>
<span class="xsj_heading_content">2、ssh无法使用内网账号密码登录,只能使用公网密码登录</span></h4>
<p class="xsj_paragraph xsj_paragraph_level_0" style="margin: 1.1em 0 1.6em">ssh无法使用内网账号密码登录,只能使用公网密码登录;一登录直接跳转到外网服务器,没有实现穿透效果,此时需要设置<code style="background-color: rgba(240, 240, 240, 1); border-radius: 4px; padding: 2px 4px; margin: 0 0.225em; color: rgba(136, 0, 0, 1); border: 0; font-size: 0.9em">内网服务器</code>的<code style="background-color: rgba(240, 240, 240, 1); border-radius: 4px; padding: 2px 4px; margin: 0 0.225em; color: rgba(136, 0, 0, 1); border: 0; font-size: 0.9em">frpc.ini</code>文件,修改<code style="background-color: rgba(240, 240, 240, 1); border-radius: 4px; padding: 2px 4px; margin: 0 0.225em; color: rgba(136, 0, 0, 1); border: 0; font-size: 0.9em">local_ip = 127.0.0.1</code>。</p>
<h4 class="xsj_heading_hash xsj_heading xsj_heading_h4" id="3e38081sshe697a0e6b395e799bbe5bd95e588b0frpe69c8de58aa1e599a8efbc8ce68f90e7a4bae8b685e697b6_12" style="font-weight: bold; text-rendering: optimizelegibility; font-size: 1.5rem; margin: 0.5em 0 0.3em"><div class="xiaoshujiang_element xsj_anchor" style="overflow: hidden; float: right">

</div>
<span class="xsj_heading_content">3、ssh无法登录到frp服务器,提示超时</span></h4>
<p class="xsj_paragraph xsj_paragraph_level_0" style="margin: 1.1em 0 1.6em">此问题的原因是公网未开放<code style="background-color: rgba(240, 240, 240, 1); border-radius: 4px; padding: 2px 4px; margin: 0 0.225em; color: rgba(136, 0, 0, 1); border: 0; font-size: 0.9em">ssh</code>配置的端口,开放一下即可,如我的是阿里云,<code style="background-color: rgba(240, 240, 240, 1); border-radius: 4px; padding: 2px 4px; margin: 0 0.225em; color: rgba(136, 0, 0, 1); border: 0; font-size: 0.9em">ssh</code>端口为<code style="background-color: rgba(240, 240, 240, 1); border-radius: 4px; padding: 2px 4px; margin: 0 0.225em; color: rgba(136, 0, 0, 1); border: 0; font-size: 0.9em">6000</code>,我去阿里云<strong class="markdown_strong_asterisk" style="font-weight: bold">安全组规则</strong>允许访问6000端口才搞定。</p>
<h4 class="xsj_heading_hash xsj_heading xsj_heading_h4" id="4e38081tcpe68ba8e58fb7e68f90e7a4bae8b685e697b6_13" style="font-weight: bold; text-rendering: optimizelegibility; font-size: 1.5rem; margin: 0.5em 0 0.3em"><div class="xiaoshujiang_element xsj_anchor" style="overflow: hidden; float: right">

</div>
<span class="xsj_heading_content">4、tcp拨号提示超时</span></h4>
<div class="xiaoshujiang_code_container" style="margin: 1em 0 2em; position: relative"><pre data-processed="true" style="line-height: initial !important; word-wrap: break-word; tab-size: 4; white-space: pre-wrap; font-family: monospace; margin: 0"><code class="language-powershell hljs" data-info="powershell" style="background: rgba(240, 240, 240, 1); border-radius: 4px; padding: 0.5em; margin: 0 0.225em; color: rgba(68, 68, 68, 1); border: 0; font-size: 0.9em; overflow: visible !important; display: block; overflow-x: auto"><span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">2020</span>/<span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">09</span>/<span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">22</span> <span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">10</span>:<span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">55</span>:<span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">42</span> login to server failed: dial tcp xx.xx.xx.xx:<span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">7000</span>: connect: connection timed out
dial tcp xx.xx.xx.xx:<span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">7000</span>: connect: connection timed out <span class="hljs-comment" style="overflow: visible !important; color: rgba(136, 136, 136, 1)"># 检查阿里云的安全组规则与宝塔的开放端口</span>
</code></pre></div>
<p class="xsj_paragraph xsj_paragraph_level_0" style="margin: 1.1em 0 1.6em">更多信息:</p>
<ul class="markdown_ul" style="padding: 0; margin: 1.1em 0 1.1em 3em">
<li>Frp官方文档</li>
<li>Frp内网搭建网站</li>
</ul>
<h2 class="xsj_heading_hash xsj_heading xsj_heading_h2" id="e5ae89e585a8e59cb0e69ab4e99cb2e58685e7bd91e69c8de58aa1_14" style="font-weight: bold; text-rendering: optimizelegibility; font-size: 1.8rem; margin: 0.7em 0 0.5em"><div class="xiaoshujiang_element xsj_anchor" style="overflow: hidden; float: right">

</div>
<span class="xsj_heading_content">安全地暴露内网服务</span></h2>
<p class="xsj_paragraph xsj_paragraph_level_0" style="margin: 1.1em 0 1.6em">对于某些服务来说如果直接暴露于公网上将会存在安全隐患。</p>
<p class="xsj_paragraph xsj_paragraph_level_0" style="margin: 1.1em 0 1.6em">使用 <strong class="markdown_strong_asterisk" style="font-weight: bold">stcp(secret tcp)</strong> 类型的代理可以避免让任何人都能访问到要穿透的服务,但是访问者也需要运行另外一个 frpc。</p>
<p class="xsj_paragraph xsj_paragraph_level_0" style="margin: 1.1em 0 1.6em">以下示例将会创建一个只有自己能访问到的 ssh 服务代理。</p>
<p class="xsj_paragraph xsj_paragraph_level_0" style="margin: 1.1em 0 1.6em">frps 的部署步骤同上。</p>
<ol class="markdown_ol" style="padding: 0; margin: 1.1em 0 1.1em 3em">
<li><span class="xsj_placeholder_span"></span>启动 frpc,转发内网的 ssh 服务,配置如下,不需要指定远程端口:</li>
</ol>
<div class="xiaoshujiang_code_container" style="margin: 1em 0 2em; position: relative"><pre data-processed="true" style="line-height: initial !important; word-wrap: break-word; tab-size: 4; white-space: pre-wrap; font-family: monospace; margin: 0"><code class="language-powershell hljs" data-info="powershell" style="background: rgba(240, 240, 240, 1); border-radius: 4px; padding: 0.5em; margin: 0 0.225em; color: rgba(68, 68, 68, 1); border: 0; font-size: 0.9em; overflow: visible !important; display: block; overflow-x: auto"><span class="hljs-comment" style="overflow: visible !important; color: rgba(136, 136, 136, 1)"># frpc.ini</span>

server_addr = x.x.x.x
server_port = <span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">7000</span>


type = stcp
<span class="hljs-comment" style="overflow: visible !important; color: rgba(136, 136, 136, 1)"># 只有 sk 一致的用户才能访问到此服务</span>
sk = abcdefg
local_ip = <span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">127.0</span>.<span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">0.1</span>
local_port = <span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">22</span></code></pre></div>
<ol class="markdown_ol" style="padding: 0; margin: 1.1em 0 1.1em 3em">
<li><span class="xsj_placeholder_span"></span>在要访问这个服务的机器上启动另外一个 frpc,配置如下:</li>
</ol>
<div class="xiaoshujiang_code_container" style="margin: 1em 0 2em; position: relative"><pre data-processed="true" style="line-height: initial !important; word-wrap: break-word; tab-size: 4; white-space: pre-wrap; font-family: monospace; margin: 0"><code class="language-powershell hljs" data-info="powershell" style="background: rgba(240, 240, 240, 1); border-radius: 4px; padding: 0.5em; margin: 0 0.225em; color: rgba(68, 68, 68, 1); border: 0; font-size: 0.9em; overflow: visible !important; display: block; overflow-x: auto"><span class="hljs-comment" style="overflow: visible !important; color: rgba(136, 136, 136, 1)"># frpc.ini</span>

server_addr = x.x.x.x
server_port = <span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">7000</span>


type = stcp
<span class="hljs-comment" style="overflow: visible !important; color: rgba(136, 136, 136, 1)"># stcp 的访问者</span>
role = visitor
<span class="hljs-comment" style="overflow: visible !important; color: rgba(136, 136, 136, 1)"># 要访问的 stcp 代理的名字</span>
server_name = secret_ssh
sk = abcdefg
<span class="hljs-comment" style="overflow: visible !important; color: rgba(136, 136, 136, 1)"># 绑定本地端口用于访问 ssh 服务</span>
bind_addr = <span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">127.0</span>.<span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">0.1</span>
bind_port = <span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">6000</span></code></pre></div>
<ol class="markdown_ol" style="padding: 0; margin: 1.1em 0 1.1em 3em">
<li><span class="xsj_placeholder_span"></span>通过 ssh 访问内网机器,假设用户名为 test:</li>
</ol>
<div class="xiaoshujiang_code_container" style="margin: 1em 0 2em; position: relative"><pre data-processed="true" style="line-height: initial !important; word-wrap: break-word; tab-size: 4; white-space: pre-wrap; font-family: monospace; margin: 0"><code class="language-powershell hljs" data-info="powershell" style="background: rgba(240, 240, 240, 1); border-radius: 4px; padding: 0.5em; margin: 0 0.225em; color: rgba(68, 68, 68, 1); border: 0; font-size: 0.9em; overflow: visible !important; display: block; overflow-x: auto">ssh -oPort=<span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">6000</span> test@<span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">127.0</span>.<span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">0.1</span></code></pre></div>
<p class="xsj_paragraph xsj_paragraph_level_0" style="margin: 1.1em 0 1.6em">如果出现问题:</p>
<div class="xiaoshujiang_code_container" style="margin: 1em 0 2em; position: relative"><pre data-processed="true" style="line-height: initial !important; word-wrap: break-word; tab-size: 4; white-space: pre-wrap; font-family: monospace; margin: 0"><code class="language-powershell hljs" data-info="powershell" style="background: rgba(240, 240, 240, 1); border-radius: 4px; padding: 0.5em; margin: 0 0.225em; color: rgba(68, 68, 68, 1); border: 0; font-size: 0.9em; overflow: visible !important; display: block; overflow-x: auto"> start error: listen tcp <span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">127.0</span>.<span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">0.1</span>:<span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">6000</span>: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted.</code></pre></div>
<p class="xsj_paragraph xsj_paragraph_level_0" style="margin: 1.1em 0 1.6em">将本地地址改为<code style="background-color: rgba(240, 240, 240, 1); border-radius: 4px; padding: 2px 4px; margin: 0 0.225em; color: rgba(136, 0, 0, 1); border: 0; font-size: 0.9em">127.0.0.2</code>或者其他地址</p>
<p class="xsj_paragraph xsj_paragraph_level_0" style="margin: 1.1em 0 1.6em">设置bat文件,这样就不需要每次都定位到指定目录:</p>
<div class="xiaoshujiang_code_container" style="margin: 1em 0 2em; position: relative"><pre data-processed="true" style="line-height: initial !important; word-wrap: break-word; tab-size: 4; white-space: pre-wrap; font-family: monospace; margin: 0"><code class="language-powershell hljs" data-info="powershell" style="background: rgba(240, 240, 240, 1); border-radius: 4px; padding: 0.5em; margin: 0 0.225em; color: rgba(68, 68, 68, 1); border: 0; font-size: 0.9em; overflow: visible !important; display: block; overflow-x: auto">cd C:\Users\JChan\Desktop\frp_0.<span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">25.0</span>_windows_amd64\frp_0.<span class="hljs-number" style="overflow: visible !important; color: rgba(136, 0, 0, 1)">25.0</span>_windows_amd64
start /b frpc -c frpc.ini</code></pre></div>
</div>
</div><br><br>
来源:https://www.cnblogs.com/xlchan/p/13643231.html
頁: [1]
查看完整版本: Linux服务器所以Frp实现内网穿透(阿里云Ubuntu)