/etc/hosts.allow
/etc/hosts.deny
/etc/hosts.allow
— The TCP-wrapped service sequentially parses the /etc/hosts.allow
file and applies the first rule specified for that service. If it finds a matching rule, it allows the connection. If not, it moves on to the next step.
/etc/hosts.deny
— The TCP-wrapped service sequentially parses the /etc/hosts.deny
file. If it finds a matching rule, it denies the connection. If not, it grants access to the service.
hosts.allow
are applied first, they take precedence over rules specified in hosts.deny
. Therefore, if access to a service is allowed in hosts.allow
, a rule denying access to that same service in hosts.deny
is ignored.
hosts.allow
or hosts.deny
take effect immediately, without restarting network services.
/var/log/messages
or /var/log/secure
. This is also the case for a rule that spans multiple lines without using the backslash character. The following example illustrates the relevant portion of a log message for a rule failure due to either of these circumstances:
warning: /etc/hosts.allow, line 20: missing newline or line too long
/etc/hosts.allow
and /etc/hosts.deny
is identical. Each rule must be on its own line. Blank lines or lines that start with a hash (#) are ignored.
<daemon list>
:<client list>
[:<option>
:<option>
: ...]
<daemon list>
— A comma-separated list of process names (not service names) or the ALL
wildcard. The daemon list also accepts operators (refer to Section 2.3.2.1.4, “Operators”) to allow greater flexibility.
<client list>
— A comma-separated list of hostnames, host IP addresses, special patterns, or wildcards which identify the hosts affected by the rule. The client list also accepts operators listed in Section 2.3.2.1.4, “Operators” to allow greater flexibility.
<option>
— An optional action or colon-separated list of actions performed when the rule is triggered. Option fields support expansions, launch shell commands, allow or deny access, and alter logging behavior.
vsftpd : .example.com
vsftpd
) from any host in the example.com
domain. If this rule appears in hosts.allow
, the connection is accepted. If this rule appears in hosts.deny
, the connection is rejected.
sshd : .example.com \ : spawn /bin/echo `/bin/date` access denied>>/var/log/sshd.log \ : deny
sshd
) is attempted from a host in the example.com
domain, execute the echo
command to append the attempt to a special log file, and deny the connection. Because the optional deny
directive is used, this line denies access even if it appears in the hosts.allow
file. Refer to Section 2.3.2.2, “Option Fields” for a more detailed look at available options.
ALL
— Matches everything. It can be used for both the daemon list and the client list.
LOCAL
— Matches any host that does not contain a period (.), such as localhost.
KNOWN
— Matches any host where the hostname and host address are known or where the user is known.
UNKNOWN
— Matches any host where the hostname or host address are unknown or where the user is unknown.
PARANOID
— Matches any host where the hostname does not match the host address.
KNOWN
, UNKNOWN
, and PARANOID
wildcards should be used with care, because they rely on a functioning DNS server for correct operation. Any disruption to name resolution may prevent legitimate users from gaining access to a service.
example.com
domain:
ALL : .example.com
192.168.x.x
network:
ALL : 192.168.
192.168.0.0
through 192.168.1.255
:
ALL : 192.168.0.0/255.255.254.0
3ffe:505:2:1::
through 3ffe:505:2:1:ffff:ffff:ffff:ffff
:
ALL : [3ffe:505:2:1::]/64
example.com
domain:
ALL : *.example.com
/etc/telnet.hosts
file for all Telnet connections:
in.telnetd : /etc/telnet.hosts
hosts_access
man 5 page for more information.
Portmap
's implementation of TCP Wrappers does not support host look-ups, which means portmap
can not use hostnames to identify hosts. Consequently, access control rules for portmap in hosts.allow
or hosts.deny
must use IP addresses, or the keyword ALL
, for specifying hosts.
portmap
access control rules may not take effect immediately. You may need to restart the portmap
service.
portmap
to operate, so be aware of these limitations.
EXCEPT
. It can be used in both the daemon list and the client list of a rule.
EXCEPT
operator allows specific exceptions to broader matches within the same rule.
hosts.allow
file, all example.com
hosts are allowed to connect to all services except cracker.example.com
:
ALL: .example.com EXCEPT cracker.example.com
hosts.allow
file, clients from the 192.168.0.x
network can use all services except for FTP:
ALL EXCEPT vsftpd: 192.168.0.
EXCEPT
operators. This allows other administrators to quickly scan the appropriate files to see what hosts are allowed or denied access to services, without having to sort through EXCEPT
operators.