Projekt

Allgemein

Profil

Setup denyhosts » Historie » Version 2

Jeremias Keihsler, 17.01.2019 10:39

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