Limour

Limour

临床医学在读。

【探索】基於QUIC的內網穿透協議

環境和依賴#

mkdir -p ~/base/NPS && cd ~/base/NPS && mkdir conf
nano docker-compose.yml
nano conf/nps.conf
touch conf/{clients,hosts,tasks}.json
sudo docker-compose up -d
# 反代 dashboard 8080
version: '3.3'
services:
  nps:
    container_name: nps
    restart: unless-stopped
    ports:
      - '8024:8024'
      - '6000-6002:6000-6002/udp'
    volumes:
      - './conf:/conf'
      - '/etc/localtime:/etc/localtime:ro'
    image: yisier1/nps
 
networks:
  default:
    external: true
    name: ngpm
appname = nps
#啟動模式(dev|pro)
runmode = pro
 
#HTTP(S) 代理端口,若為空則不啟動
http_proxy_ip=0.0.0.0
http_proxy_port=18081
 
##橋接
bridge_type=tcp
bridge_port=8024
bridge_ip=0.0.0.0
 
#流量數據持久化間隔(分鐘)
#忽略表示不持久化
#flow_store_interval=1
 
# 日誌級別 LevelEmergency->0  LevelAlert->1 LevelCritical->2 LevelError->3 LevelWarning->4 LevelNotice->5 LevelInformational->6 LevelDebug->7
log_level=7
#log_path=nps.log
 
#是否限制IP訪問,true或false或忽略
#ip_limit=true
 
#allow_ports=9001-9009,10001,11000-12000
 
#Web管理多用戶登錄
allow_user_login=false
allow_user_register=false
allow_user_change_username=false
 
#擴展
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=true
 
#緩存
http_cache=false
http_cache_length=100
 
#獲取原始IP
http_add_origin_header=false
 
#pprof調試選項
#pprof_ip=0.0.0.0
#pprof_port=9999
 
#客戶端斷開超時
disconnect_timeout=60
 
# 以下的需要進行配置
# 公共密碼,客戶端可以用來連接服務器
# 連接後,服務器將能夠根據自己的配置文件打開相關端口並解析相關域名。
public_vkey=<16個字符>
 
#Web API 未經身份驗證的IP地址(auth_crypt_key的長度必須為16)
#如有需要,請移除註釋
auth_key=<24個字符>
auth_crypt_key=<16個字符>
 
#web
web_host=limour.top
web_username=Limour
web_password=<16個字符>
web_port = 8080
web_ip=0.0.0.0
web_open_ssl=false
web_base_url=
open_captcha=true
# 如果web在代理下使用子路徑。像http://host/nps需要這個。
#web_base_url=/nps
 
#p2p
p2p_ip=<寫服務器的ip>
p2p_port=6000
# 設置為6000,請在控制台防火牆開放6000~6002(額外添加2個端口)udp端口

配置端口映射#

nano Port-Hopping.sh && chmod +x Port-Hopping.sh
nano /etc/systemd/system/Port-Hopping.service
systemctl enable Port-Hopping && systemctl start Port-Hopping && systemctl status Port-Hopping && iptables -t nat -L
#!/bin/bash
# IPv4
/usr/sbin/iptables  -t nat -A PREROUTING -i eth0 -p udp --dport 32768:61000 -j DNAT --to-destination :3234
# IPv6
/usr/sbin/ip6tables -t nat -A PREROUTING -i eth0 -p udp --dport 32768:61000 -j DNAT --to-destination :3234
[Unit]
Description=Port-Hopping
After=network.target docker.service
[Service]
ExecStart=/root/Port-Hopping.sh
Restart=on-failure
[Install]
WantedBy=multi-user.target

配置 quic#

sudo docker network create sswitch
mkdir -p ~/app/quic && cd ~/app/quic && nano docker-compose.yml
nano hysteria.yaml
sudo docker-compose up -d && sudo docker-compose logs
version: '3.9'
services:
  hysteria:
    image: tobyxdd/hysteria
    restart: always
    extra_hosts:
      - 'host.docker.internal:host-gateway'
    ports:
      - '3234:3234/udp'
    volumes:
      - ./hysteria.yaml:/etc/hysteria.yaml
      - /root/base/NGPM/letsencrypt:/home/ubuntu/letsencrypt
    command: ["server", "-c", "/etc/hysteria.yaml"]
 
networks:
  default:
    external: true
    name: sswitch
listen: :3234 
 
tls:
  cert: /home/ubuntu/letsencrypt/live/npm-1/fullchain.pem
  key: /home/ubuntu/letsencrypt/live/npm-1/privkey.pem
 
auth:
  type: password
  password: Se7RAuFZ8Lzg 
 
bandwidth:
  up: 3 mbps
  down: 3 mbps
 
masquerade: 
  type: proxy
  proxy:
    url: https://hexo.limour.top/ 
    rewriteHost: true

測試轉發#

  • 在客戶端新建config.yaml, 寫入以下內容
server: hexo.limour.top:32768-61000
 
auth: Se7RAuFZ8Lzg 
 
bandwidth: 
  up: 3 mbps
  down: 3 mbps
 
#socks5:
#  listen: 127.0.0.1:1580 
 
#http:
#  listen: 127.0.0.1:8580 
 
tcpForwarding:
  - listen: 127.0.0.1:8024 
    remote: host.docker.internal:8024 

測試穿透#

.\npc.exe --server=127.0.0.1:8024 -vkey=<vkey> -type=tcp

客戶端示例#

mkdir -p ~/app/quic-npc && cd ~/app/quic-npc && nano docker-compose.yml
nano config.yaml
sudo docker-compose up -d && sudo docker-compose logs
version: '3.3'
services:
  quic_nps:
    image: tobyxdd/hysteria
    network_mode: host
    restart: always
    volumes:
      - ./config.yaml:/etc/config.yaml
    command: ["--config", "/etc/config.yaml"]
 
  npc_lk:
    depends_on:
      - quic_nps
    network_mode: host
    image: yisier1/npc
    restart: unless-stopped
    command: -server=127.0.0.1:8024 -vkey=<vkey> -type=tcp
server: hexo.limour.top:32768-61000
 
auth: Se7RAuFZ8Lzg 
 
bandwidth: 
  up: 3 mbps
  down: 3 mbps
 
tcpForwarding:
  - listen: 127.0.0.1:8024 
    remote: host.docker.internal:8024 
載入中......
此文章數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。