diff --git a/scripts/menus/network_menu.sh b/scripts/menus/network_menu.sh index c6a97c1..12f586c 100644 --- a/scripts/menus/network_menu.sh +++ b/scripts/menus/network_menu.sh @@ -13,7 +13,8 @@ # Advanced network management and troubleshooting tool for Proxmox VE. # Features include interface detection, bridge management, connectivity testing, # network diagnostics, configuration backup/restore, and automated repairs. - +# Special thanks to @Andres_Eduardo_Rojas_Moya for contributing the persistent +# network naming function and for the original idea. # Configuration ============================================ REPO_URL="https://raw.githubusercontent.com/MacRimi/ProxMenux/main" BASE_DIR="/usr/local/share/proxmenux" @@ -727,6 +728,66 @@ guided_configuration_cleanup() { } +# ========================================================== + + + +setup_persistent_network() { + local LINK_DIR="/etc/systemd/network" + local BACKUP_DIR="/etc/systemd/network/backup-$(date +%Y%m%d-%H%M%S)" + + if ! dialog --title "$(translate "Network Interface Setup")" \ + --yesno "$(translate "Create persistent network interface names?")" 8 60; then + return 1 + fi + show_proxmenux_logo + msg_info "$(translate "Setting up persistent network interfaces")" + sleep 2 + # Create directory + mkdir -p "$LINK_DIR" + + # Backup existing files + if ls "$LINK_DIR"/*.link >/dev/null 2>&1; then + mkdir -p "$BACKUP_DIR" + cp "$LINK_DIR"/*.link "$BACKUP_DIR"/ 2>/dev/null || true + fi + + # Process physical interfaces + local count=0 + for iface in $(ls /sys/class/net/ | grep -vE "lo|docker|veth|br-|vmbr|tap|fwpr|fwln|virbr|bond|cilium|zt|wg"); do + if [[ -e "/sys/class/net/$iface/device" ]] || [[ -e "/sys/class/net/$iface/phy80211" ]]; then + local MAC=$(cat /sys/class/net/$iface/address 2>/dev/null) + + if [[ "$MAC" =~ ^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$ ]]; then + local LINK_FILE="$LINK_DIR/10-$iface.link" + + cat > "$LINK_FILE" <&1 1>&3) exit_status=$? exec 3>&-