blob: eac41474e414be7468aef94087418b5f76911c6e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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!"
|