Linux防火牆相關練習

2021-10-04 21:26:08 字數 3965 閱讀 2133

一、iptables

yum install iptables-services

1.iptables有幾個表以及每個表有幾個鏈

四表五鏈

filter,nat,mangle,raw

prerouting,input,forward,output,postrouting

2.iptables有幾個表以及每個表對應鏈的作用,對應企業應用場景

fileter 預設主機防火牆,過濾輸入輸出主機的資料報

input 處理輸入資料報

forword 處理流經本主機的資料報

output 處理輸出資料報

nat 負責網路位址轉換

porward 處理**資料報

prerouting 用於目標位址轉換

postouting 用於源位址轉換

3.請寫出檢視iptables當前所有規則的命令

[root@localhost ~]

# iptables -l -n --line-numbers

4.禁止來自192.168.100.20 ip位址訪問80埠的請求

[root@localhost ~]

# iptables -a input -p tcp -s 192.168.100.20 --dport 80 -j drop

5.實現把訪問192.168.100.20:80的請求轉到192.168.100.30:80

[root@localhost ~]

# iptables -t nat -a prerouting -d 192.168.100.20 -p tcp --dport 80 -j dnat --to-destination 192.168.100.30

6.寫乙個防火牆配置指令碼,只允許遠端主機訪問本機的80埠

#!/bin/bash

iptables -a input -p tcp --dport 80 -j accpet

iptables -a input -p tcp -j drop

7.限制客戶端對本機telnet服務併發連線數小於等於3

[root@localhost ~]

# iptables -a input -d 192.168.100.10 -p tcp --dport 80 -m connlimit --connlimit-upto 3 -j accept(設定為同一主機最大同時能連線3個)

[root@localhost ~]

# iptables -a input -p tcp --dport 23 -j drop

8.僅允許周1、3、5,8點到18點訪問本機telnet

[root@localhost ~]

# iptables -i input -d 192.168.100.10 -p tcp --dport 80 -m time --timestart 09:00:00 --timestop 18:00:00 --weekdays mon,wed,fri -j accept

9.iptables只開啟ssh、web、telnet訪問

[root@localhost ~]

# iptables -a input -d 192.168.100.10 -p tcp -m multiport --dports 22,23,80 -j accept (連續的埠可用xx到xx表示)

[root@localhost ~]

# iptables -a output -s 192.168.100.10 -p tcp -m multiport --sports 22:23,80 -j accept

[root@localhost ~]

# iptables -a input -d 192.168.100.10 -j drop

[root@localhost ~]

# iptables -a output -s 192.168.100.10 -j drop

10.指定ip位址範圍可以訪問本機mysql

[root@localhost ~]

# iptables -i input 2 -d 192.168.100.10 -p tcp --dport 3306 -m iprange --src-range 192.168.100.10-192.168.100.30 -j accept

[root@localhost ~]

# iptables -i output 2 -d 192.168.100.10 -p tcp --dport 3306 -m iprange --dst-range 192.168.100.10-192.168.88.30 -j accept

二、firewalld

1、預設public區域對外開放所有人能通過ssh服務連線,但拒絕192.168.200.0/24網段通過ssh連線伺服器。

[root@localhost ~]

# firewall-cmd --add-rich-rule='rule family=ipv4 source address=192.168.200.0/24 port port=22 protocol=tcp drop'

2、使firewalld允許所有人能訪問http,nginx服務、但只有192.168.100.10主機可以訪問ssh服務。

[root@localhost ~]

# firewall-cmd --add-service=

[root@localhost ~]

# firewall-cmd --add-rich-rule='rule family=ipv4 source address=192.168.100.10 port port=22 protocol=tcp accept'

[root@localhost ~]

# firewall-cmd --add-rich-rule='rule family="ipv4" source address="192.168.200.0/24" forward-port port=5555 protocol=tcp to-port=22 to-addr=192.168.100.10'

4、將tcp協議埠3300-3400新增到external區域。

[root@localhost ~]

# firewall-cmd --zone=external --add-port=3300-3400/tcp

success

5、查詢internal區域中是否包含介面ens33。

[root@localhost ~]

# firewall-cmd --zone=internal --query-inte***ce=ens33

6、為internal區域刪除繫結的網路介面ens33。

[root@localhost ~]

# firewall-cmd --zone=internal --remove-inte***ce=ens33

7、查詢internal區域中是否啟用了ssh服務。

[root@localhost ~]

# firewall-cmd --zone=internal --query-service=ssh

8、為internal區域設定允許訪問ssh服務

[root@localhost ~]

# firewall-cmd --zone=internal --add-service=ssh

linux防火牆相關

linux 防火牆 selinux設定 sestatus v 檢視selinux執行狀態 semanage fcontext a t httpd sys content t home deploy share portal 設定目錄許可權 nginx403錯誤 restorecon rv home ...

防火牆相關

iptables防火牆 1 基本操作 檢視防火牆狀態 service iptables status 停止防火牆 service iptables stop 啟動防火牆 service iptables start 重啟防火牆 service iptables restart 永久關閉防火牆 chk...

防火牆相關

檢視防火牆服務狀態 systemctl status firewalld 關閉防火牆 systemctl stop firewalld 開啟防火牆 systemctl start firewalld 禁止防火牆開啟啟動 systemctl disable firewalld 重啟防火牆使配置生效 s...