Skip to content

Instantly share code, notes, and snippets.

@dcode
Last active May 11, 2023 03:11
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcode/bbf990ea781bed1e42d39e2351b6c432 to your computer and use it in GitHub Desktop.
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.
#!/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