NPS内网穿透和宝塔以及守护进程的教程

发布于 2023-02-07  27 次阅读


安装NPS服务端

安装

1.使用wget命令拉取NPS最新源码镜像,依然是在宝塔终端里进行操作。
国外服务器

wget https://github.com/ehang-io/nps/releases/download/v0.26.10/linux_amd64_server.tar.gz

国内服务器

wget https://ghproxy.com/https://github.com/ehang-io/nps/releases/download/v0.26.10/linux_amd64_server.tar.gz

2.解压NPS到服务器目录

tar -xzvf linux_amd64_server.tar.gz

到这一步就不截图演示了,直接复制粘贴使用命令就可以了。(已经安装过了)
3.安装部署到服务器

sudo ./nps install

4.启动开启nps服务

nps start

修改配置文件并启用nps服务

1.因为nps默认使用的TCP端口是80 443 8080 8024,宝塔面板的80 433 8080会被占用,因此这时候打不开nps的前端Web管理页面;我们需要修改nps的配置文件,后重新启动nps服务。

2.找到nps.conf文件,在宝塔根目录的etc文件夹下,路径/etc/nps/conf/nps.conf

3.使用文本编辑器打开nps.conf文件后进行修改,具体修改方法见代码注释。

appname = nps
#Boot mode(dev|pro)
runmode = dev

#HTTP(S) proxy port, no startup if empty
http_proxy_ip=0.0.0.0
#http_proxy_port=80  //80端口建议禁止注释掉,在宝塔面板上安装的nps不会用到
#https_proxy_port=443  //443端口建议禁止注释掉,在宝塔面板上安装的nps不会用到
https_just_proxy=true
#default https certificate setting
https_default_cert_file=conf/server.pem
https_default_key_file=conf/server.key

##bridge
bridge_type=tcp
bridge_port=8024  //与npc客户端通讯的默认端口,建议修改为其他端口如:8424
bridge_ip=0.0.0.0

# Public password, which clients can use to connect to the server
# After the connection, the server will be able to open relevant ports and parse related domain names according to its own configuration file.
public_vkey=123

#Traffic data persistence interval(minute)
#Ignorance means no persistence
#flow_store_interval=1

# log level LevelEmergency->0  LevelAlert->1 LevelCritical->2 LevelError->3 LevelWarning->4 LevelNotice->5 LevelInformational->6 LevelDebug->7
log_level=7
#log_path=nps.log

#Whether to restrict IP access, true or false or ignore
#ip_limit=true

#p2p
#p2p_ip=127.0.0.1
#p2p_port=6000  //p2p代理要使用的端口,如果需要使用p2p代理服务,也可以修改一下端口

#web
web_host=a.o.com
web_username=admin  //nps默认登录账号,建议更换为自己牢记的账号,如admin123
web_password=123  //nps默认登录密码,建议更换为自己牢记的密码,如admin123
web_port = 8080  //nps默认web管理页面访问端口,建议修改为其他端口如:9090
web_ip=0.0.0.0
web_base_url=
web_open_ssl=false
web_cert_file=conf/server.pem
web_key_file=conf/server.key
# if web under proxy use sub path. like http://host/nps need this.
#web_base_url=/nps

#Web API unauthenticated IP address(the len of auth_crypt_key must be 16)
#Remove comments if needed
#auth_key=test
auth_crypt_key =1234567812345678

#allow_ports=9001-9009,10001,11000-12000

#Web management multi-user login
allow_user_login=false
allow_user_register=false
allow_user_change_username=false


#extension
allow_flow_limit=false
allow_rate_limit=false
allow_tunnel_num_limit=false
allow_local_proxy=false
allow_connection_num_limit=false
allow_multi_ip=false
system_info_display=false

#cache
http_cache=false
http_cache_length=100

#get origin ip
http_add_origin_header=false

#pprof debug options
#pprof_ip=0.0.0.0
#pprof_port=9999

#client disconnect timeout
disconnect_timeout=60

其他的TCP端口就不需要修改了,修改完成后保存进入下一个步骤,请牢记你修改的TCP端口,后续还会用到。

4.回到宝塔终端使用nps重启命令后上一步的配置文件才会成功被应用,会用到以下命令。

sudo nps restart

5.这个时候还需要放行以上你修改后的所有TCP端口,你的nps服务才能正常运行,相应位置在宝塔面板安全选项里和服务器防火墙/安全组里,很多人错在没有做这一步。

使用客户端

应该先创建客户端,然后等客户端上线创建隧道,并且记录唯一密钥

客户端安装

#下载客户端
apt install -y wget && wget --no-check-certificate -O npc.tar.gz https://img.zeruns.tech/down/linux_amd64_client.tar.gz
#安装客户端
mkdir /opt/npc && tar -zxvf npc.tar.gz -C /opt/npc && cd /opt/npc
#执行客户端
npc server=(ip:port) -vkey=(web界面中显示的密钥)

宝塔Supervisor进程管理器守护进程

服务器守护

客户端守护

名 称 : NPSClient
运行目录:/opt/npc
启动命令:npc -server=(ip:port) -vkey=(web界面中显示的密钥)


本当の声を響かせてよ