wireguard-go Documentation

repository·master·Indexed 26 days ago

https://github.com/wireguard/wireguard-go

A userspace Go implementation of the WireGuard protocol compatible with Linux, macOS, Windows, FreeBSD, and OpenBSD. This documentation covers CLI usage for creating network interfaces, foreground and background execution, environment variable configuration (such as LOG_LEVEL and WG_TUN_FD), and building the project from source.

Tokens
682
Snippets
5
Records
8
Agent score
38%

What's inside wireguard-go

  1. Run wireguard-go as a background interface

    master

    To create a WireGuard interface and fork the process into the background, run the command followed by the desired interface name (e.g., wg0).

    Once running, you can configure the interface using standard tools like wg(8), ip(8), or ifconfig(8). To remove the interface, use ip link del <interface_name>. If your system does not support direct interface removal, you can shut down wireguard-go by removing its control socket: rm -f /var/run/wireguard/<interface_name>.sock.

    $ wireguard-go wg0
  2. Configure wireguard-go via environment variables

    master

    You can control the behavior of wireguard-go using the following environment variables:

    VariableDescription
    WG_TUN_FDThe file descriptor of an existing TUN device. If set, wireguard-go will use this instead of creating a new one.
    WG_UAPI_FDThe file descriptor of an existing UAPI socket. If set, wireguard-go will use this instead of opening a new one.
    WG_PROCESS_FOREGROUNDSet to 1 to force the process to run in the foreground (prevents daemonization).
    LOG_LEVELSets the logging verbosity. Supported values: verbose, debug, error, silent. (Defaults to error)
  3. Run wireguard-go via CLI

    master

    The wireguard-go binary can be executed as a userspace WireGuard daemon. By default, it daemonizes itself unless the foreground flag is provided. You must specify an interface name.

    Usage: wireguard-go [-f|--foreground] INTERFACE-NAME

    Arguments:

    • -f, --foreground: Run the process in the foreground. If not provided, the process will daemonize.
    • INTERFACE-NAME: The name of the network interface to create.

    Version Check: Use --version to print the current version and build information.