Mail Server DNS, PTR, Firewall and SELinux on RHEL
Publishing an MX record and opening a firewall are production changes, not setup chores. They decide where other systems send mail and which untrusted clients can reach Postfix. This lesson exposes only server-to-server SMTP after forward DNS, reverse DNS, routing, firewall ownership and SELinux state are independently verified. Submission and mailbox ports remain closed until their authentication and TLS lessons.
Prerequisites and inherited lab checkpoint
Start from the Lesson 2 checkpoint: Postfix is installed, validated and bound to loopback with no broadened relay trust. Obtain an approved public hostname and static address only for an authorized Internet-facing build. The worked values use example.test and documentation addresses, so they must not be published as real DNS.
Confirm who controls the forward zone, reverse zone, network firewall, host firewall and cloud security policy. PTR records are normally controlled by the address provider, not by the domain registrar. Decide whether IPv6 is genuinely supported end to end; an AAAA record creates a real delivery path and reputation identity.
Install and prepare the required components
sudo dnf install -y bind-utils firewalld policycoreutils-python-utils
sudo systemctl enable --now firewalld
sudo firewall-cmd --get-active-zones
nmcli -f NAME,DEVICE,TYPE connection show --active
getenforce
sestatuspolicycoreutils-python-utilssupplies SELinux diagnostic and management utilities on current RHEL. Verify package availability and ownership on the installed release.- Do not start firewalld blindly on a host governed by another approved firewall manager. Inventory ownership first and preserve console access.
- Opening
smtpin firewalld affects only the selected zone. Cloud ACLs, provider filters, routing and Postfix binding remain separate layers. - DNS changes need rollback TTL planning. Lowering a TTL after publishing an incorrect record does not immediately shorten cached copies.
Publish identity and expose only the reviewed SMTP path
The authoritative zone conceptually needs one MX target and address record. The address owner publishes the PTR. In a real deployment replace every example with approved values and omit AAAA unless IPv6 sending and receiving are fully operated.
example.test. 3600 IN MX 10 mail1.example.test.
mail1.example.test. 3600 IN A 192.0.2.25
mail1.example.test. 3600 IN AAAA 2001:db8::25
25.2.0.192.in-addr.arpa. 3600 IN PTR mail1.example.test.On the host, change Postfix from loopback to the intended interfaces, validate, then add SMTP only to the active public-facing firewalld zone:
sudo postconf -e 'inet_interfaces = all'
sudo postfix check
sudo systemctl reload postfix
sudo firewall-cmd --zone=public --add-service=smtp
sudo firewall-cmd --zone=public --add-service=smtp --permanent
sudo firewall-cmd --reloadApply the runtime rule first from a retained administrative session, test it, then persist it. This ordering makes a mistake easier to reverse. If the interface belongs to a different zone, correct the reviewed zone mapping rather than opening every zone.
| Record or control | Required relationship | Common failure |
|---|---|---|
| MX | Recipient domain points to a hostname, never directly to an IP | Wrong target, missing final dot, stale preference or private address |
| A/AAAA | MX hostname resolves to operated addresses | Publishing IPv6 without routing, PTR, firewall or monitoring |
| PTR | Outbound address resolves to an approved mail hostname | Provider-controlled reverse zone was never delegated or requested |
| Forward confirmation | PTR hostname resolves back to the same sending address | Generic provider PTR or mismatched multihomed identity |
| firewalld zone | SMTP opens only on the intended ingress interface | Correct service added to an inactive or overbroad zone |
| SELinux | Enforcing, with labelled supported paths and permitted ports | Disabling enforcement instead of diagnosing an AVC denial |
Verify the working path
dig +noall +answer MX example.test
dig +noall +answer A mail1.example.test
dig +noall +answer AAAA mail1.example.test
dig +noall +answer -x 192.0.2.25
sudo ss -lntp | grep ':25 '
sudo firewall-cmd --zone=public --query-service=smtp
sudo firewall-cmd --zone=public --list-all
getenforce
sudo ausearch -m AVC,USER_AVC -ts recent- Run DNS queries against the authoritative servers and at least two independent recursive resolvers. A local resolver answer alone can hide split DNS or cache differences.
- Forward-confirmed reverse DNS means the sending IP has a PTR and that PTR hostname resolves back to the same IP. It is operational identity evidence, not a guarantee of inbox placement.
- Test TCP/25 from outside the destination network. A local connection cannot prove upstream routing or perimeter policy.
- No unexplained AVC denials should accompany SMTP tests. Investigate with timestamps and labels before creating any custom policy.
Production decisions before continuing
| Decision | Choose deliberately | Evidence to retain |
|---|---|---|
| Hostname | Use a stable, role-specific FQDN that appears consistently in DNS, SMTP greeting and TLS identity. | Forward/PTR lookup and SMTP transcript |
| IPv6 | Publish AAAA only when routing, reverse DNS, firewall, monitoring and sender reputation are operated. | External IPv6 connection and delivery evidence |
| Firewall zone | Map the mail interface to one intentional zone and expose only required services. | Zone/interface inventory and external port scan |
| DNS TTL | Balance rollback speed with query volume and change stability. | Authoritative zone serial and resolver comparisons |
| Provider port policy | Confirm that the hosting provider permits inbound and outbound TCP/25. | Provider policy and controlled external connection |
Treat reachability, routing and sender identity as separate layers
MX controls inbound routing for a recipient domain. PTR contributes to the identity of an outbound IP. Many receiving systems expect a meaningful PTR and forward confirmation, but no DNS record purchases reputation or overrides filtering. SPF, DKIM and DMARC are added later because publishing them before the signing and sending paths are known can create false failures.
Host reachability crosses the sender route, provider policy, perimeter controls, RHEL firewalld, SELinux port/type rules, Postfix binding and smtpd policy. Record evidence from both ends. A timeout, connection refusal and SMTP 5xx reply are different failure classes and must not be described as one “port issue.”
SELinux remains enforcing. Standard Postfix paths and ports usually work with packaged policy. Custom ports, storage paths or sockets require inspection of existing labels and booleans before any change. A generated allow rule can conceal a wrong path or compromised behavior, so it is a last reviewed step, not the first diagnostic command.
Understand the component before configuring it
| Layer | Question to answer | Evidence |
|---|---|---|
| Authoritative DNS | What does the domain owner publish? | Zone answer, serial, TTL and DNSSEC status if used |
| Recursive DNS | What do external senders currently observe? | Independent resolver answers and cache timing |
| Network path | Can an external host reach the intended address and port? | Route, packet capture, perimeter and refusal/timeout distinction |
| Host policy | Which zone and SELinux rule govern the service? | firewalld configuration, labels and AVC evidence |
| Application | Does Postfix own the expected listener and enforce relay policy? | ss, transcript, queue ID and negative relay test |
Build it step by step
- Inventory authority. Name owners for forward DNS, reverse DNS, network perimeter and host controls.
- Prepare DNS. Publish MX and address records with deliberate TTL; request PTR from the address provider.
- Verify from outside. Compare authoritative and recursive answers over both enabled address families.
- Bind Postfix deliberately. Change interfaces, validate and reload while the host firewall still limits reachability.
- Open one service. Add SMTP to the exact active firewalld zone and leave submission, IMAP and POP closed.
- Test positive and negative behavior. Accept a valid local recipient only when configured, deny third-party relay and retain transcripts.
- Inspect policy evidence. Confirm SELinux enforcing with no unexplained denials and record the final external path.
Operate and inspect the component
dig +trace MX example.test
dig @AUTH_SERVER example.test MX +noall +answer
dig @1.1.1.1 example.test MX +noall +answer
dig @8.8.8.8 example.test MX +noall +answer
traceroute 192.0.2.25
nc -vz 192.0.2.25 25
firewall-cmd --get-zone-of-interface=INTERFACE
semanage port -l | grep smtp
ausearch -m AVC -ts recent | audit2why- Replace placeholders only after resolving exact authoritative servers and interfaces. Do not paste example addresses into a live change.
dig +traceis useful for delegation diagnosis but differs from the cached view most senders use. Check both.audit2whyhelps interpret AVC records; it does not authorize blindly installing generated policy.- Unsafe: broad packet capture or Internet scans may cross privacy and authorization boundaries. Limit targets to systems you own or have permission to test.
Evidence and acceptance criteria
| Evidence | Healthy result | Failure meaning |
|---|---|---|
| DNS routing | Authoritative and recursive MX/address answers match the approved change | Delegation, publication or cache state differs |
| Reverse identity | PTR and forward confirmation match the sending host | Address-provider action or hostname design is incomplete |
| External SMTP | Remote client reaches the expected banner on TCP/25 | Route, provider, perimeter, firewalld or bind failure |
| Closed services | 587, 465, 993 and 995 remain unavailable at this checkpoint | Premature exposure of unconfigured services |
| SELinux | Enforcing with no relevant unexplained AVC denial | Wrong labels, custom port or unsupported access needs correction |
An AAAA record can silently create a second production service
A team validates IPv4 delivery, then publishes an AAAA record copied from the VM inventory. Some remote senders prefer IPv6, but the provider blocks inbound IPv6 TCP/25 and no PTR exists for outbound IPv6. Delivery becomes intermittent by sender and outbound identity fails basic reputation checks. The IPv4 tests remain green, hiding the second path.
The operator compares MX address answers over both families, tests from an external IPv6 host and identifies the timeout before Postfix. The approved short-term correction removes the AAAA record with planned cache awareness. The long-term option is to provision routing, firewall, PTR, monitoring and reputation for IPv6 before republishing it. Disabling IPv6 inside Postfix alone would leave a published unreachable address.
Troubleshooting by symptom
| Symptom | Inspect first | Defensible next action |
|---|---|---|
| MX resolves but connection times out | A/AAAA choice, route, provider policy and packet arrival | Fix the first network boundary; Postfix configuration is not yet implicated |
| Connection refused | Destination address, host listener and local reject evidence | Bind the intended interface or resolve wrong-host/service ownership |
| IPv4 works, IPv6 fails | AAAA, IPv6 route, PTR, firewall and listener | Operate the complete IPv6 path or remove AAAA after review |
| PTR lookup is empty | Address provider control and reverse-zone delegation | Request provider PTR; adding a forward-zone PTR is ineffective |
| SELinux AVC appears | Timestamp, source/target context, path and requested operation | Correct labels or supported policy; do not disable enforcement |
Unsafe operations and recovery boundaries
- Unsafe:
setenforce 0converts a diagnosable policy denial into an unprotected service and is not an acceptable fix. - Unsafe: opening
0-65535/tcpor every firewalld zone to troubleshoot SMTP expands the attack surface and destroys layer evidence. - Unsafe: publishing an AAAA record without a complete IPv6 operational path makes real senders select an untested route.
- Unsafe: creating SELinux policy directly from unreviewed AVC output can authorize behavior caused by a wrong label or compromised process.
Rewritten knowledge checks
Cumulative lab checkpoint
- Create a DNS change plan using reserved example values, including MX, A, optional AAAA, PTR, TTL and rollback timing.
- Verify authoritative and recursive views and explain any cache difference.
- Change Postfix to the intended lab interface, validate and retain the before/after effective configuration.
- Open SMTP only in the exact lab firewalld zone while retaining console access.
- From the second VM, distinguish successful connection, refusal and timeout using controlled tests.
- Confirm SELinux enforcing, no relevant AVC denial, closed future-service ports and the relay boundary, then snapshot Lesson 3.