jailmaker/docs/network.md

5.3 KiB

Jailmaker Docs

Host Networking

Notes on the default host networking are in the main README.md file.

Bridge Networking

As an alternative to the default host networking mode, you may want to connect to a bridge interface instead and let the jail obtain its IP address via DHCP.

TrueNAS Scale: Setting up a Static IP and Network Bridge // Access NAS host from VM - YouTube Video
Watch on YouTube

The above YouTube video may be helpful when setting up the bridge interface.

Bridge Flaws

This type of interface takes much longer to set up both in complexity and wait time (you may have to be patient for up to 60 seconds after the jail started for networking to work, assigning the IP address via DHCP is somehow slow). Furthermore, if the configuration is not correct it can render your TrueNAS inaccessible via ssh or the web interface, necessitating a reset using a keyboard and monitor plugged into the TrueNAS server and use /etc/netcli to reset the networking interface.

Bridge Setup

Add the --network-bridge=br1 --resolv-conf=bind-host systemd-nspawn flag when asked for Additional flags during jail creation, or set it post-creation by editing the SYSTEMD_NSPAWN_USER_ARGS variable inside the config file.

The TrueNAS host and the jail will be able to communicate with each other as if the jail was just another device on the LAN. It will use the same DNS servers as the TrueNAS host because the --resolv-conf=bind-host option bind mounts the /etc/resolv.conf file from the host inside the jail. If you want to use the DNS servers advertised via DHCP, then check DNS via DHCP.

Bridge Static IP

To configure a static IP with our bridge interface, we need to edit the /etc/systemd/network/80-container-host0.network file. Change the [Network] section to look like this:

[Network]
DHCP=false
Address=192.168.0.12/24
Gateway=192.168.0.1
LinkLocalAddressing=no
LLDP=yes
EmitLLDP=customer-bridge

Then restart the systemd-networkd service and check your network configuration.

systemctl restart systemd-networkd
systemctl status systemd-networkd
ifconfig

Macvlan Networking

Some services require the use of port 80 or 443, or would benefit from a separate IP. For these situations the easiest network configuration is the MAC VLAN configuration. This creates a virtual interface with its own separate randomly generated MAC address and IP. The default config uses DHCP by default, but can easily be set to a Static IP.

Macvlan Flaws

Any services in the jail cannot communicate with the direct host (TrueNAS). The jail can communicate with any other jail or device on the network, besides TrueNAS or VMs hosted on TrueNAS. This may be a benefit (security) or disadvantage (no communication) depending on your service. If that's required it would be better to use Bridge Networking.

Macvlan Setup

Add the following argument to the "additional flags" prompt of jail creation or the "systemd_nspawn_user_arguments" line of the jail config file: --network-macvlan=eno1 --resolv-conf=bind-host. Where eno1 is the name of your physical network interface.

Macvlan Static IP

To set a Static IP you need to disable DHCP in the macvlan config file /etc/systemd/network/mv-dhcp.network. You can do this with a network client like WinSCP by navigating into the jail's filesystem then the path above, or by using a text editing program like nano by running nano /etc/systemd/network/mv-dhcp.network in the jail's shell.

The DHCP in [Network] needs to be set to false, an Address (static IP) needs to be added, a Gateway needs to be defined (e.g your router such as 192.168.0.1) and the entire DHCP section needs to be removed.

An example static IP configuration is as follows:

[Match]
Virtualization=container
Name=mv-*

[Network]
DHCP=false
Address=192.168.X.XXX/24
Gateway=192.168.X.X

Then restart the network interface inside the jail systemctl restart systemd-networkd or restart the jail by running jlmkr stop JAILNAME && jlmkr start JAILNAME from the TrueNAS shell. Use ifconfig to verify the interface is up and has the correct IP.

DNS via DHCP

If you're not using host networking, and you're not using the --resolv-conf= in case of bridge/macvlan networking, then you have to configure the DNS servers to use.

To get DNS servers via DHCP install and enable resolvconf.

# Only run this inside the jail!

# Temporarily fix DNS resolution,
# otherwise we can't install packages
echo 'nameserver 8.8.8.8' > /etc/resolv.conf
# On debian based distro
apt update && apt -y install resolvconf

References