在centos系統(tǒng)中有些時候需要查看來自某個地址的鏈接數(shù),我們就可以使用組合命令來查看和統(tǒng)計某個服務(wù)器上所有鏈接按照ip分類統(tǒng)計結(jié)果
netstat -tun|awk '{print $5}'|cut -d : -f1|sort|uniq -c|sort -n
命令解釋
netstat命令功能是顯示網(wǎng)絡(luò)連接、和網(wǎng)絡(luò)接口信息,可以得到服務(wù)器有哪些網(wǎng)絡(luò)連接正在運作;-t顯示tcp傳輸協(xié)議的連線狀況,-u顯示udp傳輸協(xié)議的連線狀況,-n直接用ip地址顯示,而不是通過域名服務(wù)器。
centos 服務(wù)器禁止ip訪問/ip 黑名單
一、iptables 防火墻
先查看是否已經(jīng)安裝防火墻 如果已經(jīng)安裝跳過此步驟
yum install iptables-services # 2.安裝 iptables 防火墻
systemctl enable iptables # 3.設(shè)置開機自啟
service iptables [save|stop|start|restart]
二、iptables開啟某些端口可以進來
# 因為我們防火墻剛開,默認(rèn)端口都是屏蔽的,會發(fā)現(xiàn)網(wǎng)站訪問不了
# 1.我們需要放行端口,這里先放行 80 、 443 和 22 端口
iptables -I INPUT -p tcp --dport 80 -j ACCEPT
iptables -I INPUT -p tcp --dport 443 -j ACCEPT
iptables -I INPUT -p tcp --dport 22 -j ACCEPT
三、禁止某些ip訪問本機
#屏蔽114.111.0.69的請求
iptables -I INPUT -s 114.111.0.69 -j DROP
四、查看當(dāng)前防墻的規(guī)文章來源:http://www.zghlxwxcb.cn/news/detail-525107.html
iptables -L -n --line-number
5刪除某個的防火墻規(guī)則文章來源地址http://www.zghlxwxcb.cn/news/detail-525107.html
# 例如:刪除INPUT的第一條規(guī)則用如下命令。這個1就是行號
iptables -D INPUT 1
再執(zhí)行查看即可看到上述規(guī)則已刪除。
iptables -L -n --line-number
到了這里,關(guān)于centos查看訪問ip和屏蔽某些ip的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!