wg
The wg
command is a tool provided by WireGuard for managing WireGuard interfaces and peers. It allows you to configure, view, and manage WireGuard settings directly from the command line.
Purpose
The wg
command provides various subcommands and options to create, configure, and monitor WireGuard VPN interfaces and their peers. It allows administrators to perform tasks such as generating keys, setting configuration parameters, and displaying interface status.
Common wg
Commands and Options
wg
Commands and Options1. Key Management
Generate a private key:
Example:
Generate a public key from a private key:
Example:
2. Interface Management
Bring up a WireGuard interface:
Assign an IP address to the interface:
Set the private key for the interface:
Set the listen port for the interface:
Bring up the interface:
3. Peer Management
Add a peer to the interface:
Set persistent keepalive interval:
4. Viewing Configuration and Status
View the current configuration of an interface:
View the full configuration in configuration file format:
View all WireGuard interfaces and their status:
Example Commands
Generating Key Pairs
Generate a private key and derive the public key:
Setting Up an Interface and Adding a Peer
Create the interface:
Assign an IP address:
Set the private key:
Set the listen port:
Add a peer:
Bring up the interface:
Viewing the Status of the Interface
To see the current status and configuration of the interface:
Configuration File Example
Here is an example configuration file /etc/wireguard/wg0.conf
:
To bring up the interface using the configuration file:
To bring it down:
Conclusion
The wg
command is a central tool for managing WireGuard VPN interfaces and peers. By leveraging its capabilities, administrators can efficiently set up, configure, and monitor secure VPN connections. The simplicity and performance of WireGuard, combined with the flexibility of the wg
command, make it an excellent choice for modern VPN setups.
Last updated