TCP Wrappers

TCP Wrappers is a host-based access control system for Unix-like operating systems such as Linux and BSD. It lets an administrator decide which IP addresses and hostnames may connect to network services on a machine. Although it is now largely retired, understanding it is still useful when maintaining older systems, and the idea behind it remains a security best practice.
A Brief History
Wietse Venema wrote the original code in 1990 to monitor an intruder’s activity on Unix workstations in the Department of Mathematics and Computer Science at Eindhoven University of Technology. It became a standard part of many Unix and Linux systems for the next two decades.
Why Host-Based Access Control Matters
Access control lists (ACLs) are usually enforced at the network level, on firewalls and switches. Adding an ACL on the host itself provides defense in depth: if an intruder gets onto the same network segment as a server, bypassing the network firewall, the server can still refuse connections from unauthorized addresses.
How TCP Wrappers Works
Services either run through the tcpd wrapper program or are built with the libwrap library. When a connection arrives, the rules in two files are checked in order:
- If a rule in
/etc/hosts.allowmatches, the connection is allowed. - Otherwise, if a rule in
/etc/hosts.denymatches, the connection is refused. - If neither file matches, the connection is allowed.
Each rule takes the form service : clients. For example, to allow SSH only from a single internal subnet:
# /etc/hosts.allow
sshd : 192.168.1.0/255.255.255.0
# /etc/hosts.deny
sshd : ALL
Because hosts.allow is checked first, hosts on the 192.168.1.0 network can connect, and every other address is refused. Changes take effect immediately, without restarting the service. Note that a service is only protected if it actually uses TCP Wrappers; you can check whether a program is linked against the library with:
ldd /usr/sbin/sshd | grep libwrap
TCP Wrappers Today
TCP Wrappers is now considered legacy software. Its last release dates to 1997, and both OpenSSH and systemd dropped support for it in 2014. Fedora stopped supporting it by default in Fedora 28, and Red Hat Enterprise Linux removed it in RHEL 8. On many current systems, editing hosts.allow and hosts.deny has no effect at all, which can create a false sense of security. If you rely on these files, verify that your services still honor them, and plan a migration.

Modern Alternatives
The goal of TCP Wrappers, restricting which hosts can reach a service, is still sound. Today it is achieved with these tools. When testing any of them on a remote server, keep an existing session open so a mistake doesn’t lock you out.
1. A Host Firewall
Firewalls such as firewalld, nftables, or ufw filter traffic before it ever reaches a service. With firewalld, for example, you can limit SSH to one subnet:
sudo firewall-cmd --permanent --remove-service=ssh
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.0/24" service name="ssh" accept'
sudo firewall-cmd --reload
2. systemd Service Filtering
Since version 235, systemd can restrict network access for any individual service. Run sudo systemctl edit sshd (the service is named ssh on Debian and Ubuntu) and add:
[Service]
IPAddressDeny=any
IPAddressAllow=192.168.1.0/24
3. Application Settings
Many services have their own access controls. OpenSSH, for instance, can limit which users may log in and from where:
# /etc/ssh/sshd_config
AllowUsers admin@192.168.1.*
For the strongest protection, combine these layers: a network firewall, a host firewall, and application-level restrictions.
The Bottom Line
TCP Wrappers introduced a lasting principle: every server should decide for itself who is allowed to connect. The tool has been retired, but the principle hasn’t. If you’d like help reviewing access controls on your systems, contact us.
0 Comments