diff --git a/misc/core.func b/misc/core.func index ff20efb9b..d6d4555cc 100644 --- a/misc/core.func +++ b/misc/core.func @@ -898,7 +898,14 @@ function get_lxc_ip() { get_current_ip() { local ip - # Try hostname -I first (most reliable for LXC containers) + # Try direct interface lookup for eth0 FIRST (most reliable for LXC) + ip=$(ip -4 addr show eth0 2>/dev/null | awk '/inet / {print $2}' | cut -d/ -f1 | head -n1) + if [[ -n "$ip" && "$ip" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "$ip" + return 0 + fi + + # Fallback: Try hostname -I if command -v hostname >/dev/null 2>&1; then ip=$(hostname -I 2>/dev/null | awk '{print $1}') if [[ -n "$ip" && "$ip" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then @@ -907,13 +914,6 @@ function get_lxc_ip() { fi fi - # Fallback: Try direct interface lookup for eth0 - ip=$(ip -4 addr show eth0 2>/dev/null | awk '/inet / {print $2}' | cut -d/ -f1 | head -n1) - if [[ -n "$ip" ]]; then - echo "$ip" - return 0 - fi - # Last resort: Use routing table local targets=("8.8.8.8" "1.1.1.1" "default") for target in "${targets[@]}"; do