About Linux FAQ

Browse More FAQs:

Howto Secure portmap service using iptables and TCP Wrappers under Linux

Posted by Vivek Gite [Last updated: January 28, 2007]

Q. How do I secure the portmap service? I am using Debian Linux.

A. According to wikipedia, "Portmap is server software running under Unix-like systems that converts RPC program numbers into DARPA protocol port numbers. Its design objective was to minimize the number of ports in use, but this never happened as it never had wide adoption. It must be running in order to make RPC calls."

When an RPC server is started, it will tell portmap what port number it is listening to, and what RPC program numbers it is prepared to serve. When a client wishes to make an RPC call to a given program number, it will first ontact portmap on the server machine to determine the port number where RPC packets should be sent.

It is extensively used by NIS, NFS, and FAM. It is used to assign a dynamic port to NIS and NFS.

You can protect portmap with:
=> TCP Wrappers

=> Iptables

TCP Wrappers

If you're going to protect the portmapper use the name "portmap" for the daemon name. Remember that you can only use the keyword "ALL" and IP addresses (NOT host or domain names) for the portmapper, as well as for rpc.mountd (the NFS mount daemon).
Open /etc/hosts.allow file:
# vi /etc/hosts.allow
Sample entires for portmap server to allow access from 192.168.1.0/24 only.
sshd : ALL
portmap : 192.168.1.0/24

Save and close the file.

IPTables portmap rules

Portmap listens on port 111. Add following rules to your iptables:

Drop UPD port 111 packets if they are not from 192.168.1.0/24
iptables -A INPUT -p udp -s! 192.168.1.0/24 --dport 111 -j DROP

Drop TCP port 111 packets if they are not from 192.168.1.0/24 and localhost (127.0.0.1)
iptables -A INPUT -p tcp -s! 192.168.1.0/24 --dport 111 -j DROP
iptables -A INPUT -p tcp -s 127.0.0.1 --dport 111 -j ACCEPT

For more information refer to following man pages:
man iptables
man tcpd
man 5 hosts_access
man portmap

Subscribe to our free e-mail newsletter or RSS feed to get all updates. You can Email this page to a friend.

Related Other Helpful FAQs:

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Copyright © 2006-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.