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