This is a simple script that allows the easy creation of LXC/LXD containers for immediate use. This includes:
- Assignment of public IPv6
- Assignment of Hostnames:
- Hybrid Hostname (IPv4 of host, IPv6 of container) for Apache2 ProxyPass (DIY)
- IPv6 Only Hostname
- Assignment of random root password
- Enabling of SSH for remote access
It is designed with the following in mind:
- You are (or will be) using LXC/LXD for containers
- You are using Netplan to manage your public IPv6 addresses and have set it up for static IPv6 addresses
- You are (or will be) using BIND for DNS records for hostnames for the container (There is an example config for BIND further down)
- Your LXC network bridge is named
lxcbr0
sudo apt install python3-pip iptables-persistent
sudo pip3 install setuptools wheel
sudo pip3 install -U pyyaml pylxd
If you do not have an existing BIND config, it is recommend you do the following: Replace server-name, public-ipv4 and public-ipv6 with the correlating information
Bash:
apt install bind9
mkdir /etc/bind/zones
cp /etc/bind/db.local /etc/bind/zones/db.server-name
Edit /etc/bind/named.conf.options:
listen-on-v6 { public-ipv6; };
listen-on { public-ipv4; };
allow-transfer { none; };
forwarders { 8.8.8.8; 8.8.4.4 };
Edit /etc/bind/named.conf.local:
zone "server-name" {
type master;
file "/etc/bind/zones/db.server-name";
};
Edit /etc/bind/zones/db.server-name:
;
; BIND data file for server-name
;
$TTL 604800
@ IN SOA ns1.server-name. admin.server-name. (
3 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
IN NS ns1.server-name.
ns1.server-name. IN A public-ipv4
ns1.server-name. IN AAAA public-ipv6
server-name. IN A public-ipv4
server-name. IN AAAA public-ipv6
txtrec.server-name. 300 IN TXT TestConf ; Test Configuration
Bash:
systemctl restart bind9
dig txtrec.server-name @public-ipv4 txt +short ; Should output "TestConf" if BIND is working
Your DNS Provider:
A ns1.server-name public-ipv4
NS server-name ns1.server-name
Bash:
dig txtrec.server-name txt +short ; Should output "TestConf" if your configuration is working
To configure the script, rename sampleconfig.yaml
to config.yaml
and replace the values.
The default image for the creation of LXD/LXC containers (default is "ubuntu:18.04")
Example: "ubuntu:18.04"
Your fully qualified domain name (for DNS records)
Example: "example.com"
Your public IPv4 address of your server
Example: "93.184.216.34"
Your public IPv6 address of your server
Example: "2001:0DB8:DEAD:BEEF:1337:3114:ab13:3152"
Your IPv6 /64 prefix with trailing colon
Example: "2001:0DB8:DEAD:BEEF:"
A prefix for between your public prefix and container number
Example: "1337:0420:0069:"
in
"2001:0DB8:DEAD:BEEF:
1337:0420:0069:
0001"
The TTL for your DNS records (default is 3600)
Example: 3600
The location of your BIND zone
Example: "/etc/bind/zones/db.example.com"