• Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial News Comments FAQ Related Articles

How to Block IP on Ubuntu 22.04 using CSF

  • 00:28 lsb_release -a
  • 00:45 systemctl status csf lfd
  • 01:12 vim /etc/csf/csf.deny
  • 01:57 csf -r
  • 02:09 systemctl restart csf lfd
  • 02:36 csf -d 192.168.6.123
  • 02:56 csf -r
  • 03:05 systemctl restart csf lfd
  • 03:26 vim /etc/csf/csf.deny
{{postValue.id}}

To Block IP On Ubuntu 22.04 Using CSF

Introduction :

The Configuration Server Firewall (CSF) is a firewall software application for Linux servers that controls network traffic, blocks suspicious IP addresses, and receives real-time alerts regarding threats.

Installation Steps:

Step 1: Check the OS version by using the below command

root@linuxhelp:~# lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 22.04.2 LTS
Release:	22.04
Codename:	jammy

Step 2: Check the status of the CSF and IFD by using the below command

root@linuxhelp:~# systemctl status csf lfd
● csf.service - ConfigServer Firewall & Security - csf
     Loaded: loaded (/lib/systemd/system/csf.service; enabled; vendor preset: enabled)
     Active: active (exited) since Mon 2023-06-26 04:07:30 IST; 35s ago
   Main PID: 31637 (code=exited, status=0/SUCCESS)
        CPU: 2.370s

Jun 26 04:07:30 linuxhelp csf[31637]: ACCEPT  all opt    in * out lo  ::/0  -> ::/0
Jun 26 04:07:30 linuxhelp csf[31637]: LOGDROPOUT  all opt    in * out !lo  ::/0  -> ::/0
Jun 26 04:07:30 linuxhelp csf[31637]: LOGDROPIN  all opt    in !lo out *  ::/0  -> ::/0
Jun 26 04:07:30 linuxhelp csf[31637]: csf: FASTSTART loading DNS (IPv4)
Jun 26 04:07:30 linuxhelp csf[31637]: csf: FASTSTART loading DNS (IPv6)
Jun 26 04:07:30 linuxhelp csf[31637]: LOCALOUTPUT  all opt -- in * out !lo  0.0.0.0/0  -> 0.0.0.0/0
Jun 26 04:07:30 linuxhelp csf[31637]: LOCALINPUT  all opt -- in !lo out *  0.0.0.0/0  -> 0.0.0.0/0
Jun 26 04:07:30 linuxhelp csf[31637]: LOCALOUTPUT  all opt    in * out !lo  ::/0  -> ::/0
Jun 26 04:07:30 linuxhelp csf[31637]: LOCALINPUT  all opt    in !lo out *  ::/0  -> ::/0
Jun 26 04:07:30 linuxhelp systemd[1]: Finished ConfigServer Firewall & Security - csf.

