- 工信部備案號 滇ICP備05000110號-1
- 滇公安備案 滇53010302000111
- 增值電信業(yè)務(wù)經(jīng)營(yíng)許可證 B1.B2-20181647、滇B1.B2-20190004
- 云南互聯(lián)網(wǎng)協(xié)會(huì )理事單位
- 安全聯(lián)盟認證網(wǎng)站身份V標記
- 域名注冊服務(wù)機構許可:滇D3-20230001
- 代理域名注冊服務(wù)機構:新網(wǎng)數碼
1、查看
iptables -nvL –line-number
-L查看當前表的所有規則,默認查看的是filter表,如果要查看NAT表,可以加上-t NAT參數。
-n不對ip地址進(jìn)行反查,加上這個(gè)參數顯示速度會(huì )快很多。
-v輸出詳細信息,包含通過(guò)該規則的數據包數量,總字節數及相應的網(wǎng)絡(luò )接口。
–line-number顯示規則的序列號,這個(gè)參數在刪除或修改規則時(shí)會(huì )用到。
2、添加
添加規則有兩個(gè)參數:-A和-I。其中-A是添加到規則的末尾;-I可以插入到指定位置,沒(méi)有指定位置的話(huà)默認插入到規則的首部。
當前規則:
[root@test ~]# iptables -nL --line-number
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 DROP all -- 192.168.1.1 0.0.0.0/0
2 DROP all -- 192.168.1.2 0.0.0.0/0
3 DROP all -- 192.168.1.4 0.0.0.0/0
添加一條規則到尾部:
[root@test ~]# iptables -A INPUT -s 192.168.1.5 -j DROP
再插入一條規則到第三行,將行數直接寫(xiě)到規則鏈的后面:
[root@test ~]# iptables -I INPUT 3 -s 192.168.1.3 -j DROP
查看:
[root@test ~]# iptables -nL --line-number
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 DROP all -- 192.168.1.1 0.0.0.0/0
2 DROP all -- 192.168.1.2 0.0.0.0/0
3 DROP all -- 192.168.1.3 0.0.0.0/0
4 DROP all -- 192.168.1.4 0.0.0.0/0
5 DROP all -- 192.168.1.5 0.0.0.0/0
可以看到192.168.1.3插入到第三行,而原來(lái)的第三行192.168.1.4變成了第四行。
3、刪除
刪除用-D參數
刪除之前添加的規則iptables -A INPUT -s 192.168.1.5 -j DROP:
[root@test ~]# iptables -D INPUT -s 192.168.1.5 -j DROP
有時(shí)候要刪除的規則太長(cháng),刪除時(shí)要寫(xiě)一大串,既浪費時(shí)間又容易寫(xiě)錯,這時(shí)我們可以先使用--line-number找出該條規則的行號,再通過(guò)行號刪除規則。
[root@test ~]# iptables -nv --line-number
iptables v1.4.7: no command specified
Try `iptables -h or iptables --help for more information.
[root@test ~]# iptables -nL --line-number
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 DROP all -- 192.168.1.1 0.0.0.0/0
2 DROP all -- 192.168.1.2 0.0.0.0/0
3 DROP all -- 192.168.1.3 0.0.0.0/0
刪除第二行規則
[root@test ~]# iptables -D INPUT 2
4、修改
修改使用-R參數
先看下當前規則:
[root@test ~]# iptables -nL --line-number
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 DROP all -- 192.168.1.1 0.0.0.0/0
2 DROP all -- 192.168.1.2 0.0.0.0/0
3 DROP all -- 192.168.1.5 0.0.0.0/0
將第三條規則改為ACCEPT:
[root@test ~]# iptables -R INPUT 3 -j ACCEPT
再查看下:
[root@test ~]# iptables -nL --line-number
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 DROP all -- 192.168.1.1 0.0.0.0/0
2 DROP all -- 192.168.1.2 0.0.0.0/0
3 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
第三條規則的target已改為ACCEPT。
售前咨詢(xún)
售后咨詢(xún)
備案咨詢(xún)
二維碼
TOP