Command line

Start an fv tunnel at boot with systemd

Run fv run as a systemd service with the packaged fv@.service unit, or the same unit by hand for a tarball install, and undo the package's forwarding.

Updated December 5, 2026

A systemd unit starts fv run at boot and starts it again if it fails to start. The package ships one for this, fv@.service, with no firewall. The package also ships forestvpn-quantum@.service, which is made for ForestVPN's own exit servers and also starts a firewall: do not use that one. A tarball install has no units, so step 1 gives you the same fv@.service to write by hand.

Before you start

  • A config file that already works, started by hand as in Connect two machines. The examples use /etc/forestvpn/fvq0.conf.
  • Root.
  • Do not enable the exit-server unit. systemctl enable --now forestvpn-quantum@<name> also starts forestvpn-quantum-firewall.service, because the tunnel unit requires it. That service loads /etc/forestvpn/nftables.conf, the rule set of an exit server, and its first rule is flush ruleset, which deletes every firewall rule on the machine, including those of ufw, firewalld, Docker and libvirt. It then drops all new incoming connections except SSH (ports 22 and 21847) on interfaces not named fvpn*, and UDP to port 51820. It forwards only the address pools of ForestVPN's own clients. Stopping that service flushes the rule set again. It is the right thing on an exit server and the wrong thing on any other machine.
  • Do not mask the firewall unit to get round this: a unit that requires a masked unit fails to start.
  • Installing the package turns on IP forwarding. It writes /etc/sysctl.d/99-forestvpn-quantum.conf with net.ipv4.ip_forward = 1, net.ipv6.conf.all.forwarding = 1 and net.ipv4.conf.all.src_valid_mark = 1, and applies them when it installs. This suits a gateway. On a laptop or a plain server, step 4 below undoes the two forwarding settings; skip it on any machine that forwards traffic for others, including a host running Docker, libvirt, LXD or Kubernetes. With IPv6 forwarding on, the kernel stops accepting router advertisements unless accept_ra is 2, which can cost a laptop its IPv6 address.

Steps

  1. Check for the packaged unit: systemctl cat fv@fvq0 prints it, and its first line names /usr/lib/systemd/system/fv@.service (/lib/... on an older system; /etc/systemd/system/fv@.service if you wrote it by hand from an earlier version of this page, and that file keeps working). Then you skip to step 2. If it says No files found: on an older package, upgrade it, run systemctl cat again and skip to step 2; on a tarball install, write the same unit by hand. A drop-in cannot remove the exit-server unit's Requires=, so this is a whole unit of its own.

    Creates /etc/systemd/system/fv@.service (when systemctl cat finds no unit)

    sudo tee /etc/systemd/system/fv@.service >/dev/null <<'UNIT'
    [Unit]
    Description=fv tunnel from your own config (%i)
    Documentation=https://fvpn.net/en/help/fv-service/
    After=network-online.target
    Wants=network-online.target
    ConditionPathExists=/etc/forestvpn/%i.conf
     
    [Service]
    Type=simple
    ExecStart=/usr/bin/fv run --iface %i --config /etc/forestvpn/%i.conf
    Restart=on-failure
    RestartSec=3
    # One UDP socket per port when [Interface] Ports names a pool, doubled for IPv6.
    LimitNOFILE=8192
     
    [Install]
    WantedBy=multi-user.target
    UNIT
  2. Make sure the config file is private, and that your own firewall allows the tunnel's UDP port on a machine that listens.

    Only root can read the keys

    sudo chmod 600 /etc/forestvpn/fvq0.conf
  3. First stop the fv run you started by hand (Ctrl+C). Then load the unit and start the tunnel now and at every boot. The text after the @ is the interface name and the config file name.

    Starts fv run --iface fvq0 --config /etc/forestvpn/fvq0.conf

    sudo systemctl daemon-reload
    sudo systemctl enable --now fv@fvq0
  4. Skip this step on a machine that forwards traffic for others, including any host running Docker, libvirt, LXD or Kubernetes, which need forwarding on. On any other machine that is not a gateway, switch the forwarding settings back off. A file that sorts after the package's wins, and sysctl --system reads them all.

    Creates a later settings file and applies it

    printf 'net.ipv4.ip_forward = 0\nnet.ipv6.conf.all.forwarding = 0\n' | sudo tee /etc/sysctl.d/99-zz-no-forwarding.conf
    sudo sysctl --system

Check it worked

  1. The service is active, and fv show has a peer with a handshake.

    Prints the state of the unit and then of the tunnel

    systemctl status fv@fvq0
    sudo fv show fvq0
  2. After a restart of the machine, run sudo fv show fvq0 again. The interface should be back by itself.

  3. Read the log of the unit when it does not start.

    Everything fv printed since boot

    journalctl -u fv@fvq0 -b

A clean stop, sudo systemctl stop fv@fvq0, ends the process with status 0, and Restart=on-failure does not start it again. It also runs the config's PreDown and PostDown lines, so you need no ExecStopPost= for them (if fv --version prints unknown command, your fv is older and runs neither: upgrade). A start that fails, for example because a host name in Endpoint does not resolve yet at boot, is tried again every 3 seconds. A host name is resolved only once per start.

Before you remove the package, run sudo systemctl disable --now fv@fvq0: removing it does not stop the tunnel.

Back to Help

Back to top

Ask us anything