您現在的位置是:首頁 > 運動

知了堂|iptables與firewalld 防火牆操作配置

由 知了堂 發表于 運動2022-01-02
簡介★iptables -t filter -F INPUT(7)禁止員工訪問域名為 http:www.xxxx.org 的網站(域名必須存在,且能被解析,否則會出錯)★★★iptables -A FORWARD -d http:www

如何開啟防火牆設定

一.iptables 防火牆配置

(1)為 filter 表的 INPUT 鏈新增一條規則,規則為拒絕所有使用 ICMP 協議的資料包。★★

iptables -A INPUT -p icmp -j DROP 將資料包丟棄,不迴應

REJECT 丟棄並回應

(2)為 filter 表的 INPUT 鏈新增一條規則,規則為允許訪問 TCP 協議的 80 埠的資料包透過。★★

iptables -A INPUT -p tcp ——dport 80 -j ACCEPT

(3)在 filter 表中 INPUT 鏈的第 2 條規則前插入一條新規則,規則為不允許訪問 TCP。協議的 53 埠的資料包通

過。★★

檢視:iptables -L -n ——line-number

(顯示規則的序號:num)

iptables -I INPUT 2 -p tcp ——dport 53 -j DROP

(4)在 filter 表中 INPUT 鏈的第 1 條規則前插入一條新規則,規則為允許源 IP 地址屬於 172.16.0.0/16 網段的數

據包透過。★★★

iptables -I INPUT 1 -s 172。16。0。0/16 -j ACCEPT

(5)刪除 filter 表中的第 2 條規則。★

iptables -D INPUT 2

(6)清除 filter 表中 INPUT 鏈的所有規則。★

iptables -t filter -F INPUT

(7)禁止員工訪問域名為 http://www.xxxx.org 的網站(域名必須存在,且能被解析,否則會出錯)★★★

iptables -A FORWARD -d http://www。xxxx。org -j DROP

iptables -A INPUT -d http://www。xxxx。org -j DROP

(8)禁止員工訪問 IP 地址為 212.1.2.3 的網站。★★

iptables -A FORWARD -d 212。1。2。3 -p tcp ——port 80 -j DROP

二、firewalld 防火牆

(1)設定 firewalld 防火牆,允許訪問 Vsftpd 服務進行檔案上傳與下載。★★★

firewall-cmd ——add-service=ftp ——zone=public ——permanent

或 firewall-cmd ——add-ports=21/tcp,20/tcp ——zone=public ——permanent

(2)設定 firewalld 防火牆,允許使用者使用域名訪問 http 和 https 服務。★★★

firewall-cmd ——add-service=https ——zone=public ——permanent

或 firewall-cmd ——add-ports=443/tcp,443/udp ——zone=public ——permanent

(3)設定 firewalld 防火牆,允許使用者使用域名訪問公司釋出的論壇與電商網站。★★★

firewall-cmd ——add-service=dns ——zone=public ——permanent

或 firewall-cmd ——add-ports=53/tcp,53/udp ——zone=public ——permanent

(4)允許內網主機收發郵件

客戶端傳送郵件時訪問郵件伺服器 TCP25 埠,接收郵件時訪問,可能使用的埠則較多,UDP 協議以及 TCP

協議的埠:110,143,993 以及 995。★★★★

SMTP:郵件傳送協議,tcp/25 埠 ——permanent

POP3:郵局協議(收郵件)第三版,tcp/110 埠 ——permanent

POP3S:郵局加密協議(收郵件)第三版,tcp/995 埠 ——permanent

POP2:郵局協議(收郵件)第二版,tcp/109 埠

IMAP:Internet 訊息訪問協議,和 POP3 一樣的功能,tcp/143 埠

IMAPS:Internet 訊息加密訪問協議,tcp/993 埠

firewall-cmd

——add-ports=25/tcp,110/tcp,995/tcp,143/tcp,993/tcp,——zone=public

——permanent

或 firewall-cmd ——add-service={pop3,smtp,imap,pop3s,imaps,} ——zone=public ——permanent

(5)我們之前釋出的電商網站,訪問時是透過 8080 埠,請設定 firewalld 防火牆埠轉發策略,將 8080 埠禁

用,使用 9099 埠訪問電商網站。★★★★★

firewall-cmd ——permanent ——add-masquerade ——permanent

firewall-cmd ——add-port=9090/tcp ——permanent

firewall-cmd ——remove-port=8080/tcp ——permanent

firewall-cmd ——add-forward-port=port=9099:proto=tcp:toport=8080 ——permanent

推薦文章