NPS 内网穿透配置
一直用FRP,配置简单,使用简单,比较稳定,但有时候也有抽风的事件发生,用NPS做个备用。
1、下载,因为我是linux环境,下载了linux对应的server和client,已编译好,直接运行即可
https://github.com/ehang-io/nps/releases
https://github.com/ehang-io/nps/releases/download/v0.26.9/linux_amd64_client.tar.gz
https://github.com/ehang-io/nps/releases/download/v0.26.9/linux_amd64_server.tar.gz
2、部署
公网服务器部署server、内网服务器部署client
2.1、服务器配置
解压后,直接修改配置文件,没用的删了,其它别动:
bridge 是服务端类型、地址、监听端口,把端口改成自己的就行。
public_vkey是客户端连接服务端认证用的,但是此处修改不生效,不知道为啥,不用管就行
web区块,这儿是服务端web访问的配置,看这配就行,官方说端口可以和bridge里一致,但实际测试发现不行,要两个不同的端口,其它都没用,默认就好
appname = nps #Boot mode(dev|pro) runmode = dev ##bridge bridge_type=tcp bridge_port=8888 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=/opt/nps/nps.log #web web_host=www.baidu.com web_username=admin web_password=666 web_port = 8889 web_ip=0.0.0.0 web_base_url= /nps 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 =1234567887654321 #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=true #pprof debug options #pprof_ip=0.0.0.0 #pprof_port=9999 #client disconnect timeout disconnect_timeout=60
2.2、客户端配置
除了 server_addr 和服务端 bridge 配置一致外,其它不用动,把配置文件的其余部分删了,配置也不起作用,这个版本测试发现必须从网页上配
[common] server_addr=www.baidu.com:8888 conn_type=tcp vkey=123 auto_reconnection=true max_conn=1000 flow_limit=1000 rate_limit=1000 crypt=true compress=true disconnect_timeout=60
2.3、启动服务端
./nps
2.4、服务端配置客户端访问
登录服务端管理地址:www.baidu.com:8888 用配置的用户名密码登录(admin:666)
在客户端这儿新增就行:
然后可以对每个客户端配置隧道。
客户端连接用服务端给出的命令就行,点网页上每个客户端前面的+就能看到。
2.5、启动客户端
./npc -server=www.baidu.com:8888 vkey=8rehr93fwurfj04j -type=tcp
3、防止进程奔溃
在nps和npc同目录下创建start.sh,内容如下:
cd $(dirname $0) pid=$(pgrep npc) if [ -z "$pid" ]; then nohup ./npc -server=www.baidu.com:8888 vkey=8rehr93fwurfj04j -type=tcp >/dev/null 2>&1 & fi
要记得:chmod a+x start.sh
要记得:*/10 * * * * root bash /opt/nps/start.sh
4、如果要过防火墙,可能要配置传输方式为kcp传输,
只需修改 bridge_type=kcp 即可
kcp方式时间长了会莫名断掉,重启npc客户端恢复正常,所有配置个重启脚本
cd $(dirname $0) pids=$(pgrep npc) for pid in $pids; do kill -9 $pid done nohup ./npc -server=www.baidu.com:8888 -vkey=f8hd4qtft3o22utt -type=kcp >/dev/null 2>&1 &
再配个定时任务,每两个小时来一下:
0 0 0/2 * * root /opt/nps/restart.sh
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术