In this lab, you configure your system to allow HTTP access on a nonstandard port.
Outcomes
Configure a web server that is running on servera to successfully serve content that uses a nonstandard port.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command determines whether the servera machine is reachable on the network, installs the httpd service, and configures the firewall on servera to allow HTTP connections.
[student@workstation ~]$ lab start netsecurity-ports
Instructions
Your organization is deploying a new custom web application.
The web application is running on a nonstandard port, in this case, 82/TCP.
A junior administrator already configured the application on your servera host.
However, the web server content is not accessible.
Log in to servera as the student user and switch to the root user.
[student@workstation ~]$ssh student@servera...output omitted... [student@servera ~]$ [student@servera ~]$sudo -i[sudo] password for student:student[root@servera ~]#
Try to fix the web content problem by restarting the httpd service.
Restart the httpd.service.
This command is expected to fail.
[root@servera ~]# systemctl restart httpd.service
Job for httpd.service failed because the control process exited with error code.
See "systemctl status httpd.service" and "journalctl -xe" for details.View the status of the httpd service.
Note the permission denied error.
[root@servera ~]#systemctl status -l 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 Mon 2019-04-08 14:23:29 CEST; 3min 33s ago Docs: man:httpd.service(8) Process: 28078 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1/FAILURE) Main PID: 28078 (code=exited, status=1/FAILURE) Status: "Reading configuration..." Apr 08 14:23:29 servera.lab.example.com systemd[1]: Starting The Apache HTTP Server... Apr 08 14:23:29 servera.lab.example.com httpd[28078]: (13)Permission denied: AH00072: make_sock: could not bind to address [::]:82Apr 08 14:23:29 servera.lab.example.com httpd[28078]: (13)Permission denied: AH00072: make_sock: could not bind to address 0.0.0.0:82Apr 08 14:23:29 servera.lab.example.com httpd[28078]:no listening sockets available, shutting downApr 08 14:23:29 servera.lab.example.com httpd[28078]: AH00015: Unable to open logs Apr 08 14:23:29 servera.lab.example.com systemd[1]: httpd.service: Main process exited, code=exited, status=1/FAILURE Apr 08 14:23:29 servera.lab.example.com systemd[1]: httpd.service: Failed with result 'exit-code'. Apr 08 14:23:29 servera.lab.example.com systemd[1]:Failed to start The Apache HTTP Server.
Verify whether SELinux is blocking httpd from binding to the 82/TCP port.
[root@servera ~]#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 82.***** Plugin bind_ports (99.5 confidence) suggests ************************ If you want to allow /usr/sbin/httpd to bind to network port 82 Then you need to modify the port type. Do# semanage port -a -t PORT_TYPE -p tcp 82 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....output omitted... Raw Audit Messages type=AVC msg=audit(1554726569.188:852): avc: denied { name_bind } for pid=28393 comm="httpd" src=82 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:reserved_port_t:s0 tclass=tcp_socket permissive=0 ...output omitted...
Configure SELinux to allow the httpd service to bind to the 82/TCP port, and then restart the httpd.service service.
Find an appropriate port type for the 82/TCP port.
The http_port_t type includes the default HTTP ports, 80/TCP and 443/TCP.
This type is the correct port type for the web server.
[root@servera ~]#semanage port -l | grep httphttp_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 5989
Assign the 82/TCP port the http_port_t type.
[root@servera ~]# semanage port -a -t http_port_t -p tcp 82Restart the httpd.service service.
This command should succeed.
[root@servera ~]# systemctl restart httpd.serviceVerify that you can now access the web server that runs on the 82/TCP port.
[root@servera ~]# curl http://servera.lab.example.com:82
HelloIn a different terminal window, verify whether you can access the new web service from workstation.
[student@workstation ~]$ curl http://servera.lab.example.com:82
curl: (7) Failed to connect to servera.example.com:82; No route to hostThat error means that you still cannot connect to the web service from workstation.
On servera, open the 82/TCP port on the firewall.
Open the 82/TCP port in the permanent configuration, for the default zone on the firewall, on servera.
[root@servera ~]# firewall-cmd --permanent --add-port=82/tcp
successActivate your firewall changes on servera.
[root@servera ~]# firewall-cmd --reload
successAccess the web service from workstation.
[student@workstation ~]$ curl http://servera.lab.example.com:82
HelloReturn to the workstation system as the student user.
[root@servera ~]#exitlogout [student@servera ~]$exitlogout Connection to servera closed. [student@workstation ~]$
This concludes the section.