Last active
May 11, 2023 03:11
-
-
Save dcode/bbf990ea781bed1e42d39e2351b6c432 to your computer and use it in GitHub Desktop.
NetworkManager hook to update the routing tables for dual-homed systems, allowing traffic past the gateway on either interface.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# 75-dual-home-routing | |
# Description: Updates routing tables to allow traffic on dual-homed boxes | |
# according to the interface it came in on | |
# Place in /etc/NetworkManager/dispatcher.d/ and update interface name below | |
IF=$1 | |
STATUS=$2 | |
function update_routing_table() { | |
IP_ADDR=$(echo ${IP4_ADDRESS_0} | awk -F'/' '{ print $1 }') | |
ip rule add from ${IP_ADDR} table 20 | |
ip route add default via ${IP4_GATEWAY} dev ${DEVICE_IP_IFACE} table 20 | |
} | |
function clear_routing_table() { | |
ip rule del lookup 20 | |
ip route del default via ${IP4_GATEWAY} dev ${DEVICE_IP_IFACE} table 20 | |
} | |
if [ "$IF" == "eth1" ] | |
then | |
case "$2" in | |
up) | |
logger -s "NM Script up triggered" | |
update_routing_table | |
;; | |
down) | |
logger -s "NM Script down triggered" | |
clear_routing_table | |
;; | |
*) | |
;; | |
esac | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment