alfredopalhares / openvpn-update-resolv-conf

Script that updates DNS settings are pushed by the OpenVPN server
458 stars 129 forks source link

foreign_options in client.ovpn #35

Open eoli3n opened 3 years ago

eoli3n commented 3 years ago

I want to set my DOMAIN-SEARCH, but when I use the following code in client.ovpn, the script can't read it

setenv PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
script-security 2
foreign_option_3='dhcp-option DOMAIN be.bnc.ch'
foreign_option_4='dhcp-option DOMAIN-SEARCH bnc.local'
up /etc/openvpn/scripts/openvpn-update-resolv-conf/update-resolv-conf.sh
down /etc/openvpn/scripts/openvpn-update-resolv-conf/update-resolv-conf.sh
down-pre

Is the only way is to set vars in /etc/openvpn/scripts/openvpn-update-resolv-conf/update-resolv-conf.sh ?

TinCanTech commented 3 years ago

Your syntax is incorrect: foreign_option_{n} is a variable which is set when a server pushes something to the client, which the client does not understand. I do not believe you can set it in a config file. Also, if it can be set then the syntax would be setenv foreign_option_3 'dhcp-option DOMAIN be.bnc.ch'. Also, your variable for PATH may need to be quoted.

eoli3n commented 3 years ago
setenv PATH "/usr/sbin:/usr/bin:/sbin:/bin"
setenv foreign_option_3 "dhcp-option DOMAIN-SEARCH domain.fr"                             
setenv foreign_option_4 "dhcp-option DOMAIN-SEARCH sub.domain.fr"                      
script-security 2
up /etc/openvpn/scripts/openvpn-update-resolv-conf/update-resolv-conf.sh
down /etc/openvpn/scripts/openvpn-update-resolv-conf/update-resolv-conf.sh
down-pre

keeps adding only search domain.fr instead of search domain.fr sub.domain.fr


If I edit update-resolv-conf.sh to set this, tt adds the two domains search, which is what i want

# Example envs set from openvpn:
# foreign_option_1='dhcp-option DNS 193.43.27.132'
# foreign_option_2='dhcp-option DNS 193.43.27.133'
foreign_option_3="dhcp-option DOMAIN-SEARCH domain.fr"
foreign_option_4="dhcp-option DOMAIN-SEARCH sub.domain.fr"

I just moved to an os without systemd, before i was using systemd script and I only had to set to client.ovpn, I don't know why its not working anymore.

dhcp-option DOMAIN-SEARCH domain.fr
dhcp-option DOMAIN-SEARCH sub.domain.fr