Skip to content

feat: custom wireguard port - #366

Merged
psviderski merged 4 commits into
psviderski:mainfrom
dasunsrule32:feat/wg-port
May 19, 2026
Merged

psviderski merged 4 commits into
psviderski:mainfrom
dasunsrule32:feat/wg-port

Conversation

@dasunsrule32

@dasunsrule32 dasunsrule32 commented May 13, 2026 •

Copy link
Copy Markdown
Contributor

Init machine with custom wireguard port:

uc machine init [email protected] -c default --wg-port 51823 -n host

Add machine with custom wireguard port:

uc machine add [email protected] -c default --wg-port 51823 -n host

Custom Wireguard port:

❯ ./uncloud machine ls
NAME       STATE   ADDRESS         PUBLIC IP      WIREGUARD ENDPOINTS                      MACHINE ID
host       Up      10.210.2.1/24   xx.xx.xxx.3    xx.xx.xxx.3:51823                        ffb6f370c69553fbf90c4e8541531944

Resolves #228

Init machine with custom wireguard port:
```
uc machine add [email protected] -c default --wg-port 51823 -n host
```
Add machine with custom wireguard port:
```
uc machine add [email protected] -c default --wg-port 51823 -n host
```
Custom Wireguard port:
```
❯ ./uncloud machine ls
NAME       STATE   ADDRESS         PUBLIC IP      WIREGUARD ENDPOINTS                      MACHINE ID
host       Up      10.210.2.1/24   xx.xx.xxx.3    xx.xx.xxx.3:51823                        ffb6f370c69553fbf90c4e8541531944
```
@dasunsrule32

Copy link
Copy Markdown
Contributor Author

Addresses #228

@dasunsrule32

dasunsrule32 commented May 13, 2026 •

Copy link
Copy Markdown
Contributor Author

I am able to get to services on the other nodes with this configuration:

ping 10.210.1.2
PING 10.210.1.2 (10.210.1.2) 56(84) bytes of data.
64 bytes from 10.210.1.2: icmp_seq=1 ttl=63 time=17.1 ms
64 bytes from 10.210.1.2: icmp_seq=2 ttl=63 time=18.0 ms

and back out to the other machine on the custom port:

root@uncloud1# ping 10.210.2.1
PING 10.210.2.1 (10.210.2.1) 56(84) bytes of data.
64 bytes from 10.210.2.1: icmp_seq=1 ttl=64 time=17.6 ms
64 bytes from 10.210.2.1: icmp_seq=2 ttl=64 time=16.3 ms

Other machines in cluster:

NAME       STATE   ADDRESS         PUBLIC IP      WIREGUARD ENDPOINTS                      MACHINE ID                         
host       Up      10.210.2.1/24   xx.xx.xxx.3    xx.xx.xxx.3:51823                        ffb6f370c69553fbf90c4e8541531944   
uncloud1   Up      10.210.0.1/24   xx.xxx.xx.62   192.168.0.21:51820, xx.xxx.xx.62:51820   8f4fbdedb4f7cb97bf1f8c385858195e   
uncloud2   Up      10.210.1.1/24   xx.xxx.xx.62   192.168.0.22:51820, xx.xxx.xx.62:51820   fa77298842fc48d25ab2033561b13f97

Listening port:

ss -ulnp | grep 51823
UNCONN 0      0                                        0.0.0.0:51823      0.0.0.0:*                                                
UNCONN 0      0                                           [::]:51823         [::]:* 

ListenPort:

python3 -m json.tool /var/lib/uncloud/machine.json | grep ListenPort
        "ListenPort": 51823,

Machine Config:

cat /var/lib/uncloud/machine.json
{
  "ID": "ffb6f370c69553fbf90c4e8541531944",
  "Name": "host",
  "Network": {
    "Subnet": "10.210.2.0/24",
    "ManagementIP": "fdcc::::4e27",
    "ListenPort": 51823,
    ...
}

Comment thread internal/machine/network/config.go Outdated
Comment thread internal/machine/network/config.go Outdated
Comment thread internal/machine/network/config.go Outdated
Comment thread internal/machine/network/config.go Outdated
@dasunsrule32

Copy link
Copy Markdown
Contributor Author

Yeah, I'll make the adjustments. Internet is down, so I haven't been able to test the changes and make sure everything looks good.

- Rename `network.WireGuardPort` to `network.DefaultWireGuardPort` for clarity
- Rename `network.Config.ListenPort` field to `network.Config.WireGuardPort` for consistency
- Rename `network.Config.EffectiveListenPort()` method to `network.Config.EffectiveWireGuardPort()`
- Update all references across CLI commands (add, init, update), internal machine logic, and experiments
- Improves naming consistency and makes the purpose of the port configuration more explicit

@psviderski psviderski left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good 👍

Please see a few comments on --wg-port and --wg-endpoints mismatch and using the pinned proto tooling version for generating Go code.

Please also run make cli-docs after changing help strings for flags.

Comment thread cmd/uncloud/machine/init.go Outdated
Comment thread cmd/uncloud/machine/add.go Outdated
Comment thread cmd/uncloud/machine/init.go
Comment thread internal/cli/flags.go Outdated
Comment thread internal/machine/api/pb/caddy.pb.go Outdated
…or endpoints

- Add port range validation (1-65535) in machine add and init commands
- Update ParseWireGuardEndpoints to accept configurable default port parameter
- Pass custom --wg-port value as default when parsing endpoints instead of hardcoded constant
- Update help text to reference --wg-port value instead of hardcoded port number
- Remove unnecessary network package import from flags.go
- Regenerate protobuf files with updated protoc versions (v1.34.2 and v5.27.3)
- Ensures WireGuard endpoints use the configured port when port is omitted from endpoint specification
- Update uc_machine_add.md to document --wg-port flag and clarify default port behavior
- Update uc_machine_init.md to document --wg-port flag and clarify default port behavior
@dasunsrule32
dasunsrule32 requested review from miekg and psviderski May 18, 2026 15:09
@psviderski
psviderski merged commit 424263b into psviderski:main May 19, 2026
4 checks passed
@dasunsrule32
dasunsrule32 deleted the feat/wg-port branch May 19, 2026 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make WireGuard listen port (51820/udp) configurable

3 participants