77 lines
1.5 KiB
Markdown
77 lines
1.5 KiB
Markdown
## Force DNS Usage inside VPN
|
|
|
|
### Bash script
|
|
Save file into /bin/vpn-dns swith 755 permissions
|
|
|
|
```bash
|
|
#!/bin/bash
|
|
|
|
echo "Getting current DNS servers, this takes a couple of seconds"
|
|
|
|
/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -Command '
|
|
$ErrorActionPreference="SilentlyContinue"
|
|
Get-NetAdapter -InterfaceDescription "WireGuard Tunnel*" | Get-DnsClientServerAddress | Select -ExpandProperty ServerAddresses
|
|
Get-NetAdapter | ?{-not ($_.InterfaceDescription -like "WireGuard Tunnel*") } | Get-DnsClientServerAddress | Select -ExpandProperty ServerAddresses
|
|
' | \
|
|
awk 'BEGIN { print "# Generated by vpn fix func on", strftime("%c"); print } { print "nameserver", $1 }' | \
|
|
tr -d '\r' > /etc/resolv.conf
|
|
clear
|
|
```
|
|
|
|
### Configure Init
|
|
|
|
#### SystemD
|
|
|
|
Save file into /etc/systemd/system/vpn-dns.service with 755 permissions
|
|
|
|
```bash
|
|
[Unit]
|
|
Description=VPN DNS Configuration
|
|
|
|
[Service]
|
|
Type=oneshot
|
|
ExecStart=/bin/vpn-dns
|
|
Environment=TERM=xterm
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
```
|
|
|
|
Enable service
|
|
|
|
```console
|
|
systemctl enable vpn-dns
|
|
```
|
|
|
|
#### OpenRC
|
|
|
|
Save file into /etc/init.d/vpn-dns with 755 permissions
|
|
|
|
```bash
|
|
#!/sbin/openrc-run
|
|
# Distributed under the terms of the GNU General Public License v3 or later
|
|
name="vpn-dns"
|
|
description="VPN DNS Configuration"
|
|
command="/bin/vpn-dns"
|
|
|
|
depend() {
|
|
use net
|
|
}
|
|
|
|
start() {
|
|
ebegin "Starting VPN DNS Configuration"
|
|
"${command}"
|
|
eend $? "Failed to start VPN DNS Configuration"
|
|
}
|
|
```
|
|
|
|
Enable service
|
|
|
|
```console
|
|
rc-update add vpn-dns boot
|
|
```
|
|
|
|
### Show Networks
|
|
|
|
c/> Get-NetAdapter
|