Sub topic 13
Opening the Firewall
This chapter assumes you can use sudo, manage services with systemctl, and identify the server's client subnet. It also assumes a distribution that uses firewalld. The exact commands differ when a system uses only nftables or ufw.
A firewall filters network traffic before it reaches a service. A file-sharing service can be running correctly but still be unreachable because its ports are blocked. Open only the services and source networks that clients need.
Samba firewall rules
Samba uses SMB. Modern clients normally connect through TCP port 445. Older NetBIOS-based discovery and connections can also use TCP 139 and UDP ports 137 and 138. The samba firewalld service includes the usual Samba ports.
First inspect the active zones and interfaces:
sudo firewall-cmd --get-active-zones
sudo firewall-cmd --list-allThe active zone is the firewall policy attached to an interface or source address. Add Samba to the zone used by the client-facing interface:
sudo firewall-cmd --permanent --zone=public --add-service=samba
sudo firewall-cmd --reload
sudo firewall-cmd --zone=public --list-servicesThe --permanent option changes the saved configuration. The reload makes that configuration active. Without --permanent, a rule usually disappears when firewalld restarts.
If only one subnet should use the share, place that source in a restricted zone and allow Samba there:
sudo firewall-cmd --permanent --zone=internal --add-source=192.168.1.0/24
sudo firewall-cmd --permanent --zone=internal --add-service=samba
sudo firewall-cmd --reloadDo not expose Samba to the public internet. A source restriction reduces the attack surface, but authentication and share permissions are still required.
NFS firewall rules
NFSv4 normally uses TCP port 2049. NFSv3 also depends on RPC services such as rpcbind and mountd, which may use additional ports. Prefer NFSv4 when possible because it needs fewer firewall exceptions.
For a firewalld system, allow the NFS service only in the client-facing zone:
sudo firewall-cmd --permanent --zone=internal --add-source=192.168.1.0/24
sudo firewall-cmd --permanent --zone=internal --add-service=nfs
sudo firewall-cmd --reload
sudo firewall-cmd --zone=internal --list-allThe nfs service definition may open more than TCP 2049 to support the distribution's NFS tooling. If you require NFSv4 only, verify the resulting rules and consider a custom rule that permits TCP 2049 from the client subnet.
Verify the complete path
Check firewall rules from the server:
sudo firewall-cmd --zone=internal --list-all
sudo ss -lntup | grep -E ':(445|2049)\b'The ss output confirms that a process is listening. It does not prove that the firewall permits the client. From a client, test the actual protocol with smbclient, mount.cifs, or an NFS mount. Also check that the server's interface belongs to the zone you modified.
Exercise
A Samba service is listening on TCP 445, but clients on 192.168.1.0/24 cannot connect. Name two server-side checks.
Show answer
Confirm that the client-facing interface is in the expected firewalld zone, then check that that zone allows the samba service. Also verify that the source subnet restriction includes 192.168.1.0/24.