<?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=Gratuxri</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=Gratuxri"/>
	<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/wiki/Special:Contributions/Gratuxri"/>
	<updated>2026-04-26T23:51:38Z</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=31135</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=31135"/>
		<updated>2025-10-03T18:31:28Z</updated>

		<summary type="html">&lt;p&gt;Gratuxri: add ipv6&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{TOC right}}&lt;br /&gt;
&lt;br /&gt;
[https://en.wikipedia.org/wiki/WireGuard WireGuard] multiple platform vpn solution. WireGuard itself is now integrated into the linux kernel since v5.6. Only the userland configuration tools are required.&lt;br /&gt;
&lt;br /&gt;
== Installation  ==&lt;br /&gt;
&lt;br /&gt;
The most straightforward method to configure WireGuard is to use the tool &amp;lt;code&amp;gt;wg-quick&amp;lt;/code&amp;gt; available in the package {{pkg|wireguard-tools-wg-quick}}. &lt;br /&gt;
&lt;br /&gt;
Install the meta package {{pkg|wireguard-tools}} to install the necessary WireGuard packages  and {{pkg|iptables}} as follows: {{Cmd|# apk add wireguard-tools iptables}}&lt;br /&gt;
&lt;br /&gt;
== Configuration ==&lt;br /&gt;
&lt;br /&gt;
=== Create Server Keys and Interface Config ===&lt;br /&gt;
&lt;br /&gt;
Create a server private and public key: {{Cmd|&amp;lt;nowiki&amp;gt;# wg genkey | tee server.privatekey | wg pubkey &amp;gt; server.publickey&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Then, we create a new config file {{Path|/etc/wireguard/wg0.conf}} using these new keys as follows:{{Cat|/etc/wireguard/wg0.conf|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
[Interface]&lt;br /&gt;
Address = 192.168.2.1/24, fddd::ffff/64&lt;br /&gt;
ListenPort = 45340&lt;br /&gt;
PrivateKey = &amp;lt;server private key value&amp;gt; # 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; ip6tables -A FORWARD -i %i -j ACCEPT; ip6tables -t nat -A POSTROUTING -o eth0 -j MASQUERADE;ip6tables -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; ip6tables -D FORWARD -i %i -j ACCEPT; ip6tables -t nat -D POSTROUTING -o eth0 -j MASQUERADE;ip6tables -D FORWARD -o %i -j ACCEPT&lt;br /&gt;
 &lt;br /&gt;
[Peer]&lt;br /&gt;
PublicKey = &amp;lt;client public key value&amp;gt; # obtained from client device via wireguard connection setup process&lt;br /&gt;
AllowedIPs = 192.168.2.2/32, fddd::1/128&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
The PostUp and PostDown iptable rules forward traffic from the wg0 subnet (192.168.2.1/24) to the lan subnet on interface eth0. Refer to [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;
Bring up the new {{ic|wg0}} interface:{{Cmd|# 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;
&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;
=== Use with network interfaces ===&lt;br /&gt;
&lt;br /&gt;
To enable connecting with Wireguard on boot, open your {{Path|/etc/network/interfaces}} and add this information after your auto other network interfaces as follows:{{Cat|/etc/network/interfaces|&amp;lt;nowiki&amp;gt;...&lt;br /&gt;
auto wg0&lt;br /&gt;
iface wg0 inet static&lt;br /&gt;
pre-up wg-quick up /etc/wireguard/wg0.conf&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
=== Service configuration ===&lt;br /&gt;
&lt;br /&gt;
Since Alpine 3.20, {{pkg|wireguard-tools-openrc}} package provides an OpenRC initd service file. &lt;br /&gt;
&lt;br /&gt;
To use this, install the package:{{Cmd|# apk add wireguard-tools-openrc }}&lt;br /&gt;
&lt;br /&gt;
To use the WireGuard OpenRC script with {{ic|wg-quick.wg0}}, create a symbolic link to it with the configuration name as follows:{{Cmd|# ln -s /etc/init.d/wg-quick /etc/init.d/wg-quick.wg0}}&lt;br /&gt;
&lt;br /&gt;
Add the {{ic|wg-quick.wg0}} service to the default runlevel:{{Cmd|# rc-update add wg-quick.wg0}}&lt;br /&gt;
To start|stop|restart the [[OpenRC]] service:{{Cmd|# rc-service wg-quick.wg0 start}}&lt;br /&gt;
&lt;br /&gt;
=== Enable IP Forwarding ===&lt;br /&gt;
&lt;br /&gt;
With a NAT destination rule in place on your router, you should be able connect to the wireguard instance and access the host. However, if you intend for peers to be able to access external resources (including the internet), you will need to enable ip forwarding.&lt;br /&gt;
&lt;br /&gt;
Edit the file {{Path|/etc/sysctl.conf}} or a &amp;lt;code&amp;gt;.conf&amp;lt;/code&amp;gt; file under {{Path|/etc/sysctl.d/}} folder add the following line as follows:{{Cat|/etc/sysctl.conf|&lt;br /&gt;
net.ipv4.ip_forward {{=}} 1&lt;br /&gt;
net.ipv6.conf.all.forwarding {{=}} 1&lt;br /&gt;
net.ipv6.conf.default.forwarding {{=}} 1}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add the sysctl service to run at boot:{{Cmd|# rc-update add sysctl}}&lt;br /&gt;
&lt;br /&gt;
Then either reboot or run {{ic|# sysctl -p /etc/sysctl.conf}} to reload the settings. To ensure forwarding is turned on, run {{ic|# sysctl -a | grep ip_forward}} and ensure &amp;lt;Code&amp;gt;net.ipv4.ip_forward&amp;lt;/code&amp;gt; is set to &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In the file {{Path|/etc/conf.d/iptables}}, Change the setting as follows:{{Cat|/etc/conf.d/iptables|...&lt;br /&gt;
IPFORWARD{{=}}&amp;quot;yes&amp;quot;}}&lt;br /&gt;
&lt;br /&gt;
== Running with modloop ==&lt;br /&gt;
&lt;br /&gt;
If you are running [[Diskless Mode]] i.e 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;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/pirate/wireguard-docs WireGuard documentation]&lt;br /&gt;
&lt;br /&gt;
[[Category:Networking]]&lt;/div&gt;</summary>
		<author><name>Gratuxri</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Alpine_Linux_in_a_chroot&amp;diff=13580</id>
		<title>Alpine Linux in a chroot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Alpine_Linux_in_a_chroot&amp;diff=13580"/>
		<updated>2017-06-06T17:23:54Z</updated>

		<summary type="html">&lt;p&gt;Gratuxri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This document explains how to set up an Alpine build environment in a chroot under a different Linux distro, such as Arch, Debian, Fedora, Gentoo, or Ubuntu. Once inside the chroot environment, you can build, debug, and run alpine packages. The guide can also be used to install Alpine Linux from a non-Alpine Linux livecd such as Ubuntu or System rescue CD.&lt;br /&gt;
&lt;br /&gt;
This example installation of Alpine Linux in a chroot will work with the lastest release. But it&#039;s also possible to make a chroot with &#039;&#039;&#039;[[Edge|edge]]&#039;&#039;&#039; or older releases of Alpine Linux to test backports.&lt;br /&gt;
&lt;br /&gt;
You can also use script [https://github.com/alpinelinux/alpine-chroot-install/ alpine-chroot-install] that simplifies this process to just two commands. This script is useful especially on CI environment (e.g. Travis CI).&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
For the base Alpine Linux you will only need around 6MB of free space; though to build packages you&#039;ll need at least 500 MB.&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
The variables below: &lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;${chroot_dir}&#039;&#039;&#039; = Should point to the chroot directory where you &lt;br /&gt;
*&#039;&#039;&#039;${mirror}&#039;&#039;&#039; = Should be replaced with [http://nl.alpinelinux.org/alpine/MIRRORS.txt one of the available Alpine Linux mirrors].&lt;br /&gt;
&lt;br /&gt;
== Set up APK ==&lt;br /&gt;
&lt;br /&gt;
{{Tip|In the command below, replace x86_64 with x86 if running on a 32 bit installation}}&lt;br /&gt;
&lt;br /&gt;
{{Warning|You will need Kernel version 2.6.22 or later to use apk-tools-static}}&lt;br /&gt;
&lt;br /&gt;
Download the latest apk static package (replace &amp;lt;tt&amp;gt;${version}&amp;lt;/tt&amp;gt; with actual version):&lt;br /&gt;
&lt;br /&gt;
{{Cmd|wget ${mirror}/latest-stable/main/x86_64/apk-tools-static-${version}.apk}}&lt;br /&gt;
&lt;br /&gt;
.apk packages are just gzipped tarballs, unpack using:&lt;br /&gt;
{{Cmd|tar -xzf apk-tools-static-*.apk}}&lt;br /&gt;
&lt;br /&gt;
== Install the alpine base installation onto the chroot ==&lt;br /&gt;
&lt;br /&gt;
{{Cmd|./sbin/apk.static -X ${mirror}/latest-stable/main -U --allow-untrusted --root ${chroot_dir} --initdb add alpine-base}}&lt;br /&gt;
&lt;br /&gt;
== Set up the chroot ==&lt;br /&gt;
&lt;br /&gt;
Set up some devices in the chroot&lt;br /&gt;
{{Tip|Manually creating devices is not needed if you choose to mount /dev of the hosts in the chroot described later.}}&lt;br /&gt;
&lt;br /&gt;
{{Cmd|mknod -m 666 ${chroot_dir}/dev/full c 1 7&lt;br /&gt;
mknod -m 666 ${chroot_dir}/dev/ptmx c 5 2&lt;br /&gt;
mknod -m 644 ${chroot_dir}/dev/random c 1 8&lt;br /&gt;
mknod -m 644 ${chroot_dir}/dev/urandom c 1 9&lt;br /&gt;
mknod -m 666 ${chroot_dir}/dev/zero c 1 5&lt;br /&gt;
mknod -m 666 ${chroot_dir}/dev/tty c 5 0}}&lt;br /&gt;
&lt;br /&gt;
If you need SCSI disc access:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|mknod -m 666 ${chroot_dir}/dev/sda b 8 0&lt;br /&gt;
mknod -m 666 ${chroot_dir}/dev/sda1 b 8 1&lt;br /&gt;
mknod -m 666 ${chroot_dir}/dev/sda2 b 8 2&lt;br /&gt;
mknod -m 666 ${chroot_dir}/dev/sda3 b 8 3&lt;br /&gt;
mknod -m 666 ${chroot_dir}/dev/sda4 b 8 4&lt;br /&gt;
mknod -m 666 ${chroot_dir}/dev/sda5 b 8 5&lt;br /&gt;
mknod -m 666 ${chroot_dir}/dev/sda6 b 8 6&lt;br /&gt;
mknod -m 666 ${chroot_dir}/dev/sdb b 8 16&lt;br /&gt;
mknod -m 666 ${chroot_dir}/dev/sdb1 b 8 17&lt;br /&gt;
mknod -m 666 ${chroot_dir}/dev/sdb2 b 8 18&lt;br /&gt;
mknod -m 666 ${chroot_dir}/dev/sdb3 b 8 19&lt;br /&gt;
mknod -m 666 ${chroot_dir}/dev/sdb4 b 8 20&lt;br /&gt;
mknod -m 666 ${chroot_dir}/dev/sdb5 b 8 21&lt;br /&gt;
mknod -m 666 ${chroot_dir}/dev/sdb6 b 8 22}}&lt;br /&gt;
&lt;br /&gt;
A resolv.conf is needed for name resolution: &lt;br /&gt;
&lt;br /&gt;
{{Cmd|cp /etc/resolv.conf ${chroot_dir}/etc/&lt;br /&gt;
mkdir -p ${chroot_dir}/root}}&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t want to copy the resolv.conf from the local machine, you can create a new one using OpenDNS servers (or any other): &lt;br /&gt;
{{Cmd|echo -e &#039;nameserver 208.67.222.222\nnameserver 2620:0:ccc::2&#039; &amp;gt; ${chroot_dir}/etc/resolv.conf}}&lt;br /&gt;
&lt;br /&gt;
Set up APK mirror (replace &amp;lt;tt&amp;gt;${branch}&amp;lt;/tt&amp;gt; with the latest stable branch name, e.g. v3.3):&lt;br /&gt;
&lt;br /&gt;
{{Cmd|mkdir -p ${chroot_dir}/etc/apk&lt;br /&gt;
echo &amp;quot;${mirror}/${branch}/main&amp;quot; &amp;gt; ${chroot_dir}/etc/apk/repositories}}&lt;br /&gt;
&lt;br /&gt;
== Entering your chroot ==&lt;br /&gt;
At this point, Alpine has been succesfully installed onto the chroot directory. Before you chroot in you&lt;br /&gt;
will probably want to mount /proc and /sys in the chroot:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|mount -t proc none ${chroot_dir}/proc&lt;br /&gt;
mount -o bind /sys ${chroot_dir}/sys}}&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t want to create special device files yourself, mount the hosts device directory onto the chroot:&lt;br /&gt;
{{Cmd|mount -o bind /dev ${chroot_dir}/dev}}&lt;br /&gt;
&lt;br /&gt;
You can now chroot:&lt;br /&gt;
{{Cmd|chroot ${chroot_dir} /bin/sh -l}}&lt;br /&gt;
&lt;br /&gt;
To make the system actually bootable, we need to add some initscripts to appropriate runlevels:&lt;br /&gt;
{{Cmd|rc-update add devfs sysinit&lt;br /&gt;
rc-update add dmesg sysinit&lt;br /&gt;
rc-update add mdev sysinit&lt;br /&gt;
&lt;br /&gt;
rc-update add hwclock boot&lt;br /&gt;
rc-update add modules boot&lt;br /&gt;
rc-update add sysctl boot&lt;br /&gt;
rc-update add hostname boot&lt;br /&gt;
rc-update add bootmisc boot&lt;br /&gt;
rc-update add syslog boot&lt;br /&gt;
&lt;br /&gt;
rc-update add mount-ro shutdown&lt;br /&gt;
rc-update add killprocs shutdown&lt;br /&gt;
rc-update add savecache shutdown}}&lt;br /&gt;
&lt;br /&gt;
Alpine Linux has a great meta-package for building Alpine packages from source available called alpine-sdk. To install, run:&lt;br /&gt;
{{Cmd|apk add alpine-sdk}}&lt;br /&gt;
&lt;br /&gt;
If you are using Alpine as a Native build system you will have to make sure that chroot can run chmod. Add following to /etc/sysctl.conf&lt;br /&gt;
&lt;br /&gt;
 kernel.grsecurity.chroot_deny_chmod = 0&lt;br /&gt;
&lt;br /&gt;
Then run the following command&lt;br /&gt;
&lt;br /&gt;
{{Cmd|sysctl -p}}&lt;br /&gt;
&lt;br /&gt;
== Alpine Linux in a chroot on Fedora ==&lt;br /&gt;
&lt;br /&gt;
If you want to generate a chroot on a Fedora based system, you can use this [http://git.alpinelinux.org/cgit/user/fab/scripts/tree/alpine-chroot.sh script].&lt;br /&gt;
&lt;br /&gt;
{{Note|Maybe you are able to use this script on other distribution but this is not tested.}}&lt;br /&gt;
&lt;br /&gt;
= Troubleshooting =&lt;br /&gt;
== WARNING: Ignoring APKINDEX.xxxx.tar.gz ==&lt;br /&gt;
Make sure &amp;lt;tt&amp;gt;${chroot_dir}/etc/apk/repositories&amp;lt;/tt&amp;gt; is valid and inside the chroot run:&lt;br /&gt;
{{Cmd|apk update}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation]]&lt;/div&gt;</summary>
		<author><name>Gratuxri</name></author>
	</entry>
</feed>