Create single-port CSF rule via SSH
- Login to SSH.
- Open /etc/csf/csf.allow in your preferred text editor. For the sake of this tutorial I'll be using VIM.
- Add your rules to this file, one per line.
- We'll be adding lines in the same format as
tcp/udp|in/out|s/d=port|s/d=ip. - Example:
So to open the mysql port to IP 11.22.33.44 , add the following lines. tcp:in:d=3306:d=11.22.33.44 tcp:out:d:3306:d=11.22.33.44
For example if we want to create a rule to allow inbound MySQL connections from IP 67.222.0.1 it would look like this:tcp|in|d=3306|s=67.222.0.1
- Save the file. If you're in nano, use ^X (Ctrl+X) and tell it "Y" to overwrite the file.
- Restart CSF using
csf -r.
Open Port in CSF Firewall through SSH
- Login to your Linux machine through SSH. Open csf.conf file using any text editor.
/etc/csf/csf.conf
- Add the port you wish to open and restart CSF firewall for the changes to take into effect.
# Allow incoming TCP ports TCP_IN = "20,443,465,21,22,587,993,25,53,80,110,143,995" # Allow outgoing TCP ports TCP_OUT = "20,21,443,587,22,25,80,110,43,53"
csf -r // To restart CSF firewall
Useful CSF SSH Command Line Commands (CSF Cheat Sheet)
| Command | Description | Example |
|---|---|---|
| csf -s | Start the firewall rules | root@server[~]#csf -s |
| csf -f | Flush/Stop firewall rules (note: lfd may restart csf) | root@server[~]#csf -f |
| csf -r | Restart the firewall rules | root@server[~]#csf -r |
| csf -a [IP.add.re.ss] [comment] | Allow an IP and add to /etc/csf/csf.allow | root@server[~]#csf -a 187.33.3.3 Home IP Address |
| csf -tr [IP.add.re.ss] | Remove an IP from the temporary IP ban or allow list. | root@server[~]#csf -tr 66.192.23.1 |
| csf -tf | Flush all IPs from the temporary IP entries | root@server[~]#csf -tf |
| csf -d [IP.add.re.ss] [comment] | Deny an IP and add to /etc/csf/csf.deny | root@server[~]#csf -d 66.192.23.1 Blocked This Guy |
| csf -dr [IP.add.re.ss] | Unblock an IP and remove from /etc/csf/csf.deny | root@server[~]#csf -dr 66.192.23.1 |
| csf -df | Remove and unblock all entries in /etc/csf/csf.deny | root@server[~]#csf -df |
| csf -g [IP.add.re.ss] | Search the iptables and ip6tables rules for a match (e.g. IP, CIDR, Port Number) | root@server[~]#csf -g 66.192.23.1 |
| csf -t | Displays the current list of temporary allow and deny IP entries with their TTL and comment | root@server[~]#csf -t |
Comments