Need to block all ports and open only select ports on Ubuntu 7.1
Hi,
I need to block all ports by defaults on linux system and need to allow only few ports to be opened using iptable rules.
ex. to open only ssh port ( 22) , I tried following commands.
iptables -A INPUT -p tcp --dport 22 -j ACCEPT ;
iptables -A INPUT -p udp --dport 22 -j ACCEPT ;
iptables -A OUTPUT -p tcp --dport 22 -j ACCEPT ;
iptables -A OUTPUT -p udp --dport 22 -j ACCEPT ;
iptables -A OUTPUT -p tcp -j DROP ;
iptables -A OUTPUT -p udp -j DROP ;
iptables -A INPUT -p tcp -j DROP ;
iptables -A INPUT -p tcp -j DROP;
iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh
ACCEPT udp -- anywhere anywhere udp dpt:ssh
DROP tcp -- anywhere anywhere
DROP tcp -- anywhere anywhere
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh
ACCEPT udp -- anywhere anywhere udp dpt:ssh
ACCEPT udp -- anywhere anywhere udp dpt:ssh
DROP tcp -- anywhere anywhere
DROP udp -- anywhere anywhere
After this when I tried to ssh a machine, it just timed out.
|