# 11. Replacing an existing VPN server

You can run Tunnelry **next to** the VPN server you have now, check that everything works, and only then switch the
people over. This chapter is the checklist, with the places where it usually goes wrong: the network, not Tunnelry, is
where most of the surprises are.

## The plan

1. Install Tunnelry on a **new machine** in the same network as the old server, with its **own VPN networks** (the
   setup wizard proposes free ones). Both servers can run side by side.
2. Make the new server work for one device. Only then move the others, one by one, and finally turn the old one off.
3. Move the DNS last, or not at all, if the old server did not do it ([guide 10](https://tunnelry.com/docs/dns/index.md)).

## 1. Decide what the network should see

When a VPN device talks to something in your network, that thing sees an address. You decide which one, on the **VPN
server** page, under **Which addresses do other networks see?**

| Choice | The device in your network | You need |
|---|---|---|
| This server's address, always (NAT) | the address of the Tunnelry server | nothing |
| The device's own address in your networks, this server's address on the internet | the address of the VPN device (for example `10.213.1.2`) | a route to the VPN networks through the server |
| The device's own address, always (no NAT) | the address of the VPN device | a route to the VPN networks through the server, and the router translates for the internet |

Choose the first one if you have nothing in your network that goes by the address of a VPN device. Choose the second or
third one if the **router, a NAS or a firewall decides by the address of the VPN device**: access rules that list
`10.8.1.0/24` for the old VPN, a group such as "VPN admins", a firewall that lets only these networks reach a port. With
NAT everything looks like one device (the Tunnelry server), the rules do not match, and the connection is dropped
without a word. This is the most common reason for "the VPN connects, but I cannot reach anything".

## 2. Give the router a way back

If you chose the second or the third option, devices in your network answer to the **VPN address**, so the router
needs a static route for each VPN network, with this server as the next hop:

| Destination | Next hop |
|---|---|
| the OpenVPN network of Tunnelry (for example `10.213.0.0/16`) | the address of the Tunnelry server |
| the WireGuard network of Tunnelry (for example `10.214.0.0/16`), if you use WireGuard | the address of the Tunnelry server |

The networks are on the **VPN server** page. Without the route, requests arrive and the replies are lost: the
connection hangs instead of failing.

## 3. Put the new networks everywhere the old ones are

Wherever the old VPN network is on an allow list, add the new ones. Go through every place that filters by source address:

- the **router's** access rules and address groups,
- a **NAS** (for example Synology: the access control profile and the firewall),
- the **firewalls of servers** (UFW, `iptables`),
- **Docker hosts**: published ports are filtered by the `DOCKER-USER` chain, not by UFW. A rule there that lets only
  `10.8.1.0/24` through also stops the new networks. It is easy to miss, because it only affects containers,
- reverse proxies and anything with an "allowed networks" setting.

Do not forget the WireGuard network if you use it. Add only the networks of the roles that need the service.

## 4. Roles: name every network

The setup wizard proposes only the network the server is in. A role reaches nothing else. On the **Roles** page add
the networks your people need (every VLAN and every server network), or even single addresses, and the ports.

## 5. Move the DNS and your own names

If the old server (or a DNS filter such as AdGuard Home) gave names to your devices, copy the important settings to the
**DNS** page: own names (rewrites), blocked and allowed names, a filter list. Then change the DNS server in the DHCP
settings of your router, or move devices one by one. Names that point to a server in your network need a rule in the role
that lets the device reach that address.

## 6. Find out where the traffic stops

When something does not work, do not guess: find the place where the packets disappear. From a connected device, first
check the name and the way:

```bash
nslookup serwer.example.com
```

On the Tunnelry server, install `tcpdump` once (`sudo apt install -y tcpdump`) and watch one connection while the
device tries it (put the address of the target in place of `192.168.100.10`):

```bash
sudo tcpdump -ni any -c 20 host 192.168.100.10 and tcp port 443
```

Read the result like this:

| What you see | Where the problem is |
|---|---|
| The request comes in on `tunnelry0` and does **not** go out | the role does not allow it (guide 3), or the target is outside the networks of the role |
| It goes out, with the address you expected, and no reply returns | the router, a firewall in between, or the target itself drops it |
| It goes out with the **server's** address instead of the device's | NAT is on, and a rule that lists the VPN networks does not match (step 1) |
| The reply comes back to the server but the device does not receive it | very rare: check the role and the firewall of the server |

Run the same `tcpdump` on the target machine to see whether the request arrives there. If it does not, the router
dropped it (step 3, router). If it arrives and no reply leaves, the machine's own firewall dropped it (step 3,
firewalls). If a reply leaves but never reaches the Tunnelry server, look at the route back (step 2).

## 7. Switch over

When one device works, create profiles for the rest, hand them out, and watch the **Dashboard** until everybody is
connected. Keep the old server on for a few days, and turn it off only when nobody uses it. The old profiles stop working
when the old server is gone, so tell people to remove them.

Next: [uninstalling and troubleshooting](https://tunnelry.com/docs/uninstall-and-troubleshooting/index.md).
