<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: VPSFreeio</title>
    <description>The latest articles on DEV Community by VPSFreeio (@vpsfreeio).</description>
    <link>https://dev.to/vpsfreeio</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4250573%2Ff802aafc-d887-4520-89de-5b0c77423ce1.png</url>
      <title>DEV Community: VPSFreeio</title>
      <link>https://dev.to/vpsfreeio</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vpsfreeio"/>
    <language>en</language>
    <item>
      <title>Why WireGuard Fails on LXC NAT VPS (and How to Fix It)</title>
      <dc:creator>VPSFreeio</dc:creator>
      <pubDate>Tue, 17 Nov 2026 20:58:08 +0000</pubDate>
      <link>https://dev.to/vpsfreeio/why-wireguard-fails-on-lxc-nat-vps-and-how-to-fix-it-1om5</link>
      <guid>https://dev.to/vpsfreeio/why-wireguard-fails-on-lxc-nat-vps-and-how-to-fix-it-1om5</guid>
      <description>&lt;p&gt;You've got a cheap NAT VPS – shared IPv4, a small range of forwarded ports, maybe 192 MB of RAM inside an LXC container – and you want your own WireGuard VPN on it.&lt;/p&gt;

&lt;p&gt;You run the popular install script and get this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;RTNETLINK answers: Not supported
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;…or a script that refuses to run with &lt;em&gt;"LXC is not supported"&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;This post explains &lt;strong&gt;why that happens&lt;/strong&gt;, how to tell in one line whether your box can do it, and the minimal setup that works on a NAT VPS with only a handful of forwarded ports. I tested every step on a 192 MB LXC container on an AMD EPYC host – screenshots below.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why WireGuard fails inside LXC
&lt;/h2&gt;

&lt;p&gt;WireGuard lives in the Linux kernel. A VM (KVM) has its own kernel and can load the module itself. An &lt;strong&gt;LXC container shares the host's kernel&lt;/strong&gt; and isn't allowed to load modules. So it depends entirely on the host:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Host has &lt;code&gt;wireguard&lt;/code&gt; module loaded?&lt;/th&gt;
&lt;th&gt;Result in the container&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Kernel WireGuard works at full speed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;&lt;code&gt;RTNETLINK answers: Not supported&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The user-space alternatives (&lt;code&gt;wireguard-go&lt;/code&gt;, &lt;code&gt;boringtun&lt;/code&gt;) need &lt;code&gt;/dev/net/tun&lt;/code&gt; passed into the container – which many hosts don't do either.&lt;/p&gt;

&lt;p&gt;If you run the host yourself (Incus/LXD), the fix is two commands on the &lt;strong&gt;host&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;modprobe wireguard &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; wireguard &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; /etc/modules-load.d/wireguard.conf
incus profile device add default tun unix-char &lt;span class="nv"&gt;source&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/dev/net/tun &lt;span class="nv"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/dev/net/tun &lt;span class="nv"&gt;mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;0666
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you don't run the host, ask your provider to load the &lt;code&gt;wireguard&lt;/code&gt; module for containers.&lt;/p&gt;

&lt;h2&gt;
  
  
  The one-line test
&lt;/h2&gt;

&lt;p&gt;Run this inside your container:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ip link add wgtest &lt;span class="nb"&gt;type&lt;/span&gt; wireguard &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; ip link del wgtest &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"WIREGUARD OK"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F267iephue30g82niog3d.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F267iephue30g82niog3d.webp" alt="WireGuard test passing inside a 192 MB LXC container" width="661" height="388"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;WIREGUARD OK&lt;/code&gt; → continue. &lt;code&gt;Not supported&lt;/code&gt; → the host doesn't allow it, no amount of apt installing will fix that.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup on a NAT VPS
&lt;/h2&gt;

&lt;p&gt;The only NAT-specific part: &lt;strong&gt;WireGuard must listen on one of your forwarded UDP ports&lt;/strong&gt;. In my case the range is &lt;code&gt;20001-20019&lt;/code&gt;, so I use &lt;code&gt;20001&lt;/code&gt;. Replace it with yours.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Tools and keys
&lt;/h3&gt;

