How to force MacOS to regenerate /etc/resolv.conf file?

Apple states clearly that the /etc/resolv.conf file is managed by Mac OS so it will be regenerated. The problem is that it seems that when I join the OpenVPN this does not happen and as a result tools like nslookup fail to see the vpn.

#
# Mac OS X Notice
#
# This file is not used by the host name and address resolution
# or the DNS query routing mechanisms used by most processes on
# this Mac OS X system.
#
# This file is automatically generated.
#
domain local
nameserver 192.168.1.1

I need to know which command can I run in order to force MacOS (Sierra) to regenerate the file.

As you can see my file does not contain the correct list of DNS servers. For example the scutil --dns returns a long list of DNS servers, one that includes the OpenVPN dns servers.


I found a solution today. Actually the file is not /etc/resolv.conf in mac OS. It is /var/run/resolv.conf

So do this:

sudo rm /etc/resolv.conf
sudo ln -s /var/run/resolv.conf /etc/resolv.conf

I guess, this file is created/updated when you change the network settings in 'System Preferences'. You need to 'System Preferences...' -> Network -> (select the active NIC device)

In the Network dialog select: 'Advanced'. You can make changes for TCP/IP, DNS, WINS, 802.1X, Proxies, Hardware in the corresponding dialog tabs. Close this dialog with Ok. Now you need to click 'Apply' in the Network settings dialog to make the change persistent. (For me, that was the tricky part)

Also confirming the location of resolv.conf:

➜  ~ ls -al /etc/resolv.conf 
lrwxr-xr-x  1 root  wheel  22 May  1  2017 /etc/resolv.conf -> ../var/run/resolv.conf

➜  ~ ls -al /var/run/resolv.conf
-rw-r--r--  1 root  daemon  303 Nov 27 09:27 /var/run/resolv.conf

➜  ~ cat /var/run/resolv.conf
#
# Mac OS X Notice
#
# This file is not used by the host name and address resolution
# or the DNS query routing mechanisms used by most processes on
# this Mac OS X system.
#
# This file is automatically generated.
#
search example.com
nameserver 8.8.4.4
nameserver 8.8.8.8

EDIT: Note that '/etc' is a symlink to 'private/etc'