Centos7如何安裝iptables?本教程以Centos7系統(tǒng)為例
本配置適用于centos7版本
1.先檢查是否安裝了iptables
Service iptables status
2.安裝iptables
yum install -y iptables
3.升級iptables
yum update iptables
4.安裝iptables-services
yum install iptables-services
禁用/停止自帶的firewalld服務
#停止firewalld服務
systemctl stop firewalld
#禁用firewalld服務
systemctl mask firewalld
配置文件路徑為:/etc/sysconfig/iptables
5.規(guī)則的寫法:
iptables定義規(guī)則的方式比較復雜:
格式:
iptables [-t table] COMMAND chain CRETIRIA -j ACTION
-t table :3個filter nat mangle
COMMAND:定義如何對規(guī)則進行管理
chain:指定你接下來的規(guī)則到底是在哪個鏈上操作的,當定義策略的時候,是可以省略的
CRETIRIA:指定匹配標準
-j ACTION :指定如何進行處理
比如:不允許172.16.0.0/24的進行訪問。
iptables -t filter -A INPUT -s 172.16.0.0/16 -p udp --dport 53 -j DROP
當然你如果想拒絕的更徹底:
比如:打開8080端口為例子。
iptables -A INPUT -p tcp --dport 8080 -j ACCEPT