#!/usr/bin/env bash echo "🚀 LXD New Container Setup Script" read -p "📝 Enter the new container name: " name read -p "🌐 Enter static IP to assign (e.g. 10.196.1.70): " ip echo "🔧 Launching new Ubuntu 22.04 container: $name" lxc launch ubuntu:22.04 "$name" echo "🔧 Overriding eth0 device to allow static IP assignment..." lxc config device override "$name" eth0 echo "🔧 Assigning static IP: $ip" lxc config device set "$name" eth0 ipv4.address "$ip" echo "🔄 Restarting $name to apply new IP..." lxc restart "$name" echo "🛠️ Validating IP and hostname inside the container..." actual_ip=$(lxc exec "$name" -- hostname -I | awk '{print $1}') hostname_inside=$(lxc exec "$name" -- hostname) echo "✅ Container '$name' has been assigned IP: $actual_ip" echo "🌐 Container DNS hostname: $hostname_inside" ping -c 2 "$ip" > /dev/null 2>&1 if [[ $? -eq 0 ]]; then echo "✅ Ping to $ip successful!" else echo "❌ Ping to $ip failed!" fi echo "🎉 Container setup complete!"