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 servera machine as the student user and switch to the root user.
[student@workstation ~]$ssh student@servera...output omitted... [student@servera ~]$sudo -i[sudo] password for student:student[root@servera ~]#
Install the httpd and mod_ssl packages.
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.html file.
Add one line of text that reads: I am servera.
[root@servera ~]# echo 'I am servera.' > /var/www/html/index.htmlStart and enable the httpd service.
[root@servera ~]# systemctl enable --now httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.Return to the workstation machine as the student user.
[root@servera ~]#exitlogout [student@servera ~]$exitlogout Connection to servera closed. [student@workstation ~]$
From workstation, try to access the web server on servera by using both the 80/TCP clear-text port and the 443/TCP SSL encapsulated port.
Both attempts should fail.
The curl command should fail.
[student@workstation ~]$ curl http://servera.lab.example.com
curl: (7) Failed to connect to servera.lab.example.com port 80: No route to hostThe curl command with the -k option for insecure connections should also fail.
[student@workstation ~]$ curl -k https://servera.lab.example.com
curl: (7) Failed to connect to servera.lab.example.com port 443: No route to hostVerify that the firewalld service on servera is 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 https service to the public firewall zone.
Verify that the default firewall zone is set to the public zone.
[root@servera ~]# firewall-cmd --get-default-zone
publicIf the earlier step does not return public as the default zone, then correct it with the following command:
[root@servera ~]# firewall-cmd --set-default-zone publicAdd the https service to the permanent configuration for the public network 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 on servera to verify the https service to the public firewall zone.
Open Firefox and navigate to https://servera.lab.example.com:9090 to access the web console.
Click and to accept the self-signed certificate.
Log in as the student user with student as the password.
Click and enter the student password again.
Click in the left navigation bar.
Click in the section of the page.
Verify that the https service is listed in the Service column.
Return to a terminal on workstation, and verify your work by attempting to access the servera web server.
Return to the workstation machine as the student user.
[root@servera ~]#exitlogout [student@servera ~]$exitlogout Connection to servera closed. [student@workstation ~]$
Verify the access to the http://servera.lab.example.com web server.
[student@workstation ~]$ curl http://servera.lab.example.com
curl: (7) Failed to connect to servera.lab.example.com port 80: No route to hostVerify the access to the http://servera.lab.example.com web server through the port 443 for insecure connection.
[student@workstation ~]$ curl -k https://servera.lab.example.com
I am servera.This concludes the section.