内网穿透 利用nps实现本地web服务在公网访问
内网穿透-利用nps实现本地web服务在公网访问
- what: 内网穿透-利用nps实现本地web服务在公网访问
- where: centos7,云服务器
- when: 2022.6.3
- who: JRT
- why: 记录,本地搭建一个web服务,没公网ip,但有一个云服务器(绑定公网ip),如何通过端口映射实现公网访问本地电脑的web服务
- how:
搭建web服务
为快速搭建,利用vm虚拟软件和docker快速启动两个服务
[root@master ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
70c9aadf5fcc jrt101/mrdoc:latest "./docker_mrdoc.sh sh" 58 minutes ago Up 58 minutes 0.0.0.0:8000->10086/tcp, :::8001->10086/tcp doc1
d470033f08d9 jrt101/mrdoc:latest "./docker_mrdoc.sh sh" 59 minutes ago Up 59 minutes 0.0.0.0:8001->10086/tcp, :::8000->10086/tcp doc2
[root@master ~]# ip a |grep ens33
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
inet 192.168.3.100/24 brd 192.168.3.255 scope global noprefixroute ens33
[root@master ~]#
本地访问
web1: http://192.168.3.100:8000/
web2: http://192.168.3.100:8001/
服务端下载
[root@JRT data]# mkdir nps
[root@JRT data]# cd nps
[root@JRT nps]# wget https://github.com/ehang-io/nps/releases/download/v0.26.10/linux_amd64_server.tar.gz
[root@JRT nps]# ls
linux_amd64_server.tar.gz
[root@JRT nps]# tar -xf linux_amd64_server.tar.gz
[root@JRT nps]# ls
conf linux_amd64_server.tar.gz nps web
服务端配置
#端口规划
server需要放开的端口:9001 9002 9003 9004 9005 9006
server
80-9001 网站访问
443-9002 端口访问
8080-9003 面板
brige-9004 网桥端口
#local
9005-8000 web1
9006-8001 web2
#修改配置
[root@JRT conf]# diff nps.conf /root/nps/conf/nps.conf
7,8c7,8
< http_proxy_port=80
< https_proxy_port=443
---
> http_proxy_port=9001
> https_proxy_port=9002
16c16
< bridge_port=8024
---
> bridge_port=9004
42c42
< web_port = 8080
---
> web_port = 9003
[root@JRT conf]# cd ..
#配置环境变量
[root@JRT nps]# nps install
#启动
[root@JRT nps]# nps start
#查启动状态
[root@JRT nps]# netstat -nltp |grep nps
tcp6 0 0 :::9001 :::* LISTEN 3324175/nps
tcp6 0 0 :::9002 :::* LISTEN 3324175/nps
tcp6 0 0 :::9003 :::* LISTEN 3324175/nps
tcp6 0 0 :::9004 :::* LISTEN 3324175/nps
tcp6 0 0 :::9005 :::* LISTEN 3324175/nps
tcp6 0 0 :::9006 :::* LISTEN 3324175/nps
[root@JRT nps]#
服务端nps面板访问
http://1.117.176.116:9003/
账号密码见服务端配置文件


服务端管理配置





客户端配置
[root@master nps]# wget https://github.com/ehang-io/nps/releases/download/v0.26.10/linux_amd64_client.tar.gz
[root@master nps]#tar -xf linux_amd64_client.tar.gz
[root@master nps]# cd nps
[root@master nps]# ls
conf npc
#不做任何配置
#配置环境变量
[root@master nps]# ./npc install -server=1.117.176.116:9004 -vkey=abcdefg
#启动
[root@master nps]# npc start

查服务


测试
http://1.117.176.116:9005/
http://1.117.176.116:9006/

参考
#nps 使用教程
https://ehang-io.github.io/nps/#/nps_use
#下载
https://github.com/ehang-io/nps/releases
#server
https://github.com/ehang-io/nps/releases/download/v0.26.10/linux_amd64_server.tar.gz
#client
https://github.com/ehang-io/nps/releases/download/v0.26.10/linux_amd64_client.tar.gz