<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Self-Hosted VPN Notes]]></title><description><![CDATA[Self-hosted AmneziaWG VPN notes: one-command installs on Ubuntu and Debian, two-server cascades, split routing and troubleshooting.]]></description><link>https://bivlked.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Sun, 29 Nov 2026 00:51:48 GMT</lastBuildDate><atom:link href="https://bivlked.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Separate Entry and Exit IPs on One AmneziaWG or WireGuard Server]]></title><description><![CDATA[Clients connect to one IPv4, websites see another: one SNAT rule for AmneziaWG or WireGuard, an installer flag, and what happens if the exit IP dies.]]></description><link>https://bivlked.hashnode.dev/separate-entry-and-exit-ips-on-one-amneziawg-or-wireguard-server</link><guid isPermaLink="true">https://bivlked.hashnode.dev/separate-entry-and-exit-ips-on-one-amneziawg-or-wireguard-server</guid><category><![CDATA[vpn]]></category><category><![CDATA[wireguard]]></category><category><![CDATA[self-hosted]]></category><category><![CDATA[networking]]></category><category><![CDATA[Linux]]></category><dc:creator><![CDATA[Ivan Bondarev]]></dc:creator><pubDate>Fri, 27 Nov 2026 13:46:16 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6aff32d63ce3219b7df92644/6e3a17bc-e049-4252-9236-86750c071242.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>How do you make AmneziaWG clients connect to one IP address while websites see a different one? You put a second public IPv4 on the server and add one SNAT rule for the client subnet. Below: how to do it by hand, with my installer, and on a server set up by the Amnezia VPN app. Then what happens when the exit address disappears or gets blocked, and how to swap it without touching client configs.</p>
<p>Why would you want it? In autumn 2026 this stopped being a theory for people in Russia. In early November <a href="https://github.com/net4people/bbs/issues/671">its0ka reported on net4people</a> that only the outgoing address of their server was banned, about two days after they started using it. The next exit address lasted roughly 25 hours. A <a href="https://habr.com/ru/articles/1103460/">widely read guide by mureevms on Habr</a> (in Russian, more than 130,000 reads in its first two and a half weeks) is built on the same rule: user traffic should not leave to the internet from the address clients connect to.</p>
<p>To be honest about the evidence: nobody has proven that servers get blocked <em>because</em> of their exit traffic. What is known is that in these cases the addresses that disappeared were the ones traffic left from. The guide's authors, and runetfreedom in a <a href="https://habr.com/ru/articles/1020080/">separate investigation</a> (also in Russian), think apps on the phone see the exit address and can report it somewhere. If entry and exit are the same address, losing the exit means losing the VPN.</p>
<p>There are reasons outside Russia too. Datacenter IPs pick up bad reputation: CAPTCHAs, blocklists, services that refuse hosting ranges. Those lists often work by subnet or network, so a second address from the same range may inherit the same reputation. Still, with separate addresses you can swap the exit without touching a single client config, which matters a lot once your VPN runs on your parents' phones.</p>
<p>The guides I found cover this for Xray. For AmneziaWG I couldn't find a step-by-step recipe, and people keep asking me about it; <a href="https://github.com/yuretzgt">yuretzgt</a> suggested adding it to my installer in <a href="https://github.com/bivlked/amneziawg-installer/issues/384">#384</a>. Where I measured something myself, I say so.</p>
<h2>The short version</h2>
<ol>
<li>Get a second public IPv4 on the server and make sure it's on the interface.</li>
<li>Add a SNAT rule for the client subnet to the exit address, first in the POSTROUTING chain, above the usual MASQUERADE. With my installer that's <code>--exit-ip</code>.</li>
<li>Check from a client: <code>curl -4 ifconfig.me</code> should print the exit address.</li>
<li>When the exit gets blocked, put a new address in the rule. Client configs stay the same.</li>
</ol>
<p>If the exit address disappears from the interface but the rule stays, clients don't fall back to the entry address; usually their connection just stops. The manual recipe is the same for plain WireGuard with <code>wg-quick</code>. Full details are in the <a href="https://github.com/bivlked/amneziawg-installer/blob/main/ADVANCED.en.md#exit-ip-adv">exit address section of the docs</a>.</p>
<p>In the examples below the entry address is <code>198.51.100.2</code>, the exit address is <code>203.0.113.7</code>, the client subnet is <code>10.9.9.0/24</code> and the external interface is <code>ens3</code>. Take your own values from <code>ip -br addr</code> and the server config.</p>
<h2>Who sees which address</h2>
<table>
<thead>
<tr>
<th>Who</th>
<th>Sees</th>
</tr>
</thead>
<tbody><tr>
<td>The client's ISP and its DPI</td>
<td>the entry address</td>
</tr>
<tr>
<td>Websites and apps, for traffic inside the tunnel</td>
<td>the exit address</td>
</tr>
<tr>
<td>Your hosting provider</td>
<td>both</td>
</tr>
<tr>
<td>Services the server itself talks to (updates, DNS, NTP)</td>
<td>usually the main address, i.e. the entry</td>
</tr>
</tbody></table>
<p><img src="https://dev-to-uploads.s3.us-east-2.amazonaws.com/uploads/articles/x0e72r3a5t05tcogso92.png" alt="One address for entry and exit versus separate entry and exit IPs in AmneziaWG: websites see only the exit, the ISP and DPI see the entry" /></p>
<p>With split tunneling, whatever bypasses the tunnel reaches websites from the client's home address; the server has nothing to do with it. The SNAT rule rewrites the source only for client traffic and leaves the server's own connections alone.</p>
<p>Does this matter for AmneziaWG at all? In the Xray research (Xray is a proxy core widely used in Russia), apps found the exit address through the local SOCKS5 proxy that Xray and sing-box clients open. AmneziaWG clients have no such proxy, it's a tunnel at the network interface level. But any app inside the tunnel can learn the exit address the boring way, with a plain request to its own server. So yes, it matters.</p>
<h2>First: a second IPv4 on the server</h2>
<p>You can also split entry and exit with a separate exit server or through Cloudflare WARP. I'm covering the second IPv4 on the same server because it's the simplest path and usually the cheapest. This step is needed whichever way you set up the rule, including with my installer and on a server from the Amnezia app.</p>
<p><strong>Add the address.</strong> Your provider assigns the second address in its panel, but sometimes you have to configure it on the server yourself. Look at <code>ip -br addr</code> first: on my test server the provider wrote the address into netplan through cloud-init when I restarted the server from the panel, and I had nothing to do. If the address isn't there, on Ubuntu you add it with netplan. Use the same key your existing netplan file uses for this interface (usually the interface name), otherwise netplan treats it as a different device:</p>
<pre><code class="language-yaml"># /etc/netplan/60-exit-ip.yaml
network:
  version: 2
  ethernets:
    ens3:
      addresses: [203.0.113.7/32]
