Server 1 is the Wireguard server (listening). Its Wireguard interface wg0
interface IP is 10.100.100.1.
Server 2 is a Wireguard client connecting via the Internet to server 1. Its Wireguard interface gets the IP address 10.100.100.2.
Is there any way, from server 2, to programmatically determine the IP address of the interface on server 1? i.e. from server 2, I want to programmatically get the value 10.100.100.1
.
EDIT: Worth noting that both ends of the tunnel are running Linux, so no need to worry about Windows here.
This is relevant to me because I am writing some scripts on the client end that setup some complex routing and NAT rules, and I need to know the IP address that packets from the server will arrive into the client from via the Wireguard tunnel. In other words, I need to do things to packets coming from 10.100.100.1
. I want to do this programmatically because I want to replicate this setup and I do not like the idea of hardcoding the tunnel host interface IP address in my scripts.
I do not want to simply match on packets coming into the client's wg0
because there's the possibility of packets with other source IPs coming in based on my advanced routing setup. For example, packets may come in from another client machine at 10.100.100.3
via the tunnel. In other words, packets originating from the tunnel server itself need to be treated differently than packets routed into the tunnel from the server.