RHCSA Rapid Track
In this exercise, you will control access to system services by adjusting system firewall rules with firewalld.
Outcomes
You should be able to configure firewall rules to control access to services.
Log in as the student user on workstation using student as the password.
From workstation, run the lab netsecurity-firewalls start command.
The command runs a start script to determine whether the servera host is reachable on the network.
[student@workstation ~]$lab netsecurity-firewalls start
From
workstation, use SSH to log in toserveraasstudentuser. The systems are configured to use SSH keys for authentication, so a password is not required.[student@workstation ~]$ssh student@servera...output omitted...[student@servera ~]$On the
serverasystem, ensure that both httpd and mod_ssl packages are installed. These packages provide the Apache web server you will protect with a firewall, and the necessary extensions for the web server to serve content over SSL.[student@servera ~]$sudo yum install httpd mod_ssl[sudo] password for student:student...output omitted...Is this ok [y/N]:y...output omitted... Complete!As the
studentuser onservera, create the/var/www/html/index.htmlfile. Add one line of text that reads:I am servera.[student@servera ~]$sudo bash -c \"echo 'I am servera.' > /var/www/html/index.html"Start and enable the
httpdservice on yourserverasystem.[student@servera ~]$sudo systemctl enable --now httpdCreated symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.Exit from
servera.[student@servera ~]$exitlogout Connection to servera closed. [student@workstation ~]$From
workstation, attempt to access your web server onserverausing both the cleartext port80/TCPand the SSL encapsulated port443/TCP. Both attempts should fail.This command should fail:
[student@workstation ~]$curl http://servera.lab.example.comcurl: (7) Failed to connect to servera.lab.example.com port 80: No route to hostThis command should also fail:
[student@workstation ~]$curl -k https://servera.lab.example.comcurl: (7) Failed to connect to servera.lab.example.com port 443: No route to host
Log in to
serveraas thestudentuser.[student@workstation ~]$ssh student@servera...output omitted...[student@servera ~]$On
servera, make sure that thenftablesservice is masked and thefirewalldservice is enabled and running.Determine whether the status of the
nftablesservice ismasked.[student@servera ~]$sudo systemctl status nftables[sudo] password for student:student● nftables.service - Netfilter Tables Loaded: loaded (/usr/lib/systemd/system/nftables.service; disabled; vendor preset: disabled) Active: inactive (dead) Docs: man:nft(8)The results show that
nftablesis disabled and inactive but not masked. Run the following command to mask the service.[student@servera ~]$sudo systemctl mask nftablesCreated symlink /etc/systemd/system/nftables.service → /dev/null.Verify that the status of the
nftablesservice ismasked.[student@servera ~]$sudo systemctl status nftables● nftables.service Loaded: masked (Reason:Unit nftables.service is masked.) Active: inactive (dead)Verify that the status of the
firewalldservice is enabled and running.[student@servera ~]$sudo systemctl status firewalld● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service;enabled; vendor preset: enabled) Active:active (running)since Wed 2019-05-22 15:36:02 CDT; 5min ago Docs: man:firewalld(1) Main PID: 703 (firewalld) Tasks: 2 (limit: 11405) Memory: 29.8M CGroup: /system.slice/firewalld.service └─703 /usr/libexec/platform-python -s /usr/sbin/firewalld --nofork --nopid May 22 15:36:01 servera.lab.example.com systemd[1]: Starting firewalld - dynamic firewall daemon... May 22 15:36:02 servera.lab.example.com systemd[1]: Started firewalld - dynamic firewall daemon.Exit from
servera.[student@servera ~]$exitlogout Connection to servera closed. [student@workstation ~]$
From
workstation, open Firefox and log in to the Web Console running onserverato add thehttpdservice to thepublicnetwork zone.Open Firefox and browse to
https://servera.lab.example.com:9090to access the Web Console. Accept the self-signed certificate used byserveraby adding an exception.Select the check box next to Reuse my password for privileged tasks to ensure administrative privileges.
Log in as
studentuser withstudentas the password.Click Networking in the left navigation bar.
Click the Firewall link in main Networking page.
Click the button located in the upper right side of the Firewall page.
In the Add Services user interface, scroll down or use Filter Services to locate and select the check box next to the Secure WWW (HTTPS) service.
Click the button located at the lower right side of the Add Services user interface.
Return to a terminal on
workstationand verify your work by attempting to view the web server contents ofservera.This command should fail:
[student@workstation ~]$curl http://servera.lab.example.comcurl: (7) Failed to connect to servera.lab.example.com port 80: No route to hostThis command should succeed:
[student@workstation ~]$curl -k https://servera.lab.example.comI am servera.
Note
If you use Firefox to connect to the web server, it will prompt for verification of the host certificate if it successfully gets past the firewall.