🔘 SELinux Booleans

SELinux Series: Part 1 — Basics  |  Part 2 — Contexts  |  Part 3 — Booleans  |  Part 4 — Troubleshooting

What are SELinux Booleans?

SELinux Booleans are on/off switches built into the policy that allow administrators to enable or disable specific behaviors without writing custom policy modules. Think of them as pre-built policy knobs — the SELinux developers anticipated common configuration needs and provided a safe, supported way to adjust policy behavior.

Instead of disabling SELinux entirely because Apache needs to connect to a database, flip the httpd_can_network_connect_db boolean to on. One command, targeted change, security maintained.

Key commands:
getsebool -a                               # list all booleans
getsebool boolean_name                    # check one boolean
setsebool boolean_name on|off              # set runtime (lost on reboot)
setsebool -P boolean_name on|off           # set persistent (-P flag)
semanage boolean -l                        # list with descriptions
semanage boolean -m --on boolean_name      # set persistent via semanage

Examples

1
List and Query Booleans — getsebool

See what booleans exist and what state they are currently in:

# List ALL booleans and their current state
getsebool -a

# Check a specific boolean
getsebool httpd_can_network_connect
getsebool httpd_can_network_connect_db

# Filter — find all httpd-related booleans
getsebool -a | grep httpd

# Find all booleans that are currently ON
getsebool -a | grep " on$"

# Find all booleans that are currently OFF
getsebool -a | grep " off$"

# Count total booleans on the system
getsebool -a | wc -l
getsebool -a | grep httpd (partial):
httpd_can_connect_ftp --> off httpd_can_network_connect --> off httpd_can_network_connect_db --> off httpd_can_sendmail --> off httpd_dontaudit_search_dirs --> off httpd_enable_cgi --> on httpd_enable_homedirs --> off httpd_execmem --> off httpd_read_user_content --> off httpd_sys_script_anon_write --> off httpd_use_nfs --> off httpd_use_openstack --> off
💡 Hundreds of booleans: A typical RHEL system has 300+ booleans. Use grep to filter by service name — getsebool -a | grep ftp, getsebool -a | grep samba, etc.
2
Set a Boolean — setsebool

Two forms — runtime only, or persistent across reboots:

# Runtime only — takes effect immediately, lost on reboot
sudo setsebool httpd_can_network_connect on
sudo setsebool httpd_can_network_connect off

# Persistent — survives reboots (-P flag)
sudo setsebool -P httpd_can_network_connect on
sudo setsebool -P httpd_can_network_connect off

# Set multiple booleans at once
sudo setsebool -P httpd_can_network_connect on \
                  httpd_can_network_connect_db on \
                  httpd_can_sendmail on

# Verify
getsebool httpd_can_network_connect
After setsebool -P httpd_can_network_connect on:
httpd_can_network_connect --> on
Always use -P in production. Without -P the boolean change is runtime only — the next reboot reverts it and your application breaks again. Use plain setsebool (no -P) only when testing, then confirm with -P once you know it's correct.
3
Get Descriptions — semanage boolean -l

semanage boolean -l gives you the human-readable description of each boolean — far more useful than the name alone:

# List all booleans with descriptions
sudo semanage boolean -l

# Filter to a service
sudo semanage boolean -l | grep -i httpd
sudo semanage boolean -l | grep -i ftp
sudo semanage boolean -l | grep -i samba
sudo semanage boolean -l | grep -i nfs

# Show only booleans that differ from default
sudo semanage boolean -l -C

# Set persistent boolean via semanage (alternative to setsebool -P)
sudo semanage boolean -m --on httpd_can_network_connect
semanage boolean -l | grep httpd_can_network (partial):
httpd_can_network_connect (off , off) Allow httpd to make any network connection httpd_can_network_connect_db (off , off) Allow httpd to connect to databases over the network httpd_can_network_relay (off , off) Allow httpd to act as a relay
Reading the output: The two values in parentheses are (current, default). When they differ, a persistent change has been made. -C flag shows only those customized entries.
4
Apache / httpd Booleans

The most commonly needed httpd booleans for web server administration:

# Allow Apache to make outbound network connections (APIs, proxying)
sudo setsebool -P httpd_can_network_connect on

# Allow Apache to connect to databases (MySQL, PostgreSQL, etc.)
sudo setsebool -P httpd_can_network_connect_db on

# Allow Apache to send email (contact forms, notifications)
sudo setsebool -P httpd_can_sendmail on

# Allow Apache to serve content from user home directories (~user/public_html)
sudo setsebool -P httpd_enable_homedirs on

# Allow Apache to read user home directory content
sudo setsebool -P httpd_read_user_content on

# Allow Apache to use NFS-mounted content
sudo setsebool -P httpd_use_nfs on

# Allow Apache to use Samba/CIFS-mounted content
sudo setsebool -P httpd_use_cifs on

# Allow CGI scripts to be executed
sudo setsebool -P httpd_enable_cgi on

# Allow Apache to connect to FTP servers
sudo setsebool -P httpd_can_connect_ftp on
💡 PHP/Python apps connecting to databases: The most common boolean needed for web applications is httpd_can_network_connect_db. If your app returns a database connection error and everything else looks correct, this boolean is the first thing to check.
5
FTP, Samba, and NFS Booleans
# FTP — allow users to access home directories via FTP
sudo setsebool -P ftp_home_dir on

# FTP — allow anonymous FTP write access
sudo setsebool -P allow_ftpd_anon_write on

# FTP — allow FTP to read/write files on CIFS/Samba shares
sudo setsebool -P allow_ftpd_use_cifs on

