Sharing Knowledge | System Admin Articles

Configuring TCP Wrappers for Linux Security

The TCP Wrappers package is installed by default on Fedora Linux and provides host-based security separate from that provided by a firewall running on the server itself or elsewhere.
The application relies on two main files:

/etc/hosts.allow: Defines the hosts and networks allowed to connect to the server. The TCP Wrappers enabled application searches this file for a matching entry, and if it finds one, then the connection is allowed.

/etc/hosts.deny: Defines the hosts and networks prohibited from connecting to the server. If a match is found in this file, the connection is denied. No match means the connection proceeds normally.

The /etc/hosts.allow file is always read first and both files are always read from top to bottom, therefore the ordering of the entries is important.

The TCP Wrappers File Format:

The format of the file is:

    <TCP-daemon-name> <client-list> : <option>

This example allows all traffic from the and the networks and SSH from only two hosts, and All HTTP Web traffic is allowed. All other TCP traffic to the host is denied. Notice how the subnet masks can use the slash nomenclature or the dotted decimal format.

     # File: hosts.allow
     httpd:  ALL

     # File: hosts.deny
     ALL:    ALL

Determining the TCP Daemon's Name:

The easiest way of determining the name of a daemon is to use the ps command and then use grep to filter for the name of the service. Here, the example quickly determines the daemon name (/usr/sbin/sshd) for the SSH server process. Because TCP Wrappers only requires the program name and not the path, sshd therefore becomes the entry to place in the TCP-daemon-name column of the configuration file.

     [[email protected]ysrv1 tmp]# ps -ef | grep -i ssh
     root     10053     1  0 Nov06 ?        00:00:00 /usr/sbin/sshd
     root     14145 10053  0 Nov13 ?        00:00:02 sshd: [email protected]/1
     root     18100 14148  0 21:56 pts/1    00:00:00 grep ssh
     [[email protected] tmp]#

For a full explanation of all the options available, refer to section 5 of the man pages for hosts_access:
   [[email protected] tmp]# man 5 hosts_access

TCP Wrappers is simple to implement, but you have to set them on every host. Management is usually easier on a firewall that protects the entire network.

My Profile PhotoAbout the Author

I'm Parthiban, An UNIX System Admin by Profession. I'm Experienced in Linux/Unix System Administration and Scripting. I have done lot of work on the infrastructure Mgmt side in Linux, UNIX and Windows system administration, Hardware, Storage and Data center. I'm blogging since 2008.
Follow Me On Twitter or On Facebook

0 Comments for "Configuring TCP Wrappers for Linux Security"

What do you think about this Article? Add your Opinion..!

Back To Top