To secure our Nautilus infrastructure in Stratos Datacenter we have decided to install and configure firewalld on all app servers. We have Apache and Nginx services running on these apps. Nginx is running as a reverse proxy server for Apache. We might have more robust firewall settings in the future, but for now, we have decided to go with the given requirements listed below:
a. Allow all incoming connections on Nginx port.
b. Allow incoming connections from LB host only on Apache port and block for all others.
c. All rules must be permanent.
d. Zone should be public.
e. If Apache or Nginx services aren't running already, please make sure to start them.
Sample Answer:
##first let's start with apache and nginx service, ports verification
#login to app server
ssh <user>@<server>
#switch to root user
sudo su
#check the apache service status
systemctl status httpd
#check the nginx service status
systemctl status nginx
# if the above services not running you can start it using the below command otherwise ignore it.
systemctl start httpd
systemctl start nginx
# now we will get the apache Listen port by using the below command (note down the port number we will use for later configuration)
cat /etc/httpd/conf/httpd.conf | grep Listen
Listen 5003
#now let's install firewalld service
yum install -y firewalld
# enable and start the firewalld service and check the status using below comands
systemctl start firewalld
systemctl status firewalld
#before doing the any firewall changes do some pre-check using these commands
firewall-cmd --zone=public --list-ports
firewall-cmd --get-active-zones
firewall-cmd --permanent --zone=public --add-rich-rule='rule family="ipv4" source address="<LB-host-IP>" port protocol=tcp port=5003 accept'
#add interface
firewall-cmd --permanent --zone=public --change-interface=wan
#relaod firewalld service to take effect
firewall-cmd --reload
#now do the post-check using these commands
firewall-cmd --zone=public --list-ports
firewall-cmd --get-active-zones