● lfd.service - ConfigServer Firewall & Security - lfd
     Loaded: loaded (/lib/systemd/system/lfd.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2023-06-26 04:07:31 IST; 34s ago
   Main PID: 31819 (lfd - sleeping)
      Tasks: 3 (limit: 4573)
     Memory: 228.9M
        CPU: 4.723s
     CGroup: /system.slice/lfd.service
             ├─31819 "lfd - sleeping"
             ├─31829 "lfd - (child) (PT) checking user processes"
             └─31831 /usr/sbin/sendmail -f root -t

Jun 26 04:07:30 linuxhelp systemd[1]: Starting ConfigServer Firewall & Security - lfd...
Jun 26 04:07:31 linuxhelp systemd[1]: Started ConfigServer Firewall & Security - lfd.
Jun 26 04:07:32 linuxhelp sendmail[31831]: My unqualified host name (linuxhelp) unknown; sleeping for ret>

Step 3: Go the csf.deny file in /etc/csf and enter the ip you want to block by using the below command

root@linuxhelp:~# vim /etc/csf/csf.deny
# See readme.txt for more information regarding advanced port filtering
#
192.168.6.120

Step 4: Reload the CSF by using the below command

root@linuxhelp:~# csf -r
Flushing chain `INPUT'
Deleting chain `LOCALOUTPUT'
csf: FASTSTART loading UDP6_OUT (IPv6)
ACCEPT  all opt -- in lo out *  0.0.0.0/0  -> 0.0.0.0/0  
ACCEPT  all opt -- in * out lo  0.0.0.0/0  -> 0.0.0.0/0  
LOGDROPOUT  all opt -- in * out !lo  0.0.0.0/0  -> 0.0.0.0/0  
LOGDROPIN  all opt -- in !lo out *  0.0.0.0/0  -> 0.0.0.0/0  
ACCEPT  all opt    in lo out *  ::/0  -> ::/0  
ACCEPT  all opt    in * out lo  ::/0  -> ::/0  
LOGDROPOUT  all opt    in * out !lo  ::/0  -> ::/0  
LOGDROPIN  all opt    in !lo out *  ::/0  -> ::/0  
csf: FASTSTART loading DNS (IPv4)
csf: FASTSTART loading DNS (IPv6)
LOCALOUTPUT  all opt -- in * out !lo  0.0.0.0/0  -> 0.0.0.0/0  
LOCALINPUT  all opt -- in !lo out *  0.0.0.0/0  -> 0.0.0.0/0  
LOCALOUTPUT  all opt    in * out !lo  ::/0  -> ::/0  
LOCALINPUT  all opt    in !lo out *  ::/0  -> ::/0  

*WARNING* RESTRICT_SYSLOG is disabled. See SECURITY WARNING in /etc/csf/csf.conf.

Step 5: Restart CSF and IFD by using the below command

root@linuxhelp:~# systemctl restart csf lfd

Step 6 : Another way to block IP by using the below command

root@linuxhelp:~# csf -d 192.168.6.123
Adding 192.168.6.123 to csf.deny and iptables DROP...
DROP  all opt -- in !lo out *  192.168.6.123  -> 0.0.0.0/0  
LOGDROPOUT  all opt -- in * out !lo  0.0.0.0/0  -> 192.168.6.123  

Step 7: Reload the CSF by using the below command

root@linuxhelp:~# csf -r
Flushing chain `INPUT'
Deleting chain `ALLOWIN'
Flushing chain `OUTPUT'
Deleting chain `INVDROP'
LOCALOUTPUT  all opt -- in * out !lo  0.0.0.0/0  -> 0.0.0.0/0  
LOCALINPUT  all opt -- in !lo out *  0.0.0.0/0  -> 0.0.0.0/0  
LOCALOUTPUT  all opt    in * out !lo  ::/0  -> ::/0  
LOCALINPUT  all opt    in !lo out *  ::/0  -> ::/0  

*WARNING* RESTRICT_SYSLOG is disabled. See SECURITY WARNING in /etc/csf/csf.conf.

Step 8: Restart the CSF and IFD by using the below command

 root@linuxhelp:~# systemctl restart csf lfd

Step 9: Check the csf.deny file where the deny ip’s are stored by using the below command

root@linuxhelp:~# vim /etc/csf/csf.deny

Conclusion:

By this how to block IP on Ubuntu 22.04 using CSF has come to an end.

Tags:
sebastian
Author: 

Comments ( 0 )

No comments available

Add a comment
{{postCtrl.cmtErrMsg}}

Frequently asked questions ( 5 )

Q

What is the command to deny ip in CSF?

A

csf -d

Q

Where did the deny location?

A

/etc/csf/csf.deny

Q

What is the command to reload CSF?

A

The reload command is csf -r

Q

Where did the allow location?

A

/etc/csf/csf.allow

Q

What is the command to start CSF?

A

The reload command is csf -s

Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help Isaac ?
How to run windows application in linux

I need to run the windows application in my Linux machine, instead of installing from yum repo or any other repos. How to do that..??

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.