Archived article. DWG builds and accompanying scripts have not been updated for a long time and require serious updates. The material is preserved as historical.
Hello everyone! I’m replying to a popular question: how to ensure the connection to a WireGuard server goes through a port different from the standard 51820.
WireGuard is a modern VPN protocol that provides secure and private connections to remote networks. By default, WireGuard uses port 51820 to connect to the server, however sometimes there may be a need to change this port to another.
Changing the port in docker-compose.yml
To change the port for connecting to the WireGuard server, you need to modify the docker-compose.yml file used to run the WireGuard container.
Here is an example of corrected code in the file docker-compose.yml:
- WG_PORT=8443
- WG_DEFAULT_ADDRESS=10.10.10.x
- WG_DEFAULT_DNS=10.2.0.100
- WG_ALLOWED_IPS=10.2.0.0/24, 0.0.0.0/0, ::/0
- WG_PERSISTENT_KEEPALIVE=25
- WG_MTU=1280
image: ditek/wg-easy
container_name: wg-easy
volumes:
- .:/etc/wireguard
ports:
- "8443:51820/udp"
- "51821:51821/tcp"
What we changed
- Added the environment variable
WG_PORT=8443— it allows setting a new port for connecting to the WireGuard server. - In the ports section we specified
"8443:51820/udp". This means that the external port 8443 will be forwarded to the internal port 51820 of the WireGuard container. Thus we set a new port for connecting to WireGuard.
After applying these changes and restarting the container, connections to the WireGuard server will go through port 8443.
Verifying operation
In the DWG-CLI variant, it will be the same: change serverport and similarly fix port forwarding.
The article was first published on 01.08.2023 on openode.xyz; moved and updated on 04.08.2026.
