iptables for blocking traffic from a box

Had a situation today where it would have been useful to be able to block traffic on a certain port from getting off a box.

There’s a great intro to iptables over on the CentOS Wiki, entitled IPTables that explains the syntax you’d need to know on a typical RHEL system.

From what I have gathered so far, to set up an entry to block all outgoing traffic on a particular port you’d issue this command:

iptables -A OUTPUT -p tcp -dport 389 -j DROP

To block only traffic on that port to a particular host, the syntax would be:

iptables -A OUTPUT -p tcp -d 192.168.23.105 -dport 389 -j DROP