#!/bin/bash is_serverip6route_set() { local server_ip6=${1} if [[ -z "${server_ip6}" ]]; then return 0 fi if ! ip -6 route | grep -q "^${server_ip6}"; then return 1 fi } unset_serverip6route() { local server_ip6=${1} local ip6_gw=${2} local wired_device=${3} ip route delete "${server_ip6}/128" via "${ip6_gw}" dev "${wired_device}" } wired_device=$(ip route | awk '/default via/ { print $5; }') # See https://openvpn.net/community-resources/reference-manual-for-openvpn-2-4/#environmental-variables # to have a list of variables provided by OpenVPN, i.e: # - ifconfig_ipv6_remote # - net_gateway_ipv6 # Check old state of the server ipv6 route if [[ -n "${ifconfig_ipv6_remote}" && -n "${net_gateway_ipv6}" && -n "${wired_device}" ]]; then if is_serverip6route_set "${ifconfig_ipv6_remote}"; then unset_serverip6route "${ifconfig_ipv6_remote}" "${net_gateway_ipv6}" "${wired_device}" fi fi