首先明確配置CentOS防火墻的核心是理解區(qū)域、服務(wù)和持久化設(shè)置,具體需掌握firewalld的zone劃分如public、internal等,使用firewall-cmd命令管理運(yùn)行時(shí)與永久規(guī)則,通過--add-service或--add-port開放服務(wù)端口,結(jié)合--permanent參數(shù)確保規(guī)則重啟生效,并在修改后執(zhí)行--reload應(yīng)用配置。
Configuring a firewall on CentOS using firewalld-cmd is straightforward once you understand the core concepts of zones, services, and runtime vs. permanent settings. firewalld uses dynamic zones to define trust levels for network connections, and you can manage rules with the firewall-cmd
command-line tool.
Understanding Zones and Default Configuration
When you start firewalld, it assigns interfaces to zones based on predefined rules. Common zones include:
- public: For public areas where you don’t trust other computers (default for most installations)
- internal: For internal networks with some level of trust
- home: For home networks
- trusted: All traffic is accepted
To check the current active zone and assigned interfaces:
firewall-cmd --get-active-zonesTo see the default zone:
firewall-cmd --get-default-zoneYou can change the default zone with:
firewall-cmd --set-default-zone=internalOpening Ports and Services
Instead of managing raw ports, firewalld allows you to enable predefined services (like http, ssh). To allow HTTP traffic in the current session:
firewall-cmd --add-service=httpTo make this change permanent across reboots:
firewall-cmd --permanent --add-service=httpThen reload the firewall:
firewall-cmd --reloadIf you need to open a custom port, such as TCP 8080:
firewall-cmd --add-port=8080/tcpfirewall-cmd --permanent --add-port=8080/tcp
Managing Runtime and Permanent Settings
By default, firewall-cmd
applies changes only to the runtime configuration. These are lost after reboot unless made permanent.
To list all currently active settings:
firewall-cmd --list-allTo list permanent settings:
firewall-cmd --permanent --list-allAlways use --permanent
when you want rules to persist. Remember to run --reload
after making permanent changes to apply them to the running configuration.
Working with Specific Zones
If your system has multiple network interfaces, assign them to appropriate zones. For example, to add an interface eth1 to the internal zone:
firewall-cmd --zone=internal --add-interface=eth1To allow SSH access only in the trusted zone:
firewall-cmd --zone=trusted --add-service=sshfirewall-cmd --permanent --zone=trusted --add-service=ssh
You can also block all traffic in a zone by removing unwanted services or using rich rules for fine-grained control.
Basically, get familiar with zones, use services when possible, always consider the permanent flag, and reload when needed. That’s how you maintain a secure and functional firewall on CentOS with firewalld.
以上是如何在CentOS上使用firewalld-cmd配置防火墻?的詳細(xì)內(nèi)容。更多信息請(qǐng)關(guān)注PHP中文網(wǎng)其他相關(guān)文章!

熱AI工具

Undress AI Tool
免費(fèi)脫衣服圖片

Undresser.AI Undress
人工智能驅(qū)動(dòng)的應(yīng)用程序,用于創(chuàng)建逼真的裸體照片

AI Clothes Remover
用于從照片中去除衣服的在線人工智能工具。

Stock Market GPT
人工智能驅(qū)動(dòng)投資研究,做出更明智的決策

熱門文章

熱工具

記事本++7.3.1
好用且免費(fèi)的代碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
功能強(qiáng)大的PHP集成開發(fā)環(huán)境

Dreamweaver CS6
視覺化網(wǎng)頁開發(fā)工具

SublimeText3 Mac版
神級(jí)代碼編輯軟件(SublimeText3)

卸載舊版本Docker避免沖突,2.安裝yum-utils并添加官方Docker倉庫,3.安裝DockerCE、CLI和containerd,4.啟動(dòng)并啟用Docker服務(wù),5.運(yùn)行hello-world鏡像驗(yàn)證安裝成功,6.可選配置非root用戶運(yùn)行Docker。

startbyCheckingNetwork InterfacestatuswithipAddrshow,Suseit'supandhasavalidip; ifDown,bringitupusitusiplinkSetup.verifyConnectivityBypingThegateway(findviaiproute | grepdefeault)

sodrootpasswordwithsudopasswdroot,edit/ett/etc/ssh/sshd_configtosetpermitrootloginyesand andpasswordauthenticationyes,thenRestartSshviasudoSystemctLrestartsshd,testingnewaccessbebeforeclosingclosingcortentssession。

createa2gbswapfileusingddif =/dev/zeroof =/swapfilebs = 1mcount = 2048.2.setpermissionswithChmod600/swapfile.3.formatasswapusemks wap/swapfile.4.enablewithswapon/swapfile.5.makepermanentbyadding/swapfilenoneswapsw00to/etc/fstab.6.optionallysetvm.swappines

使用sudoyumcleanall清除所有緩存并用sudoyummakecache重建,可解決包問題并釋放磁盤空間。

首先,checkInternetanddnsconnectivity disepingAndnslookup;如果flaged,更新/etc/etc/confwithvaliddnssservers.thencleanyumcachewith“ yumcleanall”,remove/var/var/cacke/cache/yum yum yum andregenerateMetAtaTavia“ yummakecececace,yummakakecache”

首先安裝EPEL源和certbot工具,然后根據(jù)Web服務(wù)器選擇對(duì)應(yīng)插件,運(yùn)行certbot獲取證書并自動(dòng)配置,最后設(shè)置cron任務(wù)實(shí)現(xiàn)每半年自動(dòng)續(xù)期,確保SSL證書持續(xù)有效。

檢查CPU虛擬化支持,確認(rèn)BIOS中已啟用;2.安裝KVM相關(guān)包并啟動(dòng)libvirtd服務(wù);3.驗(yàn)證模塊加載與服務(wù)狀態(tài),使用virt-install創(chuàng)建虛擬機(jī);4.可選配置橋接網(wǎng)絡(luò)以提升性能。
