> ## Content Index
> Fetch the complete content index at: https://ivans.io/llms.txt
> Use this file to discover other available public pages before exploring further.

# Fixing DNS for Wireguard on MacOS
- URL: https://ivans.io/wireguard-on-macos/
- Published: 2021-04-13T23:55:00.000Z
- Updated: 2021-04-13T23:55:00.000Z
- Description: Fix wireguard DNS resolution on MacOS with PostUp and PostDown + CLI usage.
- Author: Ivan Smirnov
- Tags: macos, tech, Import 2022-12-02 03:12, #Import 2026-08-12 21:23

If you are using the [Wireguard MacOS App](https://apps.apple.com/us/app/wireguard/id1451685025?ls=1&mt=12&ref=ivans.io) with your VPN's, you will notice that your custom DNS entries are not getting set at the system level. 

You can manually edit Network Preferences -> Wi-Fi -> Advanced -> DNS and add your DNS server, but that will cause DNS errors if your VPN drops and your system DNS still points to the wireguard DNS instance.

![](https://ivans.io/content/images/2021/04/Screen-Shot-2021-04-09-at-3.10.25-PM.png)

A workaround is to add a `PostUp` and `PostDown` option to your wireguard config:

```ini
[Interface]
Address = 10.200.200.1/24
ListenPort = 51820
PrivateKey = SERVER_PRIVATE_KEY

# DNS server
DNS = 10.66.66.1

# Commands to set and clear DNS
PostUp = sudo /usr/sbin/networksetup -setdnsservers Wi-Fi 10.66.66.1
PostDown = sudo /usr/sbin/networksetup -setdnsservers Wi-Fi "Empty"

[Peer]
# foo
PublicKey = PEER_FOO_PUBLIC_KEY
PresharedKey = PRE-SHARED_KEY
AllowedIPs = 10.200.200.2/32
```

Wireguard Sample Configuration

The wireguard GUI [will not read](https://www.reddit.com/r/WireGuard/comments/bea47m/wireguard%5Fmacos%5Fapplication%5Fpostuppostdown/?ref=ivans.io) the PostUp and PostDown, so you will have to run your wireguard commands from the command line.

## Solution: Use the CLI

First, install the tools:

```
brew install wireguard-tools wireguard-go
```

Then, save your config to the folder:

```
vim /usr/local/etc/wireguard/myvpn.conf
```

Finally, launch your VPN - using the same name as the `conf` file.

```
sudo wg-quick up myvpn
```

## Bonus: Alias/Visudo

  
You can set up an alias with `alias vpnup='sudo wg-quick up myvpn'`

If you don't want to enter your password each time, simply run `sudo visudo -f /private/etc/sudoers.d/wireguard` and paste the following contents, replacing `myuser` with your username.

```
myuser ALL = (root) NOPASSWD: /usr/local/bin/wg-quick
```