linuxserver / docker-wireguard

GNU General Public License v3.0
2.9k stars 360 forks source link

[BUG] SERVERPORT is being ignored #313

Closed slush0 closed 9 months ago

slush0 commented 9 months ago

Is there an existing issue for this?

Current Behavior

When I setup the container (using Portainer Stacks), everything works as expected, only SERVERPORT variable is being ignored; I set up SERVERPORT=1195, but I see the wg0.conf contains ListenPort = 51820 and also docker exec -ti wireguard wg displays that the process is listening at port 51820. It seems that the SERVERPORT directive is ignored when the config is recreated.

I tried to change some other values to trigger wg0.conf recreation (like SERVERADDRESS) and it regenerated successfully. So it is only SERVERPORT being ommited.

Please note that when I change server port in wg0.conf manually, everything works as expected. I'm also aware that this change will be lost on next config regeneration.

Expected Behavior

Both content of wg.conf and docker exec -ti wireguard wg should have the same server port as stated in Docker environment.

Steps To Reproduce

  1. Clean setup based on docker-compose method as described on https://github.com/linuxserver/docker-wireguard/
  2. Set SERVERPORT to alternate value
  3. Start the container
  4. wg is listening on port 51820 instead.

Environment

- OS:Ubuntu Server 22.04
- How docker service was installed: Clean setup based on docker-compose method as described on https://github.com/linuxserver/docker-wireguard/

CPU architecture

x86-64

Docker creation

services:
  wireguard:
    image: lscr.io/linuxserver/wireguard:latest
    container_name: wireguard
    cap_add:
      - NET_ADMIN
      #- SYS_MODULE #optional
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Etc/UTC
      - SERVERURL=*****redacted*****
      - SERVERPORT=1195
      - PEERS=1
      #- PEERDNS=auto #optional
      - INTERNAL_SUBNET=192.168.70.0
      - ALLOWEDIPS=172.100.0.0/16
      - PERSISTENTKEEPALIVE_PEERS=all
      - LOG_CONFS=true
    volumes:
      - ./wireguard-config:/config
      #- /lib/modules:/lib/modules #optional
    networks:
      - default
      - my_vpn
    ports:
      - 1195:1195/udp
    sysctls:
      - net.ipv4.conf.all.src_valid_mark=1
    restart: unless-stopped

Container logs

───────────────────────────────────────
GID/UID
───────────────────────────────────────

User UID:    1000
User GID:    1000
───────────────────────────────────────

Uname info: Linux 472f3c9f2fae 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64 GNU/Linux
**** It seems the wireguard module is already active. Skipping kernel header install and module compilation. ****
**** Server mode is selected ****
**** PersistentKeepalive will be set for: all ****
**** External server address is set to REDACTED ****
**** External server port is set to 1195. Make sure that port is properly forwarded to port 51820 inside this container ****
**** Internal subnet is set to 192.168.70.0 ****
**** AllowedIPs for peers 172.100.0.0/16 ****
**** PEERDNS var is either not set or is set to "auto", setting peer DNS to 192.168.70.1 to use wireguard docker host's DNS. ****
**** Server mode is selected ****
**** No changes to parameters. Existing configs are used. ****
[custom-init] No custom files found, skipping...
.:53
CoreDNS-1.10.1
linux/amd64, go1.20.11, 
**** Found WG conf /config/wg_confs/wg0.conf, adding to list ****
**** Activating tunnel /config/wg_confs/wg0.conf ****
[#] ip link add wg0 type wireguard
[#] wg setconf wg0 /dev/fd/63
[#] ip -4 address add 192.168.70.1 dev wg0
[#] ip link set mtu 1420 up dev wg0
[#] ip -4 route add 192.168.70.2/32 dev wg0
[#] iptables -A FORWARD -i wg0 -j ACCEPT; iptables -A FORWARD -o wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth+ -j MASQUERADE
**** All tunnels are now active ****
[ls.io-init] done.
github-actions[bot] commented 9 months ago

Thanks for opening your first issue here! Be sure to follow the relevant issue templates, or risk having this issue marked as invalid.

aptalca commented 9 months ago

Dupe #163