天天看點

NPS内網穿透工具的安裝和使用

作者:薄荷色調

NPS是一款輕量級、功能強大的内網穿透代理伺服器。

支援tcp、udp流量轉發,支援内網http代理、内網socks5代理,同時支援snappy壓縮、站點保護、加密傳輸、多路複用、header修改等。

尤其是支援web圖形化管理,內建多使用者模式,這個比frp要好!

  1. 準備安裝在安裝

    前,我們需要準備:

一台擁有公網位址的雲伺服器

一台需要映射出去的本地伺服器

系統都是centos

注:其他系統也可以使用,隻是我自己習慣使用centos。

  1. 安裝雲伺服器 server端

    2.1 nps位址:GitHub:

https://github.com/cnlh/nps已經釋出的版本:

https://github.com/ehang-io/nps/releases目前最新的V0.26.1版本,32位就選386,64就選amd64,具體還是以實際情況為準。

NPS内網穿透工具的安裝和使用

2.2 安裝wegt

這個指令新的作業系統不一定有,按我們先安裝上吧!

yum -y install wget

2.3 下載下傳NPS server端

直接從GitHub上下載下傳。

解壓:安裝NPS:

修改配置檔案: 裡面有預設端口、使用者名和密碼,如不需要修改就跳過

安裝寶塔面闆的使用者注意:(1.因為nps預設使用的TCP端口是80 443 8080 8024,寶塔面闆的80 433 8080會被占用,是以這時候打不開nps的前端Web管理頁面;我們需要修改nps的配置檔案,後重新啟動nps服務。wget https://github.com/cnlh/nps/releases/download/v0.26.1/linux_amd64_server.tar.gztar -zxvf linux_amd64_server.tar.gz./nps installvim conf/nps.conf

2.找到nps.conf檔案,在寶塔根目錄的etc檔案夾下,路徑/etc/nps/conf/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           

啟動服務端:重新開機服務:

上面的指令隻能是啟動,退出後程式會自動終結,是以我們需要下面的指令,讓它不會停止!

這樣就可以,使用浏覽器進行通路了,./nps startsudo nps restartnohup ./nps > file.log 2>&1 &http://ip:預設端口8080

  1. 安裝用戶端

    在安裝用戶端前,我們首先需要在背景控制頁面建立用戶端,然後将建立的參數寫入到用戶端配置檔案中!

    用戶端常駐程式運作:

    nohup ./npc -server=(ip:port) -vkey=(web界面中顯示的密鑰) > file.log 2>&1 &

如果遇到其它問題,試試下面的方法:

已解決,問題原因在于 寶塔官方,關閉了 80 / 443 /8080的 UDP回路

firewall-cmd –permanent –zone=public 80/udp > /dev/null 2>&1

firewall-cmd –reload

firewall-cmd –永久 –區域=公共 8080/UDP > /dev/null 2>&1

防火牆-cmd –重新加載

firewall-cmd –永久 –區域=公共 443/UDP > /dev/null 2>&1

防火牆-cmd –重新加載

然後建立個空網站,反向代理 127.0.0.1:8080 即可解決 ,我是騰訊雲 不管裝NPS / FRP 都是同樣問題 用這個方式即可~

(80)還有一個重要的問題,由于443 80 被寶塔占用了, 需要先把NPS配置檔案中的http 443 808 改 909 / <> 等未占用的 ,将NPS 和 寶塔 隔離 就可以正常通路了

(<>)NPS 執行安裝指令後 ,要改/etc/nps/conf 裡的配置檔案,非解壓後的配置檔案

繼續閱讀