<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>#内网穿透 - Yevpt&apos;s Blog</title>
    <link>https://www.yevpt.com</link>
    <description>Yevpt&apos;s Blog 「内网穿透」标签下的文章</description>
    <language>zh-CN</language>
    <lastBuildDate>Tue, 16 Jun 2020 02:37:50 GMT</lastBuildDate>
    <atom:link href="https://www.yevpt.com/tags/13/feed.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>内网穿透神器-NPS使用教程</title>
      <link>https://www.yevpt.com/articles/45</link>
      <guid isPermaLink="true">https://www.yevpt.com/articles/45</guid>
      <pubDate>Tue, 16 Jun 2020 02:37:50 GMT</pubDate>
      <description>Nps是一款轻量级、高性能、功能强大的内网穿透代理服务器。几乎支持所有协议，支持内网http代理、内网socks5代理、p2p等，简洁但功能强大的WEB管理界面...</description>
      <category>工具</category>
      <content:encoded><![CDATA[<h3 id="官网介绍">官网介绍</h3>
<blockquote>
<p>Nps是一款轻量级、高性能、功能强大的内网穿透代理服务器。几乎支持所有协议，支持内网http代理、内网socks5代理、p2p等，简洁但功能强大的WEB管理界面，支持服务端、客户端同时控制，扩展功能强大，全平台兼容，一键注册为服务。</p>
</blockquote>
<p><img src="https://blog-oss.yevpt.com/blog/articles/45/images/d018d0f4f7b2050d9399e96f87a97b83.png?a=e8c92f581ef7b10c06da6626469ca7b2&#x26;b=6a617c43" alt="8TFr6I.png"></p>
<h3 id="安装服务端">安装服务端</h3>
<p>这里只用centos 64位作演示
首页去<a href="https://github.com/ehang-io/nps/releases" rel="noopener noreferrer" target="_blank">官方</a>找到并复制最新的下载链接</p>
<p> </p>
<div class="md-code-wrapper"><button class="md-copy-btn md-copy-btn-abs" type="button" aria-label="复制代码"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2"></rect><path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"></path></svg></button><pre><code># 创建并进入指定目录
cd /path
mkdir nps
cd /path/nps
# 将复制的对应的服务端下载并解压到当前目录
wget https://github.com/ehang-io/nps/releases/download/v0.26.7/linux_amd64_server.tar.gz &#x26;&#x26; tar zxvf linux_amd64_server.tar.gz
# 执行安装命令
sudo ./nps install
# 启动
sudo nps start
</code></pre></div>
<p>配置文件参数如下(安装后的配置文件在/etc/nps/conf/nps.conf)：
根据实际情况修改</p>
<div class="md-code-wrapper"><button class="md-copy-btn md-copy-btn-abs" type="button" aria-label="复制代码"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2"></rect><path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"></path></svg></button><pre><code>#web管理端口
httpport
#web界面管理密码
password
#服务端客户端通信端口
bridePort
#ssl certFile绝对路径
pemPath
#ssl keyFile绝对路径
keyPath
#域名代理https代理监听端口
httpsProxyPort
#域名代理http代理监听端口
httpProxyPort
#web api免验证IP地址
authip
#客户端与服务端连接方式kcp或tcp
bridgeType
</code></pre></div>
<p>修改完配置文件后，重启服务</p>
<div class="md-code-wrapper"><button class="md-copy-btn md-copy-btn-abs" type="button" aria-label="复制代码"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2"></rect><path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"></path></svg></button><pre><code>sudo ./nps restart
</code></pre></div>
<p>服务端常用命令:</p>
<div class="md-code-wrapper"><button class="md-copy-btn md-copy-btn-abs" type="button" aria-label="复制代码"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2"></rect><path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"></path></svg></button><pre><code># 服务端开始/停止/重启/配置文件重载/卸载服务/安装服务
sudo nps start/stop/restart/reload/uninstall/install
#  服务端更新

sudo nps-update update (请更新前停止服务)
</code></pre></div>
<p>默认的web端口是8080，账号是admin/123
提前放开防火墙和云服务的安全策略</p>
<div class="md-code-wrapper"><button class="md-copy-btn md-copy-btn-abs" type="button" aria-label="复制代码"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2"></rect><path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"></path></svg></button><pre><code>firewall-cmd --zone=public --add-port=8080/tcp --permanent 
firewall-cmd --reload
</code></pre></div>
<p>另外对于服务用到的bridePort，httpsProxyPort，httpProxyPort也最好提前放开，不然客户端是无法请求到服务端的。</p>
<h3 id="客户端使用">客户端使用</h3>
<p>首先看看<a href="https://ehang-io.github.io/nps/#/use" rel="noopener noreferrer" target="_blank">官方文档</a>，了解基本操作和指令。</p>
<h4 id="1linux系统">1、Linux系统</h4>
<div class="md-code-wrapper"><button class="md-copy-btn md-copy-btn-abs" type="button" aria-label="复制代码"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2"></rect><path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"></path></svg></button><pre><code># 创建并进入指定目录
cd /path
mkdir npc
cd /path/npc
# 将复制的对应的客户端下载并解压到当前目录
wget https://github.com/ehang-io/nps/releases/download/v0.26.7/linux_amd64_client.tar.gz &#x26;&#x26; tar zxvf linux_amd64_client.tar.gz
</code></pre></div>
<p>为了客户端的服务能正确的断网重连，这里使用配置文件的方式启动</p>
<p>配置/conf/npc.conf的内容：(具体的含义和修改请根据官方文档配置)</p>
<div class="md-code-wrapper"><button class="md-copy-btn md-copy-btn-abs" type="button" aria-label="复制代码"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2"></rect><path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"></path></svg></button><pre><code>[common]
server_addr=这里填写服务端的服务端口，比如tcp端口
conn_type=tcp
vkey=这里填写服务端配置vkey
auto_reconnection=true
max_conn=1000
flow_limit=1000
rate_limit=1000
# crypt=true
# compress=true
</code></pre></div>
<p>然后启动注册服务并启动客户端：</p>
<div class="md-code-wrapper"><button class="md-copy-btn md-copy-btn-abs" type="button" aria-label="复制代码"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2"></rect><path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"></path></svg></button><pre><code>sudo ./npc install -config=/path/npc/conf/npc.conf
sudo ./npc start
</code></pre></div>
<p>但是官网这种安装方式只能安装一个npc的客户端，如果需要同时连接多个服务端同时穿透，这种方式就不合适了。
我选择使用Supervisor来配置多个npc客户端同时运行</p>
<p>在/etc/supervisord.d中配置npc-1.ini</p>
<div class="md-code-wrapper"><button class="md-copy-btn md-copy-btn-abs" type="button" aria-label="复制代码"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2"></rect><path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"></path></svg></button><pre><code>[program:npc-1]
directory = /path
command = /path/npc -config=/path/npc/conf/npc.conf -debug=false
autostart = true
startsecs = 5
autorestart = true
startretries = 3
user = root
redirect_stderr = true
stdout_logfile_maxbytes = 20MB
stdout_logfile_backups = 20
stdout_logfile = /var/log/npc/npc-1.log
</code></pre></div>
<p>完成之后执行</p>
<div class="md-code-wrapper"><button class="md-copy-btn md-copy-btn-abs" type="button" aria-label="复制代码"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2"></rect><path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"></path></svg></button><pre><code># 识别配置文件并启动
supervisorctl reread
supervisorctl update
# 启动
supervisorctl start npc-1
# 查看状态
supervisorctl status npc-1
</code></pre></div>
<p>具体的Supervisor安装和使用请参考
<a href="https://www.chengxulvtu.com/supervisor-on-centos-7/" rel="noopener noreferrer" target="_blank">CentOS 7 配置 Supervisor</a></p>
<p> </p>
<h4 id="2windows系统">2、Windows系统</h4>
<p>首先下载win版<a href="https://github.com/ehang-io/nps/releases/download/v0.26.7/windows_amd64_client.tar.gz" rel="noopener noreferrer" target="_blank">windows_amd64_client.tar.gz</a>并解压。</p>
<p>建议使用GitBash命令行软件的管理员模式来启动。</p>
<p>如果要使用最简单的模式，可以运行官方指导的以下命令。</p>
<p>但是对于我有多个服务器，想同时连接多个nps服务端的话，可以使用单独注册系统服务的方式：</p>
<div class="md-code-wrapper"><button class="md-copy-btn md-copy-btn-abs" type="button" aria-label="复制代码"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2"></rect><path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"></path></svg></button><pre><code># 如果有npc1服务请先删除
sc delete npc1
# 注册npc服务
sc create npc1 binpath= "D:\Apps\npc\npc.exe -server=xxxx -vkey=xxx -type=tcp" start= auto displayname= "npc1"

</code></pre></div>
<p><img src="https://blog-oss.yevpt.com/blog/articles/45/images/06057fc290cfa432b18d775f0fc29776.png?a=3c69416a94157761757117c240b3c2e2&#x26;b=6a617c43" alt="iShot2020052415.06.39.png"></p>
<p>然后鼠标右键底部任务栏，打开任务管理器，找到服务选项，然后底部打开服务，找到npc1,启动服务，并且点开顶部恢复菜单，将第x次失败几个选项都勾选为‘重新启动服务’，即可。
每次需要一个新的npc客户端的时候，按照上述步骤即可。</p>
<p> </p>
<h3 id="mac端">Mac端</h3>
<p>基本和Linux一致，注意的是下载的压缩包是 darwin_amd64_client.tar.gz</p>
<h3 id="参考">参考</h3>
<ul>
<li><a href="https://ehang-io.github.io/nps" rel="noopener noreferrer" target="_blank">NPS：一款轻量级、高性能、功能强大的内网穿透代理服务器</a></li>
</ul>]]></content:encoded>
    </item>
  </channel>
</rss>