Updated: 22 October 2026 · Applies to: TCP Wrappers (tcpd) on Linux

TCP Wrappers is a host-based access control system for network services on Linux. It uses two files, /etc/hosts.allow and /etc/hosts.deny, to permit or block client connections. This guide covers writing rules, testing them, and making sure your services actually use them.

Prerequisites

  • A Linux server with TCP Wrappers installed (the package is usually called tcpd).
  • Root or sudo access.
  • Basic command-line skills.

1. How TCP Wrappers works

TCP Wrappers intercepts connections for services linked against the libwrap library. When a client connects, it checks /etc/hosts.allow first; if nothing matches there, it checks /etc/hosts.deny; if neither file matches, the connection is allowed.

2. Writing rules in hosts.allow

Rules follow this format:

<service> : <client-list> [ : <command> ]

For example:

sshd : 192.168.1.0/24
vsftpd : .example.com : spawn /usr/bin/logger FTP connection from %h
ALL : 10.0.0.5

3. Writing rules in hosts.deny

Rules here use the same format, and only apply when nothing in hosts.allow matched. Common practice is to block everything else by default:

ALL : ALL

4. Testing your rules

  • tcpdmatch, to check whether a client would be allowed or denied for a service:
    tcpdmatch sshd 203.0.113.10
  • tcpdchk, to validate the syntax of your rule files:
    tcpdchk /etc/hosts.allow /etc/hosts.deny
  • Logging: check /var/log/auth.log or /var/log/daemon.log for allow/deny messages. Add : spawn logger ... to a rule for more detailed logging of that match.

5. Make sure the service actually uses TCP Wrappers

Some services need their own option enabled to defer to TCP Wrappers. For sshd, confirm /etc/ssh/sshd_config has:

UsePAM yes

and that pam_access.so is enabled in /etc/pam.d/sshd. Without this, sshd will not consult hosts.allow/hosts.deny at all, no matter what rules you write.

With clear rules in /etc/hosts.allow and /etc/hosts.deny, tested with tcpdmatch and tcpdchk, you can restrict access to network services on your Linux server with confidence that the rules are actually taking effect.

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Managed dedicated servers

our engineers look after the server for you, from $135 a month.

Was this answer helpful?

Still stuck? Open a ticket