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

9 months ago
  1. #!/bin/bash
  2. if [[ "$2" == "up" ]]; then
  3. ACTIVE_CONNECTION=$(nmcli -g NAME connection show --active | head -n1)
  4. ACTIVE_DEVICE=$(nmcli -g DEVICE connection show --active | head -n1)
  5. BRIDGE=$(ip addr show lxdbr0 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1)
  6. GATEWAY=$(ip route | head -n1 | grep default | cut -d' ' -f3)
  7. logger -t NetworkManager:Dispatcher -p info "on $ACTIVE_DEVICE:$ACTIVE_CONNECTION up , change resolver to $BRIDGE,$GATEWAY"
  8. nmcli device modify "$ACTIVE_DEVICE" ipv4.dns "$BRIDGE,$GATEWAY"
  9. if ! grep nameserver /etc/resolv.conf | head -n1 | grep -q "$BRIDGE"; then
  10. # sometimes, nmcli generates wrong order for namespace in resolv.conf, therefore forcing connection settings must be applied!
  11. logger -t NetworkManager:Dispatcher -p info "on $ACTIVE_DEVICE:$ACTIVE_CONNECTION nameservers wrong order detected, therefore forcing connection settings must be applied"
  12. nmcli connection modify "$ACTIVE_CONNECTION" ipv4.ignore-auto-dns yes
  13. nmcli connection modify "$ACTIVE_CONNECTION" ipv4.dns "$BRIDGE,$GATEWAY"
  14. logger -t NetworkManager:Dispatcher -p info "on $ACTIVE_DEVICE:$ACTIVE_CONNECTION nameservers wrong order detected, connection reloaded now!"
  15. nmcli connection up "$ACTIVE_CONNECTION"
  16. else
  17. logger -t NetworkManager:Dispatcher -p info "on $ACTIVE_DEVICE:$ACTIVE_CONNECTION nameservers look fine"
  18. fi
  19. else
  20. if [[ "$2" == "connectivity-change" ]]; then
  21. ACTIVE_DEVICE=$(nmcli -g DEVICE connection show --active | head -n1)
  22. logger -t NetworkManager:Dispatcher -p info "on $ACTIVE_DEVICE connectivity-change detected"
  23. fi
  24. fi