我的是2.4httpd的訪問(wèn)日志路徑是/usr/local/httpd/logs/access_log。里面有很多別人訪問(wèn)過(guò)來(lái)的IP。由于我不是專業(yè)的運(yùn)維。只能做點(diǎn)簡(jiǎn)單的。當(dāng)你的cat access_log看見(jiàn)很多。同一個(gè)時(shí)間點(diǎn)來(lái)訪問(wèn)ip。10:59:17 。這種類似與DDOS攻擊。可以考慮直接吧他的IP封了。如下:
58.61.66.99 - - [15/Sep/2016:10:59:17 +0800] "GET / HTTP/1.1" 200 45
58.61.66.99 - - [15/Sep/2016:10:59:17 +0800] "GET / HTTP/1.1" 200 45
58.61.66.99 - - [15/Sep/2016:10:59:17 +0800] "GET / HTTP/1.1" 200 45
58.61.66.99 - - [15/Sep/2016:10:59:17 +0800] "GET / HTTP/1.1" 200 45
58.61.66.99 - - [15/Sep/2016:10:59:17 +0800] "GET / HTTP/1.1" 200 45
58.61.66.99 - - [15/Sep/2016:10:59:17 +0800] "GET / HTTP/1.1" 200 45
58.61.66.99 - - [15/Sep/2016:10:59:17 +0800] "GET / HTTP/1.1" 200 45
58.61.66.99 - - [15/Sep/2016:10:59:17 +0800] "GET / HTTP/1.1" 200 45
58.61.66.99 - - [15/Sep/2016:10:59:17 +0800] "GET / HTTP/1.1" 200 45
58.61.66.99 - - [15/Sep/2016:10:59:17 +0800] "GET / HTTP/1.1" 200 45
這里要說(shuō)到iptables。
service iptables status 首先查看iptables有沒(méi)有開(kāi)啟,
filter表、nat表、mangle表和raw表 分別用于實(shí)現(xiàn)包過(guò)濾,網(wǎng)絡(luò)地址轉(zhuǎn)換、包重構(gòu)(修改)和數(shù)據(jù)跟蹤處理。
service iptables status //自己試試看如果是iptables: Firewall is not running. 去開(kāi)啟吧。
service iptables start //開(kāi)啟
iptables的配置文件/etc/sysconfig/iptables不存在怎么辦
首先要看一下iptables是否安裝了,使用service iptables status或yum info iptables看一下當(dāng)前狀態(tài)
如果已安裝,運(yùn)行以下命令:
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
service iptables save //保存
這樣就會(huì)提示
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
這樣就會(huì)有iptables的初始配置文件了
chkconfig --level 35 iptables on 設(shè)置35開(kāi)機(jī)啟動(dòng)
service iptables start
cat /etc/sysconfig/iptables //看一下。里面的規(guī)則
iptables -F //清空所有吧,本來(lái)也沒(méi)有什么東西的
service iptables save //保存規(guī)則
解釋一下一些東西。
input: 外面的數(shù)據(jù)到我們服務(wù)器
output: 服務(wù)器給我們的響應(yīng),就是服務(wù)器發(fā)數(shù)據(jù)發(fā)外面
寫一條禁止80端口的,httpd默認(rèn)是80端口,意思80端口就不給訪問(wèn)了。
iptables -t filter -A INPUT -p tcp --dport 80 -j DROP
-t filter //就是filter表,實(shí)現(xiàn)包過(guò)濾
-A //就是追加新規(guī)則 -I 插入,插到前面 -D 刪除
-p //使用什么傳輸協(xié)議TCP/UDP/ICMP
--dport //目標(biāo)端口
-j //ACCEPT:接受 , DROP:直接丟棄 ,REJECT:明示拒絕
這樣,80端口就訪問(wèn)不了。但是可以訪問(wèn)其他的。
再寫一條允許80端口的
iptables -t filter -A INPUT -p tcp --dport 80 -j ACCEPT
iptables-save > /etc/sysconfig/iptables //可以這樣來(lái)保存規(guī)則
cat /etc/sysconfig/iptables //查看規(guī)則
-A INPUT -p tcp -m tcp --dport 80 -j DROP
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
會(huì)出現(xiàn)兩條規(guī)則,有點(diǎn)矛盾一個(gè)是DROP 一個(gè)是ACCEPT。其實(shí)是前面的允許了,后面的就沒(méi)用了。
或者這樣干,把這條插到前面,這樣前面的允許了,后面的就沒(méi)用了。
iptables -t filter -I INPUT -p tcp --dport 80 -j ACCEPT
或者是這樣干。把DROP 刪除。
iptables -t filter -D INPUT -p tcp --dport 80 -j DROP
//跟著寫到這里,差不多可以知道怎么用了。
//就是當(dāng)不給ip是58.61.66.99的訪問(wèn)80端口,這樣干
iptables -I INPUT -p tcp -s 58.61.66.99 --dport 80 -j DROP
//就是要主要iptables的前后關(guān)系,前面的規(guī)則覆蓋后面的,寫再多也沒(méi)用。
//做個(gè)好玩的事情就是當(dāng)討厭的IP(58.61.66.99)進(jìn)來(lái)的時(shí)候,讓他跳到另外的端口,寫上 YOU ARE SB
//結(jié)合多站點(diǎn)。就是給他顯示8888端口的頁(yè)面,寫著 you are sb
PREROUTING是目的地址轉(zhuǎn)換—進(jìn)站(-j DNAT) POSTROUTING是源地址轉(zhuǎn)換—出站 (-j SNAT)
iptables -t nat -A PREROUTING -p tcp -s 58.61.66.99 --dport 80 -j DNAT --to-destination :8888