(1)屏蔽所有端口
(2)把SSH的缺省端口設置為56565
(3)把56565、80、3306端口打開
(4)把3306端口設置為只允許本機訪問
如果沒有安裝iptables的話,運行命令yum install iptables完成iptables安裝
初始化安裝以后,顯示為以下信息:
[root@tp ~]# iptables -L -n
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
(1)屏蔽所有端口
[root@tp ~]# iptables -F
[root@tp ~]# iptables -X
[root@tp ~]# iptables -P INPUT DROP
[root@tp ~]# iptables -P OUTPUT DROP
[root@tp ~]# iptables -P FORWARD DROP
當超出了IPTABLES里filter表里的兩個鏈規則 (INPUT,FORWARD)時,不在這兩個規則里的數據包怎么處理呢,那就是DROP(放棄),有同學喜歡配置OUTPUT為accpet,因為如果 被入侵,對方可以使用服務器做為中轉,發起攻擊,也會產生大量的數據包,所以這里配置為DROP
(2)把SSH的缺省端口設置為56565
在修改ssh端口時,應先把要修改的端口號56565加入白名單
[root@tp ~]# iptables -A INPUT -p tcp --dport 56565 -j ACCEPT
[root@tp ~]# iptables -A OUTPUT -p tcp --sport 56565 -j ACCEPT
[root@tp ~]# /etc/rc.d/init.d/iptables save
[root@tp ~]# service iptables restart
再修改端口號
[root@linux ~]# vi /etc/ssh/sshd_config
將"#Port 22"修改為"Port 56565"
重啟ssh服務
[root@linux ~]# /etc/init.d/sshd restart
Stopping sshd: [ OK ]
Starting sshd: [ OK ]
如果想看看sshd端口號是否修改成功的話,可以使用 netstat -an 命令查看一下或退出ssh使用新端口號登陸嘗試。
(3)把80端口打開
[root@tp ~]# iptables -A INPUT -p tcp --dport 80 -j ACCEPT
[root@tp ~]# iptables -A OUTPUT -p tcp --sport 80 -j ACCEPT
[root@tp ~]# /etc/rc.d/init.d/iptables save
[root@tp ~]# service iptables restart
(4)把3306端口設置為只允許本機訪問
[root@tp ~]#/sbin/iptables -A INPUT -p tcp -s 127.0.0.1 --dport 3306 -j ACCEPT
[root@tp ~]#/sbin/iptables -A OUTPUT -p tcp -s 127.0.0.1 --dport 3306 -j ACCEPT
http://gzjhj88.blog.51cto.com/1049760/629563
http://www.redicecn.com/html/qita/20110331/243.html
http://wenku.baidu.com/view/94fadf1252d380eb62946d95.html
http://www.bugbeta.cn/?p=495
http://gzjhj88.blog.51cto.com/1049760/629563
http://gzjhj88.blog.51cto.com/1049760/315021