// learn Β· security Β· rhcsa Β· 8 min

SELinux booleans.

Before you write a custom SELinux policy, check if there's already a switch for it. Booleans are named on/off toggles that enable or disable whole pre-written chunks of policy β€” like 'let Apache talk to the network' β€” at runtime, no recompile needed.

SELinux booleans animated tutorial. Runtime policy switches, getsebool, setsebool, persistent changes with -P, semanage boolean -l, common booleans like httpd_can_network_connect, and the denial-troubleshooting workflow. RHCSA EX200 ready.
// selinux booleans

SELinux ships with rules for hundreds of common situations, turned off by default. A boolean is the switch that turns one of those rule sets on β€” no custom policy required.

// before you start
you should know
  • Β·The SELinux contexts lesson (what type enforcement is)
  • Β·Comfortable running commands as root / with sudo
  • Β·Know that SELinux can block a working-looking service
by the end you'll

Read a boolean's state, flip it persistently with setsebool -P, discover the right boolean for a service, and use audit2why to find which one a denial needs.

pace: 8 minutes

selinux booleans β€” step 1 / 6 Β· what it is
SELinux policy switches
httpd_can_network_connectoff
let Apache make outbound network connections
httpd_enable_homedirsoff
serve files from users' ~/public_html
ftpd_anon_writeoff
allow anonymous FTP uploads
nfs_export_all_rwoff
export NFS shares read-write
samba_enable_home_dirsoff
share home directories over Samba

A boolean is a switch over pre-written policy

The SELinux policy that ships with RHEL already contains rules for hundreds of common situations β€” they're just turned OFF by default for safety. A boolean is a named on/off switch that flips one of those rule sets on or off at runtime, no policy recompile, no custom modules. Before writing any custom policy, always ask: is there already a boolean for this?

// key insight

The SELinux fix hierarchy: boolean β†’ label β†’ custom module, in that order. Most "SELinux is blocking my service" problems are solved by a single setsebool -P. And never forget the -P β€” a runtime-only flip is a time bomb that detonates at the next reboot.

// exam-ready Β· boolean commands & common booleans
$getsebool BOOL
$getsebool -a
$getsebool -a | grep httpd
$setsebool BOOL on
$setsebool -P BOOL on
$semanage boolean -l
$semanage boolean -l -C
$ausearch -m AVC -ts recent
$audit2why -al
$httpd_can_network_connect
$httpd_enable_homedirs
$httpd_can_sendmail
$ftpd_anon_write
$nfs_export_all_rw
$samba_enable_home_dirs
$ssh_sysadm_login
// check yourself
4 quick questions
Q1

Apache (httpd) needs to connect to a database on another server, but SELinux is blocking it. What should you try FIRST?

Q2

You run `setsebool httpd_can_network_connect on` (no -P) and it works. Three weeks later after a reboot, Apache breaks again. Why?

Q3

Which command shows every boolean WITH its current state, default state, and a description?

Q4

What's the advantage of a boolean over writing a custom SELinux policy module?

These aren't graded β€” they're just for active recall, which is what actually makes the lesson stick.

πŸ›‘οΈ
// the other half of SELinux

SELinux contexts

Booleans toggle policy; contexts (labels) decide what can touch what. When a boolean isn't the fix, a wrong file label usually is β€” learn to read and restore them.

open β†’

