nps内网穿透配置
- 教程更新时间:2025-8-11
- 作者QQ:2774118934
准备阶段
注!!!
NPS 默认会去 /etc/nps/conf/nps.conf。
你的 systemd 或命令行指定了 /nps/conf/nps.conf,但 NPS 实际尝试访问的是 /etc/nps/conf/nps.conf。
这可能是 NPS 3.2 的逻辑,它会把配置路径解析到 /etc/nps 下。
- 先看完两个视频
- 到Github那个接力棒作者那里下载最新版的软件项目下载地址——注:必要时请使用魔法网络
README地址 - 下载对应架构的压缩包。一般PC都是amd64。查看方法自行百度
- 接上一条,需要下载服务端
(server)和客户端(client)的压缩包。当时作者下载的是- linux_amd64_client.tar.gz——适用于Linux的客户端(被连接方,内网服务器)
- linux_amd64_server.tar.gz——适用于Linux的服务端(连接方,有公网ip的一方)
注:真正的配置文件在
/etc/nps/conf/nps.conf
配置服务端
-
连接上你的具有公网ip的服务器
-
在根目录创建文件夹(位置自行选择)
sudo mkdir /nps/ -
把server的压缩包移动
到文件夹中并解压
注:解压.tar.gz文件的命令tar -xzf 压缩文件名.tar.gz -
cd到创建的
/nps/目录,并修改解压出的nps权限为755(即打开执行权限) -
执行命令
sudo ./nps install
出现以下界面即为安装成功2025/08/11 18:49:20 install path:/etc/nps 2025/08/11 18:49:20 copy file: /nps/web/views/client/add.html -> /etc/nps/web/views/client/add.html 2025/08/11 18:49:20 copy file: /nps/web/views/client/edit.html -> /etc/nps/web/views/client/edit.html ... 2025/08/11 18:49:20 The new configuration file is located in /etc/nps you can edit them 2025/08/11 18:49:20 You can start with: nps start|stop|restart|uninstall|update or nps-update update anywhere! -
执行命令以更新项目
sudo nps-update update注:这一步可能会遇到超时的情况,如遇到请重新执行该命令,多试几次一般能过。再不行的话请开启魔法网络
出现以下页面即为成功
The latest version is v0.32.2 Trying: https://github.com/djylb/nps/releases/download/v0.32.2/linux_amd64_server.tar.gz Trying: https://cdn.jsdelivr.net/gh/djylb/nps-mirror@v0.32.2/linux_amd64_server.tar.gz Trying: https://fastly.jsdelivr.net/gh/djylb/nps-mirror@v0.32.2/linux_amd64_server.tar.gz 2025/08/11 19:00:57 copy file: /tmp/nps-168925125/web/views/client/add.html -> /etc/nps/web/views/client/add.html 2025/08/11 19:00:57 copy file: /tmp/nps-168925125/web/views/client/edit.html -> /etc/nps/web/views/client/edit.html ... 2025/08/11 19:00:57 copy file: /tmp/nps-168925125/web/static/webfonts/glyphicons-halflings-regular.woff2 -> /etc/nps/web/static/webfonts/glyphicons-halflings-regular.woff2 Update completed, please restart -
上一步成功后,执行命令以启动项目
sudo nps start -
访问nps自带的web管理页面
服务器ip:8080
默认用户名:admin
默认密码:123 -
进入到页面后,点击右侧边栏的
客户端;
点击左上角的新增
备注随便填,自己认识就行。然后点击右下角新增完成创建。 -
此时客户端列表已经出现了刚刚新建的客户端。
点击右侧的隧道
然后点击左上角的新增
备注可写可不写。
服务器端口填写你期望在具有公网ip上开的端口
目标填写你期望在内网服务器上开的端口,格式为:内网IPv4地址:端口
成功后可以将公网服务器端口与内网服务器端口连接,即访问公网ip:对应端口与访问内网服务器目标端口等效 -
点击客户端左侧的
+,复制启动命令
说明:客户端有两种启动方式:命令行启动与配置文件启动
配置客户端
- 在根目录创建文件夹(可自行选择创建路径)
sudo mkdir /npc/ - 把客户端文件
(linux_amd64_client.tar.gz)移动到该目录中,并解压 - cd到
/npc/文件夹,并执行复制的启动命令 - 刷新web后台管理页面,查看客户端状态是否变为
在线。
额外配置
创建Systemd服务配置,确保它能在 Ubuntu 系统中 开机自启、崩溃自动重启,并方便管理
- 创建配置文件
sudo vim /etc/systemd/system/npc.service
(如果 vim 未安装,先运行 sudo apt install vim安装vim)
2. 编辑配置文件
[Unit]
Description=NPS Client (npc) - 内网穿透客户端
After=network.target
[Service]
Type=simple
User=root
WorkingDirectory=/npc #改成你自己的工作目录
# 如果使用配置文件,就这样写:
#ExecStart=/npc/npc(npc文件所在的路径) -config=/npc/conf/npc.conf(配置文件的路径)
# 如果不使用配置文件,想直接用参数,就这样写(二选一):
ExecStart=/npc/npc -server="公网ip服务器:8024" -vkey="你的秘钥" -type="tcp" #改成自己的目录、服务器和秘钥
Restart=always # 崩溃自动重启
RestartSec=3 # 重启间隔(秒)
StandardOutput=file:/var/log/npc.log # 日志输出
StandardError=file:/var/log/npc-error.log
[Install]
WantedBy=multi-user.target
注:若设置的路径不同,则配置文件的编写也有细微差异,请结合自身设置的路径来配置。key值也不同,请结合自身情况,或把启动命令丢给AI,让AI生成
3. 启动服务并设置开机自启
# 重新加载 Systemd 配置
sudo systemctl daemon-reload
# 启动 npc 服务
sudo systemctl start npc
# 设置开机自启
sudo systemctl enable npc
# 检查状态
sudo systemctl status npc
- 管理命令
| 命令 | 用途 |
|---|---|
| sudo systemctl stop npc | 停止服务 |
| sudo systemctl start npc | 启动服务 |
| sudo systemctl restart npc | 重启服务 |
| sudo systemctl status npc | 查看状态/日志 |
| journalctl -u npc -f | 实时查看日志 |
注:
- 可以通过
nps start|stop|restart|uninstall|update来控制nps的状态 - 可在
/etc/nps/conf/nps.conf配置文件中修改后台管理的用户名和密码(web_password)

浙公网安备 33010602011771号