aboutsummaryrefslogtreecommitdiffstats
path: root/wsl/README.md
blob: e1dfe1e35420a7190d46b88a651090a9e3e6f31f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
## Force DNS Usage inside VPN

### SystemD
```bash
$ cat /etc/systemd/system/vpn-dns.service
[Unit]
Description=VPN DNS Configuration

[Service]
Type=oneshot
ExecStart=/bin/vpn-dns
Environment=TERM=xterm

[Install]
WantedBy=multi-user.target
```

### OpenRC

```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 $?
}
```

```bash
$ cat /bin/vpn-dns
#!/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
```
### Show Networks

c/> Get-NetAdapter