CentOS 6.5 学习笔记 关闭 iptables, 关闭 selinux


iptables 和 selinux 是 CentOS 6.5 内置的两道防火墙,功能强大,配置复杂,对新手极不友好.

有时,文件配置无误,但服务无法启动,多半是因为被这两道防火墙拦截了.

初学 Linux 建议关闭 iptables 和 selinux, 待熟练后再开启.

1.关闭 iptables

>>> 1.1 查看 iptables 状态

[root@ ~]#: /etc/init.d/iptables status  #  查看 iptables 状态

表格:filter  # 正在运行
Chain INPUT (policy ACCEPT)  
num target prot opt source destination
1 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
...

Chain FORWARD (policy ACCEPT)
num target prot opt source destination
1 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)
num target prot opt source destination

>>> 1.2 临时关闭 iptables,系统重启后, iptables 再次自动开启

 [root@ ~]#: /etc/init.d/iptables stop  # 临时关闭,重启失效 

iptables:将链设置为政策 ACCEPT:filter [确定]
iptables:清除防火墙规则: [确定]
iptables:正在卸载模块: [确定]

[root@ ~]#: /etc/init.d/iptables status  # 再次查看
iptables:未运行防火墙。

>>> 1.3 永久关闭 iptables,系统重启后生效.

[root@ ~]#: chkconfig iptables off  # 永久关闭,重启后生效. 

[root@ ~]#: reboot  # 重启

[root@ ~]#: /etc/init.d/iptables status
iptables:未运行防火墙。 # 重启后不会自动开启,说明已永久关闭

如需重新开启 iptables, 使用 chkconfig iptables on, 然后 reboot.

2.关闭selinux

>>> 2.1 临时关闭 selinux, 系统重启后, selinux 再次自动开启

[root@ ~]#: /usr/sbin/sestatus  # 查看 selinux 状态

SELinux status: enabled  # 可用
SELinuxfs mount: /selinux
Current mode: enforcing
Mode from config file: enforcing
Policy version: 24
Policy from config file: targeted

[root@ ~]#: setenforce 0  # 临时关闭,重启失效

[root@ ~]#: /usr/sbin/sestatus
SELinux status: enabled # 这里显示的还是"可用",但实际不可用

...

>>> 2.2 永久关闭  selinux, 重启系统后生效

[root@ ~]#: vi /etc/selinux/config  # 修改配置

1
2 # This file controls the state of SELinux on the system.
3 # SELINUX= can take one of these three values:
4 # enforcing - SELinux security policy is enforced.
5 # permissive - SELinux prints warnings instead of enforcing.
6 # disabled - No SELinux policy is loaded.
7 SELINUX=disabled  #  改 enforcing 为 disabled(不可用)
8 # SELINUXTYPE= can take one of these two values:
9 # targeted - Targeted processes are protected,
10 # mls - Multi Level Security protection.
11 SELINUXTYPE=targeted

# 保存退出.

[root@ ~]#: init 6  # 重启

[root@ ~]#: /usr/sbin/sestatus
SELinux status: disabled  # 不可用,说明已关闭

如需再次开启 selinux, 修改配置文件, 改 SELINUX=disabled 为 SELINUX=enforcing,然后 reboot.

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM