系統(tǒng)運(yùn)維
iptables是Linux上常用的防火qiang軟件,下面說一下iptables的安裝、清除iptables規(guī)則、iptables只開放指定端口、iptables屏蔽指定ip、ip段及解封、刪除已添加的iptables規(guī)則、設(shè)置iptables開機(jī)啟動等iptables的基本應(yīng)用。

如果沒有安裝iptables需要先安裝,則需執(zhí)行:
[root@node1 ~]# yum -y install iptables
[root@node1 ~]# yum -y install iptables-services
2、iptables常用的選項(xiàng)參數(shù)如下:3、iptables中的四表五鏈及動作四個表如下:
五個鏈如下:
動作如下:
[root@node1 ~]# iptables -F
[root@node1 ~]# iptables -X
[root@node1 ~]# iptables -Z
5、開放指定的端口
[root@node1 ~]# iptables -A INPUT -i lo -j ACCEPT #允許本地回環(huán)接口(即運(yùn)行本機(jī)訪問本機(jī))
[root@node1 ~]# iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT #允許已建立的或相關(guān)連的通行
[root@node1 ~]# iptables -A OUTPUT -j ACCEPT # 允許已建立的或相關(guān)連的通行
[root@node1 ~]# iptables -A INPUT -p tcp --dport 22 -j ACCEPT # 允許訪問22端口
[root@node1 ~]# iptables -A INPUT -p tcp --dport 80 -j ACCEPT #允許訪問80端口
[root@node1 ~]# iptables -A INPUT -p tcp --dport 443 -j ACCEPT #允許訪問443端口
[root@node1 ~]# iptables -A INPUT -p tcp --dport 20 -j ACCEPT #允許FTP服務(wù)的20端口
[root@node1 ~]# iptables -A INPUT -p tcp --dport 21 -j ACCEPT #允許FTP服務(wù)的21端口
[root@node1 ~]# iptables -A INPUT -p icmp -j ACCEPT #允許ping
# 以下兩條是禁止其他未允許的規(guī)則訪問及轉(zhuǎn)發(fā)
[root@node1 ~]# iptables -A INPUT -j REJECT
[root@node1 ~]# iptables -A FORWARD -j REJECT
6、屏蔽IP
#如果只是想屏蔽IP的話“上面開放指定的端口”部分設(shè)置可以直接跳過。
[root@node1 ~]# iptables -I INPUT -s 123.4.5.6 -j DROP #屏蔽單個IP
[root@node1 ~]# iptables -I INPUT -s 123.0.0.0/8 -j DROP #屏蔽一個網(wǎng)段
[root@node1 ~]# iptables -I INPUT -s 192.168.10.0/24 -j DROP #屏蔽一個網(wǎng)段
7、屏蔽或允許某IP訪問指定端口
[root@node1 ~]# iptables -I INPUT -s 192.168.1.1 -p tcp --dport 22 -j DROP #屏蔽某IP訪問tcp的22端口
[root@node1 ~]# iptables -I INPUT -p tcp --dport 22 -j DROP #拒絕所有訪問tcp的22端口
[root@node1 ~]# iptables -I INPUT -s 192.168.1.2 -p tcp --dport 22 -j ACCEPT #允許某個IP訪問tcp的22端口
8、查看已添加的iptables規(guī)則
[root@node1 ~]# iptables -L -n -v # “-n”只顯示IP地址和端口號,不將IP解析為域名
9、刪除已添加的iptables規(guī)則
[root@node1 ~]# iptables -L -n --line-numbers #將所有iptables以序號標(biāo)記顯示
[root@node1 ~]# iptables -D INPUT 1 #刪除INPUT里序號為1的規(guī)則
10、iptables的開機(jī)啟動及規(guī)則保存
[root@node1 ~]# systemctl enable iptables #設(shè)置iptables開機(jī)自啟
[root@node1 ~]# service iptables save #保存,若提示沒有service命令,執(zhí)行下面命令進(jìn)行安裝service命令
[root@node1 ~]# yum install initscripts -y #安裝service命令———————— 本文至此結(jié)束,感謝閱讀 ————————
當(dāng)前題目:centos之iptables配置命令舉例
本文地址:http://chinadenli.net/article4/cjeioe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)、微信公眾號、網(wǎng)站維護(hù)、網(wǎng)站導(dǎo)航、網(wǎng)站排名、網(wǎng)站營銷
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)