Disable IPv6 inside an Incus container
1. Manually
These commands can disable it:
# incus shell container_name
sysctl -w net.ipv6.conf.all.disable_ipv6=1
sysctl -w net.ipv6.conf.default.disable_ipv6=1
sysctl -w net.ipv6.conf.lo.disable_ipv6=1
The problem is that this is not permanent, next time that the container restarts we have to disable IPv6 again.
2. Create a script
So, let’s save them in a simple script:
cat <<EOF > /usr/local/bin/disable_ipv6.sh
#!/bin/bash
sysctl -w net.ipv6.conf.all.disable_ipv6=1
sysctl -w net.ipv6.conf.default.disable_ipv6=1
sysctl -w net.ipv6.conf.lo.disable_ipv6=1
EOF
chmod +x /usr/local/bin/disable_ipv6.sh
ip addr
disable_ipv6.sh
ip addr
3. Create a service
Now let’s create also a simple systemd service that runs this script each time that the container starts:
cat <<EOF > /etc/systemd/system/disable_ipv6.service
[Unit]
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/disable_ipv6.sh
[Install]
WantedBy=default.target
EOF
systemctl daemon-reload
systemctl enable disable_ipv6