As @jtgrassie already mentioned, ufw
is one of the tools that allows you to manage your ports.
It is convenient to use ufw
in a script, in conjunction with a cronjob, that automates the opening and closing of the port. I find such script particularly useful when I may want to temporarily stop my monerod
for the sake of freeing my computer's resources (CPU/RAM/bandwith). And so the following script opens and closes port 18080 for you.
#!/usr/bin/bash
/usr/bin/pgrep -f /home/jerzy/monero-x86_64-linux-gnu-v0.17.2.0/monerod
#The following ifs deal with monerod when it is running.
if [[ "$?" == 0 ]]; then
/usr/sbin/ufw allow 18080 && /usr/sbin/ufw reload
else
/usr/sbin/ufw deny 18080 && /usr/sbin/ufw reload
fi
Please remember to replace /home/jerzy/monero-x86_64-linux-gnu-v0.17.2.0/
with the path to monerod
on your computer.
Once you've made your script executable with sudo chmod 755 name_of_the_script.sh
than proceed to schedule its execution by cron:
sudo crontab -e
and appending the following line:
* * * * * /path_to_the_script.sh