How to ensure OpenVPN connection uses specific DNS?

I'm using OpenVPN through Tunnelblick on MacOS X Lion.

I need to set specific DNS (with local IP, which works only when VPN is up) for the duration of this VPN session only.

I do not have access to the OpenVPN server configuration. Only client config. Also, DNS from the server doesn't work.

So it works like this: I connect to VPN, go the Network preferences and manually set DNS. After VPN is disconnected, I switch back to default. It works, but it needs to be automatic.

After some exploration I found that OpenVPN up- and down- scripts might help me with that. Unfortunately, I haven't found any specific documentation about how exactly it can be done.

How it can or can't be done? Any advice would be appreciated!


Solution 1:

try adding:

# put actual dns name here
dhcp-option DNS 10.11.12.13

to your client's config

Solution 2:

If you (unlike the OP) have access to the OpenVPN server configuration, you can add this option in your OpenVPN server.conf if you want to push for all the clients:

push "dhcp-option DNS 8.8.8.8"

You can change the 8.8.8.8 to your desired DNS.