• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here:Home » Configure Apache With Fail2Ban on Ubuntu 18.04

By Abhishek Ghosh September 10, 2018 10:03 pm Updated on September 11, 2018

Configure Apache With Fail2Ban on Ubuntu 18.04

Advertisement

Our oldest guide on fail2ban on this website is Installing Fail2ban on Ubuntu 14.04. In this context, it is important to read the article on pam_unix(sushi:auth): authentication failure, which is result of a type of attack. Here is How To Configure Apache With Fail2Ban on Ubuntu 18.04 to block more types of malicious attempts towards server to create a practical firewall. If you are pretty new to server, simply do the following to get started with fail2ban :

Vim
1
2
3
4
5
6
7
apt update -y
apt upgrade -y
apt install fail2ban
# check content
cat /etc/fail2ban/jail.conf
cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
apt install iptables-persistent

Run iptables -L to list current rules and if rules are not present then run :

Vim
1
2
3
4
5
sudo iptables -A INPUT -i lo -j ACCEPT
sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
sudo iptables -A INPUT -j DROP

Restart fail2ban :

Advertisement

---

Vim
1
service fail2ban restart

Next you can read our guides like :

  1. Fail2Ban Log Analysis Bash Script For Report Generation
  2. Configuring Fail2Ban With WordPress
  3. WordPress with Fail2Ban Plugin
  4. Fail2ban GeoIP Action Script to Block SSH by Country
  5. Fail2Ban Log Analytics Graph With badips.com

Up to this point our setup was not Apache webserver specific.

Configure Apache With Fail2Ban on Ubuntu 18-04

 

Configure Apache With Fail2Ban on Ubuntu 18.04

 

Actually we can only edit /etc/fail2ban/jail.local to add new rules. /etc/fail2ban/jail.conf get overwritten upon update. Of course, you can write rules on /etc/fail2ban/jail.conf and copy to /etc/fail2ban/jail.local. I usually keep them same. That is about settings file.

We have some filters in the /etc/fail2ban/filter.d/ directory :

Vim
1
2
cd /etc/fail2ban/filter.d/
ls | grep apache

We have the following filters available :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
apache-auth.conf
apache-noscript.conf
apache-badbots.conf
apache-overflows.conf
apache-nohome.conf
apache-botsearch.conf
apache-fakegooglebot.conf
apache-shellshock.conf
 
apache-common.conf
apache-pass.conf
apache-modsecurity.conf

We will create the following settings, notice web root of the filters :

[apache] : blocks failed login attempts (apache-auth.conf). Run cat on apache-auth.conf to read.
[apache-noscript] : block remote clients who are searching for scripts on the website to execute. Run cat on apache-noscript.conf to read.
[apache-overflows] : blocks clients who are attempting to request suspicious URLs. Run cat on apache-overflows.conf to read.
[apache-noscript] : blocks remote clients who are searching for scripts on website to execute. Run cat on apache-noscript.conf to read. It may give some error on WordPress.
[apache-badbots] : blocks malicious bot requests. Run cat on apache-badbots.conf to read.
[apache-botsearch] : blocks malicious bot requests. Run cat on apache-botsearch.conf to read.
[apache-fakegooglebot] : blocks bots faking as Google bot. Run cat on apache-fakegooglebot.conf to read.
[apache-shellshock] : blocks possible shellshock exploit. Run cat on apache-shellshock.conf to read.

Open :

Vim
1
nano apache-botsearch.conf

And edit the web root. These are your extra settings :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
[apache]
enabled  = true
port     = http,https
filter   = apache-auth
logpath  = /var/log/apache*/*error.log
maxretry = 6
 
[apache-noscript]
enabled  = true
port     = http,https
filter   = apache-noscript
logpath  = /var/log/apache*/*error.log
maxretry = 6
 
[apache-overflows]
enabled  = true
port     = http,https
filter   = apache-overflows
logpath  = /var/log/apache*/*error.log
maxretry = 2
 
[apache-nohome]
enabled  = true
port     = http,https
filter   = apache-nohome
logpath  = /var/log/apache*/*error.log
maxretry = 2
 
