|
|
|
@ -17,6 +17,7 @@ const { |
|
|
|
WG_DEFAULT_DNS, |
|
|
|
WG_DEFAULT_ADDRESS, |
|
|
|
WG_ALLOWED_IPS, |
|
|
|
WG_NAT, |
|
|
|
} = require('../config'); |
|
|
|
|
|
|
|
module.exports = class WireGuard { |
|
|
|
@ -53,10 +54,14 @@ module.exports = class WireGuard { |
|
|
|
await this.__saveConfig(config); |
|
|
|
await Util.exec('wg-quick down wg0').catch(() => {}); |
|
|
|
await Util.exec('wg-quick up wg0'); |
|
|
|
await Util.exec(`iptables -t nat -A POSTROUTING -s ${WG_DEFAULT_ADDRESS.replace('x', '0')}/24 -o eth0 -j MASQUERADE`); |
|
|
|
await Util.exec('iptables -A INPUT -p udp -m udp --dport 51820 -j ACCEPT'); |
|
|
|
await Util.exec('iptables -A FORWARD -i wg0 -j ACCEPT'); |
|
|
|
await Util.exec('iptables -A FORWARD -o wg0 -j ACCEPT'); |
|
|
|
|
|
|
|
if (WG_NAT) { |
|
|
|
await Util.exec(`iptables -t nat -A POSTROUTING -s ${WG_DEFAULT_ADDRESS.replace('x', '0')}/24 -o eth0 -j MASQUERADE`); |
|
|
|
await Util.exec('iptables -A INPUT -p udp -m udp --dport 51820 -j ACCEPT'); |
|
|
|
await Util.exec('iptables -A FORWARD -i wg0 -j ACCEPT'); |
|
|
|
await Util.exec('iptables -A FORWARD -o wg0 -j ACCEPT'); |
|
|
|
} |
|
|
|
|
|
|
|
await this.__syncConfig(); |
|
|
|
|
|
|
|
return config; |
|
|
|
|