<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.alpinelinux.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Mb720</id>
	<title>Alpine Linux - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.alpinelinux.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Mb720"/>
	<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/wiki/Special:Contributions/Mb720"/>
	<updated>2026-04-26T19:34:31Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.40.0</generator>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Configure_a_Wireguard_interface_(wg)&amp;diff=20131</id>
		<title>Configure a Wireguard interface (wg)</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Configure_a_Wireguard_interface_(wg)&amp;diff=20131"/>
		<updated>2021-09-06T17:59:53Z</updated>

		<summary type="html">&lt;p&gt;Mb720: fix link syntax&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;WireGuard is a very promising VPN technology available in the community repository since Alpine 3.10.&lt;br /&gt;
&lt;br /&gt;
There are several ways to install and configure an interface.&lt;br /&gt;
&lt;br /&gt;
In order to load the WireGuard kernel module, you need a compatible kernel:&lt;br /&gt;
&lt;br /&gt;
* linux-lts&lt;br /&gt;
* linux-virt&lt;br /&gt;
&lt;br /&gt;
== Bringing up an interface using wg-tools ==&lt;br /&gt;
&lt;br /&gt;
The most straightforward method, and the one recommended in WireGuard documentation, is to use &amp;lt;code&amp;gt;wg-quick&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Install wireguard-tools&lt;br /&gt;
&lt;br /&gt;
 apk add wireguard-tools&lt;br /&gt;
&lt;br /&gt;
Then load the module&lt;br /&gt;
&lt;br /&gt;
 modprobe wireguard&lt;br /&gt;
&lt;br /&gt;
Add it to &amp;lt;code&amp;gt;/etc/modules&amp;lt;/code&amp;gt; to automatically load it on boot.&lt;br /&gt;
&lt;br /&gt;
Then, we need to create a private and a public key:&lt;br /&gt;
&lt;br /&gt;
 wg genkey | tee privatekey | wg pubkey &amp;gt; publickey&lt;br /&gt;
&lt;br /&gt;
Then, we create a new config file &amp;lt;code&amp;gt;/etc/wireguard/wg0.conf&amp;lt;/code&amp;gt; using those keys:&lt;br /&gt;
&lt;br /&gt;
 [Interface]&lt;br /&gt;
 Address = 10.123.0.1/24&lt;br /&gt;
 ListenPort = 45340&lt;br /&gt;
 PrivateKey = SG1nXk2+kAAKnMkL5aX3NSFPaGjf9SQI/wWwFj9l9U4= # the key from the previously generated privatekey file&lt;br /&gt;
 PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE;iptables -A FORWARD -o %i -j ACCEPT&lt;br /&gt;
 PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE;iptables -D FORWARD -o %i -j ACCEPT&lt;br /&gt;
&lt;br /&gt;
The PostUp and PostDown steps are there to ensure the interface wg0 will accept and forward traffic to eth0. The postrouting and forward to %i is not required, but it will enable &amp;quot;VPN mode&amp;quot; where users can access the internet via this server if desired. Reference [https://github.com/pirate/wireguard-docs#user-content-config-reference this WireGuard documentation] for information on adding peers to the config file.&lt;br /&gt;
&lt;br /&gt;
To bring up the new interface we use:&lt;br /&gt;
&lt;br /&gt;
 wg-quick up wg0&lt;br /&gt;
&lt;br /&gt;
To take it down, we can use &amp;lt;code&amp;gt;wg-quick down wg0&amp;lt;/code&amp;gt; which will clean up the interface and remove the iptables rules.&lt;br /&gt;
Note: If running in a Docker container, you will need to run with &amp;lt;code&amp;gt;--cap-add=NET_ADMIN&amp;lt;/code&amp;gt; to modify your interfaces.&lt;br /&gt;
&lt;br /&gt;
== Bringing up an interface using ifupdown-ng ==&lt;br /&gt;
&lt;br /&gt;
The official documents from WireGuard show examples of how to set up an interface with the use of wg-quick.&lt;br /&gt;
In this how-to, we are not going to use that utility. We&#039;ll use the plain wg command and [https://github.com/ifupdown-ng/ifupdown-ng/blob/master/doc/interfaces-wireguard.scd ifupdown-ng].&lt;br /&gt;
&lt;br /&gt;
 apk add wireguard-tools-wg&lt;br /&gt;
&lt;br /&gt;
Now that all the tools are installed, you can setup the interface.&lt;br /&gt;
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.8 manual page of wg].&lt;br /&gt;
&lt;br /&gt;
After you have finished setting up your wgX interface config, you can add it to your &amp;lt;code&amp;gt;/etc/network/interfaces&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 auto wg0&lt;br /&gt;
 iface wg0 inet static&lt;br /&gt;
        requires eth0&lt;br /&gt;
        use wireguard&lt;br /&gt;
        address 192.168.42.1&lt;br /&gt;
