内网穿透
[toc]
# 官方说明文档
https://ehang-io.github.io/nps/#/use (opens new window)
# 下载服务端安装包
wget https://github.com/ehang-io/nps/releases/download/v0.26.10/linux_amd64_server.tar.gz
解压
tar -zxvf linux_amd64_server.tar.gz
# 修改配置文件
# vim conf/nps.conf
# 修改为服务器公网IP
web_host=101.43.11.108
# web页面登录账号
web_username=jast
# web页面登录密码
web_password=AAbb
# web页面端口
web_port = 28080
##bridge
# 客户端服务端连接方式
bridge_type=tcp
# 客户端服务端连接端口
bridge_port=28083
bridge_ip=0.0.0.0
# 域名代理HTTP端口(不用的话可以不修改)
http_proxy_ip=0.0.0.0
http_proxy_port=28081
https_proxy_port=28082
https_just_proxy=true
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
最终配置文件内容如下
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=28081
https_proxy_port=28082
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=28083
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
#web
web_host=101.43.11.108
web_username=adminn
web_password=user65#.com
web_port = 28080
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# 安装NPS
./nps install
安装完成后nps会到系统变量中
安装后的配置文件/etc/nps/conf/nps.conf
# 启动
./nps start
# 服务端配置文件重载(目前支持功能不多)
对于linux、darwin
sudo nps reload
对于windows
nps.exe reload
说明: 仅支持部分配置重载,例如allow_user_login
auth_crypt_key
auth_key
web_username
web_password
等,未来将支持更多
# 修改配置文件
执行完成./nps install
后,nps启动读取的配置文件为/etc/nps/conf/nps.conf
修改配置直接改这个
vim /etc/nps/conf/nps.conf
# 服务端停止或重启
对于linux、darwin
sudo nps stop|restart
对于windows
nps.exe stop|restart
# MacOS
# 下载客户端
https://github.com/ehang-io/nps/releases/download/v0.26.10/darwin_amd64_client.tar.gz
# CentOS
# 下载客户端
wget -b https://github.com/ehang-io/nps/releases/download/v0.26.10/linux_amd64_client.tar.gz
解压
tar -zxvf linux_amd64_client.tar.gz
# 无配置文件启动
./npc -server=47.98.183.51:50002 -vkey=yh3xa0z6c85s6szx
# 配置文件启动
# 先在网站中创建客户端
这里可以自己设置,也可以全部使用默认
新增成功后在页面可以看到客户端列表
填写配置文件
[common]
# 填写登录后首页显示的客户端连接端口
server_addr=185.56.25.xx:50002
conn_type=tcp
# vkey填写上面的验证密钥
vkey=yh3xa0z6c85s6szx
# 断线重连
auto_reconnection=true
[tcp]
mode=tcp
target_addr=127.0.0.1:8080
server_port=50005
2
3
4
5
6
7
8
9
10
11
12
13
# 启动
nohup ./npc -config=conf/npc.conf &
2023/11/17 15:25:34.919 [I] [npc.go:231] the version of client is 0.26.10, the core version of client is 0.26.0
2023/11/17 15:25:34.919 [I] [control.go:97] Loading configuration file conf/npc.conf successfully
2023/11/17 15:25:35.140 [N] [control.go:174] web access login username:user password:yh3xa0z6c85s6szx
2023/11/17 15:25:35.275 [I] [client.go:72] Successful connection with server 185.56.25.xx:50002
2
3
4
# windows的ubuntu安装配置
# 安装SSH服务
sudo apt-get update
sudo apt-get install openssh-server
2
启动sshd服务
sudo service ssh restart
设置允许ssh密码登录权限
# vim /etc/ssh/sshd_config
PasswordAuthentication yes
2
3
不设置会提示需要身份文件认证
# 客户端启动
# 下载客户端
wget https://github.com/ehang-io/nps/releases/download/v0.26.10/linux_amd64_client.tar.gz
# 无配置文件启动
./npc -server=ip:port -vkey=web界面中显示的密钥
./npc -server=101.43.11.108:28083 -vkey=112233
port取值:
vkey取值:
连接成功提示
./npc -server=101.43.11.108:28083 -vkey=112233
2023/09/18 20:13:10.872 [I] [npc.go:231] the version of client is 0.26.10, the core version of client is 0.26.0
2023/09/18 20:13:11.026 [I] [client.go:72] Successful connection with server 101.43.11.108:28083
2
3
连接成功在页面会提示
# 配置Ubuntu服务器连接
点击TCP隧道
-> 新增
填写信息
如:
保存后在TCP隧道
页面可以看到状态,
此时通过服务端的IP+刚刚设置的28084端口,即可通过ssh连接服务器
账号密码,就是我们设置的Ubuntu账号密码,不是Windows的账号密码
# 配置Windows
# 下载Windows客户端
# 新建客户端
填写唯一验证密钥
TCP隧道配置
配置TCP隧道模式
npc.conf
[common]
server_addr=101.43.11.108:28083
conn_type=tcp
vkey=puiskdnf!ofa2
auto_reconnection=true
max_conn=1000
crypt=false
compress=false
disconnect_timeout=60
[tcp]
mode=tcp
target_addr=3389
server_port=28085
2
3
4
5
6
7
8
9
10
11
12
13
14
15
直接双击npc.exe
会自动读取conf/npc.conf
配置文件
windows启动配置
./npc.exe -server=101.43.11.108:28083 -vkey=puiskdnf!ofa2 -config=C:\Users\Admin\Desktop\windows_amd64_client\conf\npc.conf
通过远程连接连接Windows服务器即可
# 配置Windows开机自动启动远程
创建启动脚本start-npc.bat
# 这一段是后台运行的命令
@echo off
if "%1" == "h" goto begin
mshta vbscript:createobject("wscript.shell").run("%~nx0 h",0)(window.close)&&exit
:begin
# 这一段是启动
cd C:\Users\Admin\Desktop\windows_amd64_client
.\npc.exe -server=101.43.11.108:28083 -vkey=puiskdnf!ofa2 -config=C:\Users\Admin\Desktop\windows_amd64_client\conf\npc.conf
pause
2
3
4
5
6
7
8
9
10
主要两个步骤:
- 进入npc目录
- 启动npc.exe并制定配置文件路径
在电脑运行
中输入shell:startup
自动打开这个目录
将start-npc.bat
文件或者start-npc.bat
文件的快捷方式,拖入这个目录下,就完成了开机自动启动配置。