Add custom port and interface (#700)
This commit is contained in:
commit
01bcfa3ebe
|
@ -87,7 +87,8 @@ These options can be configured by setting environment variables using `-e KEY="
|
||||||
| `PASSWORD` | - | `foobar123` | When set, requires a password when logging in to the Web UI. |
|
| `PASSWORD` | - | `foobar123` | When set, requires a password when logging in to the Web UI. |
|
||||||
| `WG_HOST` | - | `vpn.myserver.com` | The public hostname of your VPN server. |
|
| `WG_HOST` | - | `vpn.myserver.com` | The public hostname of your VPN server. |
|
||||||
| `WG_DEVICE` | `eth0` | `ens6f0` | Ethernet device the wireguard traffic should be forwarded through. |
|
| `WG_DEVICE` | `eth0` | `ens6f0` | Ethernet device the wireguard traffic should be forwarded through. |
|
||||||
| `WG_PORT` | `51820` | `12345` | The public UDP port of your VPN server. WireGuard will always listen on `51820` inside the Docker container. |
|
| `WG_PORT` | `51820` | `12345` | The public UDP port of your VPN server. This will also change the port wireguard will listen to. |
|
||||||
|
| `WG_INTERFACE` | `wg0` | `wg1` | The interface wireguard will use in the container. (Only needed if `network_mode: host` or `--net=host` is used) |
|
||||||
| `WG_MTU` | `null` | `1420` | The MTU the clients will use. Server uses default WG MTU. |
|
| `WG_MTU` | `null` | `1420` | The MTU the clients will use. Server uses default WG MTU. |
|
||||||
| `WG_PERSISTENT_KEEPALIVE` | `0` | `25` | Value in seconds to keep the "connection" open. If this value is 0, then connections won't be kept alive. |
|
| `WG_PERSISTENT_KEEPALIVE` | `0` | `25` | Value in seconds to keep the "connection" open. If this value is 0, then connections won't be kept alive. |
|
||||||
| `WG_DEFAULT_ADDRESS` | `10.8.0.x` | `10.6.0.x` | Clients IP address range. |
|
| `WG_DEFAULT_ADDRESS` | `10.8.0.x` | `10.6.0.x` | Clients IP address range. |
|
||||||
|
|
|
@ -12,6 +12,7 @@ services:
|
||||||
# Optional:
|
# Optional:
|
||||||
# - PASSWORD=foobar123
|
# - PASSWORD=foobar123
|
||||||
# - WG_PORT=51820
|
# - WG_PORT=51820
|
||||||
|
# - WG_INTERFACE=wg0
|
||||||
# - WG_DEFAULT_ADDRESS=10.8.0.x
|
# - WG_DEFAULT_ADDRESS=10.8.0.x
|
||||||
# - WG_DEFAULT_DNS=1.1.1.1
|
# - WG_DEFAULT_DNS=1.1.1.1
|
||||||
# - WG_MTU=1420
|
# - WG_MTU=1420
|
||||||
|
|
|
@ -8,6 +8,7 @@ module.exports.WEBUI_HOST = process.env.WEBUI_HOST || '0.0.0.0';
|
||||||
module.exports.PASSWORD = process.env.PASSWORD;
|
module.exports.PASSWORD = process.env.PASSWORD;
|
||||||
module.exports.WG_PATH = process.env.WG_PATH || '/etc/wireguard/';
|
module.exports.WG_PATH = process.env.WG_PATH || '/etc/wireguard/';
|
||||||
module.exports.WG_DEVICE = process.env.WG_DEVICE || 'eth0';
|
module.exports.WG_DEVICE = process.env.WG_DEVICE || 'eth0';
|
||||||
|
module.exports.WG_INTERFACE = process.env.WG_INTERFACE.toLowerCase() || 'wg0';
|
||||||
module.exports.WG_HOST = process.env.WG_HOST;
|
module.exports.WG_HOST = process.env.WG_HOST;
|
||||||
module.exports.WG_PORT = process.env.WG_PORT || 51820;
|
module.exports.WG_PORT = process.env.WG_PORT || 51820;
|
||||||
module.exports.WG_MTU = process.env.WG_MTU || null;
|
module.exports.WG_MTU = process.env.WG_MTU || null;
|
||||||
|
@ -21,9 +22,9 @@ module.exports.WG_ALLOWED_IPS = process.env.WG_ALLOWED_IPS || '0.0.0.0/0, ::/0';
|
||||||
module.exports.WG_PRE_UP = process.env.WG_PRE_UP || '';
|
module.exports.WG_PRE_UP = process.env.WG_PRE_UP || '';
|
||||||
module.exports.WG_POST_UP = process.env.WG_POST_UP || `
|
module.exports.WG_POST_UP = process.env.WG_POST_UP || `
|
||||||
iptables -t nat -A POSTROUTING -s ${module.exports.WG_DEFAULT_ADDRESS.replace('x', '0')}/24 -o ${module.exports.WG_DEVICE} -j MASQUERADE;
|
iptables -t nat -A POSTROUTING -s ${module.exports.WG_DEFAULT_ADDRESS.replace('x', '0')}/24 -o ${module.exports.WG_DEVICE} -j MASQUERADE;
|
||||||
iptables -A INPUT -p udp -m udp --dport 51820 -j ACCEPT;
|
iptables -A INPUT -p udp -m udp --dport ${module.exports.WG_PORT} -j ACCEPT;
|
||||||
iptables -A FORWARD -i wg0 -j ACCEPT;
|
iptables -A FORWARD -i ${module.exports.WG_INTERFACE} -j ACCEPT;
|
||||||
iptables -A FORWARD -o wg0 -j ACCEPT;
|
iptables -A FORWARD -o ${module.exports.WG_INTERFACE} -j ACCEPT;
|
||||||
`.split('\n').join(' ');
|
`.split('\n').join(' ');
|
||||||
|
|
||||||
module.exports.WG_PRE_DOWN = process.env.WG_PRE_DOWN || '';
|
module.exports.WG_PRE_DOWN = process.env.WG_PRE_DOWN || '';
|
||||||
|
|
|
@ -23,6 +23,7 @@ const {
|
||||||
WG_POST_UP,
|
WG_POST_UP,
|
||||||
WG_PRE_DOWN,
|
WG_PRE_DOWN,
|
||||||
WG_POST_DOWN,
|
WG_POST_DOWN,
|
||||||
|
WG_INTERFACE,
|
||||||
} = require('../config');
|
} = require('../config');
|
||||||
|
|
||||||
module.exports = class WireGuard {
|
module.exports = class WireGuard {
|
||||||
|
@ -59,18 +60,18 @@ module.exports = class WireGuard {
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.__saveConfig(config);
|
await this.__saveConfig(config);
|
||||||
await Util.exec('wg-quick down wg0').catch(() => { });
|
await Util.exec(`wg-quick down ${WG_INTERFACE}`).catch(() => { });
|
||||||
await Util.exec('wg-quick up wg0').catch((err) => {
|
await Util.exec(`wg-quick up ${WG_INTERFACE}`).catch((err) => {
|
||||||
if (err && err.message && err.message.includes('Cannot find device "wg0"')) {
|
if (err && err.message && err.message.includes(`Cannot find device ${WG_INTERFACE}`)) {
|
||||||
throw new Error('WireGuard exited with the error: Cannot find device "wg0"\nThis usually means that your host\'s kernel does not support WireGuard!');
|
throw new Error(`WireGuard exited with the error: Cannot find device ${WG_INTERFACE}\nThis usually means that your host's kernel does not support WireGuard!`);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw err;
|
throw err;
|
||||||
});
|
});
|
||||||
// await Util.exec(`iptables -t nat -A POSTROUTING -s ${WG_DEFAULT_ADDRESS.replace('x', '0')}/24 -o eth0 -j MASQUERADE`);
|
// await Util.exec(`iptables -t nat -A POSTROUTING -s ${WG_DEFAULT_ADDRESS.replace('x', '0')}/24 -o ' + WG_DEVICE + ' -j MASQUERADE`);
|
||||||
// await Util.exec('iptables -A INPUT -p udp -m udp --dport 51820 -j ACCEPT');
|
// await Util.exec('iptables -A INPUT -p udp -m udp --dport ' + WG_PORT + ' -j ACCEPT');
|
||||||
// await Util.exec('iptables -A FORWARD -i wg0 -j ACCEPT');
|
// await Util.exec('iptables -A FORWARD -i ' + WG_INTERFACE + ' -j ACCEPT');
|
||||||
// await Util.exec('iptables -A FORWARD -o wg0 -j ACCEPT');
|
// await Util.exec('iptables -A FORWARD -o ' + WG_INTERFACE + ' -j ACCEPT');
|
||||||
await this.__syncConfig();
|
await this.__syncConfig();
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
|
@ -118,7 +119,7 @@ AllowedIPs = ${client.address}/32`;
|
||||||
await fs.writeFile(path.join(WG_PATH, 'wg0.json'), JSON.stringify(config, false, 2), {
|
await fs.writeFile(path.join(WG_PATH, 'wg0.json'), JSON.stringify(config, false, 2), {
|
||||||
mode: 0o660,
|
mode: 0o660,
|
||||||
});
|
});
|
||||||
await fs.writeFile(path.join(WG_PATH, 'wg0.conf'), result, {
|
await fs.writeFile(path.join(WG_PATH, `${WG_INTERFACE}.conf`), result, {
|
||||||
mode: 0o600,
|
mode: 0o600,
|
||||||
});
|
});
|
||||||
debug('Config saved.');
|
debug('Config saved.');
|
||||||
|
@ -126,7 +127,7 @@ AllowedIPs = ${client.address}/32`;
|
||||||
|
|
||||||
async __syncConfig() {
|
async __syncConfig() {
|
||||||
debug('Config syncing...');
|
debug('Config syncing...');
|
||||||
await Util.exec('wg syncconf wg0 <(wg-quick strip wg0)');
|
await Util.exec(`wg syncconf ${WG_INTERFACE} <(wg-quick strip ${WG_INTERFACE})`);
|
||||||
debug('Config synced.');
|
debug('Config synced.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,7 +150,7 @@ AllowedIPs = ${client.address}/32`;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Loop WireGuard status
|
// Loop WireGuard status
|
||||||
const dump = await Util.exec('wg show wg0 dump', {
|
const dump = await Util.exec(`wg show ${WG_INTERFACE} dump`, {
|
||||||
log: false,
|
log: false,
|
||||||
});
|
});
|
||||||
dump
|
dump
|
||||||
|
|
Loading…
Reference in New Issue