On my current OS X version (Sierra 10.12.6) & FortiClient 5.6.1 it seems like if ServerAddresses has more than 2 addresses, then the "set" call doesn't persist anything (if you "get", nothing will have been updated). To workaround this, I decided to only keep first FortiClient DNS address and merge it with my public DNS address (8.8.8.8).
Moreover, I would suggest to automatically run the bash script on FortiClient connect : this can be done by exporting FortiClient configuration script then re-importing it
Full guide below :
1/ Create following bash script and store it somewhere (in my case, it was into ~/bashscripts/update-forticlient-dns.sh
) and don't forget to replace the <FIRST IP ADDRESS FOR FORTICLIENT DNS>
by the result of scutil --dns | grep "nameserver\[0\]"
while your FortiClient connection is up
#!/bin/bash
ROOT_PASSWORD=$1
# Uncomment this if you want to log everything happening during this script execution into a dedicated log file
# exec >/tmp/forticlient-log 2>&1
# Ensuring we did a sudo correctly once
# Because we cannot both use a pipe and an stdin redirection at the same time
# (or at least, my bash knowledge is not wide enough for that :-))
echo "$ROOT_PASSWORD" | sudo -S ls /dev/null
sudo scutil <<EOF
get State:/Network/Service/forticlientsslvpn/DNS
d.add ServerAddresses 8.8.8.8 <FIRST IP ADDRESS FOR FORTICLIENT DNS>
set State:/Network/Service/forticlientsslvpn/DNS
quit
EOF
2/ Run FortiClient, then go into Preferences > General and click the Backup button which will export your FortiClient configuration into a file
3/ In this file, locate & edit the /forticlient_configuration/vpn/sslvpn/connections/connection[name="YOUR CONNECTION"]/on_connect/script/script node and call your script inside it :
<on_connect>
<script>
<os>mac</os>
<script>/Users/fcamblor/bashscripts/update-forticlient-dns.sh "your_secret_root_password_here"</script>
</script>
</on_connect>
4/ Go back to FortiClient console, click the lock in the bottom left corner, then go to Preferences > General and click the Restore button : locate your updated configuration file and that's it, your DNS configuration will be updated on the fly each time you connect to the VPN.