服务端搭建(云服务器)
# 下载Nps服务端
yum install -y wget && wget --no-check-certificate -O nps.tar.gz https://img.zeruns.tech/down/linux_amd64_server.tar.gz
mkdir /opt/nps && tar -zxvf nps.tar.gz -C /opt/nps && cd /opt/nps
# 启动Nps服务端
./nps install && sudo nps start
访问地址:http://[公网IP]:8080,注意云服务器上默认的8080端口及网桥的8024端口都需要开放
默认登录账户admin,密码123;这些端口的账户配置都可以自定义调整配置文件
#HTTP(S) proxy port, no startup if empty
http_proxy_ip=0.0.0.0
http_proxy_port=80
https_proxy_port=443
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
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=a.o.com
web_username=admin
web_password=123
web_port = 8080
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
进入网页端后,新增客户端
此时服务端配置就已经完成,客户端处于离线状态
下一步,安装客户端
客户端搭建(本地虚拟机)
yum 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
# 复制上图的客户端命令,注意命令路径需与本地一致
./npc -server=[公网ip]:8024 -vkey=d7o871dgjlvocpkd -type=tcp
连接成功后,客户端状态显示成功
配置隧道
新增TCP隧道
接下来就可以尝试使用ssh连接虚拟机了
ssh [公网IP] -p [服务端端口]
最后附上npc启停脚本
#!/bin/bash
# 判断传入参数的数量
if [ $# -ne 1 ]; then
echo "Usage: $0 <start>"
exit 1
fi
# 判断传入参数是否为"start"
if [ "$1" = "start" ]; then
nohup /opt/npc/npc -server=[公网ip]:8024 -vkey=d7o871dgjlvocpkd -type=tcp >> /var/log/npc.log &
else
myid=$(ps -aux | grep npc | grep -v grep | awk '{print $2}')
echo "kill pid $myid"
ps -aux | grep npc | grep -v grep | awk '{print $2}' | xargs kill
fi