TCP Wrapper Hostsallow Hostsdeny Command Options in Linux
TCP Wrapper Hostsallow Hostsdeny Command Options in Linux
deny) Command
Options in Linux
thegeekdiary.com/tcp-wrapper-hosts-allow-hosts-deny-command-options-in-linux/
admin
TCP wrappers are capable of more than allowing and denying access to services. With the
optional command argument, they can send connection banners, warn of attacks from
particular hosts, and enhance logging.
220-Hello, %c
220-All activity on ftp.example.com is logged.
220-Inappropriate use results in access privileges being removed.
The %c token supplies a variety of client information. The %d token (not shown) expands
to the name of the daemon that the client attempted to connect to. For this banner to be
displayed to incoming connections, add the following line to the /etc/hosts.allow file:
# vi /etc/hosts.allow
vsftpd : ALL : banners /etc/banners/
# vi /etc/hosts.deny
ALL : 200.182.68.0 : spawn /bin/echo `date` %c %d >> /var/log/intruder_alert
To allow the connection and log it, place the spawn directive in the /etc/hosts.allow file.
# vi /etc/hosts.deny
ALL : ALL : spawn /bin/echo “%c tried to connect to %d and was blocked” >>
/var/log/tcpwrappers.log
1/2
The log level can be elevated by using the severity option. Assume that anyone attempting
to ssh to an FTP server is an intruder. To denote this, place an emerg flag in the log files
instead of the default flag, info, and deny the connection. To do this, place the following line
in /etc/hosts.deny:
# vi /etc/hosts.deny
sshd : ALL : severity emerg
This uses the default authpriv logging facility, but elevates the priority from the default value
of info to emerg, which posts log messages directly to the console.
# vi /etc/hosts.allow
sshd : .example.com \
: spawn /bin/echo `/bin/date` access denied >> /var/log/sshd.log \
: deny
Each option field (spawn and deny) is preceded by the backslash (\) to prevent failure of
the rule due to length.
2/2