&lt;br /&gt;
This config will automatically:&lt;br /&gt;
&lt;br /&gt;
* bring the WireGuard interface up after the eth0 interface&lt;br /&gt;
* assign a config to this interface (which you have previously created)&lt;br /&gt;
* setup the interface address and netmask&lt;br /&gt;
* add the route once the interface is up&lt;br /&gt;
* remove the interface when it goes down&lt;br /&gt;
&lt;br /&gt;
To start and stop the interface, you execute:&lt;br /&gt;
&lt;br /&gt;
 ifup wg0&lt;br /&gt;
 ifdown wg0&lt;br /&gt;
&lt;br /&gt;
If your interface config is not stored under &amp;lt;code&amp;gt;/etc/wireguard&amp;lt;/code&amp;gt; you need to specify a &amp;lt;code&amp;gt;wireguard-config-path&amp;lt;/code&amp;gt; as well.&lt;br /&gt;
&lt;br /&gt;
== Running with modloop ==&lt;br /&gt;
If you are running from a RAM disk, you can&#039;t modify the modloop.&lt;br /&gt;
&lt;br /&gt;
You can get around it by unpacking the modloop, mounting the unpacked modules folder, then installing WireGuard.&lt;br /&gt;
&lt;br /&gt;
 #!/bin/sh&lt;br /&gt;
 apk add squashfs-tools # install squashfs tools to unpack modloop&lt;br /&gt;
 unsquashfs -d /root/squash /lib/modloop-lts # unpack modloop to root dir&lt;br /&gt;
 umount /.modloop # unmount existing modloop&lt;br /&gt;
 mount /root/squash/ /.modloop/ # mount unpacked modloop&lt;br /&gt;
 apk del wireguard-lts # uninstall previous WireGuard install&lt;br /&gt;
 apk add wireguard-lts&lt;br /&gt;
 apk add wireguard-tools&lt;br /&gt;
&lt;br /&gt;
You can repack the squash filesystem or put this script in the /etc/local.d/ path so it runs at boot-up.&lt;br /&gt;
&lt;br /&gt;
[[Category:Networking]]&lt;/div&gt;</summary>
		<author><name>Mb720</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Configure_a_Wireguard_interface_(wg)&amp;diff=20130</id>
		<title>Configure a Wireguard interface (wg)</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Configure_a_Wireguard_interface_(wg)&amp;diff=20130"/>
		<updated>2021-09-06T17:58:14Z</updated>

		<summary type="html">&lt;p&gt;Mb720: fix spelling, add link to documentation&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;WireGuard is a very promising VPN technology available in the community repository since Alpine 3.10.&lt;br /&gt;
&lt;br /&gt;
There are several ways to install and configure an interface.&lt;br /&gt;
&lt;br /&gt;
In order to load the WireGuard kernel module, you need a compatible kernel:&lt;br /&gt;
&lt;br /&gt;
* linux-lts&lt;br /&gt;
* linux-virt&lt;br /&gt;
&lt;br /&gt;
== Bringing up an interface using wg-tools ==&lt;br /&gt;
&lt;br /&gt;
The most straightforward method, and the one recommended in WireGuard documentation, is to use &amp;lt;code&amp;gt;wg-quick&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Install wireguard-tools&lt;br /&gt;
&lt;br /&gt;
 apk add wireguard-tools&lt;br /&gt;
&lt;br /&gt;
Then load the module&lt;br /&gt;
&lt;br /&gt;
 modprobe wireguard&lt;br /&gt;
&lt;br /&gt;
Add it to &amp;lt;code&amp;gt;/etc/modules&amp;lt;/code&amp;gt; to automatically load it on boot.&lt;br /&gt;
&lt;br /&gt;
Then, we need to create a private and a public key:&lt;br /&gt;
&lt;br /&gt;
 wg genkey | tee privatekey | wg pubkey &amp;gt; publickey&lt;br /&gt;
&lt;br /&gt;
Then, we create a new config file &amp;lt;code&amp;gt;/etc/wireguard/wg0.conf&amp;lt;/code&amp;gt; using those keys:&lt;br /&gt;
&lt;br /&gt;
 [Interface]&lt;br /&gt;
 Address = 10.123.0.1/24&lt;br /&gt;
 ListenPort = 45340&lt;br /&gt;
 PrivateKey = SG1nXk2+kAAKnMkL5aX3NSFPaGjf9SQI/wWwFj9l9U4= # the key from the previously generated privatekey file&lt;br /&gt;
 PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE;iptables -A FORWARD -o %i -j ACCEPT&lt;br /&gt;
 PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE;iptables -D FORWARD -o %i -j ACCEPT&lt;br /&gt;
