OpenVPN client maintenance

disable_openvpn_client_dns.sh

A companion to install_openvpn_client_centos7.sh for hosts where the VPN should keep tunneling traffic but must stop forcing its own DNS (e.g. 10.7.7.53). It backs up the client config, comments out the DNS hooks, restarts the service, and can optionally write your own resolvers via --set-dns. Idempotent and reversible.

ワンライナー

curl -fsSL helper.sh/disable_openvpn_client_dns.sh | sudo bash
curl -fsSL helper.sh/disable_openvpn_client_dns.sh | sudo bash -s -- --set-dns "114.114.114.114 223.5.5.5"

実行条件

  • CentOS 7 (or compatible)
  • root privileges or sudo
  • An existing client config at /etc/openvpn/client/client.conf

適用場面

  • Keep the VPN tunnel up but stop it from forcing an internal DNS like 10.7.7.53
  • Restore your own public resolvers on a host that does not need *.internal name resolution
  • Undo the DNS hooks added by install_openvpn_client_centos7.sh without reinstalling

主なポイント

  • Backs up client.conf to a timestamped .bak before changing anything
  • Comments out script-security / up / down DNS hooks (idempotent, safe to re-run)
  • Restarts openvpn-client@client so the change takes effect immediately
  • Optional --set-dns "ns1 ns2" writes /etc/resolv.conf for you
  • Supports --config-dir / --config-name for non-default install locations
  • Reversible: remove the leading # from the hooks and restart to re-enable

推奨手順

  1. Run the one-liner with sudo or as root on the host where OpenVPN client is already installed.
  2. The script backs up client.conf, comments out the DNS hooks, and restarts openvpn-client@client.
  3. If you did not pass --set-dns, edit /etc/resolv.conf yourself to point at your preferred resolvers.
  4. Verify with cat /etc/resolv.conf, and confirm the tunnel still works with ping to an internal IP.

注意事項

  • After disabling the VPN DNS, internal names (e.g. *.reshub.cn) will no longer resolve unless you keep that resolver another way.
  • A timestamped client.conf backup is created automatically; keep it until you confirm the change is correct.
  • --set-dns overwrites /etc/resolv.conf entirely, so list every nameserver you need.