Free 80,443 Ports On Synology NAS (DSM)¶
Synology NAS (DSM) is a network storage device, with some additional features like native support for virtualization, and docker support. One of the issues is that the default ports 80 and 443 are used by the web server even if you change the default ports of the Synology's DSM to other ports. In some cases, you want to use these ports for other purposes, such as a reverse proxy as an entry point for the web services. The following steps will help you to free the default ports 80 and 443 on the Synology NAS (DSM) for other purposes.
Configure the Synology NAS (DSM) to Listen on Other Ports¶
First, you need to configure the Synology NAS (DSM) to listen on other ports then 80, 443.
Login to the Synology NAS (DSM) as administrator user open Control Panel
and find Login Portal
under System
Under DSM
tab, change the DSM port (http) to a different port then 80, and the DSM port (https) to a different port then 443.
Click Save
to save the changes. Then, re-login to the Synology NAS (DSM) with the new port as administrator user as we did above.
Disable the Synology NAS (DSM) to Listen on 80, 443 Ports¶
Synology NAS (DSM) will listen on 80, 443 ports after each reboot. Therefore, the changes will be lost after each reboot. The workaround is to run the a script to free the ports 80, 443 on each time the Synology NAS (DSM) is boots.
The following one liner will free the ports 80, 443 on Nginx web server of the Synology NAS (DSM), until the Synology NAS (DSM) is rebooted. It removes the port 80, 443 from the Nginx
config and restarts the Nginx
service.
sed -i -e 's/80/81/' -e 's/443/444/' /usr/syno/share/nginx/server.mustache /usr/syno/share/nginx/DSM.mustache /usr/syno/share/nginx/WWWService.mustache
synosystemctl restart nginx
sed -i -e 's/80/81/' -e 's/443/444/' /usr/syno/share/nginx/server.mustache /usr/syno/share/nginx/DSM.mustache /usr/syno/share/nginx/WWWService.mustache
synoservicecfg --restart nginx
In order to persist the changes, we will create a Scheduled Task
to run the above script on each reboot.
Head to Control Panel
and find Task Scheduler
, then click Create
and select Triggerd Task
- User-defined script
.
At Create Task
- General
page, fill in the following information:
Task: Disable_DSM_Listening_on_80_443
User: root
Event: Boot-up
Pre-taks: None
Enabled: Yes
At Task Settings
tab, under Run command
fill the User-defined script
with the following depending on Synology NAS (DSM) version:
sed -i -e 's/80/81/' -e 's/443/444/' /usr/syno/share/nginx/server.mustache /usr/syno/share/nginx/DSM.mustache /usr/syno/share/nginx/WWWService.mustache
synosystemctl restart nginx
sed -i -e 's/80/81/' -e 's/443/444/' /usr/syno/share/nginx/server.mustache /usr/syno/share/nginx/DSM.mustache /usr/syno/share/nginx/WWWService.mustache
synoservicecfg --restart nginx
Suggestion: Select the Notification when the task is terminated abnormally.
Click OK
. The new task should be created. You can check the task by clicking Run
in the Task Scheduler
page. Preferred to reboot the Synology NAS (DSM) to make sure the changes are applied at boot.