Difference between revisions of "Configure a Wireguard interface (wg)"

From Alpine Linux
Jump to: navigation, search
(Created page with "Wireguard is a very promising VPN technology but is currently (Alpine 3.9.0) not stable and thus only available via the edge/testing repository. To be able to use it you will...")
 
Line 12: Line 12:
  
 
Now that you have all the tools installed we can setup the interface.
 
Now that you have all the tools installed we can setup the interface.
The setup of your interface config is out of the scope of this document, you should consolt the [https://git.zx2c4.com/WireGuard/about/src/tools/man/wg-quick.8 manual page of wg].
+
The setup of your interface config is out of the scope of this document, you should consult the [https://git.zx2c4.com/WireGuard/about/src/tools/man/wg-quick.8 manual page of wg].
 +
 
 +
After you have finished setting up your wgX interface config you can add it to your /etc/networking/interfaces:
 +
 
 +
auto wg0
 +
iface wg0 inet static
 +
        address x.x.x.x
 +
        netmask 255.255.255.0
 +
        pre-up ip link add dev wg0 type wireguard
 +
        pre-up wg setconf wg0 /etc/wireguard/wg0.conf
 +
        post-up ip route add x.x.x.x/24 dev wg0
 +
        post-down ip link delete dev wg0
 +
 
 +
This config will do:
 +
 +
* bring the wireguard interface up
 +
* assign a config to this interface (which you have previously created)
 +
* setup the interface address and netmask
 +
* add the route ones the interface is up
 +
* remove the interface when it goes down

Revision as of 22:39, 4 February 2019

Wireguard is a very promising VPN technology but is currently (Alpine 3.9.0) not stable and thus only available via the edge/testing repository. To be able to use it you will need to install a kernel from the edge/testing repository including all the out of tree modules you like to use. This mean when you are running a stable system you will have to pin the edge/testing repository in your repositories file and install it by:

apk add linux-vanilla (or linux-virt)
apk add wireguard-vanilla (or wireguard-virt)

The official documents from wireguard will show examples of how to setup an inteface with the use of wg-quick. In this howto we are not going to use this utility but are going to use the plain wg command and busybox ifupdown.

apk add wireguard-tools-wg

Now that you have all the tools installed we can setup the interface. The setup of your interface config is out of the scope of this document, you should consult the manual page of wg.

After you have finished setting up your wgX interface config you can add it to your /etc/networking/interfaces:

auto wg0 iface wg0 inet static

       address x.x.x.x
       netmask 255.255.255.0
       pre-up ip link add dev wg0 type wireguard
       pre-up wg setconf wg0 /etc/wireguard/wg0.conf
       post-up ip route add x.x.x.x/24 dev wg0
       post-down ip link delete dev wg0

This config will do:

  • bring the wireguard interface up
  • assign a config to this interface (which you have previously created)
  • setup the interface address and netmask
  • add the route ones the interface is up
  • remove the interface when it goes down