Chris Stryczynski

Software Developer / Consultant

Nixos container example with private network + ipv4 + ipv6

Posted on: 17/11/2019

As a basic example to give a container a private network + ipv4 + ipv6 connectivity.

  containers.example = {
    privateNetwork = true;
    autoStart = true;
    hostAddress = "192.168.140.10";
    localAddress = "192.168.140.11";
    hostAddress6 = "fc00::1";
    localAddress6 = "fc00::2";

    config = { config, pkgs, ... }:
    {
      networking.firewall.enable = false;
      networking.useHostResolvConf = true;
      networking.firewall.rejectPackets = true;
      networking.firewall.allowedTCPPorts =  [ 80 443 ];
    };
  };
    networking.nat.enable = true;
    networking.nat.internalInterfaces = ["ve-+"];
    networking.nat.externalInterface = "wlp2s0f0u8";

Also NAT does not work by default for me so I have to run the below manually:

sudo iptables --flush
sudo iptables --table nat --flush
sudo iptables -t nat -A POSTROUTING -o wlp2s0f0u7 -j MASQUERADE
Comments

No comments, yet!

Submit a comment