I'm trying to route all traffic from a specific Docker Network (10.222.111.0/24) via an wg0 systemd network interface, config:
/etc/systemd/network/30-wg0.netdev
[NetDev]
Name = wg0
Kind = wireguard
Description = Wireguard
[WireGuard]
PrivateKey = XXXX
[WireGuardPeer]
PublicKey = XXXX
AllowedIPs = 10.222.111.0/24
Endpoint = XXXX:51820
PersistentKeepalive = 25
/etc/systemd/network/30-wg0.network
[Match]
Name=wg0
[Network]
Address = 10.0.3.227/19
DNS = X.X.X.X
[Route]
Gateway = 10.0.3.227
Destination = 10.222.111.0/24
Now I can see the interface comeing up, and the correct route in the routing table
# ip route show
...
10.222.111.0/24 via 10.0.3.227 dev wg0 proto static
...
The interface is up and running
# networkctl status wg0
● 251: wg0
Link File: /lib/systemd/network/99-default.link
Network File: /etc/systemd/network/30-wg0.network
Type: none
State: routable (configured)
Address: 10.0.3.227
DNS: X.X.X.X
However an attempt at testing this fails:
# curl --interface wg0 https://ifconfig.me
# public ip of remote server
# docker network create vpn --subnet 10.222.111.0/24
# docker run --rm --dns X.X.X.X --network vpn --ip 10.222.111.110 appropriate/curl -s https://ifconfig.me
# no output
Output of tcpdump when running the docker run command:
# tcpdump -nn -i wg0 host ifconfig.me
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on wg0, link-type RAW (Raw IP), capture size 262144 bytes
08:36:16.127461 IP 10.0.3.227.33182 > 216.239.38.21.443: Flags [S], seq 1530371569, win 27600, options [mss 1380,sackOK,TS val 3454949182 ecr 0,nop,wscale 7], length 0
08:36:17.152770 IP 10.0.3.227.33182 > 216.239.38.21.443: Flags [S], seq 1530371569, win 27600, options [mss 1380,sackOK,TS val 3454950207 ecr 0,nop,wscale 7], length 0
08:36:17.152830 IP 10.0.3.227.33182 > 216.239.38.21.443: Flags [S], seq 1530371569, win 27600, options [mss 1380,sackOK,TS val 3454950207 ecr 0,nop,wscale 7], length 0
08:36:17.153083 IP 10.0.3.227.48686 > 216.239.36.21.443: Flags [S], seq 1139719299, win 27600, options [mss 1380,sackOK,TS val 3564689990 ecr 0,nop,wscale 7], length 0
08:36:18.176752 IP 10.0.3.227.48686 > 216.239.36.21.443: Flags [S], seq 1139719299, win 27600, options [mss 1380,sackOK,TS val 3564691014 ecr 0,nop,wscale 7], length 0
08:36:18.176798 IP 10.0.3.227.48686 > 216.239.36.21.443: Flags [S], seq 1139719299, win 27600, options [mss 1380,sackOK,TS val 3564691014 ecr 0,nop,wscale 7], length 0
08:36:18.176891 IP 10.0.3.227.59316 > 216.239.34.21.443: Flags [S], seq 3848190866, win 27600, options [mss 1380,sackOK,TS val 3672200215 ecr 0,nop,wscale 7], length 0
08:36:19.200840 IP 10.0.3.227.59316 > 216.239.34.21.443: Flags [S], seq 3848190866, win 27600, options [mss 1380,sackOK,TS val 3672201239 ecr 0,nop,wscale 7], length 0
08:36:19.200938 IP 10.0.3.227.59316 > 216.239.34.21.443: Flags [S], seq 3848190866, win 27600, options [mss 1380,sackOK,TS val 3672201239 ecr 0,nop,wscale 7], length 0
08:36:19.201089 IP 10.0.3.227.39842 > 216.239.32.21.443: Flags [S], seq 4281397520, win 27600, options [mss 1380,sackOK,TS val 1995655620 ecr 0,nop,wscale 7], length 0
08:36:20.224781 IP 10.0.3.227.39842 > 216.239.32.21.443: Flags [S], seq 4281397520, win 27600, options [mss 1380,sackOK,TS val 1995656643 ecr 0,nop,wscale 7], length 0
08:36:20.224894 IP 10.0.3.227.39842 > 216.239.32.21.443: Flags [S], seq 4281397520, win 27600, options [mss 1380,sackOK,TS val 1995656643 ecr 0,nop,wscale 7], length 0
^C
12 packets captured
12 packets received by filter
0 packets dropped by kernel
I'm sure I've missed something, however I fail to see what. Partly based on https://nbsoftsolutions.com/blog/leaning-on-algo-to-route-docker-traffic-through-wireguard
run
severalbash
s in the container, use them totcpdump
bothwg0
and the container interface (and maybe the host interface, too, for good measure), do the same on the other end of the wireguard interface, thenping
(orcurl
, if you insist) and see how far the packets get and where they get dropped. Then you have narrowed down the problem.wg0
, but no packets coming out. This doesn't tell us anything new, which is why you needtcpdump
on the other interfaces (container, host) too. For example, if you see packets going to the other wireguard interface on the host interface, but no packets coming back, the problem is somewhere in the wireguard connection. If there are no outgoing packets to the other end on the host, the problem is with docker routing. Etc.curl --interface wg0
test works (tcpdump confirms), however from within the docker it fails. I'm guessing a missing route rule?