&lt;p&gt;Only the user-space tools – the kernel part comes from the host, so &lt;strong&gt;don't&lt;/strong&gt; install &lt;code&gt;wireguard-dkms&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;apt update &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; apt install -y wireguard-tools iptables qrencode curl
mkdir -p /etc/wireguard &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;cd&lt;/span&gt; /etc/wireguard &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;umask&lt;/span&gt; 077
wg genkey &lt;span class="o"&gt;|&lt;/span&gt; tee server.key &lt;span class="o"&gt;|&lt;/span&gt; wg pubkey &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; server.pub
wg genkey &lt;span class="o"&gt;|&lt;/span&gt; tee phone.key  &lt;span class="o"&gt;|&lt;/span&gt; wg pubkey &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; phone.pub
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Forwarding
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cat &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /etc/sysctl.d/99-wireguard.conf &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="s1"&gt;'EOF'&lt;/span&gt;
net.ipv4.ip_forward &lt;span class="o"&gt;=&lt;/span&gt; 1
net.ipv6.conf.all.forwarding &lt;span class="o"&gt;=&lt;/span&gt; 1
net.ipv6.conf.eth0.accept_ra &lt;span class="o"&gt;=&lt;/span&gt; 2
EOF
sysctl --system &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;accept_ra = 2&lt;/code&gt; line matters: turning on IPv6 forwarding normally makes Linux ignore router advertisements, which can silently kill your VPS's own IPv6.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Server config
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cat &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /etc/wireguard/wg0.conf &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;EOF
&lt;span class="o"&gt;[&lt;/span&gt;Interface&lt;span class="o"&gt;]&lt;/span&gt;
Address    &lt;span class="o"&gt;=&lt;/span&gt; 10.66.66.1/24, fd66:66:66::1/64
ListenPort &lt;span class="o"&gt;=&lt;/span&gt; 20001
PrivateKey &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$(&lt;/span&gt;cat server.key&lt;span class="o"&gt;)&lt;/span&gt;
PostUp     &lt;span class="o"&gt;=&lt;/span&gt; iptables -t nat -A POSTROUTING -s 10.66.66.0/24 -j MASQUERADE&lt;span class="o"&gt;;&lt;/span&gt; ip6tables -t nat -A POSTROUTING -s fd66:66:66::/64 -j MASQUERADE
PostDown   &lt;span class="o"&gt;=&lt;/span&gt; iptables -t nat -D POSTROUTING -s 10.66.66.0/24 -j MASQUERADE&lt;span class="o"&gt;;&lt;/span&gt; ip6tables -t nat -D POSTROUTING -s fd66:66:66::/64 -j MASQUERADE

&lt;span class="o"&gt;[&lt;/span&gt;Peer&lt;span class="o"&gt;]&lt;/span&gt;
PublicKey  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$(&lt;/span&gt;cat phone.pub&lt;span class="o"&gt;)&lt;/span&gt;
AllowedIPs &lt;span class="o"&gt;=&lt;/span&gt; 10.66.66.2/32, fd66:66:66::2/128
EOF
chmod 600 wg0.conf
systemctl &lt;span class="nb"&gt;enable&lt;/span&gt; --now wg-quick@wg0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Clients get private IPv4 + ULA IPv6 addresses and are masqueraded out, so the tunnel works for &lt;strong&gt;both IPv4 and IPv6 sites&lt;/strong&gt; even though the IPv4 is shared.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Client config as a QR code
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cat &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; phone.conf &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;EOF
&lt;span class="o"&gt;[&lt;/span&gt;Interface&lt;span class="o"&gt;]&lt;/span&gt;
PrivateKey &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$(&lt;/span&gt;cat phone.key&lt;span class="o"&gt;)&lt;/span&gt;
Address    &lt;span class="o"&gt;=&lt;/span&gt; 10.66.66.2/32, fd66:66:66::2/128
DNS        &lt;span class="o"&gt;=&lt;/span&gt; 1.1.1.1, 2606:4700:4700::1111

