DEV Community

Cover image for Separate Entry and Exit IPs on One AmneziaWG or WireGuard Server
Ivan Bondarev
Ivan Bondarev

Posted on

Separate Entry and Exit IPs on One AmneziaWG or WireGuard Server

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.

Why would you want it? In autumn 2026 this stopped being a theory for people in Russia. In early November its0ka reported on net4people 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 widely read guide by mureevms on Habr (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.

To be honest about the evidence: nobody has proven that servers get blocked because 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 separate investigation (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.

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.

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; yuretzgt suggested adding it to my installer in #384. Where I measured something myself, I say so.

The short version

  1. Get a second public IPv4 on the server and make sure it's on the interface.
  2. 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 --exit-ip.
  3. Check from a client: curl -4 ifconfig.me should print the exit address.
  4. When the exit gets blocked, put a new address in the rule. Client configs stay the same.

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 wg-quick. Full details are in the exit address section of the docs.

In the examples below the entry address is 198.51.100.2, the exit address is 203.0.113.7, the client subnet is 10.9.9.0/24 and the external interface is ens3. Take your own values from ip -br addr and the server config.

Who sees which address

Who Sees
The client's ISP and its DPI the entry address
Websites and apps, for traffic inside the tunnel the exit address
Your hosting provider both
Services the server itself talks to (updates, DNS, NTP) usually the main address, i.e. the entry

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

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.

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.

First: a second IPv4 on the server

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.

Add the address. Your provider assigns the second address in its panel, but sometimes you have to configure it on the server yourself. Look at ip -br addr 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:

# /etc/netplan/60-exit-ip.yaml
network:
  version: 2
  ethernets:
    ens3:
      addresses: [203.0.113.7/32]
Enter fullscreen mode Exit fullscreen mode

Then sudo netplan apply.

On Debian with ifupdown, put the address in a separate file, /etc/network/interfaces.d/60-exit-ip, not in 50-cloud-init: cloud-init rewrites that one at boot. Use your own interface name from ip -br addr; the stanza only adds an address to an interface that already comes up at boot. Files in interfaces.d/ are read only if /etc/network/interfaces has the line source /etc/network/interfaces.d/*. Debian cloud images have it; a manual install may not.

iface eth0 inet static
    address 203.0.113.7/32
Enter fullscreen mode Exit fullscreen mode

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 ip -br addr: 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".

Check the address.

curl -4 -sS --max-time 10 --interface 203.0.113.7 https://api.ipify.org
Enter fullscreen mode Exit fullscreen mode

It should print 203.0.113.7. 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.

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.

By hand: one SNAT rule

This recipe is for a server running awg-quick with the config at /etc/amnezia/amneziawg/awg0.conf: a manual install and most similar scripts. For plain WireGuard it's the same with wg-quick@wg0 and /etc/wireguard/wg0.conf.

If the server was set up by my installer, use the command from the next section instead. manage exit-ip recognizes the rule only in exactly the form shown below, appended to the PostUp and PostDown lines with ;. Written any other way (another option order, -A, a separate PostUp line, a script) it won't see it: changing the exit would leave you with two rules, and exit-ip off 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.

1. Add the rule. Stop the service first, then edit the file, then start it. I'll explain why not restart in the troubleshooting section.

sudo systemctl stop awg-quick@awg0
sudo nano /etc/amnezia/amneziawg/awg0.conf
Enter fullscreen mode Exit fullscreen mode

In the [Interface] section, append the rule with ; to the end of the existing PostUp line, and the same with -D to the end of PostDown:

PostUp = <what was already there>; iptables -t nat -I POSTROUTING -s 10.9.9.0/24 -o ens3 -j SNAT --to-source 203.0.113.7
PostDown = <what was already there>; iptables -t nat -D POSTROUTING -s 10.9.9.0/24 -o ens3 -j SNAT --to-source 203.0.113.7
Enter fullscreen mode Exit fullscreen mode
sudo systemctl start awg-quick@awg0
sudo iptables -t nat -S POSTROUTING
Enter fullscreen mode Exit fullscreen mode

-I puts the rule first, above MASQUERADE. -s and -o 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.

2. Check from a client.

curl -4 -s ifconfig.me
Enter fullscreen mode Exit fullscreen mode

It should print the exit address. The same curl 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.

With my installer: the --exit-ip option

If you set up the server with my installer, one option does it (available since v6.3.0; the second address must already be on the interface):

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
Enter fullscreen mode Exit fullscreen mode

--endpoint 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 src in ip route get 1.1.1.1), and your provider may have made a different address the main one than you expect.

On a running server, turn the exit on with sudo bash /root/awg/manage_amneziawg.sh exit-ip 203.0.113.7 and off with exit-ip off. 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 manage refuse and tell you why.

A server set up by the Amnezia VPN app (Docker)

The Amnezia VPN app installs AmneziaWG in a Docker container, so a line in PostUp won't do. The rule belongs on the host, and there are two traps:

  • On my test setup the container reached the internet through the amnezia-dns-net network (172.29.172.0/24) that the app attaches, and a rule only for Docker's default bridge 172.17.0.0/16 had no effect. Which network the container uses seems to depend on the order the networks were attached, so the rule covers both.
  • systemctl restart docker puts its own MASQUERADE above your SNAT, and the exit silently goes back to the entry address.

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 /etc/systemd/system/amnezia-exit-ip.service:

[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>/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>/dev/null; do :; done; done'

[Install]
WantedBy=docker.service
Enter fullscreen mode Exit fullscreen mode
sudo systemctl daemon-reload && sudo systemctl enable --now amnezia-exit-ip
sudo iptables -t nat -S POSTROUTING
Enter fullscreen mode Exit fullscreen mode

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 203.0.113.7, 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.

What happens if the exit address disappears

Clients don't start leaving from the entry address. Usually their connection just stops.

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.

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.

Client DNS stops with everything else: by default my installer gives clients 1.1.1.1 and 1.0.0.1, and those queries go through the tunnel, from the exit address. From the outside it looks like "nothing opens at all". In this situation manage check says:

[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
Enter fullscreen mode Exit fullscreen mode

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 exit-ip off works. So it matters that the rule doesn't vanish by accident; see the first item under troubleshooting.

If the exit gets blocked

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.

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.

Swapping looks like this: get a new address from your provider, configure it and make sure ip -br addr shows it, then stop, replace the address in both lines, start, and check from a client. (The curl --interface 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, manage exit-ip <new address> (it asks for confirmation; --yes skips the question). Client configs stay the same.

Replacing a blocked exit address: the entry and client configs stay the same, only the exit address changes

Connections that are already open (a long download, a call) keep the old address until they close, unless the server has the conntrack tool; that's what I saw on my test server. With it, manage exit-ip 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 apt install conntrack won't find it, because the installer clears apt's package lists at the end. Install it like this:

sudo apt update && sudo apt install conntrack
Enter fullscreen mode Exit fullscreen mode

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.

Troubleshooting

I removed the rule from the config, but the client still leaves from the exit address. That happened to me while testing the rollback. restart stops the service using the PostDown from the file on disk at that moment, and the delete command is already gone from it. The rule stays in iptables. So always stop, edit, start. The same goes for wg-quick. If you already made the mistake, remove the rule by hand: sudo iptables -t nat -D POSTROUTING -s 10.9.9.0/24 -o ens3 -j SNAT --to-source 203.0.113.7. Same when you change the address by hand.

I set the source on the default route and nothing changed. You'll find advice to use ip route replace default via <gateway> dev ens3 src 203.0.113.7 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 src. Besides, src sets the source for the server's own connections; it doesn't rewrite the source of forwarded client packets. Those need SNAT.

I want IPv6 in the tunnel and a separate exit. The SNAT rule is IPv4 only, so with the IPv6 tunnel for clients (--allow-ipv6-tunnel) 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.

I manage nftables directly, not iptables. On current Ubuntu and Debian, iptables 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: ip saddr 10.9.9.0/24 oifname "ens3" snat to 203.0.113.7. That only works if both rules are in the same chain. If the masquerade lives in another table (iptables-nft creates ip nat), the order is decided by chain priority, not position: give your chain a lower number, for example priority srcnat - 1.

Both addresses got blocked at once. 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.

What this doesn't solve

Detection of the protocol itself. That's the job of obfuscation, and AmneziaWG has its own (the 3.1 profile, details in the docs).

Allowlists on mobile networks. If the entry address isn't on the allowed list, separating addresses won't help.

A whole subnet getting blocked, or the new exit address getting blocked again.

Going further: a separate exit server and three-server setups

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 two-VPS AmneziaWG cascade with a Russian entry and a foreign exit; in that version Russian destinations leave directly from the entry.

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 (own addresses for each role).

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 (replacing the exit). But while the awg1 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; stromnov tested it on three VPS in discussion #120 (in Russian).

Has your exit address been blocked?

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.

If the installer saves you some time, a star on GitHub helps other people find it.

Links:

Thanks to yuretzgt for the idea, Johnconnor795 for testing it on a live server, and stromnov for the three-server setup.

Top comments (0)