vps use wireguard as sever and NAT client simultaneously

in with 1 comment

1,edit wg1,wg2,and so on .for me I use notepad.

here is a exmple:

[Interface]
PrivateKey = AKSOOkZqKNZRQaAitRn02UlYOr2wfPoLxddRHfSJ828=
Address = 10.77.1.1/24
PostUp   = iptables -A FORWARD -i wg1 -j ACCEPT; iptables -A FORWARD -o wg1 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i wg1 -j ACCEPT; iptables -D FORWARD -o wg1 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
ListenPort = 37148
DNS = 8.8.8.8
MTU = 1420
[Peer]
PublicKey = 3EdQfr7dh37n1q9mXDBEoYHdfelJNcr/tels6qJ9ORY=
AllowedIPs = 10.77.1.2/32

2,Save above file as wg1.conf

3,upload wg.conf to etc/wireguard

4:Set up a VPN tunnel:

wg-quick up interface_name

In this case interface_name is wg1.

now you can check your wiregurad status use command wg.
Do not forget creat client for client.

Here is the exmple

[Interface]
PrivateKey = wN2rax4ryZS0xSK8Wx6/jRzUfncip6ZjmDxqAMO9BHo=
Address = 10.77.1.2/24 
DNS = 8.8.8.8
MTU = 1420
[Peer]
PublicKey = 13vB3gCM/oyT6ztYfIMeQYOEyyLZTUV0m3YdRbUP9CQ=
Endpoint = VPS public ip:listening port
AllowedIPs = 0.0.0.0/0, ::0/0
PersistentKeepalive = 25
Responses
  1. 此配置在中转机使用

    Reply