diff options
Diffstat (limited to 'create.sh')
| -rw-r--r-- | create.sh | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/create.sh b/create.sh new file mode 100644 index 0000000..eac4147 --- /dev/null +++ b/create.sh @@ -0,0 +1,34 @@ +#!/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!" |
