最近在看linux 防火墙iptables的相关内容,下面几个实用语句可能有用记录下。
ICMP相关应用
使自己不能ping 通 127.0.0.1
iptables -A INPUT -s 127.0.0.1 -p icmp -j DROP
192.168.0.0/24 网段无法ping能本机
iptables -A INPUT -s 192.168.0.0/24 -p icmp -j DROP
禁所有机器
# iptables -A INPUT -s 0/0 -p icmp -j DROP
# ICMP(PING) 接受 ! echo-request
/sbin/iptables -A INPUT -p icmp –icmp-type ! echo-request -j ACCEPT
accept_redirects
# echo “0” < /proc/sys/net/ipv4/conf/all/accept_redirects
or
# sysctl net.ipv4.conf.all.accept_redirects=”0″
禁止IP访问自己
[root@linux root]# iptables -A INPUT -s 192.168.0.253 -j DROP
禁止MSN
/sbin/iptables -I FORWARD -d gateway.messenger.hotmail.com -j DROP
/sbin/iptables -I FORWARD -p tcp –dport 1863 -j DROP
禁止QQ
/sbin/iptables -A FORWARD -p tcp -d tcpconn.tencent.com –dport 80 -j DROP
/sbin/iptables -A FORWARD -p tcp -d tcpconn.tencent.com –dport 443 -j DROP
/sbin/iptables -A FORWARD -p tcp -d tcpconn2.tencent.com -j DROP
/sbin/iptables -A FORWARD -i eth0 -p udp –dport 8000 -j DROP
封杀BT
/sbin/iptables -A FORWARD -i eth0 -p tcp –dport 6881:6890 -j DROP
WWW
# 禁止<<WWW
/sbin/iptables -A FORWARD -p tcp –dport 80 -j DROP
# 开放<<WWW
/sbin/iptables -A FORWARD -p tcp –dport 80 -j ACCEPT
FTP
# 禁止FTP
/sbin/iptables -A FORWARD -i eth0 -p tcp –dport 20 -j DROP
/sbin/iptables -A FORWARD -i eth0 -p tcp –dport 21 -j DROP
# 开放FTP
/sbin/iptables -A FORWARD -i eth0 -p tcp –dport 20 -j ACCEPT
/sbin/iptables -A FORWARD -i eth0 -p tcp –dport 21 -j ACCEPT
SMTP,POP3
# 禁止SMTP,POP3
/sbin/iptables -A FORWARD -i eth0 -p tcp –dport 25 -j DROP
/sbin/iptables -A FORWARD -i eth0 -p tcp –dport 110 -j DROP
# 开放SMTP,POP3
/sbin/iptables -A FORWARD -i eth0 -p tcp –dport 25 -j ACCEPT
/sbin/iptables -A FORWARD -i eth0 -p tcp –dport 110 -j ACCEPT
Samba
# 禁止Samba
[root@linux root]# iptables -A FORWARD -p tcp –sport 137:139 -j DROP
[root@linux root]# iptables -A FORWARD -p udp –sport 137:139 -j DROP
# DROP OTHERS
/sbin/iptables -A FORWARD -i eth0 -m state –state ESTABLISHED,RELATED -j ACCEPT
/sbin/iptables -A FORWARD -s 192.168.1.0/24 -j DROP