## 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 ``` #### 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" pidfile="/var/run/vpn-dns.pid" command="/bin/vpn-dns" depend() { use net } start() { ebegin "Starting ${name}" start-stop-daemon --start --exec "${command}" --pidfile "${pidfile}" eend $? } reload() { ebegin "Reloading ${name}" start-stop-daemon --signal HUP --pidfile "${pidfile}" eend $? } stop() { ebegin "Stopping ${name}" start-stop-daemon --quiet --stop --exec "${command}" --pidfile "${pidfile}" eend $? } ``` ### Show Networks c/> Get-NetAdapter