通过wireguard网络的另一个客户端访问互联网

问题描述 投票:0回答:1

我想通过我的家庭路由器从我的手机访问互联网。它们都作为客户端连接到我的 VPS 上的 WireGuard 服务器。 WireGuard 网络运行良好。我的手机可以访问我家里的电脑。

我的问题是如何将家庭路由器用作手机的互联网网关?你能写下我需要设置的路线吗?

10.8.0.1 - VPS 上的 Wireguard 服务器 10.8.0.2 - 家用路由器 10.8.0.3 - 电话

gateway wireguard
1个回答
0
投票

我遇到了类似的问题,发现这篇 post 很有帮助。这些是我为使其工作所做的更改。

在服务器上(VPS)

您需要通过在您的服务器配置中添加以下行来将所有到达 VPS 的请求转发到您的家庭路由器(假设

wg0
是您的 WireGuard 接口,
eth0
是网络接口)

## Route all traffic to home router ##
PostUp = echo 1 > /proc/sys/net/ipv4/ip_forward
PostUp = echo 1 > /proc/sys/net/ipv4/conf/all/proxy_arp
PostUp = iptables -A FORWARD -i wg0 -o wg0 -m conntrack --ctstate NEW,RELATED,ESTABLISHED -j ACCEPT
PostUp = iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

### PostDown ###
PostDown = iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i wg0 -o wg0 -m conntrack --ctstate NEW,RELATED,ESTABLISHED -j ACCEPT
PostDown = echo 0 > /proc/sys/net/ipv4/conf/all/proxy_arp
PostDown = echo 0 > /proc/sys/net/ipv4/ip_forward

要将所有流量通过隧道路由到特定对等点,请在

(0.0.0.0/0 for IPv4 and ::/0 for IPv6)
部分
AllowedIPs
中添加默认路由
[Peer]
AllowedIPs = 0.0.0.0/0, ::/0

### begin home router ###
[Peer]
PublicKey = [Public key]
PresharedKey = [Pre-shared key]
AllowedIPs = 0.0.0.0/0

客户端(家庭路由器)

将以下内容添加到配置中以将所有流量从

wg0
转发到
eth0

## Route all wg0 to eth0 ##
PostUp = echo 1 > /proc/sys/net/ipv4/ip_forward
PostUp = echo 1 > /proc/sys/net/ipv4/conf/all/proxy_arp
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE;

PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE;
PostDown = echo 0 > /proc/sys/net/ipv4/ip_forward
PostDown = echo 0 > /proc/sys/net/ipv4/conf/all/proxy_arp

在您的手机上

(0.0.0.0/0 for IPv4 and ::/0 for IPv6)
部分添加默认路由
AllowedIPs
[Peer]
AllowedIPs = 0.0.0.0/0, ::/0

[Peer]
PublicKey = [Public key]
PresharedKey = [Preshared key]
AllowedIPs = 0.0.0.0/0, ::/0, 10.8.0.0/24
Endpoint = [VPS Public IP]:[Port]

希望这有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.