wiki:firewall
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| wiki:firewall [2021/07/30 02:38] – [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 | + | '' |
| - | - Edit ''/ | + | ==== Whitelist Management |
| - | - Add entries like the others and save the file | + | |
| - | - Run: '' | + | |
| - | ==== Removing Banned | + | In general it is a good idea to whitelist administrative |
| - | === CSF === | + | To do so: |
| - | While the server only allows whitelisted IPs to connect, it might be possible | + | - Go to WHM > cPHulk Brute Force Protection |
| + | - Click on Whitelist Management tab | ||
| + | - If logging in from an IP not on the list, there might be a popup with a button | ||
| + | - If not, add the IP to the box and put a comment with # character if needed. | ||
| + | - When done, click " | ||
| - | - Under WHM > ConfigServer Security & Firewall | + | To remove an IP from the whitelist, just click delete from the same interface. |
| - | - 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 | + | |
| + | Do not forget to update the firewall by running the script: ''/ | ||
| - | === cPHulk === | + | The script runs daily, but running it now will immediately update the firewall. |
| - | cPHulk can also block IPs for various reasons. | + | **Do not forget to add the IP to each of the 2 accounts, master on chost and beacontechnology on kingscpw01.** |
| - | To find blacklisted IPs: | + | [[wiki:firewall# |
| - | Go to: WHM > cPHulk Brute Force Protection | + | ==== Blacklist Management |
| - | Click "Blacklist Management" | + | |
| - | You should see all IPs block by cPHulk on this page | + | |
| - | If you want to remove an IP from the list, just click Delete and Continue | + | |
| - | You can also whitelist in cPHulk as well by going to the " | + | Sometimes |
| + | To unblock: | ||
| - | ===== Installation General Information ===== | + | - 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 and read the IP back. | ||
| + | - When the record is located, click " | ||
| - | Two main things need to be set up | + | ==== Troubleshooting ==== |
| - | - CSF needs to be configured | + | It may |
| - | - IPs need to be added to the '' | + | |
| - | ==== Installation ==== | + | - 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 ===== | ||
| - | 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. | + | New instructions: |
| - | [[https:// | + | CSF is no longer necessary, a basic firewall solution now comes with cPanel and is called '' |
| - | Otherwise, run these commands: | + | '' |
| - | <code> | + | The current rules can be viewed by going to WHM > Host Access Control |
| - | cd /root | + | |
| - | wget https:// | + | |
| - | tar -xzf csf.tgz | + | |
| - | cd csf | + | |
| - | ./ | + | |
| - | # reboot server | + | Host Access Control is very basic and does not natively handle expressions like "any port", and so some rules say " |
| - | sed -ibak ' | + | To Add new rules: |
| - | sed -r -ibak ' | + | |
| - | sync; csf -ra | + | - edit: ''/ |
| + | - Scroll the sections where it says '' | ||
| + | - Please copy an existing rule and edit it to what is needed. | ||
| + | - When done, save and exit | ||
| + | - run the command: '' | ||
| + | - When the WHM Host Access Control page is reloaded, the changes should now be reflected. | ||
| + | |||
| + | Also note that rules are dynamically loaded into nftables by '' | ||
| + | |||
| + | ===== update_firewall.sh ===== | ||
| + | |||
| + | This script help managing nftables | ||
| + | |||
| + | <code bash update_firewall.sh> | ||
| + | # | ||
| + | |||
| + | # this script extends cpHulk to assist managing nftables. | ||
| + | |||
| + | # country codes selected in CPhulk will be banned at the IP level | ||
| + | # whitelisted ips will be included as administratively allowed | ||
| + | |||
| + | set -e | ||
| + | trap 'catch $? $LINENO' | ||
| + | |||
| + | catch() { | ||
| + | if [ " | ||
| + | echo failed to update firewall rules | ||
| + | echo "Error $1 occurred on $2" | ||
| + | fi | ||
| + | } | ||
| + | |||
| + | geoipdir='/ | ||
| + | |||
| + | whitelist=$(mktemp) | ||
| + | blacklist=$(mktemp) | ||
| + | |||
| + | # get list of CCs that are blocked | ||
| + | cclist=$( whmapi1 --output=json load_cphulk_config | | ||
| + | jq -r ' | ||
| + | |||
| + | # loop over list and concat all subnets from cpanel free geoip | ||
| + | for i in ${cclist//,/ | ||
| + | grep -oP ' | ||
| + | done | ||
| + | |||
| + | # write list of whitelist ips to temp file | ||
| + | whmapi1 --output=json read_cphulk_records list_name=' | ||
| + | jq -r ' | ||
| + | |||
| + | # 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 ' }' | ||
| + | |||
| + | # create blacklist set | ||
| + | echo -n 'add element inet filter ccblockset { ' | ||
| + | cat $blacklist | tr ' | ||
| + | echo ' }' | ||
| + | } | nft -f - | ||
| + | |||
| + | echo firewall was successfully updated | ||
| </ | </ | ||
| + | |||
| + | ===== Allowing IPs to locked down cpanel accounts ===== | ||
| + | |||
| + | On some accounts, there is htaccess that whitelists IPs for extra security. | ||
| + | |||
| + | The htaccess is normally at: ''/ | ||
| + | |||
| + | The area you are looking for looks something like this: | ||
| + | |||
| + | < | ||
| + | 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.1627612722.txt.gz · Last modified: 2021/07/30 02:38 by guidebeacon