Files
proxmox/scripts/unifi/change-ip-to-vlan11.sh
defiQUG b3a8fe4496
Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
chore: sync all changes to Gitea
- Config, docs, scripts, and backup manifests
- Submodule refs unchanged (m = modified content in submodules)

Made-with: Cursor
2026-03-02 11:37:34 -08:00

146 lines
4.2 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# Load IP configuration
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
source "${PROJECT_ROOT}/config/ip-addresses.conf" 2>/dev/null || true
# Change dev machine IP to ${IP_SERVICE_4:-${IP_SERVICE_4:-192.168.11.4}} for access to ml110
# Usage: sudo ./scripts/unifi/change-ip-to-vlan11.sh
set -e
INTERFACE="eth0"
NEW_IP="${IP_SERVICE_4:-${IP_SERVICE_4:-192.168.11.4}}"
NEW_GATEWAY="${NETWORK_GATEWAY:-192.168.11.1}"
NEW_NETMASK="255.255.255.0"
NEW_DNS="${NETWORK_GATEWAY:-192.168.11.1}"
echo "🔧 Changing IP address to $NEW_IP for interface $INTERFACE"
echo ""
# Check if running as root
if [ "$EUID" -ne 0 ]; then
echo "❌ Please run as root (use sudo)"
exit 1
fi
# Detect network manager
if command -v nmcli >/dev/null 2>&1; then
echo "✅ Using NetworkManager (nmcli)"
# Get active connection name
CONN_NAME=$(nmcli -t -f NAME connection show --active | grep -i "$INTERFACE" | head -1)
if [ -z "$CONN_NAME" ]; then
CONN_NAME=$(nmcli -t -f NAME,DEVICE connection show | grep "$INTERFACE" | cut -d: -f1 | head -1)
fi
if [ -z "$CONN_NAME" ]; then
echo "❌ Could not find connection for $INTERFACE"
echo "Available connections:"
nmcli connection show
exit 1
fi
echo "📋 Found connection: $CONN_NAME"
echo ""
echo "🔄 Changing IP configuration..."
# Change IP settings
nmcli connection modify "$CONN_NAME" ipv4.addresses "$NEW_IP/24"
nmcli connection modify "$CONN_NAME" ipv4.gateway "$NEW_GATEWAY"
nmcli connection modify "$CONN_NAME" ipv4.dns "$NEW_DNS 8.8.8.8"
nmcli connection modify "$CONN_NAME" ipv4.method manual
echo "✅ Configuration updated"
echo "🔄 Restarting connection..."
nmcli connection down "$CONN_NAME"
sleep 2
nmcli connection up "$CONN_NAME"
echo "✅ Connection restarted"
elif [ -d /etc/netplan ]; then
echo "✅ Using netplan"
# Find netplan config file
NETPLAN_FILE=$(ls /etc/netplan/*.yaml 2>/dev/null | head -1)
if [ -z "$NETPLAN_FILE" ]; then
echo "❌ No netplan config file found"
exit 1
fi
echo "📋 Found netplan config: $NETPLAN_FILE"
echo ""
echo "⚠️ Manual edit required for netplan"
echo "Please edit $NETPLAN_FILE and change:"
echo " addresses: [$NEW_IP/24]"
echo " gateway4: $NEW_GATEWAY"
echo " nameservers:"
echo " addresses: [$NEW_DNS, 8.8.8.8]"
echo ""
echo "Then run: sudo netplan apply"
exit 0
elif [ -f /etc/network/interfaces ]; then
echo "✅ Using /etc/network/interfaces"
echo "⚠️ Manual edit required"
echo "Please edit /etc/network/interfaces and change:"
echo " address $NEW_IP"
echo " netmask $NEW_NETMASK"
echo " gateway $NEW_GATEWAY"
echo ""
echo "Then run: sudo systemctl restart networking"
exit 0
else
echo "❌ Could not detect network manager"
echo "Please configure manually:"
echo " IP: $NEW_IP/24"
echo " Gateway: $NEW_GATEWAY"
echo " DNS: $NEW_DNS"
exit 1
fi
# Wait a moment for network to stabilize
sleep 3
# Verify new IP
echo ""
echo "🔍 Verifying new IP configuration..."
NEW_IP_CHECK=$(ip addr show $INTERFACE | grep -oP 'inet \K[\d.]+' | head -1)
if [ "$NEW_IP_CHECK" = "$NEW_IP" ]; then
echo "✅ IP address successfully changed to $NEW_IP"
else
echo "⚠️ IP address check: $NEW_IP_CHECK (expected $NEW_IP)"
fi
# Test gateway
echo ""
echo "🧪 Testing gateway connectivity..."
if ping -c 1 -W 2 $NEW_GATEWAY >/dev/null 2>&1; then
echo "✅ Gateway $NEW_GATEWAY is reachable"
else
echo "⚠️ Gateway $NEW_GATEWAY is not reachable"
fi
# Test ml110
echo ""
echo "🧪 Testing ml110 connectivity..."
if ping -c 1 -W 2 ${PROXMOX_HOST_ML110:-192.168.11.10} >/dev/null 2>&1; then
echo "✅ ml110 (${PROXMOX_HOST_ML110:-192.168.11.10}) is reachable!"
else
echo "⚠️ ml110 (${PROXMOX_HOST_ML110:-192.168.11.10}) is not reachable (may need firewall config)"
fi
echo ""
echo "✅ IP change complete!"
echo ""
echo "📋 Current configuration:"
ip addr show $INTERFACE | grep "inet "
ip route show | grep default