[apache-botsearch]
enabled  = true
port     = http,https
filter   = apache-botsearch
logpath  = /var/log/apache*/*error.log
maxretry = 2
 
[apache-shellshock]
enabled  = true
port     = http,https
filter   = apache-shellshock
logpath  = /var/log/apache*/*error.log
maxretry = 2
 
 
[apache-fakegooglebot]
enabled  = true
port     = http,https
filter   = apache-fakegooglebot
logpath  = /var/log/apache*/*error.log
maxretry = 2
 
[php-url-fopen]
 
enabled = true
port    = http,https
filter  = php-url-fopen
logpath = /var/log/apache*/*access.log

You edited the /etc/fail2ban/jail.local file. Make both copies updated by running :

Vim
1
cp /etc/fail2ban/jail.local /etc/fail2ban/jail.conf

Run :

Vim
1
2
3
4
5
service fail2ban reload
# wait till completes
iptables -L
 
sudo fail2ban-client status

You can find how many IPs are banned by the above Apache filter by running :

Vim
1
sudo fail2ban-client status apache

Filter related with Apache mod_security is separately discussed about the module.

I found that human invented more filters such as to stop SQL injection. Our WordPress plugin filter blocks authentication attempt, enumeration attempt, pingback error, spammed comment, XML-RPC multicall authentication failure.

I liked the apache-sqlinject. I have created a Github repo for the extra filters (copy them to /etc/fail2ban/filter.d/) and settings. apache-nodos will ban mini DOS attacks like running ab test on server.

Add these two extra settings :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[apache-sqlinject]
 
enabled  = true
port     = http,https
filter   = apache-sqlinject
logpath  = /var/log/apache2/access.log
maxretry = 3
bantime  = 3600
findtime = 600
 
[apache-nodos]
 
enabled  = false
port     = http,https
filter   = apache-nodos
logpath  = /var/log/apache2/access.log
maxretry = 3
bantime  = 3600
findtime = 600

No DOS for test purpose. That ends this article.

Tagged With fail2ban apache ubuntu 18 04 , configure fail2ban ubuntu 18 10 , ubuntu 18 04 server install fail2ban , fail2ban ubuntu 18 04 portscan , fail2ban ubuntu 18 04 apache , fail2ban ddos protection ubuntu 18 04 , fail2ban apache auth , configure fail2ban ubuntu 18 04 , configure fail2ban ubuntu , configure fail2ban to downstream the bot
Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to Configure Apache With Fail2Ban on Ubuntu 18.04

  • Configure Fail2Ban With Mod Security And Other Filters

    Here is How To Configure Fail2Ban With Mod Security & Others On Apache Server To Protect From PHP And Other Exploits. Config Files Included.

  • iptables Basics : Chapter 3, Configuring Fail2Ban With WordPress

    iptables Basics Chapter 3 Describes Configuring Fail2Ban With WordPress to Give Ultimate Protection. Thus We Secured OSI Model’s All Layers.

  • Installing Fail2ban on Ubuntu 14.04 : Nginx, HP Cloud

    Here is Guide With Steps on Installing Fail2ban on Ubuntu 14.04 on Server Running Nginx on HP Cloud. It adds a layer of security to SSH.

  • Fail2ban GeoIP Action Script to Block SSH by Country

    Instead of Using Bash Script to Restrict SSH by Countries Based on GeoIP, We Can Create Fail2ban GeoIP Action Script to Block SSH by Country.

performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Hybrid Multi-Cloud Environments Are Becoming UbiquitousJuly 12, 2023
  • Data Protection on the InternetJuly 12, 2023
  • Basics of BJT TransistorJuly 11, 2023
  • What is Confidential Computing?July 11, 2023
  • How a MOSFET WorksJuly 10, 2023
PC users can consult Corrine Chorney for Security.

Want to know more about us?

Read Notability and Mentions & Our Setup.

Copyright © 2023 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy