在OpenVPN中使用静态密钥configuration时,在客户端上设置DNS服务器

我正在使用OpenVPN的静态密钥configuration。 但是我不能设置DNS服务器。

我的server.conf是:

 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" 

而我的客户是:

 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 

我如何在客户端上设置DNS?

你可以添加一个或多个DNS,

在服务器configuration中添加以下行:

 push "dhcp-option DNS 8.8.8.8" 

或者用你自己的dns服务器replace8.8.8.8,如果你想使用私人或本地DNSlogging,否则它是首选你的公共DNS,而不是通过VPN隧道指挥DNSstream量。 因为一旦连接,这将影响正常的互联网访问。

您可能需要重新考虑

 push "redirect-gateway" 

由于这会将所有stream量redirect到VPN隧道,因此您只能指定相关的子网而不是此选项。

您可以通过networking接口dns客户端设置从OpenVPN客户端设置dns客户端。

程序因此会根据操作系统而变化,并且可能会被自动化。 这个链接是Windows的一个示例:

设置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 

这是我所知道的唯一(痛苦的)方式。

尽pipe这是一种莫名其妙的事情,但是从OpenVPN文档中可以看出,使用静态键并不能使用静态键的选项是一个背景:

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

只是猜测开发者打了一些障碍,他们没有优先考虑,当然假设这个发现是正确的。 Static Key Mini-HOWTO的这个片段似乎支持这样一个假设:

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