Update Arc Port via script

Hello! My internet is behind CGNAT so I have been using the port forwarding option from Proton VPN to connect Arc to roon which works quite well.

But since Proton always assigns a random port when a new connection is initiated I would like to update the port dynamically. I currently have a script that gives me back the open port and I can see that in RoonServer “Settings” folder there is a file for the port that is assigned named: “https_last_port”, updating this file with the current port I get from my script works but only after I restart my Roon Server, is there a way I could force a refresh after updating that file?

You’ve nor stated what OS hosts Roon Server or ProtonVPN. This information would be really helpful.

Nonetheless, I wondeing why you’ve taken this approach when Proton supports port forwarding. On Linux I use natpmpc to achieve this.

Sorry I am on Mac OS, on Mac port forwarding is not supported so I am using wireguard and looping natpmpc to keep the random assigned port open for the vpn.

I am taking this approach because each time a connection is lost a new port is assigned and I need to manually check which one it is and add it on Roon ARC settings, ideally I would be able to just replace the port that is written on the file https_last_port with a “echo $port > https_last_port” and force a refresh on the server to re-read that port like it is done on the user interface via the refresh button.

restarting the server after https_last_port is updated works but I was wondering if there is a way to do it without having to restart the server. The server is currently running on my laptop and not on a machine that I could just setup and forget.

Hopefully that makes more sense.

I don’t entirely understand. ARC shouln’t change ports once set. You should be able to set port forwarding manually on macOS.

Yes, ARC doesn’t change the port but Proton VPN does, if I disconnect for let’s say 5 min I will get assigned a new port.

Here is the script I am using:

#!/bin/bash

last_port=0 

while true; do
    date

    if natpmpc -a 1 0 udp 60 -g 10.2.0.1 && natpmpc -a 1 0 tcp 60 -g 10.2.0.1 > /tmp/natpmpc_output; then
        port=$(grep 'TCP' /tmp/natpmpc_output | grep -o 'Mapped public port [0-9]*' | awk '{print $4}')
        echo "Current port: $port"

        if [[ "$port" != "$last_port" ]]; then
            echo "Opened or changed port: $port"
            osascript -e "display notification \"Opened or changed port: $port\" with title \"NAT-PMP Port Mapping\""
            last_port=$port 
            
            echo $port > /Users/Username/Library/RoonServer/Settings/https_last_port
        fi
    else
        echo -e "ERROR with natpmpc command \a"
        break
    fi

    sleep 45
done

so after this runs my RoonServer will have the https_last_port file updated with the correct port but I will need to restart my Roon Server for it to take place and wanted to avoid that if it’s somehow possible, might not be :slight_smile:

Quick edit to add that for now the solution I found is to pkill RoonAppliance when the port changes, this freezes the UI a bit while waiting for the server but I then get the port updated automatically on Roon when RoonAppliance is restarted.

Do you have any spare devices that could support being a Subnet Router and use Tailscale? A lot of people have turned to this as they’re behind a CGNAT.

It might help in such as case as this so you’re not needlessly tinkering away, just to get things to work?

Tailscale works but most of the time I need my VPN on for work and both together don’t interact very well. There was a very interesting solution on this post: https://lemmy.world/post/7281194

But since I am behind CGNAT my exit node is still slow as they have to go through a relay I think.

Hopefully fibre will eventually come to my area but for now I am stuck with mobile internet if I want to get good speeds.

I’ve just checked on Linux, and it’s the same: the connection returns the available port using natpmpc (I use this occasionally for P2P, and would need to change the port for each session.)

However, you can specify the local port by executing this:

natpmpc -a 1 <your-port> udp 60 -g 10.2.0.1

Note that the original zero (0) means random.

Thank you! I will give this a try.

I haven’t tested this as I’m mobile-tethered at the moment. I’ll check when I return home.