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/07/24 22:20] – guidebeacon | wiki:firewall [2023/10/05 19:29] (current) – guidebeacon | ||
|---|---|---|---|
| Line 2: | Line 2: | ||
| The cPanel servers make use of various firewalling features | The cPanel servers make use of various firewalling features | ||
| - | |||
| - | '' | ||
| '' | '' | ||
| Line 31: | Line 29: | ||
| To remove an IP from the whitelist, just click delete from the same interface. | To remove an IP from the whitelist, just click delete from the same interface. | ||
| - | Additionally, | + | Do not forget |
| + | |||
| + | The script | ||
| + | |||
| + | **Do not forget to add the IP to each of the 2 accounts, master on chost and beacontechnology on kingscpw01.** | ||
| + | |||
| + | [[wiki: | ||
| ==== Blacklist Management ==== | ==== Blacklist Management ==== | ||
| Line 43: | Line 47: | ||
| - Search for the IP in question, if the IP is unknown, ask the user to go to: ipecho.net and read the IP back. | - 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 " | - 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 ===== | ===== Host Access Control ===== | ||
| Line 67: | Line 80: | ||
| Also note that rules are dynamically loaded into nftables by '' | Also note that rules are dynamically loaded into nftables by '' | ||
| - | ===== CSF ===== | + | ===== update_firewall.sh |
| - | **chost does not use CSF** | + | This script help managing nftables |
| - | **chost does not use CSF** | + | <code bash update_firewall.sh> |
| + | #!/bin/bash | ||
| - | **chost does not use CSF** | + | # this script extends cpHulk to assist managing nftables. |
| - | CSF is a third party addon for cPanel. | + | # country codes selected in CPhulk will be banned at the IP level |
| + | # whitelisted ips will be included as administratively allowed | ||
| - | ==== Whitelisting IPs ==== | + | set -e |
| + | trap 'catch $? $LINENO' | ||
| - | IPs can be whitelisted two different ways, either via the web interface or SSH | + | catch() { |
| + | if [ " | ||
| + | echo failed to update firewall rules | ||
| + | echo "Error $1 occurred on $2" | ||
| + | fi | ||
| + | } | ||
| - | If using the web interface: | + | geoipdir='/ |
| - | - Go to WHM > ConfigServer Security & Firewall | + | whitelist=$(mktemp) |
| - | - Click " | + | blacklist=$(mktemp) |
| - | - Under "csf - ConfigServer Firewall" | + | |
| - | - Add IP and comment to list how the rest are | + | |
| - | - Click Change | + | |
| - | - Click Restart csf+lfd | + | |
| - | If using shell/ssh | + | # get list of CCs that are blocked |
| + | cclist=$( whmapi1 --output=json load_cphulk_config | | ||
| + | jq -r ' | ||
| - | - Edit '' | + | # loop over list and concat all subnets from cpanel free geoip |
| - | - Add entries like the others and save the file | + | for i in ${cclist//,/ }; do |
| - | - Run: '' | + | |
| + | done | ||
| - | ==== Removing Banned IPs ==== | + | # write list of whitelist ips to temp file |
| + | whmapi1 --output=json read_cphulk_records list_name=' | ||
| + | jq -r ' | ||
| - | === CSF === | + | # generate new rules for nftables |
| + | { | ||
| + | echo 'flush set inet filter ccblockset' | ||
| + | echo 'flush set inet filter adminwhitelist' | ||
| - | 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. | + | # create whitelist set |
| + | echo -n 'add element inet filter adminwhitelist { ' | ||
| + | cat $whitelist | tr ' | ||
| + | echo ' }' | ||
| - | | + | |
| - | - Go to: csf - ConfigServer Firewall | + | |
| - | | + | |
| - | | + | |
| - | - Go to: csf - Quick Actions | + | } | nft -f - |
| - | | + | |
| - | === cPHulk === | + | echo firewall was successfully updated |
| + | </ | ||
| - | cPHulk can also block IPs for various reasons. | + | ===== Allowing |
| - | To find blacklisted | + | On some accounts, there is htaccess that whitelists |
| - | Go to: WHM > cPHulk Brute Force Protection | + | The htaccess is normally at: ''/ |
| - | Click " | + | |
| - | 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 " | + | The area you are looking for looks something like this: |
| - | ===== Installation General Information ===== | + | < |
| + | allow from xxx.xxx.xxx.xxx | ||
| + | allow from xxx.xxx.xxx.xxx | ||
| + | allow from xxx.xxx.xxx.xxx | ||
| + | allow from xxx.xxx.xxx.xxx</ | ||
| - | Two main things need to be set up | + | Just add a similar new entry below the last one in the list |
| - | + | ||
| - | - CSF needs to be configured to not allow any ports | + | |
| - | - IPs need to be added to the '' | + | |
| - | + | ||
| - | ==== Installation ==== | + | |
| - | + | ||
| - | 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. | + | |
| - | + | ||
| - | [[https:// | + | |
| - | + | ||
| - | Otherwise, run these commands: | + | |
| - | + | ||
| - | < | + | |
| - | cd /root | + | |
| - | wget https:// | + | |
| - | tar -xzf csf.tgz | + | |
| - | cd csf | + | |
| - | ./ | + | |
| - | + | ||
| - | # reboot server | + | |
| - | + | ||
| - | sed -ibak ' | + | |
| - | sed -r -ibak ' | + | |
| - | + | ||
| - | sync; csf -ra | + | |
| - | </ | + | |
wiki/firewall.1690237248.txt.gz · Last modified: 2023/07/24 22:20 by guidebeacon