【Linux系统】Linux防火墙-iptables/firewalld的使用教程

10,490
IPRoyal

Linux系统防火墙是系统安全防御的城墙,在我们平常使用中,无论是部署服务、排查问题,都离不开防火墙和端口的相关操作,在Linux系统中有debian/ubuntu和centos7以下自带的iptables防火墙,Centos7系列自带的firewalld防火墙,目前最新版的Linux系统开始使用nftables防火墙作为生产工具提供,以及centos系统搭配的SELinux安全套件。

SELinux安全套件

SElinux是Linux系统下的一个增强安全模块,虽然保护了我们的系统,但同时也会阻碍很多软件的运行,所以在部署服务后,如检查网络不通的情况下可以查看此项模块;文章源自技术白-https://jishubai.com/71.html

永久关闭SElinux在命令行输入:vi /etc/selinux/config文章源自技术白-https://jishubai.com/71.html

找到参数SELINUX=enforce,改成SELINUX=disabled文章源自技术白-https://jishubai.com/71.html

把“SELINUXTYPE=targeted”这行注释掉,变成:#“SELINUXTYPE=targeted”,然后保存文件重启服务器生效;同理如果要开启则删掉注释把disabled改成enforce。文章源自技术白-https://jishubai.com/71.html

快捷命令文章源自技术白-https://jishubai.com/71.html

setenforce 0    #临时关闭SElinux
sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config   #永久关闭SElinux

iptables防火墙命令

service iptables status  #检查是否安装了iptables
yum install -y iptables  #安装iptables
yum update iptables      #升级iptables
yum install iptables-services -y   #安装iptables-services
service iptables restart  #重启iptables
service iptables start   #启动iptables
service iptables stop    #停止iptables
service iptables restart  #重启iptables
chkconfig iptables on #开机自启
chkconfig iptables off #关闭开机自启

firewalld防火墙命令

systemctl status firewalld.service  ##查看firewall状态
yum -y install firewall*  ##安装firewall命令
yum -y remove firewall*   ##卸载firewall命令
systemctl start firewalld.service  ##打开firewall命令
systemctl stop firewalld.service   ##关闭firewall命令
systemctl restart firewalld.service  ##重启firewall
systemctl disable firewalld.service  ##禁止firewall开机自启
systemctl enable firewalld.service  ##允许firewall开机自启

UFW防火墙命令

ufw status     ##查看ufw状态
ufw enable   ##开启
ufw disable   ##关闭
文章源自技术白-https://jishubai.com/71.html文章源自技术白-https://jishubai.com/71.html

本站TG群组skill_blog   联系博主:nbskill (微信协助) 杂货铺曙光商店

IPRoyal
 最后更新:2024-1-22
技术白