RHCSA Rapid Track
Course update
An updated version of this course is available that uses a newer version of Red Hat Enterprise Linux in the lab environment. Therefore, the RHEL 9.0 version of the lab environment will retire on December 31, 2024. Please complete any work in this lab environment before it is removed on December 31, 2024. For the most up-to-date version of this course, we recommend moving to the RHEL 9.3 version.
In this exercise, you control access to system services by adjusting system firewall rules with the firewalld service.
Outcomes
Configure firewall rules to control access to services.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command prepares your environment and ensures that all required resources are available.
[student@workstation ~]$ lab start netsecurity-firewalls
Instructions
Log in to the
serveramachine as thestudentuser and switch to therootuser.[student@workstation ~]$
ssh student@servera...output omitted... [student@servera ~]$sudo -i[sudo] password for student:student[root@servera ~]#Install the
httpdandmod_sslpackages. These packages provide the Apache web server and the necessary extensions for the web server to serve content over SSL.[root@servera ~]#
dnf install httpd mod_ssl...output omitted... Is this ok [y/N]:y...output omitted... Complete!Create the
/var/www/html/index.htmlfile. Add one line of text that reads:I am servera.[root@servera ~]#
echo 'I am servera.' > /var/www/html/index.htmlStart and enable the
httpdservice.[root@servera ~]#
systemctl enable --now httpdCreated symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.Return to the
workstationmachine as thestudentuser.[root@servera ~]#
exitlogout [student@servera ~]$exitlogout Connection to servera closed. [student@workstation ~]$From
workstation, try to access the web server onserveraby using both the80/TCPclear-text port and the443/TCPSSL encapsulated port. Both attempts should fail.The
curlcommand should fail.[student@workstation ~]$
curl http://servera.lab.example.comcurl: (7) Failed to connect to servera.lab.example.com port 80: No route to hostThe
curlcommand with the-koption for insecure connections 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
Verify that the
firewalldservice onserverais enabled and running.[student@workstation ~]$
ssh student@servera...output omitted... [student@servera ~]$sudo -i[sudo] password for student:student[root@servera ~]#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 2022-04-13 11:22:50 EDT; 7min ago Docs: man:firewalld(1) Main PID: 768 (firewalld) Tasks: 2 (limit: 10798) Memory: 39.9M CPU: 584ms CGroup: /system.slice/firewalld.service └─768 /usr/bin/python3 -s /usr/sbin/firewalld --nofork --nopid Apr 13 11:22:49 servera.lab.example.com systemd[1]: Starting firewalld - dynamic firewall daemon... Apr 13 11:22:50 servera.lab.example.com systemd[1]: Started firewalld - dynamic firewall daemon.Add the
httpsservice to thepublicfirewall zone.Verify that the default firewall zone is set to the
publiczone.[root@servera ~]#
firewall-cmd --get-default-zonepublicIf the earlier step does not return
publicas the default zone, then correct it with the following command:[root@servera ~]#
firewall-cmd --set-default-zone publicAdd the
httpsservice to the permanent configuration for thepublicnetwork zone. Confirm your configuration.[root@servera ~]#
firewall-cmd --permanent --add-service=httpssuccess [root@servera ~]#firewall-cmd --reloadsuccess [root@servera ~]#firewall-cmd --permanent --zone=public --list-allpublic target: default icmp-block-inversion: no interfaces: sources: services: cockpit dhcpv6-clienthttpsssh ports: protocols: forward: yes masquerade: no forward-ports: source-ports: icmp-blocks: rich rules:
From
workstation, open Firefox and log in to the web console that is running onserverato verify thehttpsservice to thepublicfirewall zone.Open Firefox and navigate to
https://servera.lab.example.com:9090to access the web console. Click and to accept the self-signed certificate.Log in as the
studentuser withstudentas the password.Click and enter the
studentpassword again.Click in the left navigation bar.
Click in the section of the page.
Verify that the
httpsservice is listed in the Service column.
Return to a terminal on
workstation, and verify your work by attempting to access theserveraweb server.Return to the
workstationmachine as thestudentuser.[root@servera ~]#
exitlogout [student@servera ~]$exitlogout Connection to servera closed. [student@workstation ~]$Verify the access to the
http://servera.lab.example.comweb server.[student@workstation ~]$
curl http://servera.lab.example.comcurl: (7) Failed to connect to servera.lab.example.com port 80: No route to hostVerify the access to the
http://servera.lab.example.comweb server through the port 443 for insecure connection.[student@workstation ~]$
curl -k https://servera.lab.example.comI am servera.
This concludes the section.