&lt;br /&gt;
The PostUp and PostDown steps are there to ensure the interface wg0 will accept and forward traffic to eth0. The postrouting and forward to %i is not required, but it will enable &amp;quot;VPN mode&amp;quot; where users can access the internet via this server if desired. Reference [this WireGuard documentation](https://github.com/pirate/wireguard-docs#user-content-config-reference) for information on adding peers to the config file.&lt;br /&gt;
&lt;br /&gt;
To bring up the new interface we use:&lt;br /&gt;
&lt;br /&gt;
 wg-quick up wg0&lt;br /&gt;
&lt;br /&gt;
To take it down, we can use &amp;lt;code&amp;gt;wg-quick down wg0&amp;lt;/code&amp;gt; which will clean up the interface and remove the iptables rules.&lt;br /&gt;
Note: If running in a Docker container, you will need to run with &amp;lt;code&amp;gt;--cap-add=NET_ADMIN&amp;lt;/code&amp;gt; to modify your interfaces.&lt;br /&gt;
&lt;br /&gt;
== Bringing up an interface using ifupdown-ng ==&lt;br /&gt;
&lt;br /&gt;
The official documents from WireGuard show examples of how to set up an interface with the use of wg-quick.&lt;br /&gt;
In this how-to, we are not going to use that utility. We&#039;ll use the plain wg command and [https://github.com/ifupdown-ng/ifupdown-ng/blob/master/doc/interfaces-wireguard.scd ifupdown-ng].&lt;br /&gt;
&lt;br /&gt;
 apk add wireguard-tools-wg&lt;br /&gt;
&lt;br /&gt;
Now that all the tools are installed, you can setup the interface.&lt;br /&gt;
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.8 manual page of wg].&lt;br /&gt;
&lt;br /&gt;
After you have finished setting up your wgX interface config, you can add it to your &amp;lt;code&amp;gt;/etc/network/interfaces&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 auto wg0&lt;br /&gt;
 iface wg0 inet static&lt;br /&gt;
        requires eth0&lt;br /&gt;
        use wireguard&lt;br /&gt;
        address 192.168.42.1&lt;br /&gt;
&lt;br /&gt;
This config will automatically:&lt;br /&gt;
&lt;br /&gt;
* bring the WireGuard interface up after the eth0 interface&lt;br /&gt;
* assign a config to this interface (which you have previously created)&lt;br /&gt;
* setup the interface address and netmask&lt;br /&gt;
* add the route once the interface is up&lt;br /&gt;
* remove the interface when it goes down&lt;br /&gt;
&lt;br /&gt;
To start and stop the interface, you execute:&lt;br /&gt;
&lt;br /&gt;
 ifup wg0&lt;br /&gt;
 ifdown wg0&lt;br /&gt;
&lt;br /&gt;
If your interface config is not stored under &amp;lt;code&amp;gt;/etc/wireguard&amp;lt;/code&amp;gt; you need to specify a &amp;lt;code&amp;gt;wireguard-config-path&amp;lt;/code&amp;gt; as well.&lt;br /&gt;
&lt;br /&gt;
== Running with modloop ==&lt;br /&gt;
If you are running from a RAM disk, you can&#039;t modify the modloop.&lt;br /&gt;
&lt;br /&gt;
You can get around it by unpacking the modloop, mounting the unpacked modules folder, then installing WireGuard.&lt;br /&gt;
&lt;br /&gt;
 #!/bin/sh&lt;br /&gt;
 apk add squashfs-tools # install squashfs tools to unpack modloop&lt;br /&gt;
 unsquashfs -d /root/squash /lib/modloop-lts # unpack modloop to root dir&lt;br /&gt;
 umount /.modloop # unmount existing modloop&lt;br /&gt;
 mount /root/squash/ /.modloop/ # mount unpacked modloop&lt;br /&gt;
 apk del wireguard-lts # uninstall previous WireGuard install&lt;br /&gt;
 apk add wireguard-lts&lt;br /&gt;
 apk add wireguard-tools&lt;br /&gt;
&lt;br /&gt;
You can repack the squash filesystem or put this script in the /etc/local.d/ path so it runs at boot-up.&lt;br /&gt;
&lt;br /&gt;
[[Category:Networking]]&lt;/div&gt;</summary>
		<author><name>Mb720</name></author>
	</entry>
</feed>