&lt;span class="o"&gt;[&lt;/span&gt;Peer&lt;span class="o"&gt;]&lt;/span&gt;
PublicKey           &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$(&lt;/span&gt;cat server.pub&lt;span class="o"&gt;)&lt;/span&gt;
Endpoint            &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$(&lt;/span&gt;curl -4 -s ifconfig.co&lt;span class="o"&gt;)&lt;/span&gt;:20001
AllowedIPs          &lt;span class="o"&gt;=&lt;/span&gt; 0.0.0.0/0, ::/0
PersistentKeepalive &lt;span class="o"&gt;=&lt;/span&gt; 25
EOF
qrencode -t ansiutf8 &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; phone.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Scan it in the WireGuard app (&lt;strong&gt;+ → Scan from QR code&lt;/strong&gt;). The QR contains a private key – don't post it anywhere.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;PersistentKeepalive = 25&lt;/code&gt; is worth keeping on NAT setups: it stops the connection-tracking entries on both sides from expiring while the tunnel is idle.&lt;/p&gt;

&lt;h2&gt;
  
  
  Does it work?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8y8d95zbnyyqg4wkjzvz.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8y8d95zbnyyqg4wkjzvz.webp" alt="WireGuard app connected to a NAT VPS on port 20001" width="640" height="1315"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On the server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;wg show
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3opumefsdv1q399gj0jj.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3opumefsdv1q399gj0jj.webp" alt="wg show with a recent handshake and traffic" width="661" height="185"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A recent &lt;code&gt;latest handshake&lt;/code&gt; and growing &lt;code&gt;transfer&lt;/code&gt; = done. Browsing to ifconfig.co from the phone now shows the VPS address:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fus6uwife6fprrjy2ag0w.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fus6uwife6fprrjy2ag0w.webp" alt="ifconfig.co showing the VPS IP through the tunnel" width="800" height="455"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Troubleshooting
&lt;/h2&gt;

&lt;h3&gt;
  
  
  No handshake at all
&lt;/h3&gt;

&lt;p&gt;The port is wrong or blocked. &lt;code&gt;ListenPort&lt;/code&gt; and the port in &lt;code&gt;Endpoint&lt;/code&gt; must match &lt;strong&gt;and&lt;/strong&gt; be inside your forwarded range. If you run &lt;code&gt;ufw&lt;/code&gt; in the container: &lt;code&gt;ufw allow 20001/udp&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Handshake works, but no websites load
&lt;/h3&gt;

&lt;p&gt;Forwarding or NAT is missing. Check &lt;code&gt;sysctl net.ipv4.ip_forward&lt;/code&gt; returns &lt;code&gt;1&lt;/code&gt; and &lt;code&gt;iptables -t nat -S&lt;/code&gt; shows the MASQUERADE rule.&lt;/p&gt;

&lt;h3&gt;
  
  
  Some sites load, others hang forever
&lt;/h3&gt;

&lt;p&gt;Classic MTU issue. Add &lt;code&gt;MTU = 1280&lt;/code&gt; under &lt;code&gt;[Interface]&lt;/code&gt; in the client config and reconnect.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;ping google.com&lt;/code&gt; hangs on the VPS
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;ping&lt;/code&gt; prefers IPv6, and some routes filter ICMPv6 echo. Try &lt;code&gt;ping -4 google.com&lt;/code&gt; – if that works, your network is fine.&lt;/p&gt;

&lt;h2&gt;
  
  
  Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;On LXC, WireGuard support is a &lt;strong&gt;host&lt;/strong&gt; decision – test with &lt;code&gt;ip link add … type wireguard&lt;/code&gt; before debugging anything else.&lt;/li&gt;
&lt;li&gt;On NAT, the only change is picking a &lt;strong&gt;forwarded UDP port&lt;/strong&gt; as &lt;code&gt;ListenPort&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Keep &lt;code&gt;accept_ra = 2&lt;/code&gt; when enabling IPv6 forwarding, and &lt;code&gt;PersistentKeepalive&lt;/code&gt; on the client.&lt;/li&gt;
&lt;li&gt;192 MB of RAM is plenty – WireGuard itself uses a few MB.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Questions or a setup that behaves differently? Drop it in the comments.&lt;/p&gt;

</description>
      <category>wireguard</category>
      <category>linux</category>
      <category>networking</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
