linuxserver / docker-wireguard

GNU General Public License v3.0
2.97k stars 367 forks source link

External Port is not set in the peer config #157

Closed mrtnd closed 2 years ago

mrtnd commented 2 years ago

External Port is not set in the client config and the log shows the default port as well.


Expected Behavior

When changing the External port to some other number, That port should be set properly in the client config. I'm talking about the port that you map into the container

Current Behavior

Port not set. Default Port is used instead, therefore tunnel is not working. Manual change in the config fixes the problem.

Steps to Reproduce

  1. Use docker cli to create the wireguard server container.
  2. set external port to some other value, than 51820. In my example "-p 55820:51820/udp"
  3. check if the port is set in the client config

Environment

OS: Windows CPU architecture: x86_64 How docker service was installed:

official docker desktop for windows. using wsl2

Command used to create docker container (run/create/compose/screenshot)

docker run -d --name=wireguard --cap-add=NET_ADMIN --cap-add=SYS_MODULE -e PUID=1000 -e PGID=1000 -e TZ=Europe/London -e SERVERURL=<IP/DOMAIN> -e SERVERPORT=51820 -e PEERS=<2_peers> -e PEERDN S=auto -e INTERNAL_SUBNET=10.13.13.0 -e ALLOWEDIPS=0.0.0.0/0,::0/0 -p 55820:51820/udp -v wireguard:/config -v /lib/modules:/lib/modules --sysctl="net.ipv4.conf.all.src_valid_mark=1" --restart unless-stopped li nuxserver/wireguard

Docker logs

External server port is set to 51820. Make sure that port is properly forwarded to port 51820 inside this container

and this is the peer_config:

[Interface] Address = 10.13.13.3 PrivateKey = privkey ListenPort = 51820 DNS = 10.13.13.1

[Peer] PublicKey = pubkey Endpoint = IP/DOMAIN:51820 AllowedIPs = 0.0.0.0/0,::0/0

output of docker ps:

linuxserver/wireguard "/init" 4 hours ago Up 4 hours 0.0.0.0:55820->51820/udp wireguard

github-actions[bot] commented 2 years ago

Thanks for opening your first issue here! Be sure to follow the bug or feature issue templates!

mrtnd commented 2 years ago

Just tested on a raspberry pi 4 running ubuntu server. Using docker-compose this time and the result is the same. The default port is used instead.

docker-compose:

SERVERPORT=51820 ports:

  • 56820:51820/udp

logs:

External server port is set to 51820. Make sure that port is properly forwarded to port 51820 inside this container

peer config:

Endpoint = IP/DOMAIN:51820

docker ps:

0.0.0.0:56820->51820/udp, :::56820->51820/udp

aptalca commented 2 years ago

The processes inside the container have no way of knowing what host port you're mapping. That's why we have an env var named SERVERPORT. You need to set that to whatever external port you're exposing publicly so the client confs use that.

mrtnd commented 2 years ago

The processes inside the container have no way of knowing what host port you're mapping. That's why we have an env var named SERVERPORT. You need to set that to whatever external port you're exposing publicly so the client confs use that.

ohh i got it all wrong... my bad. I thought that the SERVERPORT is the port that the server is listening on inside the container.