provisioning tool for building opinionated architecture
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

27 lines
1.6 KiB

#!/bin/bash
if [[ "$2" == "up" ]]; then
ACTIVE_CONNECTION=$(nmcli -g NAME connection show --active | head -n1)
ACTIVE_DEVICE=$(nmcli -g DEVICE connection show --active | head -n1)
BRIDGE=$(ip addr show lxdbr0 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1)
GATEWAY=$(ip route | head -n1 | grep default | cut -d' ' -f3)
logger -t NetworkManager:Dispatcher -p info "on $ACTIVE_DEVICE:$ACTIVE_CONNECTION up , change resolver to $BRIDGE,$GATEWAY"
nmcli device modify "$ACTIVE_DEVICE" ipv4.dns "$BRIDGE,$GATEWAY"
if ! grep nameserver /etc/resolv.conf | head -n1 | grep -q "$BRIDGE"; then
# sometimes, nmcli generates wrong order for namespace in resolv.conf, therefore forcing connection settings must be applied!
logger -t NetworkManager:Dispatcher -p info "on $ACTIVE_DEVICE:$ACTIVE_CONNECTION nameservers wrong order detected, therefore forcing connection settings must be applied"
nmcli connection modify "$ACTIVE_CONNECTION" ipv4.ignore-auto-dns yes
nmcli connection modify "$ACTIVE_CONNECTION" ipv4.dns "$BRIDGE,$GATEWAY"
logger -t NetworkManager:Dispatcher -p info "on $ACTIVE_DEVICE:$ACTIVE_CONNECTION nameservers wrong order detected, connection reloaded now!"
nmcli connection up "$ACTIVE_CONNECTION"
else
logger -t NetworkManager:Dispatcher -p info "on $ACTIVE_DEVICE:$ACTIVE_CONNECTION nameservers look fine"
fi
else
if [[ "$2" == "connectivity-change" ]]; then
ACTIVE_DEVICE=$(nmcli -g DEVICE connection show --active | head -n1)
logger -t NetworkManager:Dispatcher -p info "on $ACTIVE_DEVICE connectivity-change detected"
fi
fi