I have a few Windows 7/8 clients connecting to a Linux OpenVPN Server (tap). I'd like to set the clients' DNS and WINS servers upon connection. The OpenVPN isn't acting as DHCP server; there is an independent DHCP sever in the network.
The most reasonably way to achieve that is through DHCP. However, the DHCP server is quite basic, and I cannot configure these parameters in the DHCP server itself. (And I'd rather not to replace the DHCP server, it'd be too complicated)
push "dhcp-option DNS 10.0.0.101" and
push "dhcp-option WINS 10.0.0.101", but it didn't help. The clients just ignored these. I assume that these options are treated only when the OpenVPN server is also the DHCP server. (am I correct?)
Setting DNS and WINS manually with windows "Network Conncections" GUI is working, but I want something automatic (as much as possible).
My next try was running a script on the client machine. I'm usually a Linux scripter; however, something that simple should be feasible even with Windows, isn't it?
First approach,PowerShell (run as Administrator)
$wmi = Get-WmiObject win32_networkadapterconfiguration -filter "ServiceName = 'tap0901'" echo $wmi $wmi.SetWinsServer("10.0.0.101","")
Strangely, I couldn't find the equivalent command for setting the DNS Server.
And that without mentioning the PowerShell complication with the default
Restricted, which makes it quite user-unfriendly as automatic solution for the end-user.
Another approach I checked was
However, in all the examples I saw with Google (such as http://community.spiceworks.com/scripts/show/2195-set-ip-address-subnet-gateway-dns-and-wins-server-all-windows-os-also-works-with-runas) they didn't refer to the Adapter name (I'm not sure that it's the correct term) - 'tap*', but to some arbitrary "Local Area Connection*", which will probably different in each machine.
So, how to continue? What's the recommended way to solve this?
Here's my client.ovpn file:
client pull # from http://serverfault.com/questions/110281/openvpn-client-on-windows-7-cannot-add-route-from-config-script script-security 2 system dev tap proto tcp-client remote A.B.C.D 443 resolv-retry infinite nobind ca .. cert .. key .. comp-lzo verb 5