I am trying to set up the wireguard docker container as in Advanced Wireguard Hub, with one container as both server and client.
I set up the server using the default configuration in the readme, I connect my clients and everything works. Clients can ping each other and the Internet.
After adding wg1.conf and wg2.conf and restarting the server, I can no longer ping the Internet. Clients can still ping each other.
I have port 51820 forwarded from my home router to the wireguard server, firewall disabled.
docker-compose.yml
wireguard:
image: lscr.io/linuxserver/wireguard:latest
container_name: wireguard
cap_add:
- NET_ADMIN
- SYS_MODULE
environment:
- PUID=1000
- PGID=1000
- TZ=Etc/UTC
- SERVERPORT=51820
- PEERS=phone,laptop
- PEERDNS=auto
- INTERNAL_SUBNET=10.13.13.0
volumes:
- ./config:/config
- /lib/modules:/lib/modules
ports:
- 51820:51820/udp
sysctls:
- net.ipv4.conf.all.src_valid_mark=1
restart: unless-stopped
Before adding wg1.conf and wg2.conf, everything works as it should:
[user@host wireguard] $ docker compose exec wireguard ip address show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host proto kernel_lo
valid_lft forever preferred_lft forever
3: wg0: <POINTOPOINT,NOARP,UP,LOWER_UP> mtu 1420 qdisc noqueue state UNKNOWN group default qlen 1000
link/none
inet 10.13.13.1/32 scope global wg0
valid_lft forever preferred_lft forever
78: eth0@if79: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:ac:13:00:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 172.19.0.2/16 brd 172.19.255.255 scope global eth0
valid_lft forever preferred_lft forever
[user@host wireguard] $ docker compose exec wireguard ip route show
default via 172.19.0.1 dev eth0
10.13.13.2 dev wg0 scope link
10.13.13.3 dev wg0 scope link
172.19.0.0/16 dev eth0 proto kernel scope link src 172.19.0.2
[user@host wireguard] $ docker compose exec wireguard ip rule
0: from all lookup local
32766: from all lookup main
32767: from all lookup default
[user@host wireguard] $ docker compose exec wireguard ping -c4 -I wg0 10.13.13.2
PING 10.13.13.2 (10.13.13.2) from 10.13.13.1 wg0: 56(84) bytes of data.
64 bytes from 10.13.13.2: icmp_seq=1 ttl=64 time=222 ms
64 bytes from 10.13.13.2: icmp_seq=2 ttl=64 time=153 ms
64 bytes from 10.13.13.2: icmp_seq=3 ttl=64 time=392 ms
64 bytes from 10.13.13.2: icmp_seq=4 ttl=64 time=303 ms
--- 10.13.13.2 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 152.731/267.369/392.109/89.508 ms
[user@host wireguard] $ docker compose exec wireguard ping -c4 -I eth0 1.1.1.1
PING 1.1.1.1 (1.1.1.1) from 172.19.0.2 eth0: 56(84) bytes of data.
64 bytes from 1.1.1.1: icmp_seq=1 ttl=55 time=8.33 ms
64 bytes from 1.1.1.1: icmp_seq=2 ttl=55 time=8.06 ms
64 bytes from 1.1.1.1: icmp_seq=3 ttl=55 time=11.8 ms
64 bytes from 1.1.1.1: icmp_seq=4 ttl=55 time=11.2 ms
--- 1.1.1.1 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 8.064/9.828/11.766/1.646 ms
wg1.conf
(Mullvad)
[Interface]
PrivateKey = MuLlVaDpRiVaTeKeY=
Address = mull.vad.ip.addr/32
Table = 55111
PostUp = ip rule add pref 10001 from 10.13.13.0/24 lookup 55111
PreDown = ip rule del from 10.13.13.0/24 lookup 55111
[Peer]
PublicKey = MuLlVaDPeErPuBlIcKeY=
AllowedIPs = 0.0.0.0/5, 8.0.0.0/7, 10.0.0.0/13, 10.8.0.0/14, 10.12.0.0/16, 10.13.0.0/21, 10.13.8.0/22, 10.13.12.0/24, 10.13.14.0/23, 10.13.16.0/20, 10.13.32.0/19, 10.13.64.0/18, 10.13.128.0/17, 10.14.0.0/15, 10.16.0.0/12, 10.32.0.0/11, 10.64.0.0/10, 10.128.0.0/9, 11.0.0.0/8, 12.0.0.0/6, 16.0.0.0/4, 32.0.0.0/3, 64.0.0.0/2, 128.0.0.0/2, 192.0.0.0/9, 192.128.0.0/11, 192.160.0.0/13, 192.168.0.0/24, 192.168.2.0/23, 192.168.4.0/22, 192.168.8.0/21, 192.168.16.0/20, 192.168.32.0/19, 192.168.64.0/18, 192.168.128.0/17, 192.169.0.0/16, 192.170.0.0/15, 192.172.0.0/14, 192.176.0.0/12, 192.192.0.0/10, 193.0.0.0/8, 194.0.0.0/7, 196.0.0.0/6, 200.0.0.0/5, 208.0.0.0/4, 224.0.0.0/3
Endpoint = mull.vad.end.point:51820
PersistentKeepalive = 25
wg2.conf
(Proton)
[Interface]
PrivateKey = PrOtOnPrIvAtEkEy=
Address = pro.ton.ip.addr/32
Table = 55112
PostUp = ip rule add pref 10002 from 10.13.13.0/24 lookup 55112
PreDown = ip rule del from 10.13.13.0/24 lookup 55112
[Peer]
PublicKey = PrOtOnPeErPuBlIvKeY=
AllowedIPs = 0.0.0.0/5, 8.0.0.0/7, 10.0.0.0/13, 10.8.0.0/14, 10.12.0.0/16, 10.13.0.0/21, 10.13.8.0/22, 10.13.12.0/24, 10.13.14.0/23, 10.13.16.0/20, 10.13.32.0/19, 10.13.64.0/18, 10.13.128.0/17, 10.14.0.0/15, 10.16.0.0/12, 10.32.0.0/11, 10.64.0.0/10, 10.128.0.0/9, 11.0.0.0/8, 12.0.0.0/6, 16.0.0.0/4, 32.0.0.0/3, 64.0.0.0/2, 128.0.0.0/2, 192.0.0.0/9, 192.128.0.0/11, 192.160.0.0/13, 192.168.0.0/24, 192.168.2.0/23, 192.168.4.0/22, 192.168.8.0/21, 192.168.16.0/20, 192.168.32.0/19, 192.168.64.0/18, 192.168.128.0/17, 192.169.0.0/16, 192.170.0.0/15, 192.172.0.0/14, 192.176.0.0/12, 192.192.0.0/10, 193.0.0.0/8, 194.0.0.0/7, 196.0.0.0/6, 200.0.0.0/5, 208.0.0.0/4, 224.0.0.0/3
Endpoint = pro.ton.end.point:51820
PersistentKeepalive = 25
After adding wg1.conf and wg2.conf, I can’t reach the Internet, clients can still reach each other:
[user@host wireguard] $ docker compose exec wireguard ip address show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host proto kernel_lo
valid_lft forever preferred_lft forever
3: wg0: <POINTOPOINT,NOARP,UP,LOWER_UP> mtu 1420 qdisc noqueue state UNKNOWN group default qlen 1000
link/none
inet 10.13.13.1/32 scope global wg0
valid_lft forever preferred_lft forever
4: wg1: <POINTOPOINT,NOARP,UP,LOWER_UP> mtu 1420 qdisc noqueue state UNKNOWN group default qlen 1000
link/none
inet 10.72.213.75/32 scope global wg1
valid_lft forever preferred_lft forever
5: wg2: <POINTOPOINT,NOARP,UP,LOWER_UP> mtu 1420 qdisc noqueue state UNKNOWN group default qlen 1000
link/none
inet 10.2.0.2/32 scope global wg2
valid_lft forever preferred_lft forever
80: eth0@if81: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:ac:13:00:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 172.19.0.2/16 brd 172.19.255.255 scope global eth0
valid_lft forever preferred_lft forever
[user@host wireguard] $ docker compose exec wireguard ip route show
default via 172.19.0.1 dev eth0
10.13.13.2 dev wg0 scope link
10.13.13.3 dev wg0 scope link
172.19.0.0/16 dev eth0 proto kernel scope link src 172.19.0.2
[user@host wireguard] $ docker compose exec wireguard ip rule
0: from all lookup local
10001: from 10.13.13.0/24 lookup 55111
10002: from 10.13.13.0/24 lookup 55112
32766: from all lookup main
32767: from all lookup default
[user@host wireguard] $ docker compose exec wireguard ping -c4 -I wg0 10.13.13.2
PING 10.13.13.2 (10.13.13.2) from 10.13.13.1 wg0: 56(84) bytes of data.
64 bytes from 10.13.13.2: icmp_seq=1 ttl=64 time=132 ms
64 bytes from 10.13.13.2: icmp_seq=2 ttl=64 time=51.8 ms
64 bytes from 10.13.13.2: icmp_seq=3 ttl=64 time=77.5 ms
64 bytes from 10.13.13.2: icmp_seq=4 ttl=64 time=101 ms
--- 10.13.13.2 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3005ms
rtt min/avg/max/mdev = 51.759/90.444/131.518/29.414 ms
[user@host wireguard] $ docker compose exec wireguard ping -c4 -I eth0 1.1.1.1
PING 1.1.1.1 (1.1.1.1) from 172.19.0.2 eth0: 56(84) bytes of data.
64 bytes from 1.1.1.1: icmp_seq=1 ttl=55 time=16.9 ms
64 bytes from 1.1.1.1: icmp_seq=2 ttl=55 time=19.9 ms
64 bytes from 1.1.1.1: icmp_seq=3 ttl=55 time=17.8 ms
64 bytes from 1.1.1.1: icmp_seq=4 ttl=55 time=23.7 ms
--- 1.1.1.1 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3005ms
rtt min/avg/max/mdev = 16.935/19.574/23.727/2.624 ms
[user@host wireguard] $ docker compose exec wireguard ping -c4 -I wg1 1.1.1.1
PING 1.1.1.1 (1.1.1.1) from 10.72.213.75 wg1: 56(84) bytes of data.
--- 1.1.1.1 ping statistics ---
4 packets transmitted, 0 received, 100% packet loss, time 3059ms
[user@host wireguard] $ docker compose exec wireguard ping -c4 -I wg2 1.1.1.1
PING 1.1.1.1 (1.1.1.1) from 10.2.0.2 wg2: 56(84) bytes of data.
--- 1.1.1.1 ping statistics ---
4 packets transmitted, 0 received, 100% packet loss, time 3058ms
I tried adding the Mullvad/Proton interface IP adresses to Disallowed IPs when calculating Allowed IPs, but it made no difference.
I think I am missing a routing step, or there is an issue with my config files, but I don’t have the networking knowledge to debug this.
Thank you for reading if you got this far!