Linux下防火墙和selinux的启动、关闭和查看
admin
2023-03-03 04:42:12
0

CentOS7.X下:

1.防火墙

防火墙状态查看:
[root@localhost sunan]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)

其中Active为inactive (dead)为关闭状态,active (running)为开启状态

关闭防火墙命令:
[root@localhost sunan]# systemctl stop firewalld.service 
开启防火墙命令:
[root@localhost sunan]# systemctl start firewalld.service
永久禁用防火墙命令(开机不自启动)
[root@localhost sunan]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
永久启动防火墙命令(开机自启动)
[root@localhost sunan]# systemctl enable firewalld.service   
Created symlink from /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service to /usr/lib/systemd/system/firewalld.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/firewalld.service to /usr/lib/systemd/system/firewalld.service.

CentOS6.X下:

1.防火墙

防火墙状态查看:
[root@localhost ~]# service iptables status
关闭防火墙命令:
[root@localhost ~]# service iptables stop
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Unloading modules:                               [  OK  ]
开启防火墙命令:
[root@localhost ~]# service iptables start
iptables: Applying firewall rules:                         [  OK  ]
永久禁用防火墙命令(开机不自启动)
[root@localhost ~]# chkconfig iptables off
永久启动防火墙命令(开机自启动)

[root@localhost ~]# chkconfig iptables on

2.selinux(CentOS7.X同CentOS6.X)

查看selinux状态:
[root@localhost sunan]# getenforce 
Enforcing

selinux状态有三种模式:
enforcing:强制模式,代表selinux运行中,且已经正确的开始限制domain/type了。
permissive:宽容模式,代表selinux运作中,不过仅会有警告信息并不会实际限制domain/type的访问。这种模式可以用来作为selinux的debug之用
disabled:关闭,selinux没有实际运行。
命令设置SELinux,前提不能是disabled状态:

[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce  
Permissive

其中setenforce 0|1
0:设置为premissive状态;
1:设置为enforcing状态;
此设置:重启系统后无效。
修改配置文件,设置selinux为disabled状态:

[root@localhost ~]# vim /etc/selinux/config

SELINUX=disabled
SELINUXTYPE=targeted

保存,重启系统生效。

相关内容

热门资讯

农业农村“半年报”发布,这些看... 7月24日召开的国新办发布会上,农业农村部介绍2026年上半年农业农村经济运行情况。夏粮喜获丰收、常...
世界遗产+1!景德镇打卡地图,... 北京时间7月25日,在韩国釜山举行的第48届世界遗产大会上,由我国申报的“景德镇手工瓷业遗存”项目经...
有人呼吁白宫“封杀”中国开源大... 未来一段时间,将有多款中国开源模型发布。Kimi K3定于7月27日正式开源,阿里即将开源2.4万亿...
20名“高考状元”选择学医!此... 2026年香港高考的24名“状元”中,有20人明确表示将留港攻读医科。多年来,香港最顶尖的“学霸们”...
“抢人大战”,风向有变? 各地一场“抢老人”的大战,已然徐徐拉开大幕。最近,有着人口净流出压力的吉林,计划拿出3亿元发展旅居康...
石家庄一家不限量的爱心素食面馆... 7月24日正午时分,记者来到位于石家庄市新华区东明家居西二环店北门旁的“素面”小店,不大的店面里坐满...
中材科技申请风电叶片外补强辅助... 国家知识产权局信息显示,中材科技(伊吾)风电叶片有限公司申请一项名为“风电叶片外补强辅助固化装置”的...
为人工智能治理提供重要公共产品 图为2026世界人工智能大会暨人工智能全球治理高级别会议举办期间,在世博展览馆灵心巧手展位,参观者观...
泽连斯基称俄对乌多地发动大规模... 当地时间25日,乌克兰总统泽连斯基通报称,俄军于当日凌晨对乌克兰多地发动大规模空袭,使用2枚导弹、近...