Projekt

Allgemein

Profil

Setup denyhosts » Historie » Version 3

Jeremias Keihsler, 17.01.2019 10:43

1 1 Jeremias Keihsler
h1. Install Procedure for denyhosts
2
3 3 Jeremias Keihsler
*denyhosts seems not to be available for Fedora 29 as of 2019-01-17*
4
*consider fail2ban as an alternative*
5
*checkout: https://fedoraproject.org/wiki/Fail2ban_with_FirewallD*
6
7 2 Jeremias Keihsler
8 1 Jeremias Keihsler
h2. Requirements
9
10
To install denyhosts you will need the following:
11
* a installed and supported operating system (e.g. Fedora 29)
12
* root-access
13
* a fast internet connection
14
* -[[repo_epel|EPEL]]-
15
16
h2. Preliminary Note
17
18
This procedure is based on a documentation supplied by http://www.techoism.com/block-ssh-server-attacks-using-denyhosts-in-centosrhel-567/
19
20
h2. Install 
21
22
<pre><code class="bash">
23
dnf install denyhosts
24
</code></pre>
25
26
h2. configure
27
28
h3. whitelist IPs
29
30
<pre><code class="bash">
31
vim /etc/hosts.allow
32
</code></pre>
33
34
<pre>
35
Below the description, add the each IP address one-by-one on a separate line, that you never want to block. The format should be as follows.
36
37
#
38
# hosts.allow   This file contains access rules which are used to
39
#               allow or deny connections to network services that
40
#               either use the tcp_wrappers library or that have been
41
#               started through a tcp_wrappers-enabled xinetd.
42
#
43
#               See 'man 5 hosts_options' and 'man 5 hosts_access'
44
#               for information on rule syntax.
45
#               See 'man tcpd' for information on tcp_wrappers
46
#
47
sshd: 28.119.25.113
48
sshd: 28.119.25.114
49
sshd: 28.119.25.115
50
sshd: 28.119.25.116
51
</pre>
52
53
h3. blacklist IPs
54
55
<pre><code class="bash">
56
vim /etc/hosts.deny
57
</code></pre>
58
59
<pre>
60
#
61
# hosts.deny    This file contains access rules which are used to
62
#               deny connections to network services that either use
63
#               the tcp_wrappers library or that have been
64
#               started through a tcp_wrappers-enabled xinetd.
65
#
66
#               The rules in this file can also be set up in
67
#               /etc/hosts.allow with a 'deny' option instead.
68
#
69
#               See 'man 5 hosts_options' and 'man 5 hosts_access'
70
#               for information on rule syntax.
71
#               See 'man tcpd' for information on tcp_wrappers
72
#
73
sshd: 28.119.25.117
74
sshd: 28.119.25.118
75
</pre>
76
77
h3. email-alerts
78
79
denyhosts is well integrated into [[setup_logwatch|logwatch]] but if you are into noise you may also send mails from denyhosts directly.
80
81
<pre><code class="bash">
82
vim /etc/denyhosts.conf
83
</code></pre>
84
85
<pre>
86
############ DENYHOSTS REQUIRED SETTINGS ############
87
SECURE_LOG = /var/log/secure
88
HOSTS_DENY = /etc/hosts.deny
89
BLOCK_SERVICE  = sshd
90
DENY_THRESHOLD_INVALID = 5
91
DENY_THRESHOLD_VALID = 10
92
DENY_THRESHOLD_ROOT = 1
93
DENY_THRESHOLD_RESTRICTED = 1
94
WORK_DIR = /var/lib/denyhosts
95
SUSPICIOUS_LOGIN_REPORT_ALLOWED_HOSTS=YES
96
HOSTNAME_LOOKUP=YES
97
LOCK_FILE = /var/lock/subsys/denyhosts
98
99
############ DENYHOSTS OPTIONAL SETTINGS ############
100
ADMIN_EMAIL = support@techoism.com
101
SMTP_HOST = localhost
102
SMTP_PORT = 25
103
SMTP_FROM = DenyHosts 
104
SMTP_SUBJECT = DenyHosts Daily Report
105
106
############ DENYHOSTS OPTIONAL SETTINGS ############
107
DAEMON_LOG = /var/log/denyhosts
108
DAEMON_SLEEP = 30s
109
DAEMON_PURGE = 1h
110
</pre>
111
112
h2. Service 
113
114
<pre><code class="bash">
115
systemctl start denyhosts
116
systemctl enable denyhosts
117
</code></pre>
118
119
h2. Remove banned IP
120
121
If you’ve ever blocked accidentally and want to remove that banned IP address. So first you need to stop the service.
122
123
<pre><code class="bash">
124
systemctl stop denyhosts
125
</code></pre>
126
127
To remove or delete banned IP address completely. You need to remove the IP address from the following files.
128
129
<pre><code class="bash">
130
vim /etc/hosts.deny
131
vim /var/lib/denyhosts/hosts
132
vim /var/lib/denyhosts/hosts-restricted
133
vim /var/lib/denyhosts/hosts-root
134
vim /var/lib/denyhosts/hosts-valid
135
vim /var/lib/denyhosts/users-hosts
136
</code></pre>
137
138
After removing the banned IP Address, start the service again.
139
140
<pre><code class="bash">
141
systemctl start denyhosts
142
</code></pre>