up vote 0 down vote favorite
share [g+] share [fb]

How can I block all ports except

  1. ssh (port 22)
  2. httpd (port 80)

using iptables and iphains?

link|improve this question
While ochach's answer is technically correct, I think you need to clarify your question. Do you mean "block all input except ssh and http"? If you follow ochach's answer, you won't be able to do anything - no data will be allowed out of your box. – baumgart Jun 15 '10 at 15:37
feedback

migrated from stackoverflow.com Jun 15 '10 at 15:17

This question came from our site for professional and enthusiast programmers.

1 Answer

Ipchains are old and i do not reccomend it

simple script

#!/bin/bash
IPTABLES=/sbin/iptables

#start and flush
$IPTABLES -F
$IPTABLES -t nat -F
$IPTABLES -X
$IPTABLES -P FORWARD DROP
$IPTABLES -P INPUT   DROP
$IPTABLES -P OUTPUT  DROP

#SSH traffic
$IPTABLES -A INPUT -p tcp --dport 22 -j ACCEPT
$IPTABLES -A INPUT -p tcp --dport 80 -j ACCEPT
link|improve this answer
feedback

Your Answer

 
or
required, but never shown