Improving multi-client netbird on Linux


The issue: Multiple accounts because of private VPN and work VPN. The solution?

First, we need a systemd-unit override for the existing [email protected].

# systemctl edit [email protected]

### Now, paste the following:
[Service]
ExecStart =
ExecStart = /usr/bin/netbird service run --config /etc/netbird/%i.json --daemon-addr unix:///var/run/netbird-%i.sock --log-file console $NETBIRD_CLIENT_ARGS

With this, it will create a different socket for every config. After that, we need a little helper script that will register a alias for each netbird config. It looks like this:

# get all available configs from /etc/netbird/*.json directory

# user can override the config folder by setting NETBIRD_CONFIG_FOLDER
CONFIG_FOLDER=${NETBIRD_CONFIG_FOLDER:-/etc/netbird}

# check if the config folder exists
if [ ! -d "$CONFIG_FOLDER" ]; then
  echo "Warning: Config folder $CONFIG_FOLDER does not exist, exiting early..." >&2
  exit 0
fi

for file in "$CONFIG_FOLDER"/*.json; do
  if [ -f "$file" ]; then
    # get name of the file without the extension
    filename=$(basename "$file" .json)
    command_name="netbird-$filename"
    alias $command_name="/usr/bin/netbird --daemon-addr unix:///var/run/netbird-$filename.sock"
  fi
done

alias "netbird"="echo 'You are using a multi-config setup. Please use the config name as a command, e.g. netbird-<config_name>.'"

If you are under archlinux, you can just install this file from the AUR!

Put this into some file and source it from your bashrc. One example would be to put it into /etc/bash.netbird and then sourcing it using source /etc/bash.netbird in your /etc/bash.bash_rc.

This should register all the commands you need for your daily work!


Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert