Port forwarding is a networking technique used to redirect communication requests from one port number to another port number, typically across a network boundary such as a router or firewall. This technique can be used with Firewalld, available in RockyLinux, or derivative distros from RHEL such as AlmaLinux, CentOS, and others.
Problem
How to configure Firewalld to be port forwarding?
Solution
If you want to see the command in firewalls to run port forwarding, type the below command:
firewall-cmd --help | grep forward
The commands in firewalld for port forwarding
There are 2 methods of port forwarding: forward the connection of a port to one IP/device and forward the connection of a port to a different IP/device.
A. Forward to the same IP/device
By default, you must use the format below to forward a port in a device:
You can add an option ‐-permanent if you want the rule to remain after reloading or rebooting the system. For example, you have a server with IP 192.168.56.2 where port 22 on the server is closed so to access the server via SSH must use port 43210. If you follow this article, then you must type the command below to access the server:
ssh sysadmin@192.168.56.2 -p 43210
Access the server via SSH using the port
However, by implementing a port forwarding you can access the server without typing the port. Let’s say, the firewalld is in the device, then on the device open port 43210 using the command:
If you want the rule to stay in place after a system reboot or reload, you can add a ‐-permanent option. As an illustration, suppose you have a server with IP address 192.168.56.2 and port 22 is available. You would like users who access port 22 to forward to port 22 with IP address 192.168.56.102. Use the command below to configure firewalls:
Add a forwarding port to a different IP in firewalld
If you type the command below:
ssh sysadmin@192.168.56.2
You will be forwarded to a server that uses IP 192.168.56.102 as shown below:
Forward a port to another IP/device
Note
To see rule forwarding is in the rule in the firewall, besides being able to use the firewall-cmd ‐-list-all command, you can also use the command below:
sudo firewall-cmd --list-forward-ports
then you will see the results as shown below:
Using –list-forward-ports option
And if you want to delete a rule port forwarding in the firewall, then you can simply change the options ‐-add-forward-port to ‐-remove-forward-port so the command will change like in the command below:
How to Configure Virtual Hosts in Apache on RockyLinux?
written by sysadmin | 21 June 2025
The previous article explained how to create virtual hosts in Ubuntu. This article will explain how to configure virtual hosts in Apache on Rocky Linux or derivatives of RHEL, such as Almalinux, CentOS, and so on.
Problem
How to configure virtual hosts in Apache on RockyLinux?
Solution
Before starting the configuration, make sure that on the RockyLinux server, the Apache application is installed by using the command:
yum install -y httpd
To see the default settings of Apache in RockyLinux, type the command below:
sudo httpd -S
Display default Apache configuration
2 types of virtual hosts can be used, name-based and IP-based, and the difference between the two can be seen in the image below:
Comparison of name-based and IP-based in virtual hosts
WARNING
This article uses a private IP, not a public IP.
A. name-based virtual hosts
The meaning of name-based is that you have many websites or domains, but you only have one IP. For example, you have 2 domain names: website1.com and website2.com, but you only have 1 IP, which is 192.168.56.2. Here are the steps to get all three domains to use the same IP:
1. Create the directories and the files
By default, Apache uses the /var/www/html folder as its rootdocument, as shown in the image above. However, to make it easier to configure it, you should create a folder for each of these websites, as shown in the image below:
You can change the above directory to another directory, but for the next steps, you have to follow the directory you created.
After that, create an index.html file for each domain:
sudo sh -c 'echo "<h1> This is for website1.com domain</h1>" > /var/www/html/website1.com/index.html'
sudo sh -c 'echo "<h1> This is for website2.com domain</h1>" > /var/www/html/website2.com/index.html'
Unlike Ubuntu and its derivatives, which use the sites-available and sites-enabled folders in configuring virtual hosts, by default, RockyLinux and its derivatives do not use both folders, but the virtual hosts configuration is inserted into the /etc/httpd/conf.d/ folder. Therefore, type the command below to create two domains in the virtual hosts:
echo "<VirtualHost *:80>" | sudo tee /etc/httpd/conf.d/website1.com.conf > /dev/null
echo " ServerName website1.com" | sudo tee -a /etc/httpd/conf.d/website1.com.conf > /dev/null
echo " ServerAlias www.website1.com" | sudo tee -a /etc/httpd/conf.d/website1.com.conf > /dev/null
echo " ServerAdmin webmaster@website1.com" | sudo tee -a /etc/httpd/conf.d/website1.com.conf > /dev/null
echo " DocumentRoot /var/www/html/website1.com" | sudo tee -a /etc/httpd/conf.d/website1.com.conf > /dev/null
echo " ErrorLog logs/website1-error.log" | sudo tee -a /etc/httpd/conf.d/website1.com.conf > /dev/null
echo " CustomLog logs/website1-access.log combined" | sudo tee -a /etc/httpd/conf.d/website1.com.conf > /dev/null
echo "</VirtualHost>" | sudo tee -a /etc/httpd/conf.d/website1.com.conf > /dev/null
echo "<VirtualHost *:80>" | sudo tee /etc/httpd/conf.d/website2.com.conf > /dev/null
echo " ServerName website2.com" | sudo tee -a /etc/httpd/conf.d/website2.com.conf > /dev/null
echo " ServerAlias www.website2.com" | sudo tee -a /etc/httpd/conf.d/website2.com.com > /dev/null
echo " ServerAdmin webmaster@website2.com" | sudo tee -a /etc/httpd/conf.d/website2.com.conf > /dev/null
echo " DocumentRoot /var/www/html/website2.com" | sudo tee -a /etc/httpd/conf.d/website2.com.conf > /dev/null
echo " ErrorLog logs/website2-error.log" | sudo tee -a /etc/httpd/conf.d/website2.com.conf > /dev/null
echo " CustomLog logs/website2-access.log combined" | sudo tee -a /etc/httpd/conf.d/website2.com.conf > /dev/null
echo "</VirtualHost>" | sudo tee -a /etc/httpd/conf.d/website2.com.conf > /dev/null
WARNING
You can change *:80 to your IP server like 192.168.56.2:80.
4. Check the configuration
Use the command below to check whether there is an Apache configuration that is an error or not by using the command below:
sudo apachectl configtest
If there is no error, then reload Apache using the command below:
sudo systemctl reload httpd
WARNING
Use the command above if there is a change in the configuration of virtual hosts in each domain.
5. Check in the browser
Because this article uses a private IP, you must configure it in the hosts file before you check the browser. If you use Windows, change the hosts file in C:\Windows\System32\drivers\etc\hosts or in /etc/hosts if you use Linux. In the hosts file, add the below script:
192.168.56.2 website1.com website2.com
Info
Change IP 192.168.56.2 with your RockyLinux IP server.
By default, Rockylinux activates the firewall, so you have to open the HTTP port using the command below:
Open your browser and type each of these domains, then there should be a site displayed as in the image below:
http://website1.com
Site website1.com
http://website2.com
site website2.com
If you use Linux, you can use the command below to check the result:
curl http://website1.com
curl http://website2.com
Using the curl command
By default, websites work on the web server using port 80. But you can change port 80 to another port as long as the port is not used on the server. For example, if you want the website1.com site to use port 8080, change the /etc/httpd/conf.d/website1.com.conf file and change its contents to something like this:
The meaning of IP-based is that you use a different IP address for each website. For example, you have 2 IPs and 2 domains, where IP 192.168.56.2 is for site1.com, and IP 192.168.56.104 is for site2.com. This article will use a server that has 2 IPs, as shown below:
Using 2 NICs in a server
1. Create the directories and the files
By default, Apache uses the /var/www/html folder as its rootdocument, as shown in the image above. However, to make it easier to configure it, you should create a folder for each of these websites, as shown in the image below:
You can change the above directory to another directory, but for the next steps, you have to follow the directory you created.
After that, create an index.html file for each domain:
sudo sh -c 'echo "<h1> This is for site1.com domain</h1>" > /var/www/html/site1.com/index.html'
sudo sh -c 'echo "h1> This is for site2.com domain</h1>" > /var/www/html/site2.com/index.html'
Unlike Ubuntu and its derivatives, which use the sites-available and sites-enabled folders in configuring virtual hosts, by default, RockyLinux and its derivatives do not use both folders, but the virtual hosts configuration is inserted into the /etc/httpd/conf.d/ folder. Therefore, type the command below to create two domains in the virtual hosts:
echo "<VirtualHost 192.168.56.2:80>" | sudo tee /etc/httpd/conf.d/website1.com.conf > /dev/null
echo " ServerName website1.com" | sudo tee -a /etc/httpd/conf.d/website1.com.conf > /dev/null
echo " ServerAlias www.website1.com" | sudo tee -a /etc/httpd/conf.d/website1.com.conf > /dev/null
echo " ServerAdmin webmaster@website1.com" | sudo tee -a /etc/httpd/conf.d/website1.com.conf > /dev/null
echo " DocumentRoot /var/www/html/website1.com" | sudo tee -a /etc/httpd/conf.d/website1.com.conf > /dev/null
echo " ErrorLog logs/website1-error.log" | sudo tee -a /etc/httpd/conf.d/website1.com.conf > /dev/null
echo " CustomLog logs/website1-access.log combined" | sudo tee -a /etc/httpd/conf.d/website1.com.conf > /dev/null
echo "</VirtualHost>" | sudo tee -a /etc/httpd/conf.d/website1.com.conf > /dev/null
echo "<VirtualHost 192.168.56.104:80>" | sudo tee /etc/httpd/conf.d/website2.com.conf > /dev/null
echo " ServerName website2.com" | sudo tee -a /etc/httpd/conf.d/website2.com.conf > /dev/null
echo " ServerAlias www.website2.com" | sudo tee -a /etc/httpd/conf.d/website2.com.com > /dev/null
echo " ServerAdmin webmaster@website2.com" | sudo tee -a /etc/httpd/conf.d/website2.com.conf > /dev/null
echo " DocumentRoot /var/www/html/website2.com" | sudo tee -a /etc/httpd/conf.d/website2.com.conf > /dev/null
echo " ErrorLog logs/website2-error.log" | sudo tee -a /etc/httpd/conf.d/website2.com.conf > /dev/null
echo " CustomLog logs/website2-access.log combined" | sudo tee -a /etc/httpd/conf.d/website2.com.conf > /dev/null
echo "</VirtualHost>" | sudo tee -a /etc/httpd/conf.d/website2.com.conf > /dev/null
4. Check the configuration
Use the command below to check whether there is an Apache configuration that is an error or not by using the command below:
sudo apachectl configtest
If there is no error, then reload Apache using the command below:
sudo systemctl reload httpd
WARNING
Use the command above if there is a change in the configuration of virtual hosts in each domain.
5. Check in the browser
Because this article uses a private IP, you must configure it in the hosts file before you check the browser. If you use Windows, change the hosts file in C:\Windows\System32\drivers\etc\hosts or in /etc/hosts if you use Linux. In the hosts file, add the below script:
192.168.56.2 site1.com
192.168.56.104 site2.com
Info
Change IP 192.168.56.2 & IP 192.168.56.104 with your RockyLinux IP server.
By default, Rockylinux activates the firewall, so you have to open the HTTP port using the command below:
Open your browser and type each of these domains then there should be a site displayed as in the image below:
http://site1.com
Site site1.com
http://site2.com
Site site2.com
If you use Linux, you can use the command below to check the result:
curl http://site1.com
curl http://site2.com
Using the curl command
By default, websites work on the web server using port 80. But you can change port 80 to another port as long as the port is not used on the server. So, if you want the site1.com site to use port 8181, change the /etc/httpd/conf.d/website1.com.conf file and change its contents to something like this:
Reload Apache and open it in the browser by typing the command:
http://site1.com:8181
Site site1.com:8181
Note
If you want to remove the error like this:
AH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using 192.168.56.103. Set the ‘ServerName’ directive globally to suppress this message
Go to the /etc/httpd/conf/httpd.conf and insert the script below:
ServerName localhost
Reload the Apache, and the error will disappear, like in the image below:
How to Configure Virtual Hosts in Apache on Ubuntu?
written by sysadmin | 21 June 2025
Virtual hosts are a feature on a web server, such as Apache or Nginx, to run more than one site on a server. By using this feature, you can easily configure multiple domains on a server and save on operational costs because you only need one server or a public IP. This article will explain how to configure virtual hosts in Apache on Ubuntu.
Problem
How to configure virtual hosts in Apache on Ubuntu?
Solution
Before starting the configuration, make sure that on the Ubuntu server, the Apache application is installed by using the command:
apt update
apt install -y apache2
To see the default settings of Apache in Ubuntu, type the command below:
sudo apache2ctl -S
Display default Apache configuration
2 types of virtual hosts can be used, name-based and IP-based, and the difference between the two can be seen in the image below:
Comparison of name-based and IP-based in virtual hosts
WARNING
This article uses a private IP, not a public IP.
A. name-based virtual hosts
The meaning of name-based is that you have many websites or domains, but you only have one IP. For example, you have 2 domain names: website1.com and website2.com, but you only have 1 IP, which is 192.168.56.100. Here are the steps to get all three domains to use the same IP:
1. Create the directories and the files
By default, Apache uses the /var/www/html folder as its rootdocument, as shown in the image above. However, to make it easier to configure it, you should create a folder for each of these websites, as shown in the image below:
You can change the above directory to another directory, but for the next steps, you have to follow the directory you created.
After that, create an index.html file for each domain:
sudo sh -c 'echo "<h1> This is for website1.com domain</h1>" > /var/www/html/website1.com/index.html'
sudo sh -c 'echo "<h1> This is for website2.com domain</h1>" > /var/www/html/website2.com/index.html'
By default, 2 directories are used to manage the many domains in the virtual hosts running on that server: the sites-available and sites-enabled directories located in the /etc/apache2 directory. The sites-enabled directory contains all the configurations of the website (virtual host) that are available on the server but are not yet activated automatically. In contrast, the sites-enabled directory contains a symlink (symbolic link) to the configuration file that exists in the sites-available directory, and only the files that exist in the sites-enabled directory will be executed and activated by the web server if the web server is restarted or reloaded. Use the command below to create two websites on virtual hosts:
echo '<VirtualHost *:80>' | sudo tee /etc/apache2/sites-available/website1.com.conf > /dev/null
echo ' ServerName website1.com' | sudo tee -a /etc/apache2/sites-available/website1.com.conf > /dev/null
echo ' ServerAlias www.website1.com' | sudo tee -a /etc/apache2/sites-available/website1.com.conf > /dev/null
echo ' ServerAdmin webmaster@website1.com' | sudo tee -a /etc/apache2/sites-available/website1.com.conf > /dev/null
echo ' DocumentRoot /var/www/html/website1.com' | sudo tee -a /etc/apache2/sites-available/website1.com.conf > /dev/null
echo ' ErrorLog ${APACHE_LOG_DIR}/website1-error.log' | sudo tee -a /etc/apache2/sites-available/website1.com.conf > /dev/null
echo ' CustomLog ${APACHE_LOG_DIR}/website1-access.log combined' | sudo tee -a /etc/apache2/sites-available/website1.com.conf > /dev/null
echo '</VirtualHost>' | sudo tee -a /etc/apache2/sites-available/website1.com.conf > /dev/null
echo '<VirtualHost *:80>' | sudo tee /etc/apache2/sites-available/website2.com.conf > /dev/null
echo ' ServerName website2.com' | sudo tee -a /etc/apache2/sites-available/website2.com.conf > /dev/null
echo ' ServerAlias www.website2.com' | sudo tee -a /etc/apache2/sites-available/website2.com.conf > /dev/null
echo ' ServerAdmin webmaster@website2.com' | sudo tee -a /etc/apache2/sites-available/website2.com.conf > /dev/null
echo ' DocumentRoot /var/www/html/website2.com' | sudo tee -a /etc/apache2/sites-available/website2.com.conf > /dev/null
echo ' ErrorLog ${APACHE_LOG_DIR}/website2-error.log' | sudo tee -a /etc/apache2/sites-available/website2.com.conf > /dev/null
echo ' CustomLog ${APACHE_LOG_DIR}/website2-access.log combined' | sudo tee -a /etc/apache2/sites-available/website2.com.conf > /dev/null
echo '</VirtualHost>' | sudo tee -a /etc/apache2/sites-available/website2.com.conf > /dev/null
WARNING
You can change *:80 to your IP server like 192.168.56.102:80.
Then type the command below to enable the Virtual Hosts configuration:
Type the command below to disable the default virtual hosts configuration:
sudo a2dissite 000-default.conf
WARNING
If you want to change the configuration of virtual hosts, you have to change it in the sites-available directory and not in the sites-enabled directory.
5. Check the configuration
Use the command below to check whether there is an Apache configuration that is an error or not by using the command below:
sudo apache2ctl configtest
If there is no error, then reload Apache using the command below:
sudo systemctl reload apache2
WARNING
Use the command above if there is a change in the configuration of virtual hosts in each domain.
6. Check in the browser
Because this article uses a private IP, you must configure it in the hosts file before you check the browser. If you use Windows, change the hosts file in C:\Windows\System32\drivers\etc\hosts or in /etc/hosts if you use Linux. In the hosts file, add the below script:
192.168.56.102 website1.com website2.com
Info
Change IP 192.168.56.102 with your Ubuntu IP server.
If your Ubuntu server uses a firewall, type the command below to open the port for Apache:
sudo ufw allow 'Apache Full'
Open your browser and type each of these domains, then there should be a site displayed as in the image below:
http://website1.com
Site website1.com
http://website2.com
site website2.com
If you use Linux, you can use the command below to check the result:
curl http://website1.com
curl http://website2.com
Using the curl command
By default, websites work on the web server using port 80. But you can change port 80 to another port as long as the port is not used on the server. For example, if you want the website1.com site to use port 8080, change the /etc/apache2/sites-available/website1.com.conf file and change its contents to something like this:
If you use the firewall in the Ubuntu server, don’t forget to open port 8080 using the command below:
sudo ufw allow 8080
Reload Apache and open it in the browser by typing the command:
http://website1.com:8080
Site website1.com:8080
B. IP-based virtual hosts
The meaning of IP-based is that you use a different IP address for each website. For example, you have 2 IPs and 2 domains, where IP 192.168.56.102 is for site1.com, and IP 192.168.56.103 is for site2.com. This article will use a server that has 2 IPs, as shown below:
Using 2 NICs in a server
1. Create the directories and the files
By default, Apache uses the /var/www/html folder as its rootdocument, as shown in the image above. However, to make it easier to configure it, you should create a folder for each of these websites, as shown in the image below:
You can change the above directory to another directory, but for the next steps, you have to follow the directory you created.
After that, create an index.html file for each domain:
sudo sh -c 'echo "<h1> This is for site1.com domain</h1>" > /var/www/html/site1.com/index.html'
sudo sh -c 'echo "<h1> This is for site2.com domain</h1>" > /var/www/html/site2.com/index.html'
By default, 2 directories are used to manage the many domains in the virtual hosts running on that server: the sites-available and sites-enabled directories located in the /etc/apache2 directory. The sites-enabled directory contains all the configuration of the website (virtual host) that is available on the server, but is not yet activated automatically while the sites-enabled directory contains a symlink (symbolic link) to the configuration file that exists in the sites-available directory and only the files that exist in the site-enabled directory will be executed and activated by the web server if the webserver is restarted or reloaded. Use the command below to create a virtual hosts directory:
echo '<VirtualHost 192.168.56.102:80>' | sudo tee /etc/apache2/sites-available/site1.com.conf > /dev/null
echo ' ServerName site1.com' | sudo tee -a /etc/apache2/sites-available/site1.com.conf > /dev/null
echo ' ServerAlias www.site1.com' | sudo tee -a /etc/apache2/sites-available/site1.com.conf > /dev/null
echo ' ServerAdmin webmaster@site1.com' | sudo tee -a /etc/apache2/sites-available/site1.com.conf > /dev/null
echo ' DocumentRoot /var/www/html/site1.com' | sudo tee -a /etc/apache2/sites-available/site1.com.conf > /dev/null
echo ' ErrorLog ${APACHE_LOG_DIR}/site1-error.log' | sudo tee -a /etc/apache2/sites-available/site1.com.conf > /dev/null
echo ' CustomLog ${APACHE_LOG_DIR}/site1-access.log combined' | sudo tee -a /etc/apache2/sites-available/site1.com.conf > /dev/null
echo '</VirtualHost>' | sudo tee -a /etc/apache2/sites-available/site1.com.conf > /dev/null
echo '<VirtualHost 192.168.56.103:80>' | sudo tee /etc/apache2/sites-available/site2.com.conf > /dev/null
echo ' ServerName site2.com' | sudo tee -a /etc/apache2/sites-available/site2.com.conf > /dev/null
echo ' ServerAlias www.site2.com' | sudo tee -a /etc/apache2/sites-available/site2.com.conf > /dev/null
echo ' ServerAdmin webmaster@site2.com' | sudo tee -a /etc/apache2/sites-available/site2.com.conf > /dev/null
echo ' DocumentRoot /var/www/html/site2.com' | sudo tee -a /etc/apache2/sites-available/site2.com.conf > /dev/null
echo ' ErrorLog ${APACHE_LOG_DIR}/site2-error.log' | sudo tee -a /etc/apache2/sites-available/site2.com.conf > /dev/null
echo ' CustomLog ${APACHE_LOG_DIR}/site2-access.log combined' | sudo tee -a /etc/apache2/sites-available/site2.com.conf > /dev/null
echo '</VirtualHost>' | sudo tee -a /etc/apache2/sites-available/site2.com.conf > /dev/null
WARNING
If you want to change the configuration of virtual hosts, you have to change it in the sites-available directory and not in the sites-enabled directory.
Then type the command below to enable the Virtual Hosts configuration:
Type the command below to disable the default virtual hosts configuration:
sudo a2dissite 000-default.conf
5. Check the configuration
Use the command below to check whether there is an Apache configuration that is an error or not by using the command below:
sudo apache2ctl configtest
If there is no error, then reload Apache using the command below:
sudo systemctl reload apache2
WARNING
Use the command above if there is a change in the configuration of virtual hosts in each domain.
6. Check in the browser
Because this article uses a private IP, you must configure it in the hosts file before you check the browser. If you use Windows, change the hosts file in C:\Windows\System32\drivers\etc\hosts or in /etc/hosts if you use Linux. In the hosts file, add the below script:
192.168.56.102 site1.com
192.168.56.103 site2.com
Info
Change IP 192.168.56.102 and IP 192.168.56.103 with your Ubuntu IP server.
If your Ubuntu server uses a firewall, type the command below to open the port for Apache:
sudo ufw allow 'Apache Full'
Open your browser and type each of these domains, then there should be a site displayed as in the image below:
http://site1.com
Site site1.com
http://site2.com
Site site2.com
If you use Linux, you can use the command below to check the result:
curl http://site1.com
curl http://site2.com
Using the curl command
By default, websites work on the web server using port 80. But you can change port 80 to another port as long as the port is not used on the server. So, if you want the site1.com site to use port 8181, change the /etc/apache2/sites-available/site1.com.conf file and change its contents to something like this:
If you use the firewall in your Ubuntu server, don’t forget to open port 8181 using the command below:
sudo ufw allow 8181
Reload Apache and open it in the browser by typing the command:
http://site1.com:8181
Site site1.com:8181
Note
If you want to remove the error like this:
AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 192.168.56.103. Set the ‘ServerName’ directive globally to suppress this message
Go to the /etc/apache2/apache2.conf and insert the script below:
ServerName localhost
Reload the Apache, and the error will disappear, like in the image below:
Remove error AH00558
WARNING
You can change the localhost to your domain name, like website1.com or another domain name.
The previous article explained how to make storage using volume in Docker. This article will explain how to make storage using Bind Mount.
Problem
How to storage mount using bind mount on Docker?
Solution
A bind mount is a method of hosting a directory or file that is directly mounted into a container. Since they aren’t isolated by Docker, both non-Docker processes on the host and container processes can modify the mounted files simultaneously. So, you can change the data from the host, and those changes will be reflected in the container. This method is useful for development environments where code must be updated and tested in real-time. There are 2 ways when use bind mount:
A. using -v option
This option (using -v or ‐-volume) uses three fields, separated by colon characters (:). The fields must be in the correct order, and the meaning of each field is not immediately obvious. To use this option, use the format below:
docker run -d –namecontainer_name-v /path/folder/in/server:/path/folder/in/container[:opts] image_name:tag
INFO
opts is the abbreviation for options like readonly, private, z, Z, and so on. The third field is optional, and is separated by colon characters. You can see the options and their descriptions on this page.
To see more detailed information about mounting a container, use the format below:
For example, you want to create a container with a nginx webserver that can be accessed with port 8080 with sources in folder /home/sysadmin/web and destination to the folder /usr/share/nginx/html on container, so first make a web folder in the server, and create a simple site then create a container using the command below:
You can see from the image above that the index.html file in the container only displays the hello world sentence, so when you open the browser then the displays in the browser as shown below:
The display of the website
You can change the appearance of the website in the index.html file on the server or in the container. For example, you add the script below to the file on the server:
echo "<h2>Additional from server</h2>" >> web/index.html
Likewise, if you add the script below to the container:
Both scripts will be included in the index.html file and will be displayed on the website as shown below:
Display of the website after additional scripts
B. Using ‐-mount Option
In general, these options are more explicit and verbose. This option consists of multiple key-value pairs, separated by commas, and each consisting of a <key>=<value> tuple. The biggest difference is that the -v syntax combines all the options in one field, while the –mount syntax separates them. The –mount syntax is more verbose than -v or –volume, but the order of the keys is not significant, and it is easier to understand. To use this option, use the format below:
docker run -d --namecontainer_name--mount type=type_mount,source=/path/folder/in/server,destination=/path/folder/in/container[,<key>=<value>...] image_name:tag
INFO
The third field is optional, and is separated by commas like readonly, bind-propagation, and so on. You can see the options and their descriptions on this page.
For example, you want to create a container with an Apache web server that can be accessed on port 8081 with sources in the folder /home/sysadmin/mount and destination to the folder /usr/local/apache2/htdocs on the container, so first make the mount folder in the server, then make the container using the command below:
Like using the -v option, you can change the appearance of the website in the index.html file on the server or in the container. For example, you add the script below to the file on the server:
echo "<h2>Additional from server</h2>" >> mount/index.html
Likewise, if you add the script below to the container:
NFS or Network File Sharing is a protocol that allows you to share directories and files with other Linux clients over a network. Similar to locally created folders, an NFS file share is accessible when mounted on a client computer. When you have limited disk space and need to share public data between client machines, NFS is especially helpful.
Problem
How to install and configure NFS on Linux?
Solution
This article will explain how to install and configure NFS on 3 Linux distros: Rockylinux, Ubuntu, and OpenSuse and this article should work in each of their derivatives of the three distros.
A. On the server
Following are the steps to install and configure NFS:
1. Install NFS
I install NFS in the server with IP 192.168.56.2, and to install the NFS application on the Linux server, use the command below:
If you see the NFS status is still not on, use the command below to turn on the NFS service:
sudo systemctl enable --now nfs-server
Check the NFS service status
Sometimes you have to check the nfs-mountd service using the command below:
sudo systemctl status nfs-mountd
If the service is not on the server, then use the command below to turn on the service:
sudo systemctl start nfs-mountd
3. Check the rpcbind status
Make sure that the rpcbind service is actively used by NFS for the mapping port. Use the command below to check the status of the service:
sudo systemctl status rpcbind
If the service is not active, use the command below to start the service:
sudo systemctl enable -now rpcbind
4. Check NFS and Portmap
To see if NFS and portmap (Portmap is a server that converts RPC program numbers into DARPA protocol port numbers. It must be running to make RPC calls) are running on the server, use the command below:
sudo rpcinfo -p
Check whether NFS and portmap run in the server or not
5. Configure firewall
If you still turn on the firewall on Linux, use the command below to open the NFS port (Port NFS is TCP Port 2049):
Create a folder to collect NFS files and folders and I make it in the folder /var/nfs using the command below:
mkdir /var/nfs
After that, copy the file(s) and folder(s) that you want to share into the folder as shown below:
Copy the file(s) and folder(s) into the folder sharing
7. Define an Export File
To grant access to NFS clients, you need to define an export file and it is typically located at /etc/exports. Use the format below to define an export file:
/folder/path accessible-host-ip-address(options)
The options you can use can be seen in the image below:
You can use more than one option like (rw,sync,no_subtree_check). By default, NFS uses the ro option where the client can only read the file or folder in the folder sharing. In this article, I only want the folder sharing can only be accessed by users who only use IP 192.168.56.0/24 and the folder can be changed by the users, then use the command below to enter the script into the exports file:
Use the command below to make the folder sharing available to the clients:
sudo exportfs -r
Use the command below to view the exports file:
showmount -e
To see which hosts access file sharing, use the command below:
sudo netstat -an | grep 2049
B. On the client
Following are the steps to install and configure NFS:
1. Install NFS client
Use the command below to install the NFS client:
RockyLinux
sudo dnf install -y nfs-utils
Ubuntu
sudo apt-get install -y nfs-common
OpenSUSE
zypper install -y nfs-client*
2. Check the ports in the NFS server
Use the command below to check whether the client can access the ports (port 2049 and 111) in the NFS server or not (the IP server NFS is 192.168.56.2):
rpcinfo -p 192.168.56.2
Check the connection between the client to the NFS server
2. Make and mount a folder
Make the folder where we want to mount the NFS shares from the server, for example, I made a folder in /tmp/nfs:
mkdir /tmp/nfs
After that the mount folder with the NFS server using the format below:
sudo mount -t nfs 192.168.56.2:/var/nfs /tmp/nfs
Mount the folder to the folder-sharing
INFO
You can use the -v option so that the above command becomes: sudo mount -v -t nfs 192.168.56.2:/var/nfs /tmp/nfs
to display the logs when mounting so that you can know if there is an error when mounting.
You should access the folder sharing on the NFS server as shown below:
Access to the NFS server
You can use the command below to see the NFS client connection:
sudo mount | grep -i nfs
Check the status of the NFS client
4. Simulation test
Try to do the simulation by changing the file name in the folder sharing. I try to rename the download.htm file to index.html using the command below:
sudo mv /tmp/nfs/download.htm /tmp/nfs/index.html
The file was successfully changed as shown below:
Rename the file in NFS
5. Configure the fstab file
To keep the folder sharing is still connected in the client after the client is rebooted, configure the /etc/fstab file using the command below:
echo '192.168.56.2:/var/nfs /tmp/nfs nfs rw 0 0' | sudo tee -a /etc/fstab
Insert the script to fstab file
C. Errors and solutions
Below are errors that often appear and their solutions:
1. No options for /var/nfs
Sometimes when you run the exportfs -r command, there is an error as below:
exportfs: No options for /var/nfs/192.168.56.0/24(rw) : suggest (sync) to avoid warning exportfs: Failed to stat /var/nfs/192.168.56.0/24(rw): No such file or directory
Error failed to stat
To eliminate the error, check in the /etc/exports file and you have to fix the writing in the file from:
/var/nfs/192.168.56.0/24(rw)
changed into
/var/nfs 192.168.56.0/24(rw)
After that, run the exportfs -r command again and the error should disappear.
2. Error Stale file handle
When you want to connect a client to the NFS server there is an error like the below (usually this happens if there is an error like number 1 or other causes on the NFS server):
Stale file handle
Stale file handle error
To solve this error you have to unmount on the side of the client and then mount back as shown below:
Solve the stale file handle error
3. RPC: Program not registered
When typing the showmount -e command on the NFS server there is an error as below:
clnt_create: RPC: Program not registered
Error Program Not Registered
The solution is that you have to run the command below so that the nfs-mountd service runs on the server:
systemctl start nfs-mountd
4. Permission denied
When you want to connect to the NFS server or when you want to change the file in the NFS, there is an error like this:
Permission denied
Error Permission denied
The solution is to check the exports file on the NFS server and make sure that the folder has been given permissions as in step 5 in the server section.
Note
If you want to block an IP address of a host so the host can’t access the NFS server, use the command below to block the IP host:
In my experience, you can’t immediately block a client to NFS if the client is still connected to the NFS. You have to wait until the client disconnects to the NFS server, either the host reboots or others.
How to Connect Storage Mount Using Volume Mount on Docker?
written by sysadmin | 21 June 2025
The previous article explained how to access the database installed in a container. But you must know that if you delete the container, it will automatically delete the database too. Therefore, you must create a storage to store a database so that if you delete the container, either intentionally or unintentionally, the database will remain. By default, Docker supports the following types of storage mounts for storing data outside of the container’s writable layer: volume mounts, bind mounts, and tmpfs mounts, each with its unique characteristics and use cases. This article will explain how to connect storage mount using volume mount. You can see a summary of the three types of storage here.
Problem
How to connect storage mount using volume mount on Docker?
Solution
Volumes are persistent storage mechanisms managed by the Docker daemon. It is stored in the filesystem on the host in /var/lib/docker/volumes folder, but to interact with the data in the volume, you must mount the volume to a container. Volumes are ideal for performance-critical data processing and long-term storage needs and are also suitable for sharing data between containers since volumes can be attached to multiple containers.
A. List, remove and create the volume
To see the volume on the server, use the command below:
docker volume ls
To remove a volume, use the command below:
docker volume rm volume_name
Use the command below to remove all unused volumes:
docker volume prune
By default, there is no volume if there is no container on the server. But if there is a container that uses storage like a container that uses a database image, the volume will form automatically. To see which containers that use volume can use the command below:
For example, use the command below if you want to create a db_mysql container with a password q1w2e3r4 using mysql_vol volume in the folder /var/lib/mysql :
docker run -d --name db_mysql -e MYSQL_ROOT_PASSWORD='q1w2e3r4' -v mysql_vol:/var/lib/mysql mysql
docker inspect db_mysql -f "{{json .Mounts}}" | python3 -m json.tool
Run the container and check the mount
C. Simulate remove the container
After that, try to enter the container by using the command below:
docker exec -it db_mysql mysql -uroot -pq1w2e3r4
Create a database and fill it as shown in the image below:
Create a database
Then, try to simulate by deleting the container and creating a new container where the data is put into the mysql_vol volume in the /var/lib/mysql folder using the command below:
docker stop db_mysql
docker rm db_mysql
docker run -d --name db_mysql_new -e MYSQL_ROOT_PASSWORD='q1w2e3r4' -v mysql_vol:/var/lib/mysql mysql
Access the container by using the command:
docker exec -it db_mysql_new mysql -uroot -pq1w2e3r4
The lab_db database should still be accessible using the container you just created, as shown in the image below:
The database can still be accessed
D. Share data in the volume among containers
Let’s do a simulation to share the data that is in the volume with more than one container on a single server. In this article, 2 containers will be created that are connected to a mysql_vol volume. Type the command below to make 2 containers:
docker run -d --name db_mysql1 -e MYSQL_ROOT_PASSWORD='q1w2e3r4' -v mysql_volume:/var/lib/mysql mysql
docker run -d --name db_mysql2 -e MYSQL_ROOT_PASSWORD='q1w2e3r4' -v mysql_volume:/var/lib/mysql mysql
docker ps
Create 2 containers
After that, type the command below to create a database and insert the data via container db_mysql1:
docker exec db_mysql bash -c "mysql -uroot -pq1w2e3r4 -e \"CREATE DATABASE db_school; USE db_school; CREATE TABLE students (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100) NOT NULL, age INT NOT NULL); INSERT INTO students (name, age) VALUES ('bob', 21), ('John', 22);select * from students;\""
Then there will be a display below:
Execute the command to create a database and insert data
From the picture above, there are 2 data in the student table in the db_school database. Type the command below to add data to the table from container db_mysql2:
docker exec db_mysql1 bash -c "mysql -uroot -pq1w2e3r4 -e \"USE db_school; INSERT INTO students (name, age) VALUES ('Laura', 20), ('Andrew', 23);select * from students;\""
Execute the command to add data
In the picture above, there are 4 data in the student table so that the Docker volume data can be shared between containers on a server well.
Note
You can see the picture below to see the difference between the three storage:
Types of storage in Docker (Image credit from linkedin.com)
How to Download a Package With Its Dependencies in RockyLinux?
written by sysadmin | 21 June 2025
To install a package on RockyLinux distro which is a derivative of RHEL and derivatives such as AlmaLinux or CentOS and others, just type yum install or dnf install and follow by the name of the package to be installed, then the package will be directly installed immediately on the server. But sometimes I just want to download a package with its dependencies for some purposes like installing into the server that can’t connect to the internet or just for some experiments.
Problems
How to download a package with its dependencies in RockyLinux?
Solution
There are 2 methods to download a package with all its dependencies without installing the package on the server and both methods work successfully on RockyLinux9:
For example, suppose you want to download nginx packages along with their dependencies, and all the packages are contained in the /tmp/nginx folder, use the following command:
For example, suppose you want to download a vim package and it is stored in the /root/vim folder, then use the command below:
yumdownloader --destdir=/root/vim --resolve vim -y
After you run the above command, the vim package and its dependencies files should be in the /root/vim folder as shown below:
Download a vim package using yumdownloader
By default, if you forget to type the ‐-destdir option, the package and its dependencies will be saved in the folder where the command is run. If for example the command is executed in /root then the package and its dependencies files will be stored in the /root folder.
Warning
You can download more than one package either using the first method or the second method, but this is not recommended because there will be mixing between dependencies files in one folder so that it makes confusion. So it is recommended to download only one package in one folder.
Note
If you have installed a package on the server and you want to download the package along with the dependencies files, but you use the downloadonly plugin then you can’t download the package like in the image below:
Failed to download a package
so you have to remove the package from the server first and then you can download the package by running the previous command. However, you can still download packages that are already installed on the server if you use yumdownloader. And if you want to install the downloaded package along with its dependency files then go to the downloaded folder and type the command below:
rpm -ivh *
so you can install the package easily and quickly like in the image below: