
我有 2 台機器運行 ubuntu 22.04,我們稱它們為伺服器和代理程式。代理程式是具有靜態公用IP的vps,伺服器在nat後面運行。我想將代理上某些連接埠上的所有流量路由到伺服器。
我已經在兩者之間設定了一個wireguard vpn,並且兩者都可以互相ping通,如果我從代理獲取伺服器的vpn位址,我會得到正確的html回應,並在代理上設定nginx(這不是預期的最終結果)解決方案,因為我想路由其他不是 http/https 的服務,允許我 proxy_pass 到 vpn ip,一旦 agin 得到正確的 html 回應。
但我無法使用 iptables/ufw 設定轉送。這是我的wiregaurd 配置,其中包含介面上的iptables 路由規則。
代理人:
[Interface]
# Proxy with static ip
Address = 10.250.0.1/32
ListenPort = 23456
PrivateKey = {private key}
# packet forwarding
PreUp = sysctl -w net.ipv4.ip_forward=1
# port forwarding
PreUp = iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 10.250.0.2
PostDown = iptables -t nat -D PREROUTING -p tcp --dport 80 -j DNAT --to-destination 10.250.0.2
PreUp = iptables -t nat -A PREROUTING -p tcp --dport 443 -j DNAT --to-destination 10.250.0.2
PostDown = iptables -t nat -D PREROUTING -p tcp --dport 443 -j DNAT --to-destination 10.250.0.2
[Peer]
# main_server behind nat
PublicKey = {pub key}
AllowedIPs = 10.250.0.2/32
伺服器:
[Interface]
Address = 10.250.0.2/32
ListenPort = 23456
PrivateKey = {priv key}
[Peer]
PublicKey = {pub key}
Endpoint = {proxy server ip}:23456
AllowedIPs = 10.250.0.0/16
PersistentKeepalive = 25
運行sudo iptables-save -c
返回以下結果
# Completed on Wed Aug 24 17:01:57 2022
# Generated by iptables-save v1.8.7 on Wed Aug 24 17:01:57 2022
*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
[0:0] -A PREROUTING -p tcp -m tcp --dport 80 -j DNAT --to-destination 10.250.0.2
[4:208] -A PREROUTING -p tcp -m tcp --dport 443 -j DNAT --to-destination 10.250.0.2
COMMIT
[4:208]
每次我嘗試透過網頁瀏覽器存取代理程式時,資料包和位元組數都會增加