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:21] – guidebeacon | wiki:firewall [2023/10/05 19:29] (current) – guidebeacon | ||
|---|---|---|---|
| Line 29: | 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 41: | 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 65: | Line 80: | ||
| Also note that rules are dynamically loaded into nftables by '' | Also note that rules are dynamically loaded into nftables by '' | ||
| + | ===== update_firewall.sh ===== | ||
| + | |||
| + | This script help managing nftables | ||
| + | |||
| + | <code bash update_firewall.sh> | ||
| + | #!/bin/bash | ||
| + | |||
| + | # 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.1690237310.txt.gz · Last modified: 2023/07/24 22:21 by guidebeacon