RHCSA Rapid Track
Configure firewall and SELinux settings to allow access to multiple web servers that run on the same host.
Outcomes
Configure firewall and SELinux settings on a web server host.
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-review
Instructions
Your company decided to run a new web application. This application listens on the 80/TCP and 1001/TCP ports. All changes that you make must persist across a reboot.
Important
The Red Hat Online Learning environment needs the 5900/TCP port to remain available to use the graphical interface. This port is also known under the vnc-server service. If you accidentally lock yourself out from the serverb machine, then you can either try to recover by using the ssh command to your serverb machine from your workstation machine, or reset your serverb machine. If you elect to reset your serverb machine, then you must run the setup scripts for this lab again. The configuration on your machines already includes a custom zone called ROL that opens these ports.
From the
workstationmachine, test access to the default web server athttp://serverb.lab.example.comand to thehttp://serverb.lab.example.com:1001virtual host.Test access to the
http://serverb.lab.example.comweb server. The test currently fails. The web server should returnSERVER B.[student@workstation ~]$
curl http://serverb.lab.example.comcurl: (7) Failed to connect to serverb.lab.example.com port80: Connection refusedTest access to the
http://serverb.lab.example.com:1001virtual host. The test currently fails. The virtual host should returnVHOST 1.[student@workstation ~]$
curl http://serverb.lab.example.com:1001curl: (7) Failed to connect to serverb.lab.example.com port1001: No route to host
Log in to the
serverbmachine to determine what is preventing access to the web servers.Log in to the
serverbmachine as thestudentuser.[student@workstation ~]$
ssh student@serverb...output omitted... [student@serverb ~]$Determine whether the
httpdservice is active.[student@serverb ~]$
systemctl is-active httpdinactiveEnable and start the
httpdservice. Thehttpdservice fails to start.[student@serverb ~]$
sudo systemctl enable --now httpd[sudo] password for student:studentCreated symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service. Job for httpd.servicefailedbecause the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xeu httpd.service" for details.Investigate why the
httpdservice fails to start.[student@serverb ~]$
systemctl status httpd.service× httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Active: failed (Result: exit-code) since Wed 2022-04-13 06:55:01 EDT; 2min 52s ago Docs: man:httpd.service(8) Process: 1640 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1/FAILURE) Main PID: 1640 (code=exited, status=1/FAILURE) Status: "Reading configuration..." CPU: 31ms Apr 13 06:55:01 serverb.lab.example.com systemd[1]: Starting The Apache HTTP Server... Apr 13 06:55:01 serverb.lab.example.com httpd[1640]: (13)Permission denied: AH00072: make_sock:could not bind to address [::]:1001Apr 13 06:55:01 serverb.lab.example.com httpd[1640]: (13)Permission denied: AH00072: make_sock:could not bind to address 0.0.0.0:1001Apr 13 06:55:01 serverb.lab.example.com httpd[1640]:no listening sockets available, shutting downApr 13 06:55:01 serverb.lab.example.com httpd[1640]: AH00015: Unable to open logs Apr 13 06:55:01 serverb.lab.example.com systemd[1]: httpd.service: Main process exited, code=exited, status=1/FAILURE Apr 13 06:55:01 serverb.lab.example.com systemd[1]: httpd.service: Failed with result 'exit-code'. Apr 13 06:55:01 serverb.lab.example.com systemd[1]: Failed to start The Apache HTTP Server.Check whether SELinux is blocking the
httpdservice from binding to the1001/TCPport.[student@serverb ~]$
sudo sealert -a /var/log/audit/audit.log100% done found 1 alerts in /var/log/audit/audit.log --------------------------------------------------------------------------------SELinux is preventing /usr/sbin/httpd from name_bind access on the tcp_socket port 1001.***** Plugin bind_ports (99.5 confidence) suggests ************************ If you want to allow /usr/sbin/httpd to bind to network port 1001 Then you need to modify the port type. Do# semanage port -a -t PORT_TYPE -p tcp 1001 where PORT_TYPE is one of the following: http_cache_port_t, http_port_t, jboss_management_port_t, jboss_messaging_port_t, ntop_port_t, puppet_port_t.***** Plugin catchall (1.49 confidence) suggests ************************** ...output omitted...
Configure SELinux to allow the
httpdservice to listen on the1001/TCPport.Use the
semanagecommand to find the correct port type.[student@serverb ~]$
sudo semanage port -l | grep 'http'http_cache_port_t tcp 8080, 8118, 8123, 10001-10010 http_cache_port_t udp 3130http_port_ttcp 80, 81, 443, 488, 8008, 8009, 8443, 9000 pegasus_http_port_t tcp 5988 pegasus_https_port_t tcp 5989Bind the
1001/TCPport to thehttp_port_ttype.[student@serverb ~]$
sudo semanage port -a -t http_port_t -p tcp 1001Confirm that the
1001/TCPport is bound to thehttp_port_tport type.[student@serverb ~]$
sudo semanage port -l | grep '^http_port_t'http_port_ttcp1001, 80, 81, 443, 488, 8008, 8009, 8443, 9000Enable and start the
httpdservice.[student@serverb ~]$
sudo systemctl enable --now httpdVerify the running state of the
httpdservice.[student@serverb ~]$
systemctl is-active httpdactive [student@serverb ~]$systemctl is-enabled httpdenabledReturn to the
workstationmachine as thestudentuser.[student@serverb ~]$
exitlogout Connection to serverb closed. [student@workstation ~]$
From
workstation, test again access to the default web server athttp://serverb.lab.example.comand to thehttp://serverb.lab.example.com:1001virtual host.Test access to the
http://serverb.lab.example.comweb server. The web server should returnSERVER B.[student@workstation ~]$
curl http://serverb.lab.example.comSERVER BTest access to the
http://serverb.lab.example.com:1001virtual host. The test continues to fail.[student@workstation ~]$
curl http://serverb.lab.example.com:1001curl: (7) Failed to connect to serverb.lab.example.com port 1001: No route to host
Log in to the
serverbmachine to determine whether the correct ports are assigned to the firewall.Log in to the
serverbmachine as thestudentuser.[student@workstation ~]$
ssh student@serverb...output omitted... [student@serverb ~]$Verify that the default firewall zone is set to the
publiczone.[student@serverb ~]$
firewall-cmd --get-default-zonepublicIf the previous step does not return
publicas the default zone, then correct it with the following command:[student@serverb ~]$
sudo firewall-cmd --set-default-zone publicDetermine the open ports that are listed in the
publicnetwork zone.[student@serverb ~]$
sudo firewall-cmd --zone=public --list-all[sudo] password for student:studentpublic target: default icmp-block-inversion: no interfaces: sources: services: cockpit dhcpv6-client http sshports: protocols: forward: yes masquerade: no forward-ports: source-ports: icmp-blocks: rich rules:
Add the
1001/TCPport to the permanent configuration for thepublicnetwork zone. Confirm your configuration.Add the
1001/TCPport to thepublicnetwork zone.[student@serverb ~]$
sudo firewall-cmd --permanent --zone=public \--add-port=1001/tcpsuccessReload the firewall configuration.
[student@serverb ~]$
sudo firewall-cmd --reloadsuccessVerify your configuration.
[student@serverb ~]$
sudo firewall-cmd --zone=public --list-allpublic target: default icmp-block-inversion: no interfaces: sources: services: cockpit dhcpv6-client http ssh ports:1001/tcpprotocols: forward: yes masquerade: no forward-ports: source-ports: icmp-blocks: rich rules:Return to the
workstationmachine as thestudentuser.[student@serverb ~]$
exitlogout Connection to serverb closed. [student@workstation ~]$
From
workstation, confirm that the default web server athttp://serverb.lab.example.comreturnsSERVER B, and that the virtual host athttp://serverb.lab.example.com:1001returnsVHOST 1.Test access to the
http://serverb.lab.example.comweb server.[student@workstation ~]$
curl http://serverb.lab.example.comSERVER BTest access to the
http://serverb.lab.example.com:1001virtual host.[student@workstation ~]$
curl http://serverb.lab.example.com:1001VHOST 1