wiki:firewall
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| wiki:firewall [2023/06/08 22:04] – [Whitelisting IPs] guidebeacon | wiki:firewall [2023/10/05 19:29] (current) – guidebeacon | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Firewall ====== | ====== Firewall ====== | ||
| - | Beacontechnology uses CSF to manage the linux firewall | + | The cPanel servers make use of various firewalling features |
| - | ===== General Management ===== | + | '' |
| - | ==== Whitelisting IPs ==== | + | ===== cPHulk ===== |
| - | IPs can be whitelisted two different ways, either via the web interface or SSH | + | '' |
| - | If using the web interface: | + | '' |
| - | - Go to WHM > ConfigServer Security & Firewall | + | The script that dumps the whitelist and country blacklist, and imports them into '' |
| - | - Click " | + | |
| - | - Under "csf - ConfigServer Firewall" | + | |
| - | - Add IP and comment to list how the rest are | + | |
| - | - Click Change | + | |
| - | - Click Restart csf+lfd | + | |
| - | If using shell/ssh | + | '' |
| - | | + | ==== Whitelist Management |
| - | - Add entries like the others | + | |
| - | - Run: '' | + | In general it is a good idea to whitelist administrative IPs to avoid getting banned. |
| + | |||
| + | To do so: | ||
| + | |||
| + | | ||
| + | - Click on Whitelist Management tab | ||
| + | - If logging in from an IP not on the list, there might be a popup with a button that can be pressed to add the current IP to the list. | ||
| + | - If not, add the IP to the box and put a comment with # character if needed. | ||
| + | - When done, click " | ||
| + | |||
| + | To remove an IP from the whitelist, just click delete from the same interface. | ||
| + | |||
| + | Do not forget to update the firewall by running the script: | ||
| + | |||
| + | The script runs daily, but running it now will immediately update the firewall. | ||
| + | |||
| + | **Do not forget to add the IP to each of the 2 accounts, master on chost and beacontechnology on kingscpw01.** | ||
| + | |||
| + | [[wiki: | ||
| + | |||
| + | ==== Blacklist Management ==== | ||
| + | |||
| + | Sometimes the user might be banned, or can't connect to a specific service for some unknown reason. It could be cPHulk blocking them. | ||
| + | |||
| + | To unblock: | ||
| + | |||
| + | - Go to WHM > cPHulk Brute Force Protection | ||
| + | - Click on Blacklist Management tab | ||
| + | - Search for the IP in question, if the IP is unknown, ask the user to go to: ipecho.net | ||
| + | - When the record is located, click " | ||
| + | |||
| + | ==== Troubleshooting ==== | ||
| + | |||
| + | It may be the case that sometimes the script gives an error for various reasons, here are some steps to try to fix it: | ||
| + | |||
| + | - Try rebooting server | ||
| + | - Try making a change in cpHulk like adding/ | ||
| + | - Try this command: '' | ||
| + | - try this command: WARNING, may result in getting locked out, add your IP to '' | ||
| + | |||
| + | ===== Host Access Control ===== | ||
| New instructions: | New instructions: | ||
| - | CSF is no longer necessary, | + | CSF is no longer necessary, |
| - | Host Access Control provides a basic firewall interface that integrates with Linux nftables. | + | '' |
| The current rules can be viewed by going to WHM > Host Access Control | The current rules can be viewed by going to WHM > Host Access Control | ||
| Line 42: | Line 77: | ||
| - run the command: '' | - run the command: '' | ||
| - When the WHM Host Access Control page is reloaded, the changes should now be reflected. | - When the WHM Host Access Control page is reloaded, the changes should now be reflected. | ||
| - | ==== Removing Banned IPs ==== | ||
| - | === CSF === | + | Also note that rules are dynamically loaded into nftables by '' |
| - | While the server only allows whitelisted IPs to connect, it might be possible that the server can ban someone that is on the list if they try to log in too many times. | + | ===== update_firewall.sh ===== |
| - | - Under WHM > ConfigServer Security & Firewall | + | This script help managing nftables |
| - | - Go to: csf - ConfigServer Firewall | + | |
| - | - Where it says: Search for IP, type in their IP and click Search. | + | |
| - | - If something comes back, click Return | + | |
| - | - Go to: csf - Quick Actions | + | |
| - | - Type in the IP to Quick Unblock and click the button | + | |
| + | <code bash update_firewall.sh> | ||
| + | #!/bin/bash | ||
| - | === cPHulk === | + | # this script extends cpHulk to assist managing nftables. |
| - | cPHulk can also block IPs for various reasons. | + | # country codes selected in CPhulk will be banned at the IP level |
| + | # whitelisted ips will be included as administratively allowed | ||
| - | To find blacklisted IPs: | + | set -e |
| + | trap 'catch $? $LINENO' | ||
| - | Go to: WHM > cPHulk Brute Force Protection | + | catch() { |
| - | Click "Blacklist Management" | + | if [ "$1" |
| - | You should see all IPs block by cPHulk | + | echo failed to update firewall rules |
| - | If you want to remove an IP from the list, just click Delete and Continue | + | echo "Error $1 occurred |
| + | fi | ||
| + | } | ||
| - | You can also whitelist in cPHulk as well by going to the " | + | geoipdir='/ |
| + | whitelist=$(mktemp) | ||
| + | blacklist=$(mktemp) | ||
| - | ===== Installation General Information ===== | + | # get list of CCs that are blocked |
| + | cclist=$( whmapi1 --output=json load_cphulk_config | | ||
| + | jq -r ' | ||
| - | Two main things need to be set up | + | # loop over list and concat all subnets from cpanel free geoip |
| + | for i in ${cclist//,/ | ||
| + | grep -oP ' | ||
| + | done | ||
| - | - CSF needs to be configured to not allow any ports | + | # write list of whitelist ips to temp file |
| - | - IPs need to be added to the '' | + | whmapi1 |
| + | jq -r '.data.ips_in_list | keys[]' | ||
| - | ==== Installation ==== | + | # generate new rules for nftables |
| + | { | ||
| + | echo 'flush set inet filter ccblockset' | ||
| + | echo 'flush set inet filter adminwhitelist' | ||
| + | # create whitelist set | ||
| + | echo -n 'add element inet filter adminwhitelist { ' | ||
| + | cat $whitelist | tr ' | ||
| + | echo ' }' | ||
| - | The administrative security policy requires that only specified Ips are allow to connect to the dev server. CSF is one of the most popular cPanel plugins to somewhat easily control the linux firewall. | + | # create blacklist set |
| + | echo -n 'add element inet filter ccblockset { ' | ||
| + | cat $blacklist | tr ' | ||
| + | echo ' }' | ||
| + | } | nft -f - | ||
| - | [[https:// | + | echo firewall was successfully updated |
| + | </code> | ||
| - | Otherwise, run these commands: | + | ===== Allowing IPs to locked down cpanel accounts ===== |
| - | < | + | On some accounts, there is htaccess that whitelists IPs for extra security. |
| - | cd /root | + | |
| - | wget https:// | + | |
| - | tar -xzf csf.tgz | + | |
| - | cd csf | + | |
| - | ./ | + | |
| - | # reboot server | + | The htaccess is normally at: ''/ |
| - | sed -ibak ' | + | The area you are looking for looks something like this: |
| - | sed -r -ibak ' | + | |
| - | sync; csf -ra | + | < |
| - | </ | + | allow from xxx.xxx.xxx.xxx |
| + | allow from xxx.xxx.xxx.xxx | ||
| + | allow from xxx.xxx.xxx.xxx | ||
| + | allow from xxx.xxx.xxx.xxx</ | ||
| + | |||
| + | Just add a similar new entry below the last one in the list | ||
wiki/firewall.1686261853.txt.gz · Last modified: 2023/06/08 22:04 by guidebeacon