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.

32 lines
1.7 KiB

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