firewalld 2

firewalld

1. firewalld的開啓

iptables  切換    firewalld

# systemctl stop iptables.service 
# systemctl disable iptables.service  關閉firewalld並且開機關閉
# systemctl mask iptables.service   爲確保關閉可以凍結
# systemctl enable --now firewalld.service  開啓iptables並且開機啓動

2. 關於firewalld的域

trusted            接受所有網絡連接

home              用於家庭網絡,允許接受ssh,dns,ipp-client,samba-client,dhcp-client

work               工作網絡 ssh ipp-client,dhcp-client

public             公共網絡 ssh,dhcp-client

dmz                軍級網絡 ssh

block               拒絕所有

drop                丟棄,任何數據沒有回覆

internal            內部網絡 ssh,mdns,ipp-client,dhcp-client

external           ipv4網絡地址僞妝轉發

# firewall-cmd --get-zones   獲取域名

   

3. 關於firewalld的設定原理及數據

/etc/firewalld       火牆配置目錄

/usr/lib/firewalld/  火牆模塊目錄

添加自定義服務      

# cd /etc/firewalld/zones/ 
# vim public.xml            添加

 

# cd /usr/lib/firewalld/services/
# cp http.xml yueyue.xml
# vim yueyue.xml        添加描述
# firewall-cmd --reload  刷新服務

 

測試

# firewall-cmd --get-services | grep yueyue
# firewall-cmd --list-all

 

4.firewalld的管理命令

firewall-cmd --state            查看火牆狀態
firewall-cmd --get-active-zones 查看生效的域
firewall-cmd --get-default-zone 查看默認域
firewall-cmd --list-all         查看默認域中的火牆策略
firewall-cmd --list-all zone=work  查看指定域的火牆策略
firewall-cmd --get-services        查看所有可以設定的服務
firewall-cmd --permanent --remove-service=cockpit    移除服務
firewall-cmd --reload           刷新服務
# firewall-cmd --permanent --add-source=192.168.1.0/24  --zone=block 指定數據來源訪問指定域
# firewall-cmd --permanent --remove-source=192.168.1.0/24 --zone=block  移除

 

# firewall-cmd --permanent --change-interface=ens224 --zone=block  更改指定域網絡接口
# firewall-cmd --reload

 

5. firewalld的高級規則

# firewall-cmd --direct --add-rule ipv4 filter INPUT 1 -s 172.25.254.0/24 -p tcp --dport=22 -j ACCEPT
# firewall-cmd --direct --get-all-rules 

6. firewalld中的NAT

SNAT

# firewall-cmd --permanent --add-masquerade 
# firewall-cmd --reload  重啓服務

測試

# ifconfig
# ssh -l root 192.168.1.33

 

 

DNAT

# firewall-cmd --permanent --add-forward-port=port=22:proto=tcp:toaddr=172.25.254.33
# firewall-cmd --reload

測試

# ssh -l root 192.168.1.32

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章