RedHat / Centos and other similar Linux distros have 3 layers of protection that can restrict access to services (Iptables, TCP Wrappers (hosts.deny, hosts.allow) and SeLinux). When a machine on a network requests access to a specific service it first goes through Iptables, when access is granted it then goes through TCP Wrappers and then SeLinux is the last layer of protection. The best part about TCP wrappers is that it is English like and is very easy to understand. Here are some examples.
vsftpd : ALL EXCEPT 192.168.1.
mysqld : ALL EXCEPT .example.com
sshd : ALL EXCEPT 192.168.1.2
ALL : 192.168.1.2
ALL : .example.com EXCEPT server.example.com
ALL : 192.168.
ALL : *.example.com
ALL : 18.104.22.168, 22.214.171.124, 126.96.36.199
ALL : 188.8.131.52/16, 184.108.40.206/24
ALL : 220.127.116.11/255.255.254.0
Denies access and logs a failed attempt to /var/log/connections.log
sshd : 192.168.11.217 \
: spawn (/bin/echo %a from %h attempted to access %d >> \
Example from the above rule:
[email@example.com ~]# ssh 192.168.11.216
ssh_exchange_identification: Connection closed by remote host
[root@nfs ~]# cat /var/log/connections.log
192.168.11.217 from 192.168.11.217 attempted to access sshd
TCP Wrappers will not work with httpd or squid, use iptables instead.
All of these rules can be placed in hosts.allow or hosts.deny
192.168. – Anything in the 192.168.x.x subnet will be allowed/denied access
192.168.1. – Anything in the 192.168.1.x subnet is allowed/denied access
.example.com – Anything in the example.com domain is denied/allowed access
*.example.com – Anything in the example.com domain is denied/allowed access
Changes to the hosts.allow hosts.deny take effect immediately.
Only one rule is allowed per service in hosts.allow and hosts.deny.
Each rule has to be on a separate line.
You need to use both Iptables and TCP Wrappers for maximum protection.
Best way to test tcp wrappers is to stop Iptables and adjust the above rules.