Info::WireGuard script wg exit switch.sh
De wiki_pcwiki2
KEYWORDS: WIREGUARD, PROJETER, XPS13, SRV18, OVH2
Le 25/08/2026: #!/usr/bin/env bash
- Bascule la sortie internet (full-tunnel) de xps13 entre srv18 (wg3),
- ovh2 (wg2), ou la sortie normale (aucun tunnel en full-tunnel).
- Usage: wg_exit_switch.sh {srv18|ovh2|off}
set -euo pipefail
usage() {
echo "Usage: $0 {srv18|ovh2|off}" >&2
echo " srv18 : sortie via 82.67.120.130 (wg3)" >&2
echo " ovh2 : sortie via 51.68.207.177 (wg2)" >&2
echo " off : desactive le full-tunnel, sortie normale" >&2
exit 1
}
$# -eq 1 || usage
WG3_CONF="/etc/wireguard/wg3.conf" WG2_CONF="/etc/wireguard/wg2.conf"
set_allowed_ips() {
local conf="$1" value="$2"
sed -i "s#^\(\s*AllowedIPs\s*=\s*\).*#\1${value}#" "${conf}"
}
case "$1" in
srv18)
set_allowed_ips "${WG3_CONF}" "0.0.0.0/0, ::/0"
set_allowed_ips "${WG2_CONF}" "10.0.2.0/24"
systemctl restart wg-quick@wg3
systemctl restart wg-quick@wg2
echo "Sortie internet basculee sur srv18 (82.67.120.130) via wg3."
;;
ovh2)
set_allowed_ips "${WG3_CONF}" "10.0.3.0/24"
set_allowed_ips "${WG2_CONF}" "0.0.0.0/0, ::/0"
systemctl restart wg-quick@wg3
systemctl restart wg-quick@wg2
echo "Sortie internet basculee sur ovh2 (51.68.207.177) via wg2."
;;
off)
set_allowed_ips "${WG3_CONF}" "10.0.3.0/24"
set_allowed_ips "${WG2_CONF}" "10.0.2.0/24"
systemctl restart wg-quick@wg3
systemctl restart wg-quick@wg2
echo "Full-tunnel desactive, sortie internet normale (wlp2s0)."
;;
*)
usage
;;
esac
sleep 1 echo "IP publique actuelle : $(curl -s -4 --max-time 5 ifconfig.me || echo 'indisponible')"