よろづやアンテナ

ITから生活の参考になる情報を備忘録代わりに残していきます

CentOS7 Red Hat Linux7でSELinux無効化の確認と設定方法

SELINUXが無効化されているかどうかを確認するには、以下のコマンドを実行します。

$ getenforce
Enforcing



上記は有効になっている場合の表示で、無効化されている場合は、以下のように表示されます。


Didabled 


・enforcing
SELinux機能、アクセス制御が有効
・permissive
SElinuxは警告を出力するが、アクセス制限は無効
・disabled
SElinux機能、アクセス制御が無効



sestatusでより詳しい情報を表示させることができます。

$ sestatus
SELinux status:                 enabled
SELinuxfs mount:                /selinux
Current mode:                   enforcing
Mode from config file:          enforcing
Policy version:                 24
Policy from config file:        targeted



また、SELinuxを無効にする場合は、
/etc/selinux/config で設定します。



# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#       enforcing - SELinux security policy is enforced.
#       permissive - SELinux prints warnings instead of enforcing.
#       disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
#       targeted - Targeted processes are protected,
#       mls - Multi Level Security protection.
SELINUXTYPE=targeted


また、一時的に無効、有効にしたい場合は、以下のコマンドを実行します。

SELinuxを一時的に無効化

$ setenforce 0
 
SELinuxを有効化

$ setenforce 1 


SELinuxを有効にしている場合、 アプリケーションなどがうまく動作しないことが多いので、基本は無効にする事が多いです。


また、同様にトラブルの原因になるiptablesの無効化手順も一緒に紹介します。


iptablesを停止するには、iptables stopコマンドを実行します。

$ /etc/init.d/iptables stop


iptables stopコマンドを実行しただけでは、一時的にiptablesが無効になっただけで、OSを再起動したときにiptablesが起動してしまいます。
 

その為、OS再起動後もiptablesを起動しないようにするには、chkconfigコマンドで設定します。
 
chkconfig iptables off 



また、iptablesを有効にしたい場合は、以下を実行します。