</code></pre>
<p>Then <code>sudo netplan apply</code>.</p>
<p>On Debian with ifupdown, put the address in a separate file, <code>/etc/network/interfaces.d/60-exit-ip</code>, not in <code>50-cloud-init</code>: cloud-init rewrites that one at boot. Use your own interface name from <code>ip -br addr</code>; the stanza only adds an address to an interface that already comes up at boot. Files in <code>interfaces.d/</code> are read only if <code>/etc/network/interfaces</code> has the line <code>source /etc/network/interfaces.d/*</code>. Debian cloud images have it; a manual install may not.</p>
<pre><code class="language-conf">iface eth0 inet static
    address 203.0.113.7/32
</code></pre>
<p>The file alone won't add the address to a running interface. I applied it with a reboot (make sure the console in your provider's panel works first) and then looked at <code>ip -br addr</code>: on Debian 13 the address was there and the default route still used the main address. I measured traffic actually leaving through the second address only on Ubuntu, so treat Debian as "should work, not checked".</p>
<p><strong>Check the address.</strong></p>
<pre><code class="language-bash">curl -4 -sS --max-time 10 --interface 203.0.113.7 https://api.ipify.org
</code></pre>
<p>It should print <code>203.0.113.7</code>. If you get an error instead, sort out the second address, DNS and the check service first; it's too early to touch the VPN. On my test server the address only started working after that restart from the panel.</p>
<p>Do this check before the VPN is set up. Most VPN setups, mine included, add a MASQUERADE rule for everything leaving the external interface, and it rewrites this probe to the main address too. On a running VPN server the probe then shows the main address even when the second one is fine.</p>
<h2>By hand: one SNAT rule</h2>
<p>This recipe is for a server running <code>awg-quick</code> with the config at <code>/etc/amnezia/amneziawg/awg0.conf</code>: a manual install and most similar scripts. For plain WireGuard it's the same with <code>wg-quick@wg0</code> and <code>/etc/wireguard/wg0.conf</code>.</p>
<p>If the server was set up by my installer, use the command from the next section instead. <code>manage exit-ip</code> recognizes the rule only in exactly the form shown below, appended to the <code>PostUp</code> and <code>PostDown</code> lines with <code>; </code>. Written any other way (another option order, <code>-A</code>, a separate <code>PostUp</code> line, a script) it won't see it: changing the exit would leave you with two rules, and <code>exit-ip off</code> would leave yours in place. The command also clears old connections with conntrack and rolls back if the service doesn't start. The Amnezia app has its own section below.</p>
<p><strong>1. Add the rule.</strong> Stop the service first, then edit the file, then start it. I'll explain why not <code>restart</code> in the troubleshooting section.</p>
<pre><code class="language-bash">sudo systemctl stop awg-quick@awg0
sudo nano /etc/amnezia/amneziawg/awg0.conf
</code></pre>
<p>In the <code>[Interface]</code> section, append the rule with <code>; </code> to the end of the existing <code>PostUp</code> line, and the same with <code>-D</code> to the end of <code>PostDown</code>:</p>
<pre><code class="language-ini">PostUp = &lt;what was already there&gt;; iptables -t nat -I POSTROUTING -s 10.9.9.0/24 -o ens3 -j SNAT --to-source 203.0.113.7
PostDown = &lt;what was already there&gt;; iptables -t nat -D POSTROUTING -s 10.9.9.0/24 -o ens3 -j SNAT --to-source 203.0.113.7
</code></pre>
<pre><code class="language-bash">sudo systemctl start awg-quick@awg0
sudo iptables -t nat -S POSTROUTING
</code></pre>
<p><code>-I</code> puts the rule first, above MASQUERADE. <code>-s</code> and <code>-o</code> limit it to client traffic going out the external interface, so the server's own traffic isn't touched. In the output of the last command, the SNAT line must come before the MASQUERADE line. On my test server the rule survived a reboot. After the start, clients are offline until a new handshake happens; for me that was about 13 seconds.</p>
<p><strong>2. Check from a client.</strong></p>
<pre><code class="language-bash">curl -4 -s ifconfig.me
</code></pre>
<p>It should print the exit address. The same <code>curl</code> on the server itself shows the main address: that's the server's own traffic, and it's supposed to. Check from a client, with a fresh connection: NAT rules apply to new connections, and ones opened before the change keep their old address until they close.</p>
<h2>With my installer: the --exit-ip option</h2>
<p>If you set up the server with <a href="https://github.com/bivlked/amneziawg-installer">my installer</a>, one option does it (available since v6.3.0; the second address must already be on the interface):</p>
<pre><code class="language-bash">wget -O install_amneziawg_en.sh https://github.com/bivlked/amneziawg-installer/releases/latest/download/install_amneziawg_en.sh
sudo bash install_amneziawg_en.sh --endpoint=198.51.100.2 --exit-ip=203.0.113.7
</code></pre>
<p><code>--endpoint</code> sets the address clients get. Without it, the installer asks an IP echo service which address the server is seen from, which is normally the main one (the <code>src</code> in <code>ip route get 1.1.1.1</code>), and your provider may have made a different address the main one than you expect.</p>
<p>On a running server, turn the exit on with <code>sudo bash /root/awg/manage_amneziawg.sh exit-ip 203.0.113.7</code> and off with <code>exit-ip off</code>. Client configs don't change; the connection drops for about 13 seconds (that's what I saw on my test server). If the exit address equals the entry address, isn't on an interface, or the IPv6 tunnel for clients is on, both the installer and <code>manage</code> refuse and tell you why.</p>
<h2>A server set up by the Amnezia VPN app (Docker)</h2>
<p>The Amnezia VPN app installs AmneziaWG in a Docker container, so a line in <code>PostUp</code> won't do. The rule belongs on the host, and there are two traps:</p>
<ul>
<li>On my test setup the container reached the internet through the <code>amnezia-dns-net</code> network (<code>172.29.172.0/24</code>) that the app attaches, and a rule only for Docker's default bridge <code>172.17.0.0/16</code> had no effect. Which network the container uses seems to depend on the order the networks were attached, so the rule covers both.</li>
<li><code>systemctl restart docker</code> puts its own MASQUERADE above your SNAT, and the exit silently goes back to the entry address.</li>
</ul>
<p>I reproduced the app's network layout from its scripts on a test server; I didn't test an install through the app itself. In that setup a small unit helped: it adds the rules after Docker starts and again every time Docker restarts. The file <code>/etc/systemd/system/amnezia-exit-ip.service</code>:</p>
<pre><code class="language-ini">[Unit]
Description=Exit IP for Amnezia containers (SNAT above Docker MASQUERADE)
After=docker.service
PartOf=docker.service

[Service]
Type=oneshot
RemainAfterExit=yes
Environment=EXIT=203.0.113.7 NIC=ens3
ExecStart=/bin/sh -c 'for n in 172.17.0.0/16 172.29.172.0/24; do while iptables -t nat -D POSTROUTING -s $n -o $NIC -j SNAT --to-source $EXIT 2&gt;/dev/null; do :; done; iptables -t nat -I POSTROUTING -s $n -o $NIC -j SNAT --to-source $EXIT; done'
ExecStop=/bin/sh -c 'for n in 172.17.0.0/16 172.29.172.0/24; do while iptables -t nat -D POSTROUTING -s $n -o $NIC -j SNAT --to-source $EXIT 2&gt;/dev/null; do :; done; done'

[Install]
WantedBy=docker.service
</code></pre>
<pre><code class="language-bash">sudo systemctl daemon-reload &amp;&amp; sudo systemctl enable --now amnezia-exit-ip
sudo iptables -t nat -S POSTROUTING
</code></pre>
<p>Both SNAT rules must come before Docker's MASQUERADE lines. I restarted Docker, rebooted the host and restarted the container: each time the exit stayed <code>203.0.113.7</code>, with a 14-19 second gap. I checked with probes from a client, not a continuous packet capture, so a brief leak from the main address during a Docker restart isn't ruled out. The rules cover IPv4 traffic from every container on those two networks, so other Amnezia protocols and its DNS container will also leave from the exit address.</p>
<h2>What happens if the exit address disappears</h2>
<p>Clients don't start leaving from the entry address. Usually their connection just stops.</p>
<p>The SNAT rule sets the exit address as the source even when that address is no longer on the interface. Packets still go out, but replies stop coming back once the provider's router can't find the address by ARP. If your provider routes the address to the server without ARP, the connection may not break at all.</p>
<p>What I measured: on Ubuntu 24.04, in three runs, the connection stopped after 28, 9 and 25 seconds; the spread is probably the router's ARP cache. In the run with a full packet capture, not a single client packet left from the entry address. In a later run the connection went on for about 20 more seconds and then stopped; the entry address never showed up on the client, and when the address came back, so did the connection, within 2 seconds.</p>
<p>Client DNS stops with everything else: by default my installer gives clients <code>1.1.1.1</code> and <code>1.0.0.1</code>, and those queries go through the tunnel, from the exit address. From the outside it looks like "nothing opens at all". In this situation <code>manage check</code> says:</p>
<pre><code class="language-plaintext">[2026-11-26 11:00:00] ERROR:  - 203.0.113.7 is not on any server interface: client traffic still leaves with this address, but replies usually stop coming back. Bring the address back (in netplan, for example) or remove it: manage exit-ip off
</code></pre>
<p>That's exactly the failure I tested: the address gone, the rule in place. If the rule itself disappears, client traffic goes through the general MASQUERADE, from the entry address. That's how <code>exit-ip off</code> works. So it matters that the rule doesn't vanish by accident; see the first item under troubleshooting.</p>
<h2>If the exit gets blocked</h2>
<p>A ping that doesn't answer and a broken traceroute prove nothing: your provider may drop ICMP, or the server may simply be down. I'd check three things: whether the address is reachable from another network (mobile data, another ISP), whether an allowed TCP port opens, and what the provider's panel says about the server.</p>
<p>The Russian guide notes that outgoing connections from a blocked address to Russian sites still work. If client traffic is flowing, you don't have to change the address that minute, but it's worth having the next one ready.</p>
<p>Swapping looks like this: get a new address from your provider, configure it and make sure <code>ip -br addr</code> shows it, then <code>stop</code>, replace the address in both lines, <code>start</code>, and check from a client. (The <code>curl --interface</code> probe from earlier won't help here: on a running VPN server the MASQUERADE rule rewrites it.) With my installer, the stop-replace-start part is one command, <code>manage exit-ip &lt;new address&gt;</code> (it asks for confirmation; <code>--yes</code> skips the question). Client configs stay the same.</p>
<p><img src="https://dev-to-uploads.s3.us-east-2.amazonaws.com/uploads/articles/5kgbdlvp8kleictk1ri8.png" alt="Replacing a blocked exit address: the entry and client configs stay the same, only the exit address changes" /></p>
<p>Connections that are already open (a long download, a call) keep the old address until they close, unless the server has the <code>conntrack</code> tool; that's what I saw on my test server. With it, <code>manage exit-ip</code> deletes the entries for the client subnet: open connections drop, and when they reconnect they use the new address. Nobody does this for you when you change the rule by hand. Minimal Ubuntu images don't have the tool, and after my installer a plain <code>apt install conntrack</code> won't find it, because the installer clears apt's package lists at the end. Install it like this:</p>
<pre><code class="language-bash">sudo apt update &amp;&amp; sudo apt install conntrack
</code></pre>
<p>The new address can get blocked too. This setup won't stop that. It just means you don't have to send new configs to anyone.</p>
<h2>Troubleshooting</h2>
<p><strong>I removed the rule from the config, but the client still leaves from the exit address.</strong> That happened to me while testing the rollback. <code>restart</code> stops the service using the <code>PostDown</code> from the file on disk at that moment, and the delete command is already gone from it. The rule stays in iptables. So always <code>stop</code>, edit, <code>start</code>. The same goes for <code>wg-quick</code>. If you already made the mistake, remove the rule by hand: <code>sudo iptables -t nat -D POSTROUTING -s 10.9.9.0/24 -o ens3 -j SNAT --to-source 203.0.113.7</code>. Same when you change the address by hand.</p>
<p><strong>I set the source on the default route and nothing changed.</strong> You'll find advice to use <code>ip route replace default via &lt;gateway&gt; dev ens3 src 203.0.113.7</code> instead of SNAT. On my test server, with the general MASQUERADE in place, it changed nothing: both clients and the server itself still left from the entry address. MASQUERADE seems to pick the address from the gateway's subnet and ignore the route's <code>src</code>. Besides, <code>src</code> sets the source for the server's own connections; it doesn't rewrite the source of forwarded client packets. Those need SNAT.</p>
<p><strong>I want IPv6 in the tunnel and a separate exit.</strong> The SNAT rule is IPv4 only, so with the IPv6 tunnel for clients (<code>--allow-ipv6-tunnel</code>) the installer won't turn on a separate exit. In full-tunnel configs from my installer (clients issued or regenerated since v5.31.0), device IPv6 goes into the tunnel and is dropped there, so it doesn't bypass the exit. With a manual install or the Amnezia app, check this yourself.</p>
<p><strong>I manage nftables directly, not iptables.</strong> On current Ubuntu and Debian, <code>iptables</code> is the nftables-backed version, so the commands above work as they are. If you write nft rules yourself, the same thing is a rule in your postrouting nat chain placed before the masquerade one: <code>ip saddr 10.9.9.0/24 oifname "ens3" snat to 203.0.113.7</code>. That only works if both rules are in the same chain. If the masquerade lives in another table (iptables-nft creates <code>ip nat</code>), the order is decided by chain priority, not position: give your chain a lower number, for example <code>priority srcnat - 1</code>.</p>
<p><strong>Both addresses got blocked at once.</strong> If the whole subnet is blocked and the second address is from the same subnet, both go. Look at the subnet when you order the address. If reliability matters, a second server is better.</p>
<h2>What this doesn't solve</h2>
<p>Detection of the protocol itself. That's the job of obfuscation, and AmneziaWG has its own (the 3.1 profile, details in the <a href="https://github.com/bivlked/amneziawg-installer/blob/main/ADVANCED.en.md">docs</a>).</p>
<p>Allowlists on mobile networks. If the entry address isn't on the allowed list, separating addresses won't help.</p>
<p>A whole subnet getting blocked, or the new exit address getting blocked again.</p>
<h2>Going further: a separate exit server and three-server setups</h2>
<p>If your provider has no second address, or you want entry and exit at different providers, you need a cascade: two servers, with traffic leaving through the second one. I wrote up a <a href="https://dev.to/bivlked/amneziawg-cascade-with-two-vps-entry-in-russia-exit-abroad-3m1j">two-VPS AmneziaWG cascade</a> with a Russian entry and a foreign exit; in that version Russian destinations leave directly from the entry.</p>
<p>The guide also shows how to give each role on the entry its own address: one for clients, one that Russian sites see, one for the tunnel to the exit (<a href="https://github.com/bivlked/amneziawg-installer/blob/main/CASCADE.en.md#own-addresses">own addresses for each role</a>).</p>
<p>In a three-server setup the entry talks only to the middle server, and client traffic leaves through the last one. If the exit gets listed, you replace it and the tunnel on the middle server; the entry and the clients aren't affected (<a href="https://github.com/bivlked/amneziawg-installer/blob/main/CASCADE.en.md#replace-exit">replacing the exit</a>). But while the <code>awg1</code> tunnel on the middle server is restarting or stopped, traffic leaves from the middle server's address: for that time the rule from the start of this post is broken, and the setup has no separate protection against it. I haven't built this one on my own servers; <a href="https://github.com/stromnov">stromnov</a> tested it on three VPS in <a href="https://github.com/bivlked/amneziawg-installer/discussions/120">discussion #120</a> (in Russian).</p>
<h2>Has your exit address been blocked?</h2>
<p>I don't have enough data on how long a second address lasts, or whether whole subnets get closed. All the reports I have are from Russia; if you've seen exit addresses blocked somewhere else, that's even more interesting. Tell me in the comments how long it took and what it looked like, and I'll add it to the docs.</p>
<p>If the installer saves you some time, a star on GitHub helps other people find it.</p>
<p>Links:</p>
<ul>
<li><a href="https://github.com/bivlked/amneziawg-installer/blob/main/ADVANCED.en.md#exit-ip-adv">Separate exit address, all the details</a></li>
<li><a href="https://github.com/bivlked/amneziawg-installer/blob/main/CASCADE.en.md#own-addresses">Cascade: own addresses for each role and replacing the exit</a></li>
<li><a href="https://dev.to/bivlked/amneziawg-cascade-with-two-vps-entry-in-russia-exit-abroad-3m1j">Two-VPS AmneziaWG cascade</a></li>
<li><a href="https://habr.com/ru/articles/1111468/">The original Russian version of this post on Habr</a></li>
<li><a href="https://github.com/bivlked/amneziawg-installer/issues/384">The issue where it started: #384</a></li>
<li><a href="https://github.com/bivlked/amneziawg-installer">The installer itself</a></li>
</ul>
<p>Thanks to <a href="https://github.com/yuretzgt">yuretzgt</a> for the idea, <a href="https://github.com/Johnconnor795">Johnconnor795</a> for testing it on a live server, and <a href="https://github.com/stromnov">stromnov</a> for the three-server setup.</p>
]]></content:encoded></item><item><title><![CDATA[AmneziaWG Cascade With Two VPS: Entry in Russia, Exit Abroad]]></title><description><![CDATA[Two VPS, one AmneziaWG connection per client: Russian IP ranges leave from a Russian entry, the rest through a foreign exit. Setup and checks.]]></description><link>https://bivlked.hashnode.dev/amneziawg-cascade-with-two-vps-entry-in-russia-exit-abroad</link><guid isPermaLink="true">https://bivlked.hashnode.dev/amneziawg-cascade-with-two-vps-entry-in-russia-exit-abroad</guid><category><![CDATA[vpn]]></category><category><![CDATA[wireguard]]></category><category><![CDATA[self-hosted]]></category><category><![CDATA[networking]]></category><category><![CDATA[Linux]]></category><dc:creator><![CDATA[Ivan Bondarev]]></dc:creator><pubDate>Thu, 19 Nov 2026 17:42:21 GMT</pubDate><content:encoded><![CDATA[<p>An AmneziaWG cascade is two VPS working as one VPN. Clients connect to an entry server in Russia; traffic to Russian IP ranges leaves directly from the entry, and everything else goes through a second server abroad.</p>
<p>Why bother? With a normal full tunnel, every Russian service sees the foreign address of your VPS. The complaint I hear most is about a banking app, not YouTube: big banks and marketplaces often meet a foreign hosting address with a bot check or just refuse it. Other Russian services take a detour through another country and back. With a cascade, Russian services see a Russian address, foreign sites still see a foreign one, and each client keeps a single connection with nothing special to configure.</p>
<p>There's one more reason. Some regional ISPs have a poor international route, and an entry server in Moscow fixes that. In one case I saw, a user in Siberia lost 30-50% of packets on the direct path to a foreign data center, and 0% when the same traffic went through Moscow first.</p>
<pre><code>                       Russian IP ranges, direct
                  +---------------------------------&gt; these destinations see the entry IP
                  |
client --------&gt; AWG0 entry (Russia)
                  |
                  +--- awg1 tunnel ---&gt; AWG1 exit (abroad) ---&gt; everything else sees the exit IP
</code></pre>
<p>The split is by destination IP, not by "Russian site". The entry keeps a list of Russian networks; addresses on the list go out directly, the rest go abroad. So a Russian site behind a foreign CDN goes abroad, and some Google caches that sit on Russian addresses go direct.</p>
<p><strong>In short:</strong> install AmneziaWG on both VPS, connect the Russian entry to the foreign exit, set up routing and autostart on the entry, then test both paths from a client. Plan on about an hour; the two installs can run in parallel.</p>
<p>The scheme comes from <a href="https://github.com/glfenix">@glfenix</a> in <a href="https://github.com/bivlked/amneziawg-installer/discussions/120">discussion #120</a>. I tested it on several test servers, wrote it up as <a href="https://github.com/bivlked/amneziawg-installer/blob/main/CASCADE.en.md">CASCADE.en.md</a>, and keep a few of these running for friends. This post is the short path; the full routing script lives in the guide.</p>
<h2>Is this for you?</h2>
<p>If one server abroad is enough, you don't need a cascade. If you're fine splitting traffic on each device, <code>AllowedIPs</code> does that without a second server (<a href="https://github.com/bivlked/amneziawg-installer/blob/main/ADVANCED.en.md#allowedips-adv">split tunneling</a>). The cascade is for when you want the split on the server, the same for every client, without configuring routing on each device.</p>
<p>A few things to know before you start:</p>
<ul>
<li>It's a manual setup on top of two normal installs; the installer itself doesn't manage it.</li>
<li>It's IPv4 only. The list of Russian networks has no IPv6.</li>
<li>The entry sees all client traffic, so keep SSH access to it restricted. Don't turn UFW off "for speed" either: it costs next to nothing.</li>
<li>On mobile data, UDP itself is sometimes cut or throttled. A Russian entry doesn't change that.</li>
<li>Exit addresses do get blocked from Russia, and not rarely. Know where you'd get a new one before you need it.</li>
</ul>
<h2>Requirements for both VPS</h2>
<ul>
<li>Two clean VPS that do nothing else, with Debian 13 or Ubuntu 24.04 / 26.04 and root. The installer removes packages a VPN server doesn't need (with <code>--yes</code>, automatic security updates too) and reboots twice.</li>
<li>The entry in Russia, the exit abroad. "Near Russia" won't do for the entry, the whole point is a Russian address. For the exit, check <a href="https://github.com/bivlked/amneziawg-installer/blob/main/ADVANCED.en.md#as-blocking-adv">which hosting networks are restricted from Russia</a> before you pay.</li>
<li>The same protocol generation on both. The installer sets up AmneziaWG 3.1 by default but picks 2.0 by itself on some systems, and the entry connects to the exit as a regular client, so they have to match. Compare the "Protocol generation" line in both final reports; if they differ, <a href="https://github.com/bivlked/amneziawg-installer/blob/main/CASCADE.en.md#prereq">the guide</a> shows how to install both with <code>--protocol=2.0</code>. Your client apps need to support that generation too.</li>
<li>A real public IP on both, not provider NAT: <code>curl -s ifconfig.me</code> should print the same address <code>ip -4 addr</code> shows on the interface.</li>
<li>The exit's UDP port open in your provider's cloud firewall, if it has one. UFW on the server is handled by the installer.</li>
<li>Different subnets. Below, the entry (AWG0) uses <code>172.16.17.1/24</code> and the exit (AWG1) uses <code>172.16.61.1/24</code>.</li>
</ul>
<h2>Step 1. Install both servers</h2>
<p>On each server, download the installer from the latest release (you can <a href="https://github.com/bivlked/amneziawg-installer/blob/main/README.en.md#verifying-a-release">verify the signature</a> first):</p>
<pre><code class="language-bash">wget -O install_amneziawg_en.sh https://github.com/bivlked/amneziawg-installer/releases/latest/download/install_amneziawg_en.sh
</code></pre>
<p>Run it with its own subnet:</p>
<pre><code class="language-bash"># on AWG1 (exit)
sudo bash install_amneziawg_en.sh --yes --disallow-ipv6 --route-all --subnet=172.16.61.1/24

# on AWG0 (entry)
sudo bash install_amneziawg_en.sh --yes --disallow-ipv6 --route-all --subnet=172.16.17.1/24
</code></pre>
<p>Each server reboots twice. After every reboot, log back in and run the same command; it continues where it stopped and ends with a final report. If you want every detail of this step, see my <a href="https://dev.to/bivlked/how-to-install-amneziawg-31-on-your-own-vps-ubuntu-and-debian-3mho">full AmneziaWG installation walkthrough</a>.</p>
<p>Then add two packages on the entry:</p>
<pre><code class="language-bash">sudo apt update &amp;&amp; sudo apt install -y curl ipset
</code></pre>
<h2>Step 2. Connect the entry to the exit</h2>
<p>On the exit, create a client for the entry. It's for the link between the servers, not for a person:</p>
<pre><code class="language-bash">sudo bash /root/awg/manage_amneziawg.sh add ru_host
</code></pre>
<p>You get <code>/root/awg/ru_host.conf</code>. It holds the private key (and on 3.1 the header protection key), so copy it with <code>scp</code>, not through a messenger. Its <code>Endpoint</code> port is the one from the exit's final report: new installs pick a random port, and servers installed before v6.3.0 without <code>--port</code> listen on 39743.</p>
<p>On the entry, save it as <code>/etc/amnezia/amneziawg/awg1.conf</code> with two edits in <code>[Interface]</code>: add <code>Table = off</code> and delete the <code>DNS = ...</code> line. Copy the rest as is, don't retype it: <code>S1</code>-<code>S4</code>, <code>H1</code>-<code>H4</code> and on 3.1 <code>HeaderProtectionKey</code> must match the exit exactly. <code>Table = off</code> stops <code>awg-quick</code> from touching routes; the script in step 3 handles that.</p>
<pre><code class="language-bash">sudo chmod 600 /etc/amnezia/amneziawg/awg1.conf
sudo systemctl start awg-quick@awg1
sudo awg show awg1
</code></pre>
<p>A <code>latest handshake</code> line means the tunnel to the exit is up. Don't test it with ping from the entry: the handshake is the check, and routing for client traffic only appears in step 3.</p>
<h2>Step 3. Add the routing script and autostart</h2>
<p>Create <code>/root/awg/awg-routing.sh</code> on the entry from <a href="https://github.com/bivlked/amneziawg-installer/blob/main/CASCADE.en.md#step4">step 4 of the guide</a> and fill in the settings at the top. These four matter:</p>
<pre><code class="language-bash">CLIENT_SUBNET="172.16.17.0/24"   # the entry's client subnet (.0/24, not the server address)
AWG1_ENDPOINT="CHANGE_ME"        # the exit's IP: an address, not a host name, no port
AWG1_SRC=""                      # leave empty; set it only to run the tunnel from a separate IP
EXTRA_RU_NETS=""                 # your own addresses that should go direct
</code></pre>
<p>It's a script that rewrites routing and firewall rules on your server, so here's what it does:</p>
<ol>
<li>Downloads the list of Russian networks from ipdeny. If that fails, it uses the snapshot in my repository, and failing that, the list it already has.</li>
<li>Loads the list into an <code>ipset</code> called <code>ru</code> through a temporary set, so the active list is never empty mid-update.</li>
<li>Creates routing table 100 with a default route through <code>awg1</code> and a fallback <code>unreachable</code> route, plus a rule that sends marked traffic there.</li>
<li>Keeps the route to the exit itself outside the tunnel, so the tunnel doesn't loop into itself.</li>
<li>Marks client traffic that isn't going to a Russian address and NATs it into <code>awg1</code>.</li>
</ol>
<p>You can run it as often as you like; each run also refreshes the list. Run it once now:</p>
<pre><code class="language-bash">sudo chmod +x /root/awg/awg-routing.sh
sudo bash /root/awg/awg-routing.sh
</code></pre>
<p>The last line should start with <code>OK: cascade routing applied</code>. <code>OK WITH A CAVEAT</code> means some <code>EXTRA_RU_NETS</code> entries weren't accepted and those addresses will go abroad.</p>
<p>For autostart, create the <code>awg-routing.service</code> unit from <a href="https://github.com/bivlked/amneziawg-installer/blob/main/CASCADE.en.md#step5">step 5 of the guide</a>; it runs the script after both tunnels are up. Then:</p>
<pre><code class="language-bash">sudo systemctl daemon-reload
sudo systemctl enable awg-quick@awg1 awg-routing
sudo systemctl start awg-routing
</code></pre>
<p>Don't skip the <code>start</code>. Without it the unit waits for the next boot, and until then restarting <code>awg1</code> won't bring the routing back.</p>
<p>Restarting the tunnel and booting the server behave differently. If you restart a working <code>awg1</code>, its route vanishes for about 10 seconds and the fallback route drops client traffic instead of letting it out directly. On a test server, before that fallback existed, the entry's own address leaked out in 17 of 25 samples during a restart. But if <code>awg1</code> doesn't come up at boot, the script never runs, and clients go out directly from the entry with no split at all. It's not a kill switch.</p>
<h2>Step 4. Add clients and check both paths</h2>
<p>Clients are added on the entry, as usual:</p>
<pre><code class="language-bash">sudo bash /root/awg/manage_amneziawg.sh add my_phone
</code></pre>
<p>Import <code>my_phone.conf</code> (or scan its QR code) in an app that supports the server's generation, connect, and check the entry:</p>
<pre><code class="language-bash">ip rule show | grep fwmark
# 10000:  from all fwmark 0x1 lookup 100

ip route show table 100
# default dev awg1 scope link
# unreachable default metric 65535

sudo ipset list ru | grep "Number of entries"
# Number of entries: 8600+

systemctl is-active awg-routing
# active
</code></pre>
<p>The test I trust most is the packet counters. Zero them, make some traffic from the connected client, and look again:</p>
<pre><code class="language-bash"># on the entry
sudo iptables -t mangle -Z PREROUTING

# on the client
curl https://ifconfig.me      # prints the exit's address
ping -c3 77.88.55.242         # a Russian address (Yandex)

# on the entry
sudo iptables -t mangle -L PREROUTING -n -v
# RETURN ... match-set ru dst   &lt;- went up: traffic to Russia went direct
# MARK   ... MARK set 0x1       &lt;- went up: the rest went through awg1
</code></pre>
<p>Reboot the entry once and repeat: <code>systemctl is-enabled awg-quick@awg1 awg-routing</code>, <code>systemctl status awg-routing</code>, then the counters. Rules can look right while the traffic doesn't, so the client test is the one that counts.</p>
<h2>Keeping it running</h2>
<ul>
<li>Russian networks change, so refresh the list weekly, for example with cron: <code>echo '0 5 * * 1 root systemctl restart awg-routing' | sudo tee /etc/cron.d/awg-routing-refresh</code>. A systemd timer works too, but the unit needs a change for it; <a href="https://github.com/bivlked/amneziawg-installer/blob/main/CASCADE.en.md#update">the guide</a> has the details.</li>
<li>If <code>awg1</code> goes down and up some other way than <code>systemctl restart</code> (a <code>stop</code> and <code>start</code>, or <code>ip link set ... down</code>), its route doesn't come back by itself; <code>sudo systemctl restart awg-routing</code> fixes that.</li>
<li>Run the script again after a <code>--force</code> reinstall of the entry.</li>
<li>After a kernel update and reboot, check that the module is loaded: <code>cat /sys/module/amneziawg/version</code> exists only when it is. I update one server at a time, exit first.</li>
<li>Put some outside monitoring on both servers, even a plain ping from another machine. A dead server can otherwise sit unnoticed for hours.</li>
</ul>
<h2>What if the exit gets blocked?</h2>
<p>On the entry, <code>sudo awg show awg1</code> stops showing a fresh <code>latest handshake</code>. Clients lose foreign sites, and Russian ones too, because their DNS goes through the exit.</p>
<p>First open the console in your provider's panel: a server frozen or switched off by the provider looks exactly like a block. If the server is fine but <code>ping</code> and <code>ssh</code> to it fail from the entry, the address is most likely blocked from Russia. Test from the entry itself, not from your laptop behind a VPN; a check from another country is useful only as a comparison. Also rule out a firewall rule or a Fail2Ban ban on the entry's address.</p>
<p>The fix is a new exit, and client profiles stay the same because clients only know the entry:</p>
<ol>
<li>Install a new exit with the same <code>--subnet</code> and issue <code>ru_host</code> on it.</li>
<li>Replace <code>awg1.conf</code> on the entry (again with <code>Table = off</code>, without <code>DNS</code>) and <code>chmod 600</code> it.</li>
<li>Put the new address into <code>AWG1_ENDPOINT</code> in the script.</li>
<li><code>sudo systemctl restart awg-quick@awg1</code> and <code>sudo ip route del OLD_EXIT_IP</code>.</li>
</ol>
<p>Then check that <code>sudo awg show awg1</code> has a fresh handshake, <code>systemctl is-active awg-routing</code> says <code>active</code>, and <code>curl -s ifconfig.me</code> on a client prints the new exit. If you moved the refresh to a systemd timer, also run <code>sudo systemctl start awg-routing</code>.</p>
<p>On a test server with the 3.1 profile I rebuilt the exit from scratch, and the entry's client worked again without touching its config; foreign sites were down for about 10 seconds while the rules were reapplied. If your provider simply gave the exit a new address, you don't need a new server: change <code>Endpoint</code> in <code>awg1.conf</code> and do items 3 and 4 (some providers want a reboot from their panel first). The full recipe, with two extra checks for older scripts and <code>AWG1_SRC</code>, is in <a href="https://github.com/bivlked/amneziawg-installer/blob/main/CASCADE.en.md#replace-exit">If the exit gets blocked</a>.</p>
<h2>When routing looks wrong</h2>
<ul>
<li>Everything goes abroad, Russian sites too: the list is probably empty. Check <code>sudo ipset list ru | grep "Number of entries"</code>, <code>systemctl status awg-routing</code> and the script's last line. If ipdeny is blocked on your network, the script falls back to the snapshot; with no list at all it stops with an error.</li>
<li>One Russian service still goes abroad: it's behind a foreign CDN, its networks are registered to a company abroad, or its DNS answer, asked through the exit, may point outside Russia. Add its addresses to <code>EXTRA_RU_NETS</code> and run <code>sudo systemctl restart awg-routing</code>.</li>
<li>YouTube and Google act "Russian": some of their caches sit on Russian addresses and go direct. <a href="https://github.com/bivlked/amneziawg-installer/blob/main/CASCADE.en.md#trouble">The guide</a> shows how to push them through the exit and what it costs.</li>
<li>A site sees two different addresses: a script on the page asked a third-party IP service, and that request went through the exit. Any split behaves this way (<a href="https://github.com/bivlked/amneziawg-installer/blob/main/ADVANCED.en.md#split-detect-adv">details</a>).</li>
<li>Upload is slow but download is fine: look at the leg from the entry to the exit. Measure it with <code>iperf3</code> between the two servers (install it on both and open TCP 5201 on the exit for the entry's address only while you test).</li>
<li>Your home IPv6 address shows up: run <code>curl -6 ifconfig.co</code> on a connected device. An error is expected with this setup; your home address means IPv6 is going around the tunnel.</li>
</ul>
<h2>What to post when asking for help</h2>
<p>On 3.1, <code>awg show</code> prints the header protection key in clear text and its <code>endpoint</code> line shows your exit's address; <code>awg show ... dump</code> prints the private and preshared keys. Never paste <code>awg1.conf</code> or <code>ru_host.conf</code>. When I ask for help, I post only this:</p>
<pre><code class="language-bash">sudo awg show awg1 | grep -E '^interface:|latest handshake|transfer'
systemctl is-active awg-quick@awg1 awg-routing
ip rule show | grep fwmark
ip route show table 100
sudo ipset list ru | grep "Number of entries"
sudo iptables -t mangle -S PREROUTING | grep -E 'match-set|MARK'
sudo iptables -t nat -S POSTROUTING | grep -- '-o awg1'
</code></pre>
<p>No <code>latest handshake</code> line in the first output means no handshake has completed on the tunnel yet, and that alone narrows things down a lot.</p>
<h2>Removing the cascade</h2>
<p>To remove it, take it apart with <a href="https://github.com/bivlked/amneziawg-installer/blob/main/CASCADE.en.md#uninstall">the commands from the guide</a> and run <code>sudo bash /root/awg/manage_amneziawg.sh remove ru_host</code> on the exit. Only then use the installer's <code>--uninstall</code>, if you want it: the installer doesn't know about <code>awg1</code> or the cascade unit.</p>
<h2>Optional setups</h2>
<p>Two variations live in the same guide. <a href="https://github.com/bivlked/amneziawg-installer/blob/main/CASCADE.en.md#three-hop">Three servers</a> puts a middle server between entry and exit, so from Russia the link only shows the middle's address and a blocked exit is replaced without touching the entry. The catch is that whenever the middle's <code>awg1</code> is down, including the first seconds after a reboot, traffic leaves from the middle's address. A user in #120 built that chain; I haven't run it on my own servers. And <a href="https://github.com/bivlked/amneziawg-installer/blob/main/CASCADE.en.md#own-addresses">own addresses for each role</a> is for an entry with several IPv4 addresses.</p>
<p>Questions go to <a href="https://github.com/bivlked/amneziawg-installer/discussions/120">discussion #120</a>, where this started, or to <a href="https://github.com/bivlked/amneziawg-installer/issues">Issues</a>. If the installer saved you some time, a star on <a href="https://github.com/bivlked/amneziawg-installer">GitHub</a> helps other people find it. There's also a <a href="https://habr.com/ru/articles/1056220/">Russian write-up on Habr</a>, and how AmneziaWG hides WireGuard traffic in the first place is <a href="https://dev.to/bivlked/amneziawg-20-self-host-an-obfuscated-wireguard-vpn-that-bypasses-dpi-4692">here</a>.</p>
]]></content:encoded></item></channel></rss>