Today we had a client who wanted us to whitelist Cloudflare IP’s on thirteen of his Plesk-Onyx servers. If you have installed and enabled the Plesk Firewall extension. Then you can whitelist those IP ranges from Plesk >> Tools & Settings >> Firewall (Under Security) >> Modify Plesk Firewall Rules >> Add Custom Rule >> Name the rule to “Cloudflare IPs”, add port 80 and 443, add the entire list of Cloudflare IP’s and save and apply it. But this method will be very time consuming and inefficient if you have do it on thirteen Plesk servers. As a system administrator you will have have to find faster and efficient way to get these things done. Fortunately Plesk also provides a command line tool to manage the firewall
We can use this tool to whitelist the IP’s fast. First of all SSH to the server as root and add the cloudflare IP ranges https://www.cloudflare.com/ips/
[root@srv ~]#/usr/local/psa/bin/modules/firewall/settings -s -name 'Cloudflare IPs' -direction input -action allow -ports '80/tcp,443/tcp' -remote-addresses "22.214.171.124/20,126.96.36.199/22,188.8.131.52/22,184.108.40.206/22,220.127.116.11/18,18.104.22.168/18,22.214.171.124/20,126.96.36.199/20,188.8.131.52/22,184.108.40.206/17,220.127.116.11/15,18.104.22.168/12,22.214.171.124/13,126.96.36.199/22,2400:cb00::/32,2606:4700::/32,2803:f800::/32,2405:b500::/32,2405:8100::/32,2a06:98c0::/29,2c0f:f248::/32" Firewall rule was successfully created; rule id: '583'.
After that apply the rules
[root@srv ~]# /usr/local/psa/bin/modules/firewall/settings -a Firewall rules were successfully activated, use --confirm command within 60 second(s) to confirm activation, otherwise all changes will be rolled back.
Now you will have to run the confirm command within 60 seconds else it will be rolled back. But the confirm command has to be run in a new shell. Running the command in same shell gives error. So make a new SSH connection to the server and run the confirm command.
[root@srv ~]# /usr/local/psa/bin/modules/firewall/settings -c Firewall rules were successfully confirmed.
Voila! you are done.