设置Iptables

设置Iptables

 


#!/bin/bash

iptables --delete-chain
iptables --flush
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -i lo -j ACCEPT

iptables -A INPUT -p udp -j DROP

service iptables save
service iptables restart

方法二:



service iptables stop

echo '
*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [15:1848]
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
COMMIT
' > /etc/sysconfig/iptables

iptables -I INPUT -p tcp --dport 80 -j ACCEPT