# FTP — allow FTP to use NFS mounts
sudo setsebool -P allow_ftpd_use_nfs on

# Samba — allow Samba to share home directories
sudo setsebool -P samba_enable_home_dirs on

# Samba — allow Samba to export any file/directory
sudo setsebool -P samba_export_all_rw on

# NFS — allow NFS to export home directories
sudo setsebool -P use_nfs_home_dirs on

# Verify all Samba booleans
getsebool -a | grep samba
Home directory sharing: Two of the most common boolean needs — FTP access to home dirs (ftp_home_dir) and Samba sharing of home dirs (samba_enable_home_dirs) — are off by default for security. Enable them only when actually needed.
6
SSH, CRON, and System Booleans
# Allow SSH to use SSH keys for authentication (usually already on)
getsebool ssh_sysadm_login

# Allow cron jobs to use NFS home directories
sudo setsebool -P cron_can_relabel on

# Allow staff/sysadm roles to run in unconfined mode (for admin work)
sudo setsebool -P ssh_sysadm_login on

# Allow rsync to read/write samba content
sudo setsebool -P rsync_use_cifs on

# Allow system mail daemon to use LDAP
sudo setsebool -P allow_postfix_local_write_mail_spool on

# Allow virt (KVM/QEMU) to use NFS
sudo setsebool -P virt_use_nfs on

# Allow containers to use all network ports
sudo setsebool -P container_use_devices on

# List all booleans that are currently ON (non-default)
sudo semanage boolean -l -C | grep "on  ,"
7
Find the Right Boolean — Workflow

When something is blocked and you suspect a boolean is needed, here is the diagnostic workflow:

# Step 1 — Check audit log for the denial
sudo ausearch -m avc -ts recent | tail -20

# Step 2 — Use audit2why to get a plain-English explanation
sudo ausearch -m avc -ts recent | audit2why

# Step 3 — audit2why will often suggest the exact boolean needed
# Example output from audit2why:
#   Was caused by:
#   The boolean httpd_can_network_connect was set incorrectly.
#   Description: Allow httpd to make any network connection
#   Allow access by executing: setsebool -P httpd_can_network_connect 1

# Step 4 — Search booleans by keyword if audit2why doesn't suggest one
sudo semanage boolean -l | grep -i "network connect"
sudo semanage boolean -l | grep -i "mail"
sudo semanage boolean -l | grep -i "home"

# Step 5 — Test with runtime change first (no -P)
sudo setsebool httpd_can_network_connect on

# Step 6 — If that fixes it, make it permanent
sudo setsebool -P httpd_can_network_connect on
💡 audit2why is your best friend. It reads an AVC denial and tells you in plain English what caused it and how to fix it — often naming the exact boolean. Install it with policycoreutils-python-utils (RHEL 8/9) or policycoreutils-python (RHEL 7).
8
Document and Audit Boolean Changes

Good practice — document what booleans have been changed from default and why:

#!/bin/bash
# selinux-boolean-audit.sh
# Report all non-default boolean settings on this system

echo "========================================"
echo " SELinux Boolean Audit — $(hostname)"
echo " $(date)"
echo "========================================"
echo ""
echo "Booleans changed from default:"
echo ""

sudo semanage boolean -l -C | \
    awk 'NR>1 {printf "  %-45s Current: %s  Default: %s\n", $1, $2, $3}'

echo ""
echo "Total non-default booleans: $(sudo semanage boolean -l -C | tail -n +2 | wc -l)"
echo ""

# Save to file for documentation
sudo semanage boolean -l -C > /root/selinux-booleans-$(date +%Y%m%d).txt
echo "Saved to /root/selinux-booleans-$(date +%Y%m%d).txt"
Example output:
======================================== SELinux Boolean Audit — web01.internal Tue Apr 14 11:30:00 EDT 2026 ======================================== Booleans changed from default: httpd_can_network_connect_db Current: on Default: off httpd_can_sendmail Current: on Default: off httpd_enable_homedirs Current: on Default: off Total non-default booleans: 3 Saved to /root/selinux-booleans-20260414.txt
Change management: Every boolean change from default is a policy decision that should be documented. The audit script above gives you a snapshot you can compare across servers or over time — useful for compliance audits and incident response.

Quick Reference

CommandWhat it does
getsebool -aList all booleans and current state
getsebool NAMECheck state of one boolean
getsebool -a | grep svcFilter booleans by service name
setsebool NAME onEnable boolean (runtime only)
setsebool -P NAME onEnable boolean persistently
setsebool -P NAME offDisable boolean persistently
semanage boolean -lList all booleans with descriptions
semanage boolean -l -CList only non-default booleans
semanage boolean -m --on NAMESet boolean persistent via semanage
ausearch -m avc -ts recent | audit2whyExplain denial and suggest boolean fix

Most Commonly Used Booleans

BooleanDefaultWhen to enable
httpd_can_network_connectoffApache needs to connect to external services/APIs
httpd_can_network_connect_dboffPHP/Python app connects to remote database
httpd_can_sendmailoffWeb app sends email via sendmail/postfix
httpd_enable_homedirsoffServing ~/public_html user web directories
httpd_use_nfsoffWeb content is on an NFS mount
httpd_use_cifsoffWeb content is on a Samba/CIFS mount
ftp_home_diroffFTP users need access to home directories
samba_enable_home_dirsoffSamba sharing of home directories
samba_export_all_rwoffSamba needs to share arbitrary directories
use_nfs_home_dirsoffHome directories are on NFS
httpd_enable_cgionCGI script execution (on by default)
virt_use_nfsoffKVM/QEMU VMs using NFS storage

← Back to SELinux Index ↑ Back to EXPANDED