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 to servera as student user.
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 servera system, 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 student user on servera, create the /var/www/html/index.html file.
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 httpd service on your servera system.
[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 on servera using both the cleartext port 80/TCP and the SSL encapsulated port 443/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 host
This 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 servera as the student user.
[student@workstation ~]$ssh student@servera...output omitted...[student@servera ~]$
On servera, make sure that the nftables service is masked and the firewalld service is enabled and running.
Determine whether the status of the nftables service is masked.
[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 nftables is 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 nftables service is masked.
[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 firewalld service 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 on servera to add the httpd service to the public network zone.
Open Firefox and browse to https://servera.lab.example.com:9090 to access the Web Console. Accept the self-signed certificate used by servera by adding an exception.
Select the check box next to Reuse my password for privileged tasks to ensure administrative privileges.
Log in as student user with student as 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 workstation and verify your work by attempting to view the web server contents of servera.
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 host
This command should succeed:
[student@workstation ~]$curl -k https://servera.lab.example.comI am servera.
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.