Read this lesson as text6 chapters Β· quiz answers

  1. 01A boolean is a switch over pre-written policy

    The SELinux policy that ships with RHEL already contains rules for hundreds of common situations β€” they're just turned OFF by default for safety. A boolean is a named on/off switch that flips one of those rule sets on or off at runtime, no policy recompile, no custom modules. Before writing any custom policy, always ask: is there already a boolean for this?

  2. 02getsebool β€” read the current state

    getsebool <name> shows whether one boolean is on or off. getsebool -a lists every boolean on the system (there are hundreds). semanage boolean -l is even better β€” it shows the current state, the default state, AND a human description of what each one does.

    • $ getsebool httpd_can_network_connect β€” β†’ ...off
    • $ getsebool -a β€” list all booleans
    • $ getsebool -a | grep httpd β€” just the httpd ones
  3. 03setsebool β€” flip it (runtime only)

    setsebool httpd_can_network_connect on flips the switch immediately β€” Apache can now make outbound connections (e.g. to a database or an API on another host). BUT this change lives only in memory: it reverts on the next reboot. Useful for testing, dangerous if you forget it isn't permanent.

    • $ setsebool httpd_can_network_connect on β€” flip ON (this boot only)
    • $ setsebool httpd_can_network_connect off β€” flip back OFF
  4. 04Make it stick β€” the -P flag

    Add -P (Persistent) and the change is written to disk so it survives reboots: setsebool -P httpd_can_network_connect on. -P is a little slower because it rebuilds the policy, but for any real configuration you ALWAYS want it. The classic production bug: someone runs setsebool without -P, it works, then the service breaks weeks later after a reboot.

    • $ setsebool -P httpd_can_network_connect on β€” ON, survives reboot
    • $ semanage boolean -l | grep httpd_can_net β€” verify current vs default
  5. 05Finding the right boolean

    You rarely memorize boolean names. Discover them: getsebool -a | grep <keyword> or semanage boolean -l | grep <keyword>. Searching for the service name (httpd, ftpd, nfs, samba) usually surfaces the switch you need. The descriptions in semanage boolean -l tell you exactly what each does.

    • $ semanage boolean -l β€” all booleans + state + description
    • $ semanage boolean -l | grep ftp β€” FTP-related switches
    • $ sepolicy booleans -a β€” richer descriptions
  6. 06The denial β†’ boolean workflow

    When a service is denied by SELinux: (1) confirm it's SELinux with ausearch -m AVC -ts recent; (2) run audit2why -al β€” for many denials it literally says 'this can be allowed by setting the X boolean'; (3) flip that boolean with setsebool -P. Booleans are the FIRST thing to try β€” far safer than relabeling files or writing a custom module.

    • $ ausearch -m AVC -ts recent β€” find the denial
    • $ audit2why -al β€” often names the boolean to set
    • $ setsebool -P <boolean> on β€” apply the fix permanently

Quiz β€” answers

Apache (httpd) needs to connect to a database on another server, but SELinux is blocking it. What should you try FIRST?
β†’Check for and enable a boolean: setsebool -P httpd_can_network_connect on.There's almost always a boolean for common needs. httpd_can_network_connect is exactly this case. Booleans are the safest, simplest fix β€” reach for them before relabeling, custom modules, or (never) disabling SELinux.
You run setsebool httpd_can_network_connect on (no -P) and it works. Three weeks later after a reboot, Apache breaks again. Why?
β†’Without -P, setsebool changes only the in-memory value β€” it reverts to the default on reboot. You needed setsebool -P to persist it.-P (Persistent) writes the change to disk so it survives reboots. Without it, the change is runtime-only. This is one of the most common 'it worked then mysteriously broke' SELinux bugs.
Which command shows every boolean WITH its current state, default state, and a description?
β†’semanage boolean -lgetsebool -a lists names and on/off only. semanage boolean -l adds the default state and a human-readable description β€” the best tool for discovering what a boolean actually does.
What's the advantage of a boolean over writing a custom SELinux policy module?
β†’A boolean toggles pre-written, vendor-tested policy at runtime with no recompile β€” it's simpler, safer, and survives policy updates, whereas a custom module is more to maintain and can drift.Booleans are maintained by the distro and cover the common cases. They're a one-command, well-understood change. Custom modules are powerful but a last resort β€” more surface area to maintain and easier to get subtly wrong.
// more in security

keep going β€” these pair well with what you just learned.

see all security β†’

See also

first: SELinux contextsall lessons