1

I’m using static key configuration for OpenVPN. But I can’t set DNS server.

My server.conf is:

port 3001
proto udp
dev tun
ifconfig 10.8.1.1 10.8.1.2
secret static.key
keepalive 10 60
ping-timer-rem
persist-tun
persist-key
#user nobody
#group nobody
comp-lzo
daemon
push "redirect-gateway def1 bypass-dhcp"

And my client is:

remote ###.###.###.### 3001
proto udp
dev tun
ifconfig 10.8.1.2 10.8.1.1
secret static.key
keepalive 10 60
ping-timer-rem
persist-tun
persist-key
comp-lzo
redirect-gateway def1

How can I set DNS on client?

  • 3
    push "dhcp-option DNS 8.8.8.8" ? – Dom Jan 2 '14 at 10:22
  • 1
    @Dom the push directives go to server config files only (if I am not mistaken). no? – nass Jan 2 '14 at 10:31
  • As said in a comment one can push it from the server which is preferrable in most (but not all) cases. Explanation: in a complex (multiple) split brain dns infrastructure I occasionally have needed to set it manually. To set it manually on a single client you do it on the network interface itself if I recall correctly, so the procedure would depend on the operating system. – ErikE Jan 2 '14 at 10:53
  • 1
    @Dom: push configs doesn't work in static key configuration! – RYN Jan 2 '14 at 12:04
  • @ErikE: So OpenVPN can't handle DNS request by itself? I should config it manually? – RYN Jan 2 '14 at 12:06
2

You can add one or more dns,

Add the following line in the server config:

push "dhcp-option DNS 8.8.8.8"

or replace 8.8.8.8 with your own dns server, if you want to use private or local dns records otherwise it's prefered to you public dns and not to direct the dns traffic via the VPN tunnel. cause this will affect normal internet access once you are connected.

You might need to reconsider the

push "redirect-gateway"

As this will redirect all the traffic to the VPN tunnel, you might direct only the related subnets instead of this option.

  • 2
    This doesn't work! push configs doesn't work in static key configuration! push "redirect-gateway" doesn't work but when I put redirect-gateway in client config it works; also dhcp-option DNS 8.8.8.8 doesn't work with push – RYN Jan 2 '14 at 11:29
  • did it work with you on certificate based openvpn ? – MohyedeenN Jan 2 '14 at 11:34
  • 1
    Yes; in server mode and with certificates it works! – RYN Jan 2 '14 at 12:03
  • Ouch! It sounds like the kind of bug someone would have noticed before though. Update your question with this info, it just gave you an upvote for good research. – ErikE Jan 2 '14 at 13:01
  • i will try test it for you this day, i will update you if it worked for me – MohyedeenN Jan 2 '14 at 13:13
1

You set the dns client from the OpenVPN client through the network interface dns client settings.

The procedure would therefore vary depending on operating system and could potentially be automated. Here is a telltale example for Windows from this link:

set-dns-client.cmd:

netsh interface ip set dns "Local Area Connection" static 1.2.3.4

netsh interface ip add dns "Local Area Connection" 5.6.7.8

This is the only (and painful) way I am aware of.

Even though it's kind of inexplicabe, one background to push options not seeming work with static keys may be this entry from the OpenVPN documentation:

*Static Key disadvantages*
Limited scalability -- one client, one server

Just speculating the devs hit on some snag and they are not prioritizing it, assuming of course that the finding holds true. This snippet from the Static Key Mini-HOWTO seems to support such a hypothesis:

Static key configurations offer the simplest 
setup, and are ideal for point-to-point VPNs
or proof-of-concept testing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.