LXC Container Internet Access

16 January 2024 · 1 min read · Linux, LXC, Container, network

Contents

I spent a long time trying to get internet access working inside an LXC container. It turned out the iptables rules were poorly configured. The following commands flush all rules and reset the policies to a permissive state, then reload the LXC daemon:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
for ipt in iptables iptables-legacy ip6tables ip6tables-legacy; do
  $ipt --flush
  $ipt --flush -t nat
  $ipt --delete-chain
  $ipt --delete-chain -t nat
  $ipt -P FORWARD ACCEPT
  $ipt -P INPUT ACCEPT
  $ipt -P OUTPUT ACCEPT
done
systemctl reload snap.lxd.daemon