{"id":13528,"date":"2019-04-03T07:50:54","date_gmt":"2019-04-03T07:50:54","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=13528"},"modified":"2019-04-03T07:50:54","modified_gmt":"2019-04-03T07:50:54","slug":"rhce-red-hat-certified-engineer","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/03\/rhce-red-hat-certified-engineer\/","title":{"rendered":"RHCE (Red Hat Certified Engineer)"},"content":{"rendered":"<h1 class=\"post-title\">RHCE Series: How to Setup and Test Static Network Routing \u2013 Part 1<\/h1>\n<p><strong>RHCE<\/strong>\u00a0(<strong>Red Hat Certified Engineer<\/strong>) is a certification from Red Hat company, which gives an open source operating system and software to the enterprise community, It also gives training, support and consulting services for the companies.<\/p>\n<div id=\"attachment_14871\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/RHCE-Exam-Series-by-TecMint.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-14871\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/RHCE-Exam-Series-by-TecMint-620x297.jpg\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/RHCE-Exam-Series-by-TecMint-620x297.jpg 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/RHCE-Exam-Series-by-TecMint.jpg 720w\" alt=\"RHCE Exam Preparation Guide\" width=\"620\" height=\"297\" aria-describedby=\"caption-attachment-14871\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-14871\" class=\"wp-caption-text\">RHCE Exam Preparation Guide<\/p>\n<\/div>\n<p>This\u00a0<strong>RHCE<\/strong>\u00a0(<strong>Red Hat Certified Engineer<\/strong>) is a performance-based exam (codename\u00a0<strong>EX300<\/strong>), who possesses the additional skills, knowledge, and abilities required of a senior system administrator responsible for Red Hat Enterprise Linux (RHEL) systems.<\/p>\n<p><strong>Important<\/strong>:\u00a0<a href=\"https:\/\/www.tecmint.com\/rhcsa-exam-reviewing-essential-commands-system-documentation\/\" target=\"_blank\" rel=\"noopener\">Red Hat Certified System Administrator<\/a>\u00a0(RHCSA) certification is required to earn\u00a0<strong>RHCE<\/strong>\u00a0certification.<\/p>\n<p>Following are the exam objectives based on the\u00a0<strong>Red Hat Enterprise Linux 7<\/strong>\u00a0version of the exam, which will going to cover in this RHCE series:<\/p>\n<div id=\"exam_announcement\"><b>Part 1<\/b>:\u00a0<b>How to Setup and Test Static Routing in RHEL 7<\/b><\/div>\n<div id=\"exam_announcement\"><b>Part 2<\/b>:\u00a0<a href=\"https:\/\/www.tecmint.com\/perform-packet-filtering-network-address-translation-and-set-kernel-runtime-parameters-in-rhel\/\" target=\"_blank\" rel=\"noopener\">How to Perform Packet Filtering, Network Address Translation and Set Kernel Runtime Parameters<\/a><\/div>\n<div id=\"exam_announcement\"><b>Part 3<\/b>:\u00a0<a href=\"https:\/\/www.tecmint.com\/linux-performance-monitoring-and-file-system-statistics-reports\/\" target=\"_blank\" rel=\"noopener\">How to Produce and Deliver System Activity Reports Using Linux Toolsets<\/a><\/div>\n<div id=\"exam_announcement\"><b>Part 4<\/b>:\u00a0<a href=\"https:\/\/www.tecmint.com\/using-shell-script-to-automate-linux-system-maintenance-tasks\/\" target=\"_blank\" rel=\"noopener\">Using Shell Scripting to Automate Linux System Maintenance Tasks<\/a><\/div>\n<div id=\"exam_announcement\"><b>Part 5<\/b>:\u00a0<a href=\"https:\/\/www.tecmint.com\/manage-linux-system-logs-using-rsyslogd-and-logrotate\/\" target=\"_blank\" rel=\"noopener\">How to Manage System Logs (Configure, Rotate and Import Into Database) in RHEL 7<\/a><\/div>\n<div id=\"exam_announcement\"><b>Part 6<\/b>:\u00a0<a href=\"https:\/\/www.tecmint.com\/setup-samba-file-sharing-for-linux-windows-clients\/\" target=\"_blank\" rel=\"noopener\">Setting Up Samba and Configure FirewallD and SELinux to Allow File Sharing on Clients<\/a><\/div>\n<div id=\"exam_announcement\"><b>Part 7<\/b>:\u00a0<a href=\"https:\/\/www.tecmint.com\/setting-up-nfs-server-with-kerberos-based-authentication\/\" target=\"_blank\" rel=\"noopener\">Setting Up NFS Server with Kerberos-based Authentication for Linux Clients<\/a><\/div>\n<div id=\"exam_announcement\"><b>Part 8<\/b>:\u00a0<a href=\"https:\/\/www.tecmint.com\/create-apache-https-self-signed-certificate-using-nss\/\" target=\"_blank\" rel=\"noopener\">Implementing HTTPS through TLS using Network Security Service (NSS) for Apache<\/a><\/div>\n<div id=\"exam_announcement\"><b>Part 9<\/b>:\u00a0<a href=\"https:\/\/www.tecmint.com\/setup-postfix-mail-server-smtp-using-null-client-on-centos\/\" target=\"_blank\" rel=\"noopener\">How to Setup Postfix Mail Server (SMTP) using null-client Configuration<\/a><\/div>\n<div id=\"exam_announcement\"><b>Part 10<\/b>:\u00a0<a href=\"https:\/\/www.tecmint.com\/install-configure-cache-only-dns-server-in-rhel-centos-7\/\" target=\"_blank\" rel=\"noopener\">Install and Configure Caching-Only DNS Server in RHEL\/CentOS 7<\/a><\/div>\n<div id=\"exam_announcement\"><b>Part 11<\/b>:\u00a0<a href=\"https:\/\/www.tecmint.com\/configure-network-bonding-or-teaming-in-rhel-centos-7\/\" target=\"_blank\" rel=\"noopener\">Setup and Configure Network Bonding or Teaming in RHEL\/CentOS 7<\/a><\/div>\n<div id=\"exam_announcement\"><b>Part 12<\/b>:\u00a0<a href=\"https:\/\/www.tecmint.com\/create-centralized-secure-storage-using-iscsi-target-initiator\/\" target=\"_blank\" rel=\"noopener\">Create Centralized Secure Storage using iSCSI Target \/ Initiator on RHEL\/CentOS 7<\/a><\/div>\n<div id=\"exam_announcement\"><b>Part 13<\/b>:\u00a0<a href=\"https:\/\/www.tecmint.com\/install-ntp-server-in-centos\/\" target=\"_blank\" rel=\"noopener\">Setting Up \u201cNTP (Network Time Protocol) Server\u201d in RHEL\/CentOS 7<\/a><\/div>\n<div><\/div>\n<p>To view fees and register for an exam in your country, check the\u00a0<a href=\"https:\/\/www.redhat.com\/en\/services\/certification\/rhce\" target=\"_blank\" rel=\"noopener\">RHCE Certification<\/a>\u00a0page.<\/p>\n<p>In this\u00a0<strong>Part 1<\/strong>\u00a0of the\u00a0<strong>RHCE<\/strong>\u00a0series and the next, we will present basic, yet typical, cases where the principles of static routing, packet filtering, and network address translation come into play.<\/p>\n<div id=\"attachment_14872\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Setup-Static-Network-Routing-in-RHEL-7.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-14872\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Setup-Static-Network-Routing-in-RHEL-7-620x297.jpg\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Setup-Static-Network-Routing-in-RHEL-7-620x297.jpg 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Setup-Static-Network-Routing-in-RHEL-7.jpg 720w\" alt=\"Setup Static Network Routing in RHEL\" width=\"620\" height=\"297\" aria-describedby=\"caption-attachment-14872\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-14872\" class=\"wp-caption-text\">RHCE: Setup and Test Network Static Routing \u2013 Part 1<\/p>\n<\/div>\n<p>Please note that we will not cover them in depth, but rather organize these contents in such a way that will be helpful to take the first steps and build from there.<\/p>\n<h3>Static Routing in Red Hat Enterprise Linux 7<\/h3>\n<p>One of the wonders of modern networking is the vast availability of devices that can connect groups of computers, whether in relatively small numbers and confined to a single room or several machines in the same building, city, country, or across continents.<\/p>\n<p>However, in order to effectively accomplish this in any situation, network packets need to be routed, or in other words, the path they follow from source to destination must be ruled somehow.<\/p>\n<p>Static routing is the process of specifying a route for network packets other than the default, which is provided by a network device known as the default gateway. Unless specified otherwise through static routing, network packets are directed to the default gateway; with static routing, other paths are defined based on predefined criteria, such as the packet destination.<\/p>\n<p>Let us define the following scenario for this tutorial. We have a Red Hat Enterprise Linux 7 box connecting to router\u00a0<strong>#1 [192.168.0.1]<\/strong>\u00a0to access the Internet and machines in\u00a0<strong>192.168.0.0\/24<\/strong>.<\/p>\n<p>A second router\u00a0<strong>(router #2)<\/strong>\u00a0has two network interface cards:\u00a0<strong>enp0s3<\/strong>\u00a0is also connected to\u00a0<strong>router #1<\/strong>\u00a0to access the Internet and to communicate with the RHEL 7 box and other machines in the same network, whereas the other (<strong>enp0s8<\/strong>) is used to grant access to the\u00a0<strong>10.0.0.0\/24<\/strong>\u00a0network where internal services reside, such as a web and \/ or database server.<\/p>\n<p>This scenario is illustrated in the diagram below:<\/p>\n<div id=\"attachment_14870\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Static-Routing-Network-Diagram.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-14870\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Static-Routing-Network-Diagram-620x118.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Static-Routing-Network-Diagram-620x118.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Static-Routing-Network-Diagram.png 824w\" alt=\"Static Routing Network Diagram\" width=\"620\" height=\"118\" aria-describedby=\"caption-attachment-14870\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-14870\" class=\"wp-caption-text\">Static Routing Network Diagram<\/p>\n<\/div>\n<p>In this article we will focus exclusively on setting up the routing table on our\u00a0<strong>RHEL 7<\/strong>\u00a0box to make sure that it can both access the Internet through\u00a0<strong>router #1<\/strong>\u00a0and the internal network via\u00a0<strong>router #2<\/strong>.<\/p>\n<p>In\u00a0<strong>RHEL 7<\/strong>, you will use the\u00a0<a href=\"https:\/\/www.tecmint.com\/ip-command-examples\/\" target=\"_blank\" rel=\"noopener\">ip command<\/a>\u00a0to configure and show devices and routing using the command line. These changes can take effect immediately on a running system but since they are not persistent across reboots, we will use\u00a0<strong>ifcfg-enp0sX<\/strong>\u00a0and\u00a0<strong>route-enp0sX<\/strong>\u00a0files inside\u00a0<strong>\/etc\/sysconfig\/network-scripts<\/strong>\u00a0to save our configuration permanently.<\/p>\n<p>To begin, let\u2019s print our current routing table:<\/p>\n<pre># ip route show\r\n<\/pre>\n<div id=\"attachment_14873\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Check-Current-Routing-Table.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-14873\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Check-Current-Routing-Table.png\" alt=\"Check Routing Table in Linux\" width=\"557\" height=\"91\" aria-describedby=\"caption-attachment-14873\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-14873\" class=\"wp-caption-text\">Check Current Routing Table<\/p>\n<\/div>\n<p>From the output above, we can see the following facts:<\/p>\n<ol>\n<li>The default gateway\u2019s IP address is\u00a0<strong>192.168.0.1<\/strong>\u00a0and can be accessed via the\u00a0<strong>enp0s3<\/strong>\u00a0NIC.<\/li>\n<li>When the system booted up, it enabled the zeroconf route to\u00a0<strong>169.254.0.0\/16<\/strong>\u00a0(just in case). In few words, if a machine is set to obtain an IP address through DHCP but fails to do so for some reason, it is automatically assigned an address in this network. Bottom line is, this route will allow us to communicate, also via\u00a0<strong>enp0s3<\/strong>, with other machines who have failed to obtain an IP address from a DHCP server.<\/li>\n<li>Last, but not least, we can communicate with other boxes inside the\u00a0<strong>192.168.0.0\/24<\/strong>\u00a0network through\u00a0<strong>enp0s3<\/strong>, whose IP address is\u00a0<strong>192.168.0.18<\/strong>.<\/li>\n<\/ol>\n<p>These are the typical tasks that you would have to perform in such a setting. Unless specified otherwise, the following tasks should be performed in\u00a0<strong>router #2<\/strong>:<\/p>\n<p>Make sure all NICs have been properly installed:<\/p>\n<pre># ip link show\r\n<\/pre>\n<p>If one of them is down, bring it up:<\/p>\n<pre># ip link set dev enp0s8 up\r\n<\/pre>\n<p>and assign an IP address in the\u00a0<strong>10.0.0.0\/24<\/strong>\u00a0network to it:<\/p>\n<pre># ip addr add 10.0.0.17 dev enp0s8\r\n<\/pre>\n<p>Oops! We made a mistake in the IP address. We will have to remove the one we assigned earlier and then add the right one (<strong>10.0.0.18<\/strong>):<\/p>\n<pre># ip addr del 10.0.0.17 dev enp0s8\r\n# ip addr add 10.0.0.18 dev enp0s8\r\n<\/pre>\n<p>Now, please note that you can only add a route to a destination network through a gateway that is itself already reachable. For that reason, we need to assign an IP address within the\u00a0<strong>192.168.0.0\/24<\/strong>\u00a0range to\u00a0<strong>enp0s3<\/strong>\u00a0so that our RHEL 7 box can communicate with it:<\/p>\n<pre># ip addr add 192.168.0.19 dev enp0s3\r\n<\/pre>\n<p>Finally, we will need to enable packet forwarding:<\/p>\n<pre># echo \"1\" &gt; \/proc\/sys\/net\/ipv4\/ip_forward\r\n<\/pre>\n<p>and stop \/ disable (just for the time being \u2013 until we cover packet filtering in the next article) the firewall:<\/p>\n<pre># systemctl stop firewalld\r\n# systemctl disable firewalld\r\n<\/pre>\n<p>Back in our\u00a0<strong>RHEL 7<\/strong>\u00a0box (<strong>192.168.0.18<\/strong>), let\u2019s configure a route to\u00a0<strong>10.0.0.0\/24<\/strong>\u00a0through\u00a0<strong>192.168.0.19<\/strong>\u00a0(<strong>enp0s3<\/strong>\u00a0in\u00a0<strong>router #2<\/strong>):<\/p>\n<pre># ip route add 10.0.0.0\/24 via 192.168.0.19\r\n<\/pre>\n<p>After that, the routing table looks as follows:<\/p>\n<pre># ip route show\r\n<\/pre>\n<div id=\"attachment_14874\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Show-Network-Routing.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-14874\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Show-Network-Routing.png\" alt=\"Show Network Routing Table\" width=\"565\" height=\"111\" aria-describedby=\"caption-attachment-14874\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-14874\" class=\"wp-caption-text\">Confirm Network Routing Table<\/p>\n<\/div>\n<p>Likewise, add the corresponding route in the machine(s) you\u2019re trying to reach in\u00a0<strong>10.0.0.0\/24<\/strong>:<\/p>\n<pre># ip route add 192.168.0.0\/24 via 10.0.0.18\r\n<\/pre>\n<p>You can test for basic connectivity using\u00a0<strong>ping<\/strong>:<\/p>\n<p>In the\u00a0<strong>RHEL 7<\/strong>\u00a0box, run<\/p>\n<pre># ping -c 4 10.0.0.20\r\n<\/pre>\n<p>where\u00a0<strong>10.0.0.20<\/strong>\u00a0is the IP address of a web server in the\u00a0<strong>10.0.0.0\/24<\/strong>\u00a0network.<\/p>\n<p>In the web server (<strong>10.0.0.20<\/strong>), run<\/p>\n<pre># ping -c 192.168.0.18\r\n<\/pre>\n<p>where\u00a0<strong>192.168.0.18<\/strong>\u00a0is, as you will recall, the IP address of our RHEL 7 machine.<\/p>\n<p>Alternatively, we can use\u00a0<a href=\"https:\/\/www.tecmint.com\/12-tcpdump-commands-a-network-sniffer-tool\/\" target=\"_blank\" rel=\"noopener\">tcpdump<\/a>\u00a0(you may need to install it with\u00a0<strong>yum install tcpdump<\/strong>) to check the 2-way communication over TCP between our RHEL 7 box and the web server at\u00a0<strong>10.0.0.20<\/strong>.<\/p>\n<p>To do so, let\u2019s start the logging in the first machine with:<\/p>\n<pre># tcpdump -qnnvvv -i enp0s3 host 10.0.0.20\r\n<\/pre>\n<p>and from another terminal in the same system let\u2019s\u00a0<strong>telnet<\/strong>\u00a0to port\u00a0<strong>80<\/strong>\u00a0in the web server (assuming\u00a0<strong>Apache<\/strong>\u00a0is listening on that port; otherwise, indicate the right port in the following command):<\/p>\n<pre># telnet 10.0.0.20 80\r\n<\/pre>\n<p>The\u00a0<strong>tcpdump<\/strong>\u00a0log should look as follows:<\/p>\n<div id=\"attachment_14875\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Tcpdump-logs.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-14875\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Tcpdump-logs-620x91.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Tcpdump-logs-620x91.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Tcpdump-logs.png 773w\" alt=\"Check Network Communication between Servers\" width=\"620\" height=\"91\" aria-describedby=\"caption-attachment-14875\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-14875\" class=\"wp-caption-text\">Check Network Communication between Servers<\/p>\n<\/div>\n<p>Where the connection has been properly initialized, as we can tell by looking at the 2-way communication between our\u00a0<strong>RHEL 7<\/strong>\u00a0box (<strong>192.168.0.18<\/strong>) and the web server (<strong>10.0.0.20<\/strong>).<\/p>\n<p>Please remember that these changes will go away when you restart the system. If you want to make them persistent, you will need to edit (or create, if they don\u2019t already exist) the following files, in the same systems where we performed the above commands.<\/p>\n<p>Though not strictly necessary for our test case, you should know that\u00a0<strong>\/etc\/sysconfig\/network<\/strong>\u00a0contains system-wide network parameters. A typical\u00a0<strong>\/etc\/sysconfig\/network<\/strong>\u00a0looks as follows:<\/p>\n<pre># Enable networking on this system?\r\nNETWORKING=yes\r\n# Hostname. Should match the value in \/etc\/hostname\r\nHOSTNAME=yourhostnamehere\r\n# Default gateway\r\nGATEWAY=XXX.XXX.XXX.XXX\r\n# Device used to connect to default gateway. Replace X with the appropriate number.\r\nGATEWAYDEV=enp0sX\r\n<\/pre>\n<p>When it comes to setting specific variables and values for each NIC (as we did for router #2), you will have to edit\u00a0<strong>\/etc\/sysconfig\/network-scripts\/ifcfg-enp0s3<\/strong>\u00a0and\u00a0<strong>\/etc\/sysconfig\/network-scripts\/ifcfg-enp0s8<\/strong>.<\/p>\n<p>Following our case,<\/p>\n<pre>TYPE=Ethernet\r\nBOOTPROTO=static\r\nIPADDR=192.168.0.19\r\nNETMASK=255.255.255.0\r\nGATEWAY=192.168.0.1\r\nNAME=enp0s3\r\nONBOOT=yes\r\n<\/pre>\n<p>and<\/p>\n<pre>TYPE=Ethernet\r\nBOOTPROTO=static\r\nIPADDR=10.0.0.18\r\nNETMASK=255.255.255.0\r\nGATEWAY=10.0.0.1\r\nNAME=enp0s8\r\nONBOOT=yes\r\n<\/pre>\n<p>for\u00a0<strong>enp0s3<\/strong>\u00a0and\u00a0<strong>enp0s8<\/strong>, respectively.<\/p>\n<p>As for routing in our client machine (192.168.0.18<strong>), we will need to edit\u00a0\/etc\/sysconfig\/network-scripts\/route-enp0s3:<\/strong><\/p>\n<pre>10.0.0.0\/24 via 192.168.0.19 dev enp0s3\r\n<\/pre>\n<p>Now\u00a0<strong>reboot<\/strong>\u00a0your system and you should see that route in your table.<\/p>\n<h3>Summary<\/h3>\n<p>In this article we have covered the essentials of static routing in\u00a0<strong>Red Hat Enterprise Linux 7<\/strong>. Although scenarios may vary, the case presented here illustrates the required principles and the procedures to perform this task. Before wrapping up, I would like to suggest you to take a look at\u00a0<a href=\"http:\/\/www.tldp.org\/LDP\/solrhe\/Securing-Optimizing-Linux-RH-Edition-v1.3\/net-manage.html\" target=\"_blank\" rel=\"noopener\">Chapter 4<\/a>\u00a0of the\u00a0<strong>Securing and Optimizing Linux<\/strong>section in The Linux Documentation Project site for further details on the topics covered here.<\/p>\n<p>Free ebook on\u00a0<strong>Securing &amp; Optimizing Linux: The Hacking Solution (v.3.0)<\/strong>\u00a0\u2013 This\u00a0<strong>800+<\/strong>\u00a0eBook contains comprehensive collection of Linux security tips and how to use them safely and easily to configure Linux-based applications and services.<\/p>\n<div id=\"attachment_14876\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Linux-Security-Optimization-Book.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-14876\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Linux-Security-Optimization-Book.gif\" alt=\"Linux Security and Optimization Book\" width=\"200\" height=\"259\" aria-describedby=\"caption-attachment-14876\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-14876\" class=\"wp-caption-text\">Linux Security and Optimization Book<\/p>\n<\/div>\n<p><a href=\"http:\/\/tecmint.tradepub.com\/free\/w_opeb01\/prgm.cgi\" target=\"_blank\" rel=\"nofollow noopener\">Download Now<\/a><\/p>\n<p>In the next article we will talk about packet filtering and network address translation to sum up the networking basic skills needed for the RHCE certification.<\/p>\n<p>As always, we look forward to hearing from you, so feel free to leave your questions, comments, and suggestions using the form below.<\/p>\n<h1 class=\"post-title\">How to Perform Packet Filtering, Network Address Translation and Set Kernel Runtime Parameters \u2013 Part 2<\/h1>\n<p>As promised in\u00a0<strong>Part 1<\/strong>\u00a0(\u201c<a href=\"https:\/\/www.tecmint.com\/how-to-setup-and-configure-static-network-routing-in-rhel\/\" target=\"_blank\" rel=\"noopener\">Setup Static Network Routing<\/a>\u201d), in this article (<strong>Part 2<\/strong>\u00a0of\u00a0<strong>RHCE<\/strong>\u00a0series) we will begin by introducing the principles of packet filtering and network address translation (NAT) in\u00a0<strong>Red Hat Enterprise Linux 7<\/strong>, before diving into setting runtime kernel parameters to modify the behavior of a running kernel if certain conditions change or needs arise.<\/p>\n<div id=\"attachment_14925\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Network-Packet-Filtering-in-RHEL.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-14925\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Network-Packet-Filtering-in-RHEL-620x297.jpg\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Network-Packet-Filtering-in-RHEL-620x297.jpg 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Network-Packet-Filtering-in-RHEL.jpg 720w\" alt=\"Network Packet Filtering in RHEL\" width=\"620\" height=\"297\" aria-describedby=\"caption-attachment-14925\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-14925\" class=\"wp-caption-text\">RHCE: Network Packet Filtering \u2013 Part 2<\/p>\n<\/div>\n<h3>Network Packet Filtering in RHEL 7<\/h3>\n<p>When we talk about packet filtering, we refer to a process performed by a firewall in which it reads the header of each data packet that attempts to pass through it. Then, it filters the packet by taking the required action based on rules that have been previously defined by the system administrator.<\/p>\n<p>As you probably know, beginning with\u00a0<strong>RHEL 7<\/strong>, the default service that manages firewall rules is\u00a0<a href=\"https:\/\/www.tecmint.com\/firewalld-rules-for-centos-7\/\" target=\"_blank\" rel=\"noopener\">firewalld<\/a>. Like iptables, it talks to the netfilter module in the Linux kernel in order to examine and manipulate network packets. Unlike iptables, updates can take effect immediately without interrupting active connections \u2013 you don\u2019t even have to restart the service.<\/p>\n<p>Another advantage of\u00a0<strong>firewalld<\/strong>\u00a0is that it allows us to define rules based on pre-configured service names (more on that in a minute).<\/p>\n<p>In\u00a0<strong>Part 1<\/strong>, we used the following scenario:<\/p>\n<div id=\"attachment_14870\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Static-Routing-Network-Diagram.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-14870\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Static-Routing-Network-Diagram-620x118.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Static-Routing-Network-Diagram-620x118.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Static-Routing-Network-Diagram.png 824w\" alt=\"Static Routing Network Diagram\" width=\"620\" height=\"118\" aria-describedby=\"caption-attachment-14870\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-14870\" class=\"wp-caption-text\">Static Routing Network Diagram<\/p>\n<\/div>\n<p>However, you will recall that we disabled the firewall on\u00a0<strong>router #2<\/strong>\u00a0to simplify the example since we had not covered packet filtering yet. Let\u2019s see now how we can enable incoming packets destined for a specific service or port in the destination.<\/p>\n<p>First, let\u2019s add a permanent rule to allow inbound traffic in\u00a0<strong>enp0s3<\/strong>\u00a0(<strong>192.168.0.19<\/strong>) to\u00a0<strong>enp0s8<\/strong>\u00a0(<strong>10.0.0.18<\/strong>):<\/p>\n<pre># firewall-cmd --permanent --direct --add-rule ipv4 filter FORWARD 0 -i enp0s3 -o enp0s8 -j ACCEPT\r\n<\/pre>\n<p>The above command will save the rule to\u00a0<strong>\/etc\/firewalld\/direct.xml<\/strong>:<\/p>\n<pre># cat \/etc\/firewalld\/direct.xml\r\n<\/pre>\n<div id=\"attachment_14917\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Check-Firewalld-Save-Rules.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-14917\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Check-Firewalld-Save-Rules-620x87.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Check-Firewalld-Save-Rules-620x87.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Check-Firewalld-Save-Rules.png 807w\" alt=\"Check Firewalld Saved Rules in CentOS 7\" width=\"620\" height=\"87\" aria-describedby=\"caption-attachment-14917\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-14917\" class=\"wp-caption-text\">Check Firewalld Saved Rules<\/p>\n<\/div>\n<p>Then enable the rule for it to take effect immediately:<\/p>\n<pre># firewall-cmd --direct --add-rule ipv4 filter FORWARD 0 -i enp0s3 -o enp0s8 -j ACCEPT\r\n<\/pre>\n<p>Now you can telnet to the web server from the\u00a0<strong>RHEL 7<\/strong>\u00a0box and run\u00a0<a href=\"https:\/\/www.tecmint.com\/12-tcpdump-commands-a-network-sniffer-tool\/\" target=\"_blank\" rel=\"noopener\">tcpdump<\/a>\u00a0again to monitor the TCP traffic between the two machines, this time with the firewall in\u00a0<strong>router #2<\/strong>\u00a0enabled.<\/p>\n<pre># telnet 10.0.0.20 80\r\n# tcpdump -qnnvvv -i enp0s3 host 10.0.0.20\r\n<\/pre>\n<p>What if you want to only allow incoming connections to the web server (<strong>port 80<\/strong>) from\u00a0<strong>192.168.0.18<\/strong>\u00a0and block connections from other sources in the\u00a0<strong>192.168.0.0\/24<\/strong>\u00a0network?<\/p>\n<p>In the web server\u2019s firewall, add the following rules:<\/p>\n<pre># firewall-cmd --add-rich-rule 'rule family=\"ipv4\" source address=\"192.168.0.18\/24\" service name=\"http\" accept'\r\n# firewall-cmd --add-rich-rule 'rule family=\"ipv4\" source address=\"192.168.0.18\/24\" service name=\"http\" accept' --permanent\r\n# firewall-cmd --add-rich-rule 'rule family=\"ipv4\" source address=\"192.168.0.0\/24\" service name=\"http\" drop'\r\n# firewall-cmd --add-rich-rule 'rule family=\"ipv4\" source address=\"192.168.0.0\/24\" service name=\"http\" drop' --permanent\r\n<\/pre>\n<p>Now you can make HTTP requests to the web server, from\u00a0<strong>192.168.0.18<\/strong>\u00a0and from some other machine in\u00a0<strong>192.168.0.0\/24<\/strong>. In the first case the connection should complete successfully, whereas in the second it will eventually timeout.<\/p>\n<p>To do so, any of the following commands will do the trick:<\/p>\n<pre># telnet 10.0.0.20 80\r\n# wget 10.0.0.20\r\n<\/pre>\n<p>I strongly advise you to check out the\u00a0<a href=\"https:\/\/fedoraproject.org\/wiki\/Features\/FirewalldRichLanguage\" target=\"_blank\" rel=\"nofollow noopener\">Firewalld Rich Language<\/a>\u00a0documentation in the Fedora Project Wiki for further details on rich rules.<\/p>\n<h3>Network Address Translation in RHEL 7<\/h3>\n<p><strong>Network Address Translation<\/strong>\u00a0(<strong>NAT<\/strong>) is the process where a group of computers (it can also be just one of them) in a private network are assigned an unique public IP address. As result, they are still uniquely identified by their own private IP address inside the network but to the outside they all \u201cseem\u201d the same.<\/p>\n<p>In addition, NAT makes it possible that computers inside a network sends requests to outside resources (like the Internet) and have the corresponding responses be sent back to the source system only.<\/p>\n<p>Let\u2019s now consider the following scenario:<\/p>\n<div id=\"attachment_14918\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Network-Address-Translation-Diagram.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-14918\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Network-Address-Translation-Diagram-620x118.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Network-Address-Translation-Diagram-620x118.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Network-Address-Translation-Diagram.png 824w\" alt=\"Network Address Translation in RHEL\" width=\"620\" height=\"118\" aria-describedby=\"caption-attachment-14918\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-14918\" class=\"wp-caption-text\">Network Address Translation<\/p>\n<\/div>\n<p>In\u00a0<strong>router #2<\/strong>, we will move the\u00a0<strong>enp0s3<\/strong>\u00a0interface to the external zone, and\u00a0<strong>enp0s8<\/strong>\u00a0to the internal zone, where masquerading, or NAT, is enabled by default:<\/p>\n<pre># firewall-cmd --list-all --zone=external\r\n# firewall-cmd --change-interface=enp0s3 --zone=external\r\n# firewall-cmd --change-interface=enp0s3 --zone=external --permanent\r\n# firewall-cmd --change-interface=enp0s8 --zone=internal\r\n# firewall-cmd --change-interface=enp0s8 --zone=internal --permanent\r\n<\/pre>\n<p>For our current setup, the internal zone \u2013 along with everything that is enabled in it will be the default zone:<\/p>\n<pre># firewall-cmd --set-default-zone=internal\r\n<\/pre>\n<p>Next, let\u2019s reload firewall rules and keep state information:<\/p>\n<pre># firewall-cmd --reload\r\n<\/pre>\n<p>Finally, let\u2019s add\u00a0<strong>router #2<\/strong>\u00a0as default gateway in the web server:<\/p>\n<pre># ip route add default via 10.0.0.18\r\n<\/pre>\n<p>You can now verify that you can ping\u00a0<strong>router #1<\/strong>\u00a0and an external site (<strong>tecmint.com<\/strong>, for example) from the web server:<\/p>\n<pre># ping -c 2 192.168.0.1\r\n# ping -c 2 tecmint.com\r\n<\/pre>\n<div id=\"attachment_14919\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Verify-Network-Routing.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-14919\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Verify-Network-Routing-620x246.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Verify-Network-Routing-620x246.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Verify-Network-Routing.png 707w\" alt=\"Verify Network Routing\" width=\"620\" height=\"246\" aria-describedby=\"caption-attachment-14919\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-14919\" class=\"wp-caption-text\">Verify Network Routing<\/p>\n<\/div>\n<h3>Setting Kernel Runtime Parameters in RHEL 7<\/h3>\n<p>In Linux, you are allowed to change, enable, and disable the kernel runtime parameters, and RHEL is no exception. The\u00a0<strong>\/proc\/sys<\/strong>\u00a0interface (<strong>sysctl<\/strong>) lets you set runtime parameters on-the-fly to modify the system\u2019s behavior without much hassle when operating conditions change.<\/p>\n<p>To do so, the echo shell built-in is used to write to files inside\u00a0<strong>\/proc\/sys\/&lt;category&gt;<\/strong>, where\u00a0<strong>&lt;category&gt;<\/strong>\u00a0is most likely one of the following directories:<\/p>\n<ol>\n<li><strong>dev<\/strong>: parameters for specific devices connected to the machine.<\/li>\n<li><strong>fs<\/strong>: filesystem configuration (quotas and inodes, for example).<\/li>\n<li><strong>kernel<\/strong>: kernel-specific configuration.<\/li>\n<li><strong>net<\/strong>: network configuration.<\/li>\n<li><strong>vm<\/strong>: use of the kernel\u2019s virtual memory.<\/li>\n<\/ol>\n<p>To display the list of all the currently available values, run<\/p>\n<pre># sysctl -a | less\r\n<\/pre>\n<p>In\u00a0<strong>Part 1<\/strong>, we changed the value of the\u00a0<strong>net.ipv4.ip<\/strong>_forward parameter by doing<\/p>\n<pre># echo 1 &gt; \/proc\/sys\/net\/ipv4\/ip_forward\r\n<\/pre>\n<p>in order to allow a Linux machine to act as router.<\/p>\n<p>Another runtime parameter that you may want to set is\u00a0<strong>kernel.sysrq<\/strong>, which enables the\u00a0<strong>Sysrq<\/strong>\u00a0key in your keyboard to instruct the system to perform gracefully some low-level functions, such as rebooting the system if it has frozen for some reason:<\/p>\n<pre># echo 1 &gt; \/proc\/sys\/kernel\/sysrq\r\n<\/pre>\n<p>To display the value of a specific parameter, use sysctl as follows:<\/p>\n<pre># sysctl &lt;parameter.name&gt;\r\n<\/pre>\n<p>For example,<\/p>\n<pre># sysctl net.ipv4.ip_forward\r\n# sysctl kernel.sysrq\r\n<\/pre>\n<p>Some parameters, such as the ones mentioned above, require only one value, whereas others (for example,\u00a0<strong>fs.inode-state<\/strong>) require multiple values:<\/p>\n<div id=\"attachment_14921\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Check-Kernel-Parameters.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-14921\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Check-Kernel-Parameters.png\" alt=\"Check Kernel Parameters in Linux\" width=\"541\" height=\"136\" aria-describedby=\"caption-attachment-14921\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-14921\" class=\"wp-caption-text\">Check Kernel Parameters<\/p>\n<\/div>\n<p>In either case, you need to read the kernel\u2019s documentation before making any changes.<\/p>\n<p>Please note that these settings will go away when the system is rebooted. To make these changes permanent, we will need to add\u00a0<strong>.conf<\/strong>\u00a0files inside the\u00a0<strong>\/etc\/sysctl.d<\/strong>\u00a0as follows:<\/p>\n<pre># echo \"net.ipv4.ip_forward = 1\" &gt; \/etc\/sysctl.d\/10-forward.conf\r\n<\/pre>\n<p>(where the number\u00a0<strong>10<\/strong>\u00a0indicates the order of processing relative to other files in the same directory).<\/p>\n<p>and enable the changes with<\/p>\n<pre># sysctl -p \/etc\/sysctl.d\/10-forward.conf\r\n<\/pre>\n<h3>Summary<\/h3>\n<p>In this tutorial we have explained the basics of packet filtering, network address translation, and setting kernel runtime parameters on a running system and persistently across reboots. I hope you have found this information useful, and as always, we look forward to hearing from you!<br \/>\nDon\u2019t hesitate to share with us your questions, comments, or suggestions using the form below.<\/p>\n<h1 class=\"post-title\">How to Produce and Deliver System Activity Reports Using Linux Toolsets \u2013 Part 3<\/h1>\n<p>As a system engineer, you will often need to produce reports that show the utilization of your system\u2019s resources in order to make sure that: 1) they are being utilized optimally, 2) prevent bottlenecks, and 3) ensure scalability, among other reasons.<\/p>\n<div id=\"attachment_15158\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Monitor-Linux-Performance-Activity-Reports.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15158\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Monitor-Linux-Performance-Activity-Reports-620x297.jpg\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Monitor-Linux-Performance-Activity-Reports-620x297.jpg 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Monitor-Linux-Performance-Activity-Reports.jpg 720w\" alt=\"Monitor Linux Performance Activity Reports\" width=\"620\" height=\"297\" aria-describedby=\"caption-attachment-15158\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15158\" class=\"wp-caption-text\">RHCE: Monitor Linux Performance Activity Reports \u2013 Part 3<\/p>\n<\/div>\n<p>Besides the well-known native Linux tools that are used to check disk, memory, and CPU usage \u2013 to name a few examples, Red Hat Enterprise Linux 7 provides two additional toolsets to enhance the data you can collect for your reports:\u00a0<strong>sysstat<\/strong>\u00a0and\u00a0<strong>dstat<\/strong>.<\/p>\n<p>In this article we will describe both, but let\u2019s first start by reviewing the usage of the classic tools.<\/p>\n<h3>Native Linux Tools<\/h3>\n<p>With\u00a0<strong>df<\/strong>, you will be able to report disk space and inode usage of by filesystem. You need to monitor both because a lack of space will prevent you from being able to save further files (and may even cause the system to crash), just like running out of inodes will mean you can\u2019t link further files with their corresponding data structures, thus producing the same effect: you won\u2019t be able to save those files to disk.<\/p>\n<pre># df -h \t\t[Display output in human-readable form]\r\n# df -h --total         [Produce a grand total]\r\n<\/pre>\n<div id=\"attachment_15146\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Check-Linux-Total-Disk-Usage.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-15146\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Check-Linux-Total-Disk-Usage.png\" alt=\"Check Linux Total Disk Usage\" width=\"492\" height=\"312\" aria-describedby=\"caption-attachment-15146\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15146\" class=\"wp-caption-text\">Check Linux Total Disk Usage<\/p>\n<\/div>\n<pre># df -i \t\t[Show inode count by filesystem]\r\n# df -i --total \t[Produce a grand total]\r\n<\/pre>\n<div id=\"attachment_15147\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Check-Linux-Total-inode-Numbers.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-15147\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Check-Linux-Total-inode-Numbers.png\" alt=\"Check Linux Total inode Numbers\" width=\"542\" height=\"313\" aria-describedby=\"caption-attachment-15147\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15147\" class=\"wp-caption-text\">Check Linux Total inode Numbers<\/p>\n<\/div>\n<p>With\u00a0<strong>du<\/strong>, you can estimate file space usage by either file, directory, or filesystem.<\/p>\n<p>For example, let\u2019s see how much space is used by the\u00a0<strong>\/home<\/strong>\u00a0directory, which includes all of the user\u2019s personal files. The first command will return the overall space currently used by the entire\u00a0<strong>\/home<\/strong>\u00a0directory, whereas the second will also display a disaggregated list by sub-directory as well:<\/p>\n<pre># du -sch \/home\r\n# du -sch \/home\/*\r\n<\/pre>\n<div id=\"attachment_15148\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Check-Linux-Directory-Disk-Size.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-15148\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Check-Linux-Directory-Disk-Size.png\" alt=\"Check Linux Directory Disk Size\" width=\"269\" height=\"175\" aria-describedby=\"caption-attachment-15148\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15148\" class=\"wp-caption-text\">Check Linux Directory Disk Size<\/p>\n<\/div>\n<p><strong>Don\u2019t Miss<\/strong>:<\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/how-to-check-disk-space-in-linux\/\" target=\"_blank\" rel=\"noopener\">12 \u2018df\u2019 Command Examples to Check Linux Disk Space Usage<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/check-linux-disk-usage-of-files-and-directories\/\" target=\"_blank\" rel=\"noopener\">10 \u2018du\u2019 Command Examples to Find Disk Usage of Files\/Directories<\/a><\/li>\n<\/ol>\n<p>Another utility that can\u2019t be missing from your toolset is\u00a0<strong>vmstat<\/strong>. It will allow you to see at a quick glance information about processes, CPU and memory usage, disk activity, and more.<\/p>\n<p>If run without arguments,\u00a0<strong>vmstat<\/strong>\u00a0will return averages since the last reboot. While you may use this form of the command once in a while, it will be more helpful to take a certain amount of system utilization samples, one after another, with a defined time separation between samples.<\/p>\n<p>For example,<\/p>\n<pre># vmstat 5 10\r\n<\/pre>\n<p>will return 10 samples taken every 5 seconds:<\/p>\n<div id=\"attachment_15149\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Check-Linux-Systerm-Performance.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15149\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Check-Linux-Systerm-Performance-620x285.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Check-Linux-Systerm-Performance-620x285.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Check-Linux-Systerm-Performance.png 685w\" alt=\"Check Linux System Performance\" width=\"620\" height=\"285\" aria-describedby=\"caption-attachment-15149\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15149\" class=\"wp-caption-text\">Check Linux System Performance<\/p>\n<\/div>\n<p>As you can see in the above picture, the output of vmstat is divided by columns:\u00a0<strong>procs<\/strong>\u00a0(processes),\u00a0<strong>memory<\/strong>,\u00a0<strong>swap<\/strong>,\u00a0<strong>io<\/strong>,\u00a0<strong>system<\/strong>, and\u00a0<strong>cpu<\/strong>. The meaning of each field can be found in the\u00a0<strong>FIELD DESCRIPTION<\/strong>\u00a0sections in the man page of\u00a0<strong>vmstat<\/strong>.<\/p>\n<p>Where can\u00a0<strong>vmstat<\/strong>\u00a0come in handy? Let\u2019s examine the behavior of the system before and during a\u00a0<strong>yum update<\/strong>:<\/p>\n<pre># vmstat -a 1 5\r\n<\/pre>\n<div id=\"attachment_15150\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Vmstat-Linux-Peformance-Monitoring.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15150\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Vmstat-Linux-Peformance-Monitoring-620x253.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Vmstat-Linux-Peformance-Monitoring-620x253.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Vmstat-Linux-Peformance-Monitoring-1024x418.png 1024w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Vmstat-Linux-Peformance-Monitoring.png 1343w\" alt=\"Vmstat Linux Performance Monitoring\" width=\"620\" height=\"253\" aria-describedby=\"caption-attachment-15150\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15150\" class=\"wp-caption-text\">Vmstat Linux Performance Monitoring<\/p>\n<\/div>\n<p>Please note that as files are being modified on disk, the amount of\u00a0<strong>active<\/strong>\u00a0memory increases and so does the number of blocks written to disk\u00a0<strong>(bo)<\/strong>\u00a0and the CPU time that is dedicated to user processes\u00a0<strong>(us)<\/strong>.<\/p>\n<p>Or during the saving process of a large file directly to disk (caused by\u00a0<strong>dsync<\/strong>):<\/p>\n<pre># vmstat -a 1 5\r\n# dd if=\/dev\/zero of=dummy.out bs=1M count=1000 oflag=dsync\r\n<\/pre>\n<div id=\"attachment_15151\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/VmStat-Linux-Disk-Performance-Monitoring.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15151\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/VmStat-Linux-Disk-Performance-Monitoring-620x143.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/VmStat-Linux-Disk-Performance-Monitoring-620x143.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/VmStat-Linux-Disk-Performance-Monitoring-1024x236.png 1024w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/VmStat-Linux-Disk-Performance-Monitoring.png 1280w\" alt=\"VmStat Linux Disk Performance Monitoring\" width=\"620\" height=\"143\" aria-describedby=\"caption-attachment-15151\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15151\" class=\"wp-caption-text\">VmStat Linux Disk Performance Monitoring<\/p>\n<\/div>\n<p>In this case, we can see a yet larger number of blocks being written to disk\u00a0<strong>(bo)<\/strong>, which was to be expected, but also an increase of the amount of CPU time that it has to wait for I\/O operations to complete before processing tasks\u00a0<strong>(wa)<\/strong>.<\/p>\n<p><strong>Don\u2019t Miss<\/strong>:\u00a0<a href=\"https:\/\/www.tecmint.com\/linux-performance-monitoring-with-vmstat-and-iostat-commands\/\" target=\"_blank\" rel=\"noopener\">Vmstat \u2013 Linux Performance Monitoring<\/a><\/p>\n<h3>Other Linux Tools<\/h3>\n<p>As mentioned in the introduction of this chapter, there are other tools that you can use to check the system status and utilization (they are not only provided by\u00a0<strong>Red Hat<\/strong>\u00a0but also by other major distributions from their officially supported repositories).<\/p>\n<p>The\u00a0<strong>sysstat<\/strong>\u00a0package contains the following utilities:<\/p>\n<ol>\n<li><strong>sar<\/strong>\u00a0(collect, report, or save system activity information).<\/li>\n<li><strong>sadf<\/strong>\u00a0(display data collected by sar in multiple formats).<\/li>\n<li><strong>mpstat<\/strong>\u00a0(report processors related statistics).<\/li>\n<li><strong>iostat<\/strong>\u00a0(report CPU statistics and I\/O statistics for devices and partitions).<\/li>\n<li>pidstat (report statistics for Linux tasks).<\/li>\n<li><strong>nfsiostat<\/strong>\u00a0(report input\/output statistics for NFS).<\/li>\n<li><strong>cifsiostat<\/strong>\u00a0(report CIFS statistics) and<\/li>\n<li><strong>sa1<\/strong>\u00a0(collect and store binary data in the system activity daily data file.<\/li>\n<li><strong>sa2<\/strong>\u00a0(write a daily report in the\u00a0<strong>\/var\/log\/sa<\/strong>\u00a0directory) tools.<\/li>\n<\/ol>\n<p>whereas\u00a0<strong>dstat<\/strong>\u00a0adds some extra features to the functionality provided by those tools, along with more counters and flexibility. You can find an overall description of each tool by running\u00a0<strong>yum info sysstat<\/strong>\u00a0or\u00a0<strong>yum info dstat<\/strong>, respectively, or checking the individual man pages after installation.<\/p>\n<p>To install both packages:<\/p>\n<pre># yum update &amp;&amp; yum install sysstat dstat\r\n<\/pre>\n<p>The main configuration file for\u00a0<strong>sysstat<\/strong>\u00a0is\u00a0<strong>\/etc\/sysconfig\/sysstat<\/strong>. You will find the following parameters in that file:<\/p>\n<pre># How long to keep log files (in days).\r\n# If value is greater than 28, then log files are kept in\r\n# multiple directories, one for each month.\r\n<strong>HISTORY=28<\/strong>\r\n# Compress (using gzip or bzip2) sa and sar files older than (in days):\r\n<strong>COMPRESSAFTER=31<\/strong>\r\n# Parameters for the system activity data collector (see sadc manual page)\r\n# which are used for the generation of log files.\r\n<strong>SADC_OPTIONS=\"-S DISK\"<\/strong>\r\n# Compression program to use.\r\n<strong>ZIP=\"bzip2\"<\/strong>\r\n<\/pre>\n<p>When\u00a0<strong>sysstat<\/strong>\u00a0is installed, two cron jobs are added and enabled in\u00a0<strong>\/etc\/cron.d\/sysstat<\/strong>. The first job runs the system activity accounting tool every\u00a0<strong>10 minutes<\/strong>\u00a0and stores the reports in\u00a0<strong>\/var\/log\/sa\/saXX<\/strong>\u00a0where\u00a0<strong>XX<\/strong>\u00a0is the day of the month.<\/p>\n<p>Thus,\u00a0<strong>\/var\/log\/sa\/sa05<\/strong>\u00a0will contain all the system activity reports from the 5th of the month. This assumes that we are using the default value in the\u00a0<strong>HISTORY<\/strong>\u00a0variable in the configuration file above:<\/p>\n<pre>*\/10 * * * * root \/usr\/lib64\/sa\/sa1 1 1\r\n<\/pre>\n<p>The second job generates a daily summary of process accounting at\u00a0<strong>11:53<\/strong>\u00a0pm every day and stores it in\u00a0<strong>\/var\/log\/sa\/sarXX<\/strong>\u00a0files, where\u00a0<strong>XX<\/strong>\u00a0has the same meaning as in the previous example:<\/p>\n<pre>53 23 * * * root \/usr\/lib64\/sa\/sa2 -A\r\n<\/pre>\n<p>For example, you may want to output system statistics from\u00a0<strong>9:30 am<\/strong>\u00a0through\u00a0<strong>5:30 pm<\/strong>\u00a0of the sixth of the month to a\u00a0<strong>.csv<\/strong>\u00a0file that can easily be viewed using\u00a0<strong>LibreOffice Calc<\/strong>\u00a0or\u00a0<strong>Microsoft Excel<\/strong>\u00a0(this approach will also allow you to create charts or graphs):<\/p>\n<pre># sadf -s 09:30:00 -e 17:30:00 -dh \/var\/log\/sa\/sa06 -- | sed 's\/;\/,\/g' &gt; system_stats20150806.csv\r\n<\/pre>\n<p>You could alternatively use the\u00a0<strong>-j<\/strong>\u00a0flag instead of\u00a0<strong>-d<\/strong>\u00a0in the\u00a0<strong>sadf<\/strong>\u00a0command above to output the system stats in\u00a0<strong>JSON<\/strong>\u00a0format, which could be useful if you need to consume the data in a web application, for example.<\/p>\n<div id=\"attachment_15152\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Linux-System-Statistics.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15152\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Linux-System-Statistics-620x278.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Linux-System-Statistics-620x278.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Linux-System-Statistics-1024x460.png 1024w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Linux-System-Statistics.png 1339w\" alt=\"Linux System Statistics\" width=\"620\" height=\"278\" aria-describedby=\"caption-attachment-15152\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15152\" class=\"wp-caption-text\">Linux System Statistics<\/p>\n<\/div>\n<p>Finally, let\u2019s see what\u00a0<strong>dstat<\/strong>\u00a0has to offer. Please note that if run without arguments,\u00a0<strong>dstat<\/strong>\u00a0assumes\u00a0<strong>-cdngy<\/strong>\u00a0by default (short for CPU, disk, network, memory pages, and system stats, respectively), and adds one line every second (execution can be interrupted anytime with\u00a0<strong>Ctrl + C<\/strong>):<\/p>\n<pre># dstat\r\n<\/pre>\n<div id=\"attachment_15153\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/dstat-command.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-15153\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/dstat-command.png\" alt=\"Linux Disk Statistics Monitoring\" width=\"598\" height=\"231\" aria-describedby=\"caption-attachment-15153\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15153\" class=\"wp-caption-text\">Linux Disk Statistics Monitoring<\/p>\n<\/div>\n<p>To output the stats to a\u00a0<strong>.csv<\/strong>\u00a0file, use the\u00a0<strong>\u2013output<\/strong>\u00a0flag followed by a file name. Let\u2019s see how this looks on LibreOffice Calc:<\/p>\n<div id=\"attachment_15154\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Monitor-Linux-Statistics-Output.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15154\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Monitor-Linux-Statistics-Output-620x159.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Monitor-Linux-Statistics-Output-620x159.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Monitor-Linux-Statistics-Output-1024x263.png 1024w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Monitor-Linux-Statistics-Output.png 1335w\" alt=\"Monitor Linux Statistics Output\" width=\"620\" height=\"159\" aria-describedby=\"caption-attachment-15154\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15154\" class=\"wp-caption-text\">Monitor Linux Statistics Output<\/p>\n<\/div>\n<p>I strongly advise you to check out the man page of\u00a0<a href=\"https:\/\/www.tecmint.com\/wp-content\/pdf\/dstat.pdf\" target=\"_blank\" rel=\"noopener\">dstat<\/a>\u00a0along with the man page of\u00a0<a href=\"https:\/\/www.tecmint.com\/wp-content\/pdf\/sysstat.pdf\" target=\"_b\">sysstat<\/a>\u00a0in PDF format for your reading convenience. You will find several other options that will help you create custom and detailed system activity reports.<\/p>\n<p><strong>Don\u2019t Miss:<\/strong>\u00a0<a href=\"https:\/\/www.tecmint.com\/install-sysstat-in-linux\/\" target=\"_blank\" rel=\"noopener\">Sysstat \u2013 Linux Usage Activity Monitoring Tool<\/a><\/p>\n<h3>Summary<\/h3>\n<p>In this guide we have explained how to use both native Linux tools and specific utilities provided with\u00a0<strong>RHEL 7<\/strong>\u00a0in order to produce reports on system utilization. At one point or another, you will come to rely on these reports as best friends.<\/p>\n<p>You will probably have used other tools that we have not covered in this tutorial. If so, feel free to share them with the rest of the community along with any other suggestions \/ questions \/ comments that you may have- using the form below.<\/p>\n<p>We look forward to hearing from you.<\/p>\n<h1 class=\"post-title\">Using Shell Scripting to Automate Linux System Maintenance Tasks \u2013 Part 4<\/h1>\n<p>Some time ago I read that one of the distinguishing characteristics of an effective system administrator \/ engineer is laziness. It seemed a little contradictory at first but the author then proceeded to explain why:<\/p>\n<div id=\"attachment_15243\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Automate-Linux-System-Maintenance-Tasks.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15243\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Automate-Linux-System-Maintenance-Tasks-620x297.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Automate-Linux-System-Maintenance-Tasks-620x297.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Automate-Linux-System-Maintenance-Tasks.png 720w\" alt=\"Automate Linux System Maintenance Tasks\" width=\"620\" height=\"297\" aria-describedby=\"caption-attachment-15243\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15243\" class=\"wp-caption-text\">RHCE Series: Automate Linux System Maintenance Tasks \u2013 Part 4<\/p>\n<\/div>\n<p>if a sysadmin spends most of his time solving issues and doing repetitive tasks, you can suspect he or she is not doing things quite right. In other words, an effective system administrator \/ engineer should develop a plan to perform repetitive tasks with as less action on his \/ her part as possible, and should foresee problems by using,<\/p>\n<p>for example, the tools reviewed in Part 3 \u2013\u00a0<a href=\"https:\/\/www.tecmint.com\/linux-performance-monitoring-and-file-system-statistics-reports\/\" target=\"_blank\" rel=\"noopener\">Monitor System Activity Reports Using Linux Toolsets<\/a>\u00a0of this series. Thus, although he or she may not seem to be doing much, it\u2019s because most of his \/ her responsibilities have been taken care of with the help of shell scripting, which is what we\u2019re going to talk about in this tutorial.<\/p>\n<h3>What is a shell script?<\/h3>\n<p>In few words, a shell script is nothing more and nothing less than a program that is executed step by step by a shell, which is another program that provides an interface layer between the Linux kernel and the end user.<\/p>\n<p>By default, the shell used for user accounts in\u00a0<strong>RHEL 7<\/strong>\u00a0is bash (<strong>\/bin\/bash<\/strong>). If you want a detailed description and some historical background, you can refer to\u00a0<a href=\"https:\/\/en.wikipedia.org\/wiki\/Bash_%28Unix_shell%29\" target=\"_blank\" rel=\"noopener\">this Wikipedia article<\/a>.<\/p>\n<p>To find out more about the enormous set of features provided by this shell, you may want to check out its\u00a0<strong>man page<\/strong>, which is downloaded in in PDF format at (<a href=\"https:\/\/www.tecmint.com\/wp-content\/pdf\/bash.pdf\" target=\"_blank\" rel=\"noopener\">Bash Commands<\/a>). Other than that, it is assumed that you are familiar with Linux commands (if not, I strongly advise you to go through\u00a0<a href=\"https:\/\/www.tecmint.com\/60-commands-of-linux-a-guide-from-newbies-to-system-administrator\/\" target=\"_blank\" rel=\"noopener\">A Guide from Newbies to SysAdmin<\/a>article in\u00a0<strong>Tecmint.com<\/strong>\u00a0before proceeding). Now let\u2019s get started.<\/p>\n<h3>Writing a script to display system information<\/h3>\n<p>For our convenience, let\u2019s create a directory to store our shell scripts:<\/p>\n<pre># mkdir scripts\r\n# cd scripts\r\n<\/pre>\n<p>And open a new text file named\u00a0<code>system_info.sh<\/code>\u00a0with your preferred text editor. We will begin by inserting a few comments at the top and some commands afterwards:<\/p>\n<pre>#!\/bin\/bash\r\n\r\n# Sample script written for Part 4 of the RHCE series\r\n# This script will return the following set of system information:\r\n# -Hostname information:\r\necho -e \"\\e[31;43m***** <strong>HOSTNAME INFORMATION<\/strong> *****\\e[0m\"\r\nhostnamectl\r\necho \"\"\r\n# -File system disk space usage:\r\necho -e \"\\e[31;43m***** <strong>FILE SYSTEM DISK SPACE USAGE<\/strong> *****\\e[0m\"\r\ndf -h\r\necho \"\"\r\n# -Free and used memory in the system:\r\necho -e \"\\e[31;43m ***** <strong>FREE AND USED MEMORY<\/strong> *****\\e[0m\"\r\nfree\r\necho \"\"\r\n# -System uptime and load:\r\necho -e \"\\e[31;43m***** <strong>SYSTEM UPTIME AND LOAD<\/strong> *****\\e[0m\"\r\nuptime\r\necho \"\"\r\n# -Logged-in users:\r\necho -e \"\\e[31;43m***** <strong>CURRENTLY LOGGED-IN USERS<\/strong> *****\\e[0m\"\r\nwho\r\necho \"\"\r\n# -Top 5 processes as far as memory usage is concerned\r\necho -e \"\\e[31;43m***** <strong>TOP 5 MEMORY-CONSUMING PROCESSES<\/strong> *****\\e[0m\"\r\nps -eo %mem,%cpu,comm --sort=-%mem | head -n 6\r\necho \"\"\r\necho -e \"\\e[1;32mDone.\\e[0m\"\r\n<\/pre>\n<p>Next, give the script execute permissions:<\/p>\n<pre># chmod +x system_info.sh\r\n<\/pre>\n<p>and run it:<\/p>\n<pre>.\/system_info.sh\r\n<\/pre>\n<p>Note that the headers of each section are shown in color for better visualization:<\/p>\n<div id=\"attachment_15238\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Server-Monitoring-Shell-Script.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15238\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Server-Monitoring-Shell-Script-556x450.png\" sizes=\"auto, (max-width: 556px) 100vw, 556px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Server-Monitoring-Shell-Script-556x450.png 556w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Server-Monitoring-Shell-Script.png 646w\" alt=\"Server Monitoring Shell Script\" width=\"556\" height=\"450\" aria-describedby=\"caption-attachment-15238\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15238\" class=\"wp-caption-text\">Server Monitoring Shell Script<\/p>\n<\/div>\n<p>That functionality is provided by this command:<\/p>\n<pre>echo -e \"\\e[<strong>COLOR1;COLOR2m&lt;YOUR TEXT HERE&gt;<\/strong>\\e[0m\"\r\n<\/pre>\n<p>Where\u00a0<strong>COLOR1<\/strong>\u00a0and\u00a0<strong>COLOR2<\/strong>\u00a0are the foreground and background colors, respectively (more info and options are explained in this entry from the\u00a0<a href=\"https:\/\/wiki.archlinux.org\/index.php\/Color_Bash_Prompt\" target=\"_blank\" rel=\"noopener\">Arch Linux Wiki<\/a>) and\u00a0<strong>&lt;YOUR TEXT HERE&gt;<\/strong>\u00a0is the string that you want to show in color.<\/p>\n<h3>Automating Tasks<\/h3>\n<p>The tasks that you may need to automate may vary from case to case. Thus, we cannot possibly cover all of the possible scenarios in a single article, but we will present three classic tasks that can be automated using shell scripting:<\/p>\n<p><strong>1)<\/strong>\u00a0update the local file database, 2) find (and alternatively delete) files with\u00a0<strong>777<\/strong>\u00a0permissions, and\u00a0<strong>3)<\/strong>\u00a0alert when filesystem usage surpasses a defined limit.<\/p>\n<p>Let\u2019s create a file named\u00a0<code>auto_tasks.sh<\/code>\u00a0in our scripts directory with the following content:<\/p>\n<pre>#!\/bin\/bash\r\n\r\n# Sample script to automate tasks:\r\n# -Update local file database:\r\necho -e \"\\e[4;32m<strong>UPDATING LOCAL FILE DATABASE<\/strong>\\e[0m\"\r\nupdatedb\r\nif [ $? == 0 ]; then\r\n        echo \"The local file database was updated correctly.\"\r\nelse\r\n        echo \"The local file database was not updated correctly.\"\r\nfi\r\necho \"\"\r\n\r\n# -Find and \/ or delete files with 777 permissions.\r\necho -e \"\\e[4;32m<strong>LOOKING FOR FILES WITH 777 PERMISSIONS<\/strong>\\e[0m\"\r\n# Enable either option (comment out the other line), but not both.\r\n# Option 1: Delete files without prompting for confirmation. Assumes GNU version of find.\r\n#find -type f -perm 0777 -delete\r\n# Option 2: Ask for confirmation before deleting files. More portable across systems.\r\nfind -type f -perm 0777 -exec rm -i {} +;\r\necho \"\"\r\n# -Alert when file system usage surpasses a defined limit \r\necho -e \"\\e[4;32m<strong>CHECKING FILE SYSTEM USAGE<\/strong>\\e[0m\"\r\nTHRESHOLD=30\r\nwhile read line; do\r\n        # This variable stores the file system path as a string\r\n        FILESYSTEM=$(echo $line | awk '{print $1}')\r\n        # This variable stores the use percentage (XX%)\r\n        PERCENTAGE=$(echo $line | awk '{print $5}')\r\n        # Use percentage without the % sign.\r\n        USAGE=${PERCENTAGE%?}\r\n        if [ $USAGE -gt $THRESHOLD ]; then\r\n                echo \"The remaining available space in $FILESYSTEM is critically low. Used: $PERCENTAGE\"\r\n        fi\r\ndone &lt; &lt;(df -h --total | grep -vi filesystem)\r\n<\/pre>\n<p>Please note that there is a space between the two\u00a0<code>&lt;<\/code>\u00a0signs in the last line of the script.<\/p>\n<div id=\"attachment_15239\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Shell-Script-to-Find-777-Permissions.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15239\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Shell-Script-to-Find-777-Permissions-620x198.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Shell-Script-to-Find-777-Permissions-620x198.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Shell-Script-to-Find-777-Permissions.png 674w\" alt=\"Shell Script to Find 777 Permissions\" width=\"620\" height=\"198\" aria-describedby=\"caption-attachment-15239\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15239\" class=\"wp-caption-text\">Shell Script to Find 777 Permissions<\/p>\n<\/div>\n<h3>Using Cron<\/h3>\n<p>To take efficiency one step further, you will not want to sit in front of your computer and run those scripts manually. Rather, you will use\u00a0<strong>cron<\/strong>\u00a0to schedule those tasks to run on a periodic basis and sends the results to a predefined list of recipients via email or save them to a file that can be viewed using a web browser.<\/p>\n<p>The following script (filesystem_usage.sh) will run the well-known\u00a0<strong>df -h<\/strong>\u00a0command, format the output into a HTML table and save it in the\u00a0<strong>report.html<\/strong>\u00a0file:<\/p>\n<pre>#!\/bin\/bash\r\n# Sample script to demonstrate the creation of an HTML report using shell scripting\r\n# Web directory\r\nWEB_DIR=\/var\/www\/html\r\n# A little CSS and table layout to make the report look a little nicer\r\necho \"&lt;HTML&gt;\r\n&lt;HEAD&gt;\r\n&lt;style&gt;\r\n.titulo{font-size: 1em; color: white; background:#0863CE; padding: 0.1em 0.2em;}\r\ntable\r\n{\r\nborder-collapse:collapse;\r\n}\r\ntable, td, th\r\n{\r\nborder:1px solid black;\r\n}\r\n&lt;\/style&gt;\r\n&lt;meta http-equiv='Content-Type' content='text\/html; charset=UTF-8' \/&gt;\r\n&lt;\/HEAD&gt;\r\n&lt;BODY&gt;\" &gt; $WEB_DIR\/report.html\r\n# View hostname and insert it at the top of the html body\r\nHOST=$(hostname)\r\necho \"Filesystem usage for host &lt;strong&gt;$HOST&lt;\/strong&gt;&lt;br&gt;\r\nLast updated: &lt;strong&gt;$(date)&lt;\/strong&gt;&lt;br&gt;&lt;br&gt;\r\n&lt;table border='1'&gt;\r\n&lt;tr&gt;&lt;th class='titulo'&gt;Filesystem&lt;\/td&gt;\r\n&lt;th class='titulo'&gt;Size&lt;\/td&gt;\r\n&lt;th class='titulo'&gt;Use %&lt;\/td&gt;\r\n&lt;\/tr&gt;\" &gt;&gt; $WEB_DIR\/report.html\r\n# Read the output of df -h line by line\r\nwhile read line; do\r\necho \"&lt;tr&gt;&lt;td align='center'&gt;\" &gt;&gt; $WEB_DIR\/report.html\r\necho $line | awk '{print $1}' &gt;&gt; $WEB_DIR\/report.html\r\necho \"&lt;\/td&gt;&lt;td align='center'&gt;\" &gt;&gt; $WEB_DIR\/report.html\r\necho $line | awk '{print $2}' &gt;&gt; $WEB_DIR\/report.html\r\necho \"&lt;\/td&gt;&lt;td align='center'&gt;\" &gt;&gt; $WEB_DIR\/report.html\r\necho $line | awk '{print $5}' &gt;&gt; $WEB_DIR\/report.html\r\necho \"&lt;\/td&gt;&lt;\/tr&gt;\" &gt;&gt; $WEB_DIR\/report.html\r\ndone &lt; &lt;(df -h | grep -vi filesystem)\r\necho \"&lt;\/table&gt;&lt;\/BODY&gt;&lt;\/HTML&gt;\" &gt;&gt; $WEB_DIR\/report.html\r\n<\/pre>\n<p>In our\u00a0<strong>RHEL 7<\/strong>\u00a0server (<strong>192.168.0.18<\/strong>), this looks as follows:<\/p>\n<div id=\"attachment_15241\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Server-Monitoring-Report.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-15241\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Server-Monitoring-Report.png\" alt=\"Server Monitoring Report\" width=\"397\" height=\"285\" aria-describedby=\"caption-attachment-15241\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15241\" class=\"wp-caption-text\">Server Monitoring Report<\/p>\n<\/div>\n<p>You can add to that report as much information as you want. To run the script every day at\u00a0<strong>1:30 pm<\/strong>, add the following crontab entry:<\/p>\n<pre>30 13 * * * \/root\/scripts\/filesystem_usage.sh\r\n<\/pre>\n<h3>Summary<\/h3>\n<p>You will most likely think of several other tasks that you want or need to automate; as you can see, using shell scripting will greatly simplify this effort. Feel free to let us know if you find this article helpful and don&#8217;t hesitate to add your own ideas or comments via the form below.<\/p>\n<h1 class=\"post-title\">How to Manage System Logs (Configure, Rotate and Import Into Database) in RHEL 7 \u2013 Part 5<\/h1>\n<p>In order to keep your\u00a0<strong>RHEL 7<\/strong>\u00a0systems secure, you need to know how to monitor all of the activities that take place on such systems by examining log files. Thus, you will be able to detect any unusual or potentially malicious activity and perform system troubleshooting or take another appropriate action.<\/p>\n<div id=\"attachment_15437\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Manage-and-Rotate-Linux-Logs-Using-Rsyslog-Logrotate.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15437\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Manage-and-Rotate-Linux-Logs-Using-Rsyslog-Logrotate-620x297.jpg\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Manage-and-Rotate-Linux-Logs-Using-Rsyslog-Logrotate-620x297.jpg 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Manage-and-Rotate-Linux-Logs-Using-Rsyslog-Logrotate.jpg 720w\" alt=\"Linux Rotate Log Files Using Rsyslog and Logrotate\" width=\"620\" height=\"297\" aria-describedby=\"caption-attachment-15437\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15437\" class=\"wp-caption-text\">RHCE Exam: Manage System LogsUsing Rsyslogd and Logrotate \u2013 Part 5<\/p>\n<\/div>\n<p>In\u00a0<strong>RHEL 7<\/strong>, the\u00a0<a href=\"https:\/\/www.tecmint.com\/wp-content\/pdf\/rsyslogd.pdf\" target=\"_blank\" rel=\"noopener\">rsyslogd<\/a>\u00a0daemon is responsible for system logging and reads its configuration from\u00a0<strong>\/etc\/rsyslog.conf<\/strong>\u00a0(this file specifies the default location for all system logs) and from files inside\u00a0<strong>\/etc\/rsyslog.d<\/strong>, if any.<\/p>\n<h3>Rsyslogd Configuration<\/h3>\n<p>A quick inspection of the\u00a0<a href=\"https:\/\/www.tecmint.com\/wp-content\/pdf\/rsyslog.conf.pdf\" target=\"_blank\" rel=\"noopener\">rsyslog.conf<\/a>\u00a0will be helpful to start. This file is divided into 3 main sections:\u00a0<strong>Modules<\/strong>(since rsyslog follows a modular design),\u00a0<strong>Global<\/strong>\u00a0directives (used to set global properties of the rsyslogd daemon), and\u00a0<strong>Rules<\/strong>. As you will probably guess, this last section indicates what gets logged or shown (also known as the selector) and where, and will be our focus throughout this article.<\/p>\n<p>A typical line in\u00a0<strong>rsyslog.conf<\/strong>\u00a0is as follows:<\/p>\n<div id=\"attachment_15424\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Rsyslogd-Configuration.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15424\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Rsyslogd-Configuration-620x131.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Rsyslogd-Configuration-620x131.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Rsyslogd-Configuration.png 623w\" alt=\"Rsyslogd Configuration\" width=\"620\" height=\"131\" aria-describedby=\"caption-attachment-15424\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15424\" class=\"wp-caption-text\">Rsyslogd Configuration<\/p>\n<\/div>\n<p>In the image above, we can see that a selector consists of one or more pairs\u00a0<strong>Facility:Priority<\/strong>\u00a0separated by semicolons, where Facility describes the type of message (refer to\u00a0<a href=\"https:\/\/tools.ietf.org\/html\/rfc3164#section-4.1.1\" target=\"_blank\" rel=\"nofollow noopener\">section 4.1.1 in RFC 3164<\/a>\u00a0to see the complete list of facilities available for rsyslog) and Priority indicates its severity, which can be one of the following self-explanatory words:<\/p>\n<ol>\n<li>debug<\/li>\n<li>info<\/li>\n<li>notice<\/li>\n<li>warning<\/li>\n<li>err<\/li>\n<li>crit<\/li>\n<li>alert<\/li>\n<li>emerg<\/li>\n<\/ol>\n<p>Though not a priority itself, the keyword\u00a0<strong>none<\/strong>\u00a0means no priority at all of the given facility.<\/p>\n<p><strong>Note<\/strong>: That a given priority indicates that all messages of such priority and above should be logged. Thus, the line in the example above instructs the\u00a0<strong>rsyslogd<\/strong>\u00a0daemon to log all messages of priority info or higher (regardless of the facility) except those belonging to\u00a0<strong>mail<\/strong>,\u00a0<strong>authpriv<\/strong>, and\u00a0<strong>cron<\/strong>\u00a0services (no messages coming from this facilities will be taken into account) to\u00a0<strong>\/var\/log\/messages<\/strong>.<\/p>\n<p>You can also group multiple facilities using the colon sign to apply the same priority to all of them. Thus, the line:<\/p>\n<pre>*.info;mail.none;authpriv.none;cron.none                \/var\/log\/messages\r\n<\/pre>\n<p>Could be rewritten as<\/p>\n<pre>*.info;mail,authpriv,cron.none                \/var\/log\/messages\r\n<\/pre>\n<p>In other words, the facilities\u00a0<strong>mail<\/strong>,\u00a0<strong>authpriv<\/strong>, and\u00a0<strong>cron<\/strong>\u00a0are grouped and the keyword\u00a0<strong>none<\/strong>\u00a0is applied to the three of them.<\/p>\n<h4>Creating a custom log file<\/h4>\n<p>To log all daemon messages to\u00a0<strong>\/var\/log\/tecmint.log<\/strong>, we need to add the following line either in\u00a0<strong>rsyslog.conf<\/strong>\u00a0or in a separate file (easier to manage) inside\u00a0<strong>\/etc\/rsyslog.d<\/strong>:<\/p>\n<pre>daemon.*    \/var\/log\/tecmint.log\r\n<\/pre>\n<p>Let\u2019s restart the daemon (note that the service name does not end with a\u00a0<strong>d<\/strong>):<\/p>\n<pre># systemctl restart rsyslog\r\n<\/pre>\n<p>And check the contents of our custom log before and after restarting two random daemons:<\/p>\n<div id=\"attachment_15425\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Create-Custom-Log-File.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15425\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Create-Custom-Log-File-620x232.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Create-Custom-Log-File-620x232.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Create-Custom-Log-File.png 687w\" alt=\"Linux Create Custom Log File\" width=\"620\" height=\"232\" aria-describedby=\"caption-attachment-15425\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15425\" class=\"wp-caption-text\">Create Custom Log File<\/p>\n<\/div>\n<p>As a self-study exercise, I would recommend you play around with the facilities and priorities and either log additional messages to existing log files or create new ones as in the previous example.<\/p>\n<h3>Rotating Logs using Logrotate<\/h3>\n<p>To prevent log files from growing endlessly, the\u00a0<strong>logrotate<\/strong>\u00a0utility is used to rotate, compress, remove, and alternatively mail logs, thus easing the administration of systems that generate large numbers of log files.<\/p>\n<p><b>Suggested Read:<\/b>\u00a0<a href=\"https:\/\/www.tecmint.com\/install-logrotate-to-manage-log-rotation-in-linux\/\" target=\"_blank\" rel=\"noopener\">How to Setup and Manage Log Rotation Using Logrotate in Linux<\/a><\/p>\n<p><strong>Logrotate<\/strong>\u00a0runs daily as a\u00a0<strong>cron<\/strong>\u00a0job (<strong>\/etc\/cron.daily\/logrotate<\/strong>) and reads its configuration from\u00a0<strong>\/etc\/logrotate.conf<\/strong>\u00a0and from files located in\u00a0<strong>\/etc\/logrotate.d<\/strong>, if any.<\/p>\n<p>As with the case of\u00a0<strong>rsyslog<\/strong>, even when you can include settings for specific services in the main file, creating separate configuration files for each one will help organize your settings better.<\/p>\n<p>Let\u2019s take a look at a typical\u00a0<strong>logrotate.conf<\/strong>:<\/p>\n<div id=\"attachment_15427\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Logrotate-Configuration.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-15427\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Logrotate-Configuration.png\" alt=\"Logrotate Configuration\" width=\"486\" height=\"413\" aria-describedby=\"caption-attachment-15427\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15427\" class=\"wp-caption-text\">Logrotate Configuration<\/p>\n<\/div>\n<p>In the example above,\u00a0<strong>logrotate<\/strong>\u00a0will perform the following actions for\u00a0<strong>\/var\/loh\/wtmp:<\/strong>\u00a0attempt to rotate only once a month, but only if the file is at least\u00a0<strong>1 MB<\/strong>\u00a0in size, then create a brand new log file with permissions set to\u00a0<strong>0664<\/strong>\u00a0and ownership given to user root and group\u00a0<strong>utmp<\/strong>. Next, only keep one archived log, as specified by the rotate directive:<\/p>\n<div id=\"attachment_15428\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Logrotate-Logs-Monthly.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-15428\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Logrotate-Logs-Monthly.png\" alt=\"Logrotate Logs Monthly\" width=\"400\" height=\"156\" aria-describedby=\"caption-attachment-15428\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15428\" class=\"wp-caption-text\">Logrotate Logs Monthly<\/p>\n<\/div>\n<p>Let\u2019s now consider another example as found in\u00a0<strong>\/etc\/logrotate.d\/httpd<\/strong>:<\/p>\n<div id=\"attachment_15429\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Rotate-Apache-Log-Files.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15429\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Rotate-Apache-Log-Files-620x154.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Rotate-Apache-Log-Files-620x154.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Rotate-Apache-Log-Files.png 738w\" alt=\"Rotate Apache Log Files\" width=\"620\" height=\"154\" aria-describedby=\"caption-attachment-15429\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15429\" class=\"wp-caption-text\">Rotate Apache Log Files<\/p>\n<\/div>\n<p>You can read more about the settings for\u00a0<strong>logrotate<\/strong>\u00a0in its man pages (<a href=\"https:\/\/www.tecmint.com\/wp-content\/pdf\/logrotate.pdf\" target=\"_blank\" rel=\"noopener\">man logrotate<\/a>\u00a0and\u00a0<a href=\"https:\/\/www.tecmint.com\/wp-content\/pdf\/logrotate.conf.pdf\" target=\"_blank\" rel=\"noopener\">man logrotate.conf<\/a>). Both files are provided along with this article in PDF format for your reading convenience.<\/p>\n<p>As a system engineer, it will be pretty much up to you to decide for how long logs will be stored and in what format, depending on whether you have\u00a0<strong>\/var<\/strong>\u00a0in a separate partition\u00a0<strong>\/<\/strong>\u00a0logical volume. Otherwise, you really want to consider removing old logs to save storage space. On the other hand, you may be forced to keep several logs for future security auditing according to your company\u2019s or client\u2019s internal policies.<\/p>\n<h4>Saving Logs to a Database<\/h4>\n<p>Of course examining logs (even with the help of tools such as\u00a0<strong>grep<\/strong>\u00a0and regular expressions) can become a rather tedious task. For that reason,\u00a0<strong>rsyslog<\/strong>\u00a0allows us to export them into a database (<strong>OTB<\/strong>\u00a0supported RDBMS include MySQL, MariaDB, PostgreSQL, and Oracle.<\/p>\n<p>This section of the tutorial assumes that you have already installed the\u00a0<strong>MariaDB<\/strong>\u00a0server and client in the same RHEL 7 box where the logs are being managed:<\/p>\n<pre># yum update &amp;&amp; yum install mariadb mariadb-server mariadb-client rsyslog-mysql\r\n# systemctl enable mariadb &amp;&amp; systemctl start mariadb\r\n<\/pre>\n<p>Then use the\u00a0<code>mysql_secure_installation<\/code>\u00a0utility to set the password for the root user and other security considerations:<\/p>\n<div id=\"attachment_15430\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Secure-MySQL-Database.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-15430\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Secure-MySQL-Database.png\" alt=\"Secure MySQL Database\" width=\"603\" height=\"236\" aria-describedby=\"caption-attachment-15430\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15430\" class=\"wp-caption-text\">Secure MySQL Database<\/p>\n<\/div>\n<p><strong>Note<\/strong>: If you don\u2019t want to use the\u00a0<strong>MariaDB<\/strong>\u00a0root user to insert log messages to the database, you can configure another user account to do so. Explaining how to do that is out of the scope of this tutorial but is explained in detail in\u00a0<a href=\"https:\/\/mariadb.com\/kb\/en\/mariadb\/create-user\/\" target=\"_blank\" rel=\"noopener\">MariaDB knowledge<\/a>\u00a0base. In this tutorial we will use the root account for simplicity.<\/p>\n<p>Next, download the\u00a0<strong>createDB.sql<\/strong>\u00a0script from\u00a0<a href=\"https:\/\/github.com\/sematext\/rsyslog\/blob\/master\/plugins\/ommysql\/createDB.sql\" target=\"_blank\" rel=\"nofollow noopener\">GitHub<\/a>\u00a0and import it into your database server:<\/p>\n<pre># mysql -u root -p &lt; createDB.sql\r\n<\/pre>\n<div id=\"attachment_15431\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Save-Server-Logs-to-Database.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15431\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Save-Server-Logs-to-Database-599x450.png\" sizes=\"auto, (max-width: 599px) 100vw, 599px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Save-Server-Logs-to-Database-599x450.png 599w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Save-Server-Logs-to-Database.png 607w\" alt=\"Save Server Logs to Database\" width=\"599\" height=\"450\" aria-describedby=\"caption-attachment-15431\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15431\" class=\"wp-caption-text\">Save Server Logs to Database<\/p>\n<\/div>\n<p>Finally, add the following lines to\u00a0<strong>\/etc\/rsyslog.conf<\/strong>:<\/p>\n<pre>$ModLoad ommysql\r\n$ActionOmmysqlServerPort 3306\r\n*.* :ommysql:localhost,Syslog,root,<strong>YourPasswordHere<\/strong>\r\n<\/pre>\n<p>Restart\u00a0<strong>rsyslog<\/strong>\u00a0and the database server:<\/p>\n<pre># systemctl restart rsyslog \r\n# systemctl restart mariadb\r\n<\/pre>\n<h4>Querying the Logs using SQL syntax<\/h4>\n<p>Now perform some tasks that will modify the logs (like stopping and starting services, for example), then log to your DB server and use standard SQL commands to display and search in the logs:<\/p>\n<pre>USE Syslog;\r\nSELECT ReceivedAt, Message FROM SystemEvents;\r\n<\/pre>\n<div id=\"attachment_15432\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Query-Logs-in-Database.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-15432\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/08\/Query-Logs-in-Database.png\" alt=\"Query Logs in Database\" width=\"608\" height=\"231\" aria-describedby=\"caption-attachment-15432\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15432\" class=\"wp-caption-text\">Query Logs in Database<\/p>\n<\/div>\n<h3>Summary<\/h3>\n<p>In this article we have explained how to set up system logging, how to rotate logs, and how to redirect the messages to a database for easier search. We hope that these skills will be helpful as you prepare for the\u00a0<a href=\"https:\/\/www.tecmint.com\/how-to-setup-and-configure-static-network-routing-in-rhel\/\" target=\"_blank\" rel=\"noopener\">RHCE exam<\/a>\u00a0and in your daily responsibilities as well.<\/p>\n<p>As always, your feedback is more than welcome. Feel free to use the form below to reach us.<\/p>\n<h1 class=\"post-title\">Setting Up Samba and Configure FirewallD and SELinux to Allow File Sharing on Linux\/Windows Clients \u2013 Part 6<\/h1>\n<p>Since computers seldom work as isolated systems, it is to be expected that as a system administrator or engineer, you know how to set up and maintain a network with multiple types of servers.<\/p>\n<p>In this article and in the next of this series we will go through the essentials of setting up\u00a0<strong>Samba<\/strong>\u00a0and\u00a0<strong>NFS<\/strong>servers with Windows\/Linux and Linux clients, respectively.<\/p>\n<div id=\"attachment_15516\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/setup-samba-file-sharing-on-linux-windows-clients.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15516\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/setup-samba-file-sharing-on-linux-windows-clients-620x297.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/setup-samba-file-sharing-on-linux-windows-clients-620x297.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/setup-samba-file-sharing-on-linux-windows-clients.png 720w\" alt=\"Setup Samba File Sharing on Linux\" width=\"620\" height=\"297\" aria-describedby=\"caption-attachment-15516\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15516\" class=\"wp-caption-text\">RHCE: Setup Samba File Sharing \u2013 Part 6<\/p>\n<\/div>\n<p>This article will definitely come in handy if you\u2019re called upon to set up file servers in corporate or enterprise environments where you are likely to find different operating systems and types of devices.<\/p>\n<p>Since you can read about the background and the technical aspects of both Samba and NFS all over the Internet, in this article and the next we will cut right to the chase with the topic at hand.<\/p>\n<h3>Step 1: Installing Samba Server<\/h3>\n<p>Our current testing environment consists of two\u00a0<strong>RHEL 7 boxes<\/strong>\u00a0and one\u00a0<strong>Windows 8<\/strong>\u00a0machine, in that order:<\/p>\n<pre>1. <strong>Samba \/ NFS server<\/strong> <strong>[box1 (RHEL 7): 192.168.0.18]<\/strong>, \r\n2. <strong>Samba client #1<\/strong> <strong>[box2 (RHEL 7): 192.168.0.20]<\/strong>\r\n3. <strong>Samba client #2<\/strong> <strong>[Windows 8 machine: 192.168.0.106]<\/strong>\r\n<\/pre>\n<div id=\"attachment_15503\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Testing-Setup-for-Samba.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15503\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Testing-Setup-for-Samba-620x48.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Testing-Setup-for-Samba-620x48.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Testing-Setup-for-Samba-1024x79.png 1024w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Testing-Setup-for-Samba.png 1138w\" alt=\"Testing Setup for Samba\" width=\"620\" height=\"48\" aria-describedby=\"caption-attachment-15503\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15503\" class=\"wp-caption-text\">Testing Setup for Samba<\/p>\n<\/div>\n<p>On\u00a0<strong>box1<\/strong>, install the following packages:<\/p>\n<pre># yum update &amp;&amp; yum install samba samba-client samba-common\r\n<\/pre>\n<p>On\u00a0<strong>box2<\/strong>:<\/p>\n<pre># yum update &amp;&amp; yum install samba samba-client samba-common cifs-utils\r\n<\/pre>\n<p>Once the installation is complete, we\u2019re ready to configure our share.<\/p>\n<h3>Step 2: Setting Up File Sharing Through Samba<\/h3>\n<p>One of the reason why\u00a0<strong>Samba<\/strong>\u00a0is so relevant is because it provides file and print services to\u00a0<strong>SMB\/CIFS<\/strong>\u00a0clients, which causes those clients to see the server as if it was a Windows system (I must admit I tend to get a little emotional while writing about this topic as it was my first setup as a new Linux system administrator some years ago).<\/p>\n<h6>Adding system users and setting up permissions and ownership<\/h6>\n<p>To allow for group collaboration, we will create a group named\u00a0<strong>finance<\/strong>\u00a0with two users (<strong>user1<\/strong>\u00a0and\u00a0<strong>user2<\/strong>) with\u00a0<a href=\"https:\/\/www.tecmint.com\/add-users-in-linux\/\" target=\"_blank\" rel=\"noopener\">useradd command<\/a>\u00a0and a directory\u00a0<strong>\/finance<\/strong>\u00a0in\u00a0<strong>box1<\/strong>.<\/p>\n<p>We will also change the group owner of this directory to\u00a0<strong>finance<\/strong>\u00a0and set its permissions to\u00a0<strong>0770<\/strong>\u00a0(read, write, and execution permissions for the owner and the group owner):<\/p>\n<pre># groupadd finance\r\n# useradd user1\r\n# useradd user2\r\n# usermod -a -G finance user1\r\n# usermod -a -G finance user2\r\n# mkdir \/finance\r\n# chmod 0770 \/finance\r\n# chgrp finance \/finance\r\n<\/pre>\n<h3>Step 3:\u200b Configuring SELinux and Firewalld<\/h3>\n<p>In preparation to configure\u00a0<strong>\/finance<\/strong>\u00a0as a Samba share, we will need to either disable\u00a0<strong>SELinux<\/strong>\u00a0or set the proper\u00a0<strong>boolean<\/strong>\u00a0and security context values as follows (otherwise, SELinux will prevent clients from accessing the share):<\/p>\n<pre># setsebool -P samba_export_all_ro=1 samba_export_all_rw=1\r\n# getsebool \u2013a | grep samba_export\r\n# semanage fcontext \u2013at samba_share_t \"\/finance(\/.*)?\"\r\n# restorecon \/finance\r\n<\/pre>\n<p>In addition, we must ensure that Samba traffic is allowed by the\u00a0<a href=\"https:\/\/www.tecmint.com\/firewalld-vs-iptables-and-control-network-traffic-in-firewall\/\" target=\"_blank\" rel=\"noopener\">firewalld<\/a>.<\/p>\n<pre># firewall-cmd --permanent --add-service=samba\r\n# firewall-cmd --reload\r\n<\/pre>\n<h3>Step 4: Configure Samba Share<\/h3>\n<p>Now it\u2019s time to dive into the configuration file\u00a0<strong>\/etc\/samba\/smb.conf<\/strong>\u00a0and add the section for our share: we want the members of the\u00a0<strong>finance<\/strong>\u00a0group to be able to browse the contents of\u00a0<strong>\/finance<\/strong>, and save\u00a0<strong>\/<\/strong>\u00a0create files or subdirectories in it (which by default will have their permission bits set to\u00a0<strong>0770<\/strong>\u00a0and\u00a0<strong>finance<\/strong>\u00a0will be their group owner):<\/p>\n<div class=\"code-label\" title=\"smb.conf\">smb.conf<\/div>\n<pre>[finance]\r\ncomment=Directory for collaboration of the company's finance team\r\nbrowsable=yes\r\npath=\/finance\r\npublic=no\r\nvalid users=@finance\r\nwrite list=@finance\r\nwriteable=yes\r\ncreate mask=0770\r\nForce create mode=0770\r\nforce group=finance\r\n<\/pre>\n<p>Save the file and then test it with the\u00a0<strong>testparm<\/strong>\u00a0utility. If there are any errors, the output of the following command will indicate what you need to fix. Otherwise, it will display a review of your Samba server configuration:<\/p>\n<div id=\"attachment_15507\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Test-Samba-Configuration.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-15507\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Test-Samba-Configuration.png\" alt=\"Test Samba Configuration\" width=\"602\" height=\"163\" aria-describedby=\"caption-attachment-15507\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15507\" class=\"wp-caption-text\">Test Samba Configuration<\/p>\n<\/div>\n<p>Should you want to add another share that is open to the public (meaning without any authentication whatsoever), create another section in\u00a0<strong>\/etc\/samba\/smb.conf<\/strong>\u00a0and under the new share\u2019s name copy the section above, only changing\u00a0<strong>public=no<\/strong>\u00a0to\u00a0<strong>public=yes<\/strong>\u00a0and not including the valid users and write list directives.<\/p>\n<h3>Step 5: Adding Samba Users<\/h3>\n<p>Next, you will need to add\u00a0<strong>user1<\/strong>\u00a0and\u00a0<strong>user2<\/strong>\u00a0as Samba users. To do so, you will use the\u00a0<strong>smbpasswd<\/strong>\u00a0command, which interacts with Samba\u2019s internal database. You will be prompted to enter a password that you will later use to connect to the share:<\/p>\n<pre># smbpasswd -a user1\r\n# smbpasswd -a user2\r\n<\/pre>\n<p>Finally, restart\u00a0<strong>Samba<\/strong>, enable the service to start on boot, and make sure the share is actually available to network clients:<\/p>\n<pre># systemctl start smb\r\n# systemctl enable smb\r\n# smbclient -L localhost \u2013U user1\r\n# smbclient -L localhost \u2013U user2\r\n<\/pre>\n<div id=\"attachment_15508\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Verify-Samba-Share.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15508\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Verify-Samba-Share-587x450.png\" sizes=\"auto, (max-width: 587px) 100vw, 587px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Verify-Samba-Share-587x450.png 587w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Verify-Samba-Share.png 745w\" alt=\"Verify Samba Share\" width=\"587\" height=\"450\" aria-describedby=\"caption-attachment-15508\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15508\" class=\"wp-caption-text\">Verify Samba Share<\/p>\n<\/div>\n<p>At this point, the Samba file server has been properly installed and configured. Now it\u2019s time to test this setup on our\u00a0<strong>RHEL 7<\/strong>\u00a0and\u00a0<strong>Windows 8<\/strong>\u00a0clients.<\/p>\n<h3>Step 6:\u200b Mounting the Samba Share in Linux<\/h3>\n<p>First, make sure the Samba share is accessible from this client:<\/p>\n<pre># smbclient \u2013L 192.168.0.18 -U user2\r\n<\/pre>\n<div id=\"attachment_15509\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Mount-Samba-Share-on-Linux.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15509\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Mount-Samba-Share-on-Linux-620x255.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Mount-Samba-Share-on-Linux-620x255.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Mount-Samba-Share-on-Linux.png 737w\" alt=\"Mount Samba Share on Linux\" width=\"620\" height=\"255\" aria-describedby=\"caption-attachment-15509\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15509\" class=\"wp-caption-text\">Mount Samba Share on Linux<\/p>\n<\/div>\n<p>(repeat the above command for user1)<\/p>\n<p>As any other storage media, you can mount (and later unmount) this network share when needed:<\/p>\n<pre># mount \/\/192.168.0.18\/finance \/media\/samba -o username=user1\r\n<\/pre>\n<div id=\"attachment_15510\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Mount-Samba-Network-Share.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15510\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Mount-Samba-Network-Share-620x109.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Mount-Samba-Network-Share-620x109.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Mount-Samba-Network-Share.png 810w\" alt=\"Mount Samba Network Share\" width=\"620\" height=\"109\" aria-describedby=\"caption-attachment-15510\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15510\" class=\"wp-caption-text\">Mount Samba Network Share<\/p>\n<\/div>\n<p>(where\u00a0<strong>\/media\/samba<\/strong>\u00a0is an existing directory)<\/p>\n<p>or permanently, by adding the following entry in\u00a0<strong>\/etc\/fstab<\/strong>\u00a0file:<\/p>\n<div class=\"code-label \" title=\"fstab\">fstab<\/div>\n<pre>\/\/192.168.0.18\/finance \/media\/samba cifs credentials=\/media\/samba\/.smbcredentials,defaults 0 0\r\n<\/pre>\n<p>Where the hidden file\u00a0<strong>\/media\/samba\/.smbcredentials<\/strong>\u00a0(whose permissions and ownership have been set to\u00a0<strong>600<\/strong>and\u00a0<strong>root:root<\/strong>, respectively) contains two lines that indicate the username and password of an account that is allowed to use the share:<\/p>\n<div class=\"code-label \" title=\"smbcredentials\">.smbcredentials<\/div>\n<pre>username=user1\r\npassword=PasswordForUser1\r\n<\/pre>\n<p>Finally, let\u2019s create a file inside\u00a0<strong>\/finance<\/strong>\u00a0and check the permissions and ownership:<\/p>\n<pre># touch \/media\/samba\/FileCreatedInRHELClient.txt\r\n<\/pre>\n<div id=\"attachment_15511\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Create-File-in-Samba-Share.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15511\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Create-File-in-Samba-Share-620x155.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Create-File-in-Samba-Share-620x155.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Create-File-in-Samba-Share.png 666w\" alt=\"Create File in Samba Share\" width=\"620\" height=\"155\" aria-describedby=\"caption-attachment-15511\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15511\" class=\"wp-caption-text\">Create File in Samba Share<\/p>\n<\/div>\n<p>As you can see, the file was created with\u00a0<strong>0770<\/strong>\u00a0permissions and ownership set to\u00a0<strong>user1:finance<\/strong>.<\/p>\n<h3>Step 7: Mounting the Samba Share in Windows<\/h3>\n<p>To mount the Samba share in Windows, go to\u00a0<strong>My PC<\/strong>\u00a0and choose\u00a0<strong>Computer<\/strong>, then\u00a0<strong>Map<\/strong>\u00a0network drive. Next, assign a letter for the drive to be mapped and check Connect using different credentials (the screenshots below are in Spanish, my native language):<\/p>\n<div id=\"attachment_15512\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Mount-Samba-Share-in-Windows.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15512\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Mount-Samba-Share-in-Windows-620x327.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Mount-Samba-Share-in-Windows-620x327.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Mount-Samba-Share-in-Windows.png 937w\" alt=\"Mount Samba Share in Windows\" width=\"620\" height=\"327\" aria-describedby=\"caption-attachment-15512\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15512\" class=\"wp-caption-text\">Mount Samba Share in Windows<\/p>\n<\/div>\n<p>Finally, let\u2019s create a file and check the permissions and ownership:<\/p>\n<div id=\"attachment_15513\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Create-Files-on-Windows-Samba-Share.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15513\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Create-Files-on-Windows-Samba-Share-620x232.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Create-Files-on-Windows-Samba-Share-620x232.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Create-Files-on-Windows-Samba-Share.png 693w\" alt=\"Create Files on Windows Samba Share\" width=\"620\" height=\"232\" aria-describedby=\"caption-attachment-15513\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15513\" class=\"wp-caption-text\">Create Files on Windows Samba Share<\/p>\n<\/div>\n<pre># ls -l \/finance\r\n<\/pre>\n<p>This time the file belongs to\u00a0<strong>user2<\/strong>\u00a0since that\u2019s the account we used to connect from the Windows client.<\/p>\n<h3>Summary<\/h3>\n<p>In this article we have explained not only how to set up a\u00a0<strong>Samba<\/strong>\u00a0server and two clients using different operating systems, but also\u00a0<a href=\"https:\/\/www.tecmint.com\/configure-firewalld-in-centos-7\/\" target=\"_blank\" rel=\"noopener\">how to configure the firewalld<\/a>\u00a0and\u00a0<a href=\"https:\/\/www.tecmint.com\/selinux-essentials-and-control-filesystem-access\/\" target=\"_blank\" rel=\"noopener\">SELinux on the server<\/a>\u00a0to allow the desired group collaboration capabilities.<\/p>\n<p>Last, but not least, let me recommend the reading of the online\u00a0<a href=\"https:\/\/www.samba.org\/samba\/docs\/man\/manpages-3\/smb.conf.5.html\" target=\"_blank\" rel=\"nofollow noopener\">man page of smb.conf<\/a>\u00a0to explore other configuration directives that may be more suitable for your case than the scenario described in this article.<\/p>\n<p>As always, feel free to drop a comment using the form below if you have any comments or suggestions.<\/p>\n<h1 class=\"post-title\">Setting Up NFS Server with Kerberos-based Authentication for Linux Clients \u2013 Part 7<\/h1>\n<p>In the last article of this series, we reviewed\u00a0<a href=\"https:\/\/www.tecmint.com\/setup-samba-file-sharing-for-linux-windows-clients\/\" target=\"_blank\" rel=\"noopener\">how to set up a Samba share over a network<\/a>\u00a0that may consist of multiple types of operating systems. Now, if you need to set up file sharing for a group of Unix-like clients you will automatically think of the\u00a0<strong>Network File System<\/strong>, or\u00a0<strong>NFS<\/strong>\u00a0for short.<\/p>\n<div id=\"attachment_15640\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Setting-Kerberos-Authentication-with-NFS.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15640\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Setting-Kerberos-Authentication-with-NFS-620x297.jpg\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Setting-Kerberos-Authentication-with-NFS-620x297.jpg 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Setting-Kerberos-Authentication-with-NFS.jpg 720w\" alt=\"Setting Up NFS Server with Kerberos Authentication\" width=\"620\" height=\"297\" aria-describedby=\"caption-attachment-15640\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15640\" class=\"wp-caption-text\">RHCE Series: Setting Up NFS Server with Kerberos Authentication \u2013 Part 7<\/p>\n<\/div>\n<p>In this article we will walk you through the process of using\u00a0<strong>Kerberos-based<\/strong>\u00a0authentication for\u00a0<strong>NFS<\/strong>\u00a0shares. It is assumed that you already have set up a NFS server and a client. If not, please refer to\u00a0<a href=\"https:\/\/www.tecmint.com\/configure-nfs-server\/\" target=\"_blank\" rel=\"noopener\">install and configure NFS server<\/a>\u00a0\u2013 which will list the necessary packages that need to be installed and explain how to perform initial configurations on the server before proceeding further.<\/p>\n<p>In addition, you will want to configure both\u00a0<a href=\"https:\/\/www.tecmint.com\/selinux-essentials-and-control-filesystem-access\/\" target=\"_blank\" rel=\"noopener\">SELinux<\/a>\u00a0and\u00a0<a href=\"https:\/\/www.tecmint.com\/firewalld-rules-for-centos-7\/\" target=\"_blank\" rel=\"noopener\">firewalld<\/a>\u00a0to allow for file sharing through NFS.<\/p>\n<p>The following example assumes that your\u00a0<strong>NFS<\/strong>\u00a0share is located in\u00a0<strong>\/nfs<\/strong>\u00a0in\u00a0<strong>box2<\/strong>:<\/p>\n<pre># semanage fcontext -a -t public_content_rw_t \"\/nfs(\/.*)?\"\r\n# restorecon -R \/nfs\r\n# setsebool -P nfs_export_all_rw on\r\n# setsebool -P nfs_export_all_ro on\r\n<\/pre>\n<p>(where the\u00a0<strong>-P<\/strong>\u00a0flag indicates persistence across reboots).<\/p>\n<p>Finally, don\u2019t forget to:<\/p>\n<h4>Create NFS Group and Configure NFS Share Directory<\/h4>\n<p><strong>1.<\/strong>\u00a0Create a group called\u00a0<strong>nfs<\/strong>\u00a0and add the\u00a0<strong>nfsnobody<\/strong>\u00a0user to it, then change the permissions of the\u00a0<strong>\/nfs<\/strong>\u00a0directory to\u00a0<strong>0770<\/strong>\u00a0and its group owner to\u00a0<strong>nfs<\/strong>. Thus,\u00a0<strong>nfsnobody<\/strong>\u00a0(which is mapped to the client requests) will have write permissions on the share) and you won\u2019t need to use\u00a0<strong>no_root_squash<\/strong>\u00a0in the\u00a0<strong>\/etc\/exports<\/strong>\u00a0file.<\/p>\n<pre># groupadd nfs\r\n# usermod -a -G nfs nfsnobody\r\n# chmod 0770 \/nfs\r\n# chgrp nfs \/nfs\r\n<\/pre>\n<p><strong>2.<\/strong>\u00a0Modify the exports file (<strong>\/etc\/exports<\/strong>) as follows to only allow access from\u00a0<strong>box1<\/strong>\u00a0using\u00a0<strong>Kerberos<\/strong>\u00a0security (<strong>sec=krb5<\/strong>).<\/p>\n<p><strong>Note<\/strong>: that the value of\u00a0<strong>anongid<\/strong>\u00a0has been set to the\u00a0<strong>GID<\/strong>\u00a0of the\u00a0<strong>nfs<\/strong>\u00a0group that we created previously:<\/p>\n<div class=\"code-label\" title=\"Add NFS Share to \/etc\/exports File\">exports \u2013 Add NFS Share<\/div>\n<pre>\/nfs box1(rw,sec=krb5,anongid=1004)\r\n<\/pre>\n<p><strong>3.<\/strong>\u00a0Re-export\u00a0<strong>(-r)<\/strong>\u00a0all\u00a0<strong>(-a)<\/strong>\u00a0the NFS shares. Adding verbosity to the output\u00a0<strong>(-v)<\/strong>\u00a0is a good idea since it will provide helpful information to troubleshoot the server if something goes wrong:<\/p>\n<pre># exportfs -arv\r\n<\/pre>\n<p><strong>4.<\/strong>\u00a0Restart and enable the NFS server and related services. Note that you don\u2019t have to enable\u00a0<strong>nfs-lock<\/strong>\u00a0and\u00a0<strong>nfs-idmapd<\/strong>\u00a0because they will be automatically started by the other services on boot:<\/p>\n<pre># systemctl restart rpcbind nfs-server nfs-lock nfs-idmap\r\n# systemctl enable rpcbind nfs-server\r\n<\/pre>\n<h4>Testing Environment and Other Prerequisites<\/h4>\n<p>In this guide we will use the following test environment:<\/p>\n<ol>\n<li>Client machine [<strong>box1: 192.168.0.18<\/strong>]<\/li>\n<li>NFS \/ Kerberos server\u00a0<strong>[box2: 192.168.0.20]<\/strong>\u00a0(also known as\u00a0<strong>Key Distribution Center<\/strong>, or\u00a0<strong>KDC<\/strong>\u00a0for short).<\/li>\n<\/ol>\n<p><strong>Note<\/strong>: that\u00a0<strong>Kerberos<\/strong>\u00a0service is crucial to the authentication scheme.<\/p>\n<p>As you can see, the\u00a0<strong>NFS<\/strong>\u00a0server and the\u00a0<strong>KDC<\/strong>\u00a0are hosted in the same machine for simplicity, although you can set them up in separate machines if you have more available. Both machines are members of the\u00a0<code>mydomain.com<\/code>domain.<\/p>\n<p>Last but not least,\u00a0<strong>Kerberos<\/strong>\u00a0requires at least a basic schema of name resolution and the\u00a0<a href=\"https:\/\/www.tecmint.com\/install-ntp-server-in-centos\/\" target=\"_blank\" rel=\"noopener\">Network Time Protocol<\/a>service to be present in both client and server since the security of Kerberos authentication is in part based upon the timestamps of tickets.<\/p>\n<p>To set up name resolution, we will use the\u00a0<strong>\/etc\/hosts<\/strong>\u00a0file in both client and server:<\/p>\n<div class=\"code-label\" title=\"Add Domains to \/etc\/hosts File\">host file \u2013 Add DNS for Domain<\/div>\n<pre>192.168.0.18    box1.mydomain.com    box1\r\n192.168.0.20    box2.mydomain.com    box2\r\n<\/pre>\n<p>In\u00a0<strong>RHEL 7<\/strong>,\u00a0<strong>chrony<\/strong>\u00a0is the default software that is used for\u00a0<strong>NTP<\/strong>\u00a0synchronization:<\/p>\n<pre># yum install chrony\r\n# systemctl start chronyd\r\n# systemctl enable chronyd\r\n<\/pre>\n<p>To make sure\u00a0<strong>chrony<\/strong>\u00a0is actually synchronizing your system\u2019s time with time servers you may want to issue the following command two or three times and make sure the offset is getting nearer to zero:<\/p>\n<pre># chronyc tracking\r\n<\/pre>\n<div id=\"attachment_15633\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Synchronize-Time-with-Chrony.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-15633\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Synchronize-Time-with-Chrony.png\" alt=\"Synchronize Server Time with Chrony\" width=\"451\" height=\"401\" aria-describedby=\"caption-attachment-15633\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15633\" class=\"wp-caption-text\">Synchronize Server Time with Chrony<\/p>\n<\/div>\n<h3>Installing and Configuring Kerberos<\/h3>\n<p>To set up the\u00a0<strong>KDC<\/strong>, install the following packages on both\u00a0<strong>server<\/strong>\u00a0and\u00a0<strong>client<\/strong>\u00a0(omit the server package in the client):<\/p>\n<pre># yum update &amp;&amp; yum install krb5-server krb5-workstation pam_krb5\r\n<\/pre>\n<p>Once it is installed, edit the configuration files (<strong>\/etc\/krb5.conf<\/strong>\u00a0and\u00a0<strong>\/var\/kerberos\/krb5kdc\/kadm5.acl<\/strong>) and replace all instances of\u00a0<strong>example.com<\/strong>\u00a0(lowercase and uppercase) with\u00a0<code>mydomain.com<\/code>\u00a0as follows.<\/p>\n<p>Now create the\u00a0<strong>Kerberos<\/strong>\u00a0database (please note that this may take a while as it requires a some level of entropy in your system. To speed things up, I opened another terminal and ran\u00a0<strong>ping -f localhost<\/strong>\u00a0for 30-45 seconds):<\/p>\n<pre># kdb5_util create -s\r\n<\/pre>\n<div id=\"attachment_15634\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Create-Kerberos-Database.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15634\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Create-Kerberos-Database-620x148.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Create-Kerberos-Database-620x148.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Create-Kerberos-Database.png 658w\" alt=\"Create Kerberos Database\" width=\"620\" height=\"148\" aria-describedby=\"caption-attachment-15634\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15634\" class=\"wp-caption-text\">Create Kerberos Database<\/p>\n<\/div>\n<p>Next, enable\u00a0<strong>Kerberos<\/strong>\u00a0through the\u00a0<strong>firewall<\/strong>\u00a0and start \/ enable the related services.<\/p>\n<p><strong>Important<\/strong>:\u00a0<strong>nfs-secure<\/strong>\u00a0must be started and enabled on the client as well:<\/p>\n<pre># firewall-cmd --permanent --add-service=kerberos\r\n# systemctl start krb5kdc kadmin nfs-secure   \r\n# systemctl enable krb5kdc kadmin nfs-secure       \r\n<\/pre>\n<p>Next, using the\u00a0<strong>kadmin.local<\/strong>\u00a0tool, create an admin principal for root:<\/p>\n<pre># kadmin.local\r\n# addprinc root\/admin\r\n<\/pre>\n<p>And add the\u00a0<strong>Kerberos<\/strong>\u00a0server to the database:<\/p>\n<pre># addprinc -randkey host\/box2.mydomain.com\r\n<\/pre>\n<p>Same with the\u00a0<strong>NFS<\/strong>\u00a0service for both client (<strong>box1<\/strong>) and server (<strong>box2<\/strong>). Please note that in the screenshot below I forgot to do it for\u00a0<strong>box1<\/strong>\u00a0before quitting:<\/p>\n<pre># addprinc -randkey nfs\/box2.mydomain.com\r\n# addprinc -randkey nfs\/box1.mydomain.com\r\n<\/pre>\n<p>And\u00a0<strong>exit<\/strong>\u00a0by typing\u00a0<strong>quit<\/strong>\u00a0and pressing Enter:<\/p>\n<div id=\"attachment_15635\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Create-Kerboros-for-NFS.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15635\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Create-Kerboros-for-NFS-620x407.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Create-Kerboros-for-NFS-620x407.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Create-Kerboros-for-NFS.png 659w\" alt=\"Add Kerberos to NFS Server\" width=\"620\" height=\"407\" aria-describedby=\"caption-attachment-15635\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15635\" class=\"wp-caption-text\">Add Kerberos to NFS Server<\/p>\n<\/div>\n<p>Then obtain and cache Kerberos ticket-granting ticket for root\/admin:<\/p>\n<pre># kinit root\/admin\r\n# klist\r\n<\/pre>\n<div id=\"attachment_15636\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Cache-kerberos-Ticket.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-15636\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Cache-kerberos-Ticket.png\" alt=\"Cache Kerberos\" width=\"599\" height=\"159\" aria-describedby=\"caption-attachment-15636\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15636\" class=\"wp-caption-text\">Cache Kerberos<\/p>\n<\/div>\n<p>The last step before actually using\u00a0<strong>Kerberos<\/strong>\u00a0is storing into a\u00a0<strong>keytab<\/strong>\u00a0file (in the server) the principals that are authorized to use Kerberos authentication:<\/p>\n<pre># kadmin.local\r\n# ktadd host\/box2.mydomain.com\r\n# ktadd nfs\/box2.mydomain.com\r\n# ktadd nfs\/box1.mydomain.com\r\n<\/pre>\n<p>Finally, mount the share and perform a write test:<\/p>\n<pre># mount -t nfs4 -o sec=krb5 box2:\/nfs \/mnt\r\n# echo \"Hello from Tecmint.com\" &gt; \/mnt\/greeting.txt\r\n<\/pre>\n<div id=\"attachment_15637\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Mount-NFS-Share.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15637\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Mount-NFS-Share-620x66.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Mount-NFS-Share-620x66.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Mount-NFS-Share-1024x109.png 1024w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Mount-NFS-Share.png 1153w\" alt=\"Mount NFS Share\" width=\"620\" height=\"66\" aria-describedby=\"caption-attachment-15637\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15637\" class=\"wp-caption-text\">Mount NFS Share<\/p>\n<\/div>\n<p>Let\u2019s now\u00a0<strong>unmount<\/strong>\u00a0the share, rename the\u00a0<strong>keytab<\/strong>\u00a0file in the client (to simulate it\u2019s not present) and try to mount the share again:<\/p>\n<pre># umount \/mnt\r\n# mv \/etc\/krb5.keytab \/etc\/krb5.keytab.orig\r\n<\/pre>\n<div id=\"attachment_15638\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Mount-Unmount-Kerberos-NFS-Share.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15638\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Mount-Unmount-Kerberos-NFS-Share-620x183.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Mount-Unmount-Kerberos-NFS-Share-620x183.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Mount-Unmount-Kerberos-NFS-Share.png 659w\" alt=\"Mount Unmount Kerberos NFS Share\" width=\"620\" height=\"183\" aria-describedby=\"caption-attachment-15638\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15638\" class=\"wp-caption-text\">Mount Unmount Kerberos NFS Share<\/p>\n<\/div>\n<p>Now you can use the\u00a0<strong>NFS<\/strong>\u00a0share with\u00a0<strong>Kerberos-based<\/strong>\u00a0authentication.<\/p>\n<h3>Summary<\/h3>\n<p>In this article we have explained how to set up\u00a0<strong>NFS<\/strong>\u00a0with\u00a0<strong>Kerberos<\/strong>\u00a0authentication. Since there is much more to the topic than we can cover in a single guide, feel free to check the online\u00a0<a href=\"http:\/\/web.mit.edu\/kerberos\/krb5-1.12\/doc\/admin\/admin_commands\/\" target=\"_blank\" rel=\"nofollow noopener\">Kerberos documentation<\/a>\u00a0and since Kerberos is a bit tricky to say the least, don\u2019t hesitate to drop us a note using the form below if you run into any issue or need help with your testing or implementation.<\/p>\n<h1 class=\"post-title\">RHCE Series: Implementing HTTPS through TLS using Network Security Service (NSS) for Apache \u2013 Part 8<\/h1>\n<p>If you are a system administrator who is in charge of maintaining and securing a web server, you can\u2019t afford to not devote your very best efforts to ensure that data served by or going through your server is protected at all times.<\/p>\n<div id=\"attachment_15741\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Setup-Apache-SSL-TLS-Server.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15741\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Setup-Apache-SSL-TLS-Server-620x297.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Setup-Apache-SSL-TLS-Server-620x297.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Setup-Apache-SSL-TLS-Server.png 720w\" alt=\"Setup Apache HTTPS Using SSL\/TLS\" width=\"620\" height=\"297\" aria-describedby=\"caption-attachment-15741\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15741\" class=\"wp-caption-text\">RHCE Series: Implementing HTTPS through TLS using Network Security Service (NSS) for Apache \u2013 Part 8<\/p>\n<\/div>\n<p>In order to provide more secure communications between web clients and servers, the\u00a0<strong>HTTPS<\/strong>\u00a0protocol was born as a combination of\u00a0<strong>HTTP<\/strong>\u00a0and\u00a0<strong>SSL<\/strong>\u00a0(<strong>Secure Sockets Layer<\/strong>) or more recently,\u00a0<strong>TLS<\/strong>\u00a0(<strong>Transport Layer Security<\/strong>).<\/p>\n<p>Due to some serious security breaches,\u00a0<strong>SSL<\/strong>\u00a0has been deprecated in favor of the more robust\u00a0<strong>TLS<\/strong>. For that reason, in this article we will explain how to secure connections between your web server and clients using TLS.<\/p>\n<p>This tutorial assumes that you have already installed and configured your Apache web server. If not, please refer to following article in this site before proceeding further.<\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/install-lamp-in-centos-7\/\" target=\"_blank\" rel=\"noopener\">Install LAMP (Linux, MySQL\/MariaDB, Apache and PHP) on RHEL\/CentOS 7<\/a><\/li>\n<\/ol>\n<h3>Installation of OpenSSL and Utilities<\/h3>\n<p>First off, make sure that\u00a0<strong>Apache<\/strong>\u00a0is running and that both\u00a0<strong>http<\/strong>\u00a0and\u00a0<strong>https<\/strong>\u00a0are allowed through the firewall:<\/p>\n<pre># systemctl start http\r\n# systemctl enable http\r\n# firewall-cmd --permanent \u2013-add-service=http\r\n# firewall-cmd --permanent \u2013-add-service=https\r\n<\/pre>\n<p>Then install the necessary packages:<\/p>\n<pre># yum update &amp;&amp; yum install openssl mod_nss crypto-utils\r\n<\/pre>\n<p><strong>Important<\/strong>: Please note that you can replace\u00a0<strong>mod_nss<\/strong>\u00a0with\u00a0<strong>mod_ssl<\/strong>\u00a0in the command above if you want to use\u00a0<strong>OpenSSL<\/strong>\u00a0libraries instead of\u00a0<strong>NSS<\/strong>\u00a0(<strong>Network Security Service<\/strong>) to implement\u00a0<strong>TLS<\/strong>\u00a0(which one to use is left entirely up to you, but we will use NSS in this article as it is more robust; for example, it supports recent cryptography standards such as\u00a0<strong>PKCS #11<\/strong>).<\/p>\n<p>Finally, uninstall\u00a0<strong>mod_ssl<\/strong>\u00a0if you chose to use\u00a0<strong>mod_nss<\/strong>, or viceversa.<\/p>\n<pre># yum remove mod_ssl\r\n<\/pre>\n<h3>Configuring NSS (Network Security Service)<\/h3>\n<p>After\u00a0<strong>mod_nss<\/strong>\u00a0is installed, its default configuration file is created as\u00a0<strong>\/etc\/httpd\/conf.d\/nss.conf<\/strong>. You should then make sure that all of the\u00a0<strong>Listen<\/strong>\u00a0and\u00a0<strong>VirtualHost<\/strong>\u00a0directives point to port\u00a0<strong>443<\/strong>\u00a0(default port for HTTPS):<\/p>\n<div class=\"code-label\" title=\"Configure NSS for HTTPS\">nss.conf \u2013 Configuration File<\/div>\n<pre>Listen 443\r\nVirtualHost _default_:443\r\n<\/pre>\n<p>Then restart\u00a0<strong>Apache<\/strong>\u00a0and check whether the\u00a0<strong>mod_nss<\/strong>\u00a0module has been loaded:<\/p>\n<pre># apachectl restart\r\n# httpd -M | grep nss\r\n<\/pre>\n<div id=\"attachment_15726\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Check-Mod_NSS-Module-in-Apache.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-15726\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Check-Mod_NSS-Module-in-Apache.png\" alt=\"Check Mod_NSS Module in Apache\" width=\"289\" height=\"65\" aria-describedby=\"caption-attachment-15726\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15726\" class=\"wp-caption-text\">Check Mod_NSS Module Loaded in Apache<\/p>\n<\/div>\n<p>Next, the following edits should be made in\u00a0<code>\/etc\/httpd\/conf.d\/nss.conf<\/code>\u00a0configuration file:<\/p>\n<p><strong>1.<\/strong>\u00a0Indicate NSS database directory. You can use the default directory or create a new one. In this tutorial we will use the default:<\/p>\n<pre>NSSCertificateDatabase \/etc\/httpd\/alias\r\n<\/pre>\n<p><strong>2.<\/strong>\u00a0Avoid manual passphrase entry on each system start by saving the password to the database directory in\u00a0<strong>\/etc\/httpd\/nss-db-password.conf<\/strong>:<\/p>\n<pre>NSSPassPhraseDialog file:\/etc\/httpd\/nss-db-password.conf\r\n<\/pre>\n<p>Where\u00a0<strong>\/etc\/httpd\/nss-db-password.conf<\/strong>\u00a0contains ONLY the following line and\u00a0<strong>mypassword<\/strong>\u00a0is the password that you will set later for the NSS database:<\/p>\n<pre>internal:mypassword\r\n<\/pre>\n<p>In addition, its permissions and ownership should be set to\u00a0<strong>0640<\/strong>\u00a0and\u00a0<strong>root:apache<\/strong>, respectively:<\/p>\n<pre># chmod 640 \/etc\/httpd\/nss-db-password.conf\r\n# chgrp apache \/etc\/httpd\/nss-db-password.conf\r\n<\/pre>\n<p><strong>3.<\/strong>\u00a0Red Hat recommends disabling\u00a0<strong>SSL<\/strong>\u00a0and all versions of\u00a0<strong>TLS<\/strong>\u00a0previous to\u00a0<strong>TLSv1.0<\/strong>\u00a0due to the\u00a0<strong>POODLE SSLv3<\/strong>vulnerability (more information\u00a0<a href=\"https:\/\/access.redhat.com\/articles\/1232123\" target=\"_blank\" rel=\"nofollow noopener\">here<\/a>).<\/p>\n<p>Make sure that every instance of the\u00a0<strong>NSSProtocol<\/strong>\u00a0directive reads as follows (you are likely to find only one if you are not hosting other virtual hosts):<\/p>\n<pre>NSSProtocol TLSv1.0,TLSv1.1\r\n<\/pre>\n<p><strong>4.<\/strong>\u00a0Apache will refuse to restart as this is a self-signed certificate and will not recognize the issuer as valid. For this reason, in this particular case you will have to add:<\/p>\n<pre>NSSEnforceValidCerts off\r\n<\/pre>\n<p><strong>5.<\/strong>\u00a0Though not strictly required, it is important to set a password for the NSS database:<\/p>\n<pre># certutil -W -d \/etc\/httpd\/alias\r\n<\/pre>\n<div id=\"attachment_15727\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Set-Password-for-NSS-Database.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-15727\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Set-Password-for-NSS-Database.png\" alt=\"Set Password for NSS Database\" width=\"471\" height=\"143\" aria-describedby=\"caption-attachment-15727\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15727\" class=\"wp-caption-text\">Set Password for NSS Database<\/p>\n<\/div>\n<h3>Creating a Apache SSL Self-Signed Certificate<\/h3>\n<p>Next, we will create a self-signed certificate that will identify the server to our clients (please note that this method is not the best option for production environments; for such use you may want to consider buying a certificate verified by a 3rd trusted certificate authority, such as\u00a0<strong>DigiCert<\/strong>).<\/p>\n<p>To create a new NSS-compliant certificate for\u00a0<strong>box1<\/strong>\u00a0which will be valid for\u00a0<strong>365<\/strong>\u00a0days, we will use the\u00a0<strong>genkey<\/strong>command. When this process completes:<\/p>\n<pre># genkey --nss --days 365 box1\r\n<\/pre>\n<p>Choose\u00a0<strong>Next<\/strong>:<\/p>\n<div id=\"attachment_15728\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Create-Apache-SSL-Key.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15728\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Create-Apache-SSL-Key-620x346.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Create-Apache-SSL-Key-620x346.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Create-Apache-SSL-Key.png 628w\" alt=\"Create Apache SSL Key\" width=\"620\" height=\"346\" aria-describedby=\"caption-attachment-15728\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15728\" class=\"wp-caption-text\">Create Apache SSL Key<\/p>\n<\/div>\n<p>You can leave the default choice for the key size (<strong>2048<\/strong>), then choose\u00a0<strong>Next<\/strong>\u00a0again:<\/p>\n<div id=\"attachment_15729\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Select-Apache-SSL-Key-Size.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-15729\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Select-Apache-SSL-Key-Size.png\" alt=\"Select Apache SSL Key Size\" width=\"609\" height=\"388\" aria-describedby=\"caption-attachment-15729\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15729\" class=\"wp-caption-text\">Select Apache SSL Key Size<\/p>\n<\/div>\n<p>Wait while the system generates random bits:<\/p>\n<div id=\"attachment_15730\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Generating-Random-Bits.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-15730\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Generating-Random-Bits.png\" alt=\"Generating Random Key Bits\" width=\"381\" height=\"159\" aria-describedby=\"caption-attachment-15730\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15730\" class=\"wp-caption-text\">Generating Random Key Bits<\/p>\n<\/div>\n<p>To speed up the process, you will be prompted to enter random text in your console, as shown in the following screencast. Please note how the progress bar stops when no input from the keyboard is received. Then, you will be asked to:<\/p>\n<p><strong>1.<\/strong>\u00a0Whether to send the\u00a0<strong>Certificate Sign Request<\/strong>\u00a0(<strong>CSR<\/strong>) to a\u00a0<strong>Certificate Authority<\/strong>\u00a0(<strong>CA<\/strong>): Choose\u00a0<strong>No<\/strong>, as this is a self-signed certificate.<\/p>\n<p><strong>2.<\/strong>\u00a0to enter the information for the certificate.<\/p>\n<div class=\"post-format\">\n<div class=\"video-container\"><iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/mgsfeNfuurA\" width=\"720\" height=\"405\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\" data-mce-fragment=\"1\"><\/iframe><\/div>\n<\/div>\n<p>Finally, you will be prompted to enter the password to the NSS certificate that you set earlier:<\/p>\n<pre># genkey --nss --days 365 box1\r\n<\/pre>\n<div id=\"attachment_15732\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Apache-NSS-Password.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15732\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Apache-NSS-Password-620x84.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Apache-NSS-Password-620x84.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Apache-NSS-Password.png 964w\" alt=\"Apache NSS Certificate Password\" width=\"620\" height=\"84\" aria-describedby=\"caption-attachment-15732\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15732\" class=\"wp-caption-text\">Apache NSS Certificate Password<\/p>\n<\/div>\n<p>At anytime, you can list the existing certificates with:<\/p>\n<pre># certutil \u2013L \u2013d \/etc\/httpd\/alias\r\n<\/pre>\n<div id=\"attachment_15733\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/List-Apache-Certificates.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15733\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/List-Apache-Certificates-620x170.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/List-Apache-Certificates-620x170.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/List-Apache-Certificates.png 638w\" alt=\"List Apache NSS Certificates\" width=\"620\" height=\"170\" aria-describedby=\"caption-attachment-15733\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15733\" class=\"wp-caption-text\">List Apache NSS Certificates<\/p>\n<\/div>\n<p>And delete them by name (only if strictly required, replacing box1 by your own certificate name) with:<\/p>\n<pre># certutil -d \/etc\/httpd\/alias -D -n \"box1\"\r\n<\/pre>\n<p>if you need to.c<\/p>\n<h3>Testing Apache SSL HTTPS Connections<\/h3>\n<p>Finally, it\u2019s time to test the secure connection to our web server. When you point your browser to\u00a0<strong>https:\/\/&lt;web server IP or hostname&gt;<\/strong>, you will get the well-known message \u201c<strong>This connection is untrusted<\/strong>\u201c:<\/p>\n<div id=\"attachment_15734\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Check-Apache-SSL-Connection.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15734\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Check-Apache-SSL-Connection-620x258.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Check-Apache-SSL-Connection-620x258.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Check-Apache-SSL-Connection.png 913w\" alt=\"Check Apache SSL Connection\" width=\"620\" height=\"258\" aria-describedby=\"caption-attachment-15734\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15734\" class=\"wp-caption-text\">Check Apache SSL Connection<\/p>\n<\/div>\n<p>In the above situation, you can click on\u00a0<strong>Add Exception<\/strong>\u00a0and then\u00a0<strong>Confirm Security Exception<\/strong>\u00a0\u2013 but don\u2019t do it yet. Let\u2019s first examine the certificate to see if its details match the information that we entered earlier (as shown in the screencast).<\/p>\n<p>To do so, click on\u00a0<strong>View\u2026<\/strong>\u00a0<strong>\u2013&gt;<\/strong>\u00a0Details tab above and you should see this when you select Issuer from the list:<\/p>\n<div id=\"attachment_15735\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Check-Apache-SSL-Certificate-Details.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15735\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Check-Apache-SSL-Certificate-Details-340x450.png\" sizes=\"auto, (max-width: 340px) 100vw, 340px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Check-Apache-SSL-Certificate-Details-340x450.png 340w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Check-Apache-SSL-Certificate-Details.png 396w\" alt=\"Confirm Apache SSL Certificate Details\" width=\"340\" height=\"450\" aria-describedby=\"caption-attachment-15735\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15735\" class=\"wp-caption-text\">Confirm Apache SSL Certificate Details<\/p>\n<\/div>\n<p>Now you can go ahead, confirm the exception (either for this time or permanently) and you will be taken to your web server\u2019s\u00a0<strong>DocumentRoot<\/strong>\u00a0directory via\u00a0<strong>https<\/strong>, where you can inspect the connection details using your browser\u2019s builtin developer tools:<\/p>\n<p>In\u00a0<strong>Firefox<\/strong>\u00a0you can launch it by right clicking on the screen, and choosing\u00a0<strong>Inspect Element<\/strong>\u00a0from the context menu, specifically through the\u00a0<strong>Network<\/strong>\u00a0tab:<\/p>\n<div id=\"attachment_15736\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Inspect-Apache-HTTPS-Connection.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15736\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Inspect-Apache-HTTPS-Connection-620x219.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Inspect-Apache-HTTPS-Connection-620x219.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Inspect-Apache-HTTPS-Connection-1024x361.png 1024w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Inspect-Apache-HTTPS-Connection.png 1295w\" alt=\"Inspect Apache HTTPS Connection \" width=\"620\" height=\"219\" aria-describedby=\"caption-attachment-15736\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15736\" class=\"wp-caption-text\">Inspect Apache HTTPS Connection<\/p>\n<\/div>\n<p>Please note that this is the same information as displayed before, which was entered during the certificate previously. There\u2019s also a way to test the connection using command line tools:<\/p>\n<p>On the left (testing\u00a0<strong>SSLv3<\/strong>):<\/p>\n<pre># openssl s_client -connect localhost:443 -ssl3\r\n<\/pre>\n<p>On the right (testing\u00a0<strong>TLS<\/strong>):<\/p>\n<pre># openssl s_client -connect localhost:443 -tls1\r\n<\/pre>\n<div id=\"attachment_15737\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Testing-Apache-SSL-and-TLS.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15737\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Testing-Apache-SSL-and-TLS-620x242.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Testing-Apache-SSL-and-TLS-620x242.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Testing-Apache-SSL-and-TLS-1024x400.png 1024w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Testing-Apache-SSL-and-TLS.png 1335w\" alt=\"Testing Apache SSL and TLS Connections\" width=\"620\" height=\"242\" aria-describedby=\"caption-attachment-15737\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15737\" class=\"wp-caption-text\">Testing Apache SSL and TLS Connections<\/p>\n<\/div>\n<p>Refer to the screenshot above for more details.<\/p>\n<h3>Summary<\/h3>\n<p>As I\u2019m sure you already know, the presence of\u00a0<strong>HTTPS<\/strong>\u00a0inspires trust in visitors who may have to enter personal information in your site (from\u00a0<strong>user names<\/strong>\u00a0and\u00a0<strong>passwords<\/strong>\u00a0all the way to financial \/ bank account information).<\/p>\n<p>In that case, you will want to get a certificate signed by a trusted\u00a0<strong>Certificate Authority<\/strong>\u00a0as we explained earlier (the steps to set it up are identical with the exception that you will need to send the\u00a0<strong>CSR<\/strong>\u00a0to a\u00a0<strong>CA<\/strong>, and you will get the signed certificate back); otherwise, a self-signed certificate as the one used in this tutorial will do.<\/p>\n<p>For more details on the use of NSS, please refer to the online help about\u00a0<a href=\"https:\/\/git.fedorahosted.org\/cgit\/mod_nss.git\/plain\/docs\/mod_nss.html\" target=\"_blank\" rel=\"nofollow noopener\">mod-nss<\/a>. And don\u2019t hesitate to let us know if you have any questions or comments.<\/p>\n<h1 class=\"post-title\">How to Setup Postfix Mail Server (SMTP) using null-client Configuration \u2013 Part 9<\/h1>\n<p>Regardless of the many online communication methods that are available today, email remains a practical way to deliver messages from one end of the world to another, or to a person sitting in the office next to ours.<\/p>\n<p>The following image illustrates the process of email transport starting with the sender until the message reaches the recipient\u2019s inbox:<\/p>\n<div id=\"attachment_15821\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/How-Mail-Setup-Works.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-15821\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/How-Mail-Setup-Works.png\" alt=\"How Mail Setup Works\" width=\"605\" height=\"273\" aria-describedby=\"caption-attachment-15821\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15821\" class=\"wp-caption-text\">How Mail Setup Works<\/p>\n<\/div>\n<p>To make this possible, several things happen behind the scenes. In order for an email message to be delivered from a client application (such as\u00a0<a href=\"https:\/\/www.tecmint.com\/install-thunderbird-17-in-ubuntu-xubuntu-linux-mint\/\" target=\"_blank\" rel=\"noopener\">Thunderbird<\/a>, Outlook, or webmail services such as\u00a0<strong>Gmail<\/strong>\u00a0or\u00a0<strong>Yahoo! Mail<\/strong>) to a mail server, and from there to the destination server and finally to its intended recipient, a\u00a0<strong>SMTP<\/strong>\u00a0(<strong>Simple Mail Transfer Protocol<\/strong>) service must be in place in each server.<\/p>\n<p>That is the reason why in this article we will explain how to set up a\u00a0<strong>SMTP<\/strong>\u00a0server in\u00a0<strong>RHEL 7<\/strong>\u00a0where emails sent by local users (even to other local users) are forwarded to a central mail server for easier access.<\/p>\n<p>In the exam\u2019s requirements this is called a\u00a0<strong>null-client<\/strong>\u00a0setup.<\/p>\n<p>Our test environment will consist of an originating mail server and a central mail server or relayhost.<\/p>\n<pre>Original Mail Server: (hostname: <strong>box1.mydomain.com<\/strong> \/ IP: <strong>192.168.0.18<\/strong>) \r\nCentral Mail Server: (hostname: <strong>mail.mydomain.com<\/strong> \/ IP: <strong>192.168.0.20<\/strong>)\r\n<\/pre>\n<p>For name resolution we will use the well-known\u00a0<strong>\/etc\/hosts<\/strong>\u00a0file on both boxes:<\/p>\n<pre>192.168.0.18    box1.mydomain.com       box1\r\n192.168.0.20    mail.mydomain.com       mail\r\n<\/pre>\n<h3>Installing Postfix and Firewall \/ SELinux Considerations<\/h3>\n<p>To begin, we will need to (in both servers):<\/p>\n<p><strong>1.<\/strong>\u00a0Install Postfix:<\/p>\n<pre># yum update &amp;&amp; yum install postfix\r\n<\/pre>\n<p><strong>2.<\/strong>\u00a0Start the service and enable it to run on future reboots:<\/p>\n<pre># systemctl start postfix\r\n# systemctl enable postfix\r\n<\/pre>\n<p><strong>3.<\/strong>\u00a0Allow mail traffic through the firewall:<\/p>\n<pre># firewall-cmd --permanent --add-service=smtp\r\n# firewall-cmd --add-service=smtp\r\n<\/pre>\n<div id=\"attachment_15822\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Allow-Traffic-through-Firewall.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-15822\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Allow-Traffic-through-Firewall.png\" alt=\"Open Mail Server Port in Firewall\" width=\"475\" height=\"167\" aria-describedby=\"caption-attachment-15822\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15822\" class=\"wp-caption-text\">Open Mail Server SMTP Port in Firewall<\/p>\n<\/div>\n<p><strong>4.<\/strong>\u00a0Configure\u00a0<strong>Postfix<\/strong>\u00a0on\u00a0<strong>box1.mydomain.com<\/strong>.<\/p>\n<p>Postfix\u2019s main configuration file is located in\u00a0<strong>\/etc\/postfix\/main.cf<\/strong>. This file itself is a great documentation source as the included comments explain the purpose of the program\u2019s settings.<\/p>\n<p>For brevity, let\u2019s display only the lines that need to be edited (yes, you need to leave\u00a0<strong>mydestination<\/strong>\u00a0blank in the originating server; otherwise the emails will be stored locally as opposed to in a central mail server which is what we actually want):<\/p>\n<div class=\"code-label\" title=\"Configure Postfix Mail Server\">Configure Postfix on box1.mydomain.com<\/div>\n<pre>myhostname = box1.mydomain.com\r\nmydomain = mydomain.com\r\nmyorigin = $mydomain\r\ninet_interfaces = loopback-only\r\nmydestination =\r\nrelayhost = 192.168.0.20\r\n<\/pre>\n<p><strong>5.<\/strong>\u00a0Configure Postfix on\u00a0<strong>mail.mydomain.com<\/strong>.<\/p>\n<div class=\"code-label\" title=\"Configure Postfix Mail Server\">Configure Postfix on mail.mydomain.com<\/div>\n<pre>myhostname = mail.mydomain.com\r\nmydomain = mydomain.com\r\nmyorigin = $mydomain\r\ninet_interfaces = all\r\nmydestination = $myhostname, localhost.$mydomain, localhost, $mydomain\r\nmynetworks = 192.168.0.0\/24, 127.0.0.0\/8\r\n<\/pre>\n<p>And set the related\u00a0<strong>SELinux<\/strong>\u00a0boolean to true permanently if not already done:<\/p>\n<pre># setsebool -P allow_postfix_local_write_mail_spool on\r\n<\/pre>\n<div id=\"attachment_15823\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Set-Postfix-SELinux-Permission.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-15823\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Set-Postfix-SELinux-Permission.png\" alt=\"Set Postfix SELinux Permission\" width=\"547\" height=\"108\" aria-describedby=\"caption-attachment-15823\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15823\" class=\"wp-caption-text\">Set Postfix SELinux Permission<\/p>\n<\/div>\n<p>The above\u00a0<strong>SELinux<\/strong>\u00a0boolean will allow Postfix to write to the mail spool in the central server.<\/p>\n<p><strong>5.<\/strong>\u00a0Restart the service on both servers for the changes to take effect:<\/p>\n<pre># systemctl restart postfix\r\n<\/pre>\n<p>If\u00a0<strong>Postfix<\/strong>\u00a0does not start correctly, you can use following commands to troubleshoot.<\/p>\n<pre># systemctl \u2013l status postfix\r\n# journalctl \u2013xn\r\n# postconf \u2013n\r\n<\/pre>\n<h3>Testing the Postfix Mail Servers<\/h3>\n<p>To test the mail servers, you can use any\u00a0<strong>Mail User Agent<\/strong>\u00a0(most commonly known as\u00a0<strong>MUA<\/strong>\u00a0for short) such as\u00a0<a href=\"https:\/\/www.tecmint.com\/send-mail-from-command-line-using-mutt-command\/\" target=\"_blank\" rel=\"noopener\">mail or mutt<\/a>.<\/p>\n<p>Since\u00a0<strong>mutt<\/strong>\u00a0is a personal favorite, I will use it in\u00a0<strong>box1<\/strong>\u00a0to send an email to user\u00a0<strong>tecmint<\/strong>\u00a0using an existing file (<strong>mailbody.txt<\/strong>) as message body:<\/p>\n<pre># mutt -s \"Part 9-RHCE series\" tecmint@mydomain.com &lt; mailbody.txt\r\n<\/pre>\n<div id=\"attachment_15824\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Test-Postfix-Mail-Server.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15824\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Test-Postfix-Mail-Server-620x89.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Test-Postfix-Mail-Server-620x89.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Test-Postfix-Mail-Server.png 643w\" alt=\"Test Postfix Mail Server\" width=\"620\" height=\"89\" aria-describedby=\"caption-attachment-15824\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15824\" class=\"wp-caption-text\">Test Postfix Mail Server<\/p>\n<\/div>\n<p>Now go to the central mail server (<strong>mail.mydomain.com<\/strong>), log on as user\u00a0<strong>tecmint<\/strong>, and check whether the email was received:<\/p>\n<pre># su \u2013 tecmint\r\n# mail\r\n<\/pre>\n<div id=\"attachment_15825\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Check-Postfix-Mail-Server-Delivery.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15825\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Check-Postfix-Mail-Server-Delivery-620x416.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Check-Postfix-Mail-Server-Delivery-620x416.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Check-Postfix-Mail-Server-Delivery.png 643w\" alt=\"Check Postfix Mail Server Delivery\" width=\"620\" height=\"416\" aria-describedby=\"caption-attachment-15825\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15825\" class=\"wp-caption-text\">Check Postfix Mail Server Delivery<\/p>\n<\/div>\n<p>If the email was not received, check root\u2019s mail spool for a warning or error notification. You may also want to make sure that the\u00a0<strong>SMTP<\/strong>\u00a0service is running on both servers and that port\u00a0<strong>25<\/strong>\u00a0is open in the central mail server using\u00a0<a href=\"https:\/\/www.tecmint.com\/nmap-command-examples\/\" target=\"_blank\" rel=\"noopener\">nmap command<\/a>:<\/p>\n<pre># nmap -PN 192.168.0.20\r\n<\/pre>\n<div id=\"attachment_15826\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Troubleshoot-Postfix-Mail-Server.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-15826\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Troubleshoot-Postfix-Mail-Server.png\" alt=\"Troubleshoot Postfix Mail Server\" width=\"520\" height=\"242\" aria-describedby=\"caption-attachment-15826\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15826\" class=\"wp-caption-text\">Troubleshoot Postfix Mail Server<\/p>\n<\/div>\n<h3>Summary<\/h3>\n<p>Setting up a\u00a0<strong>mail server<\/strong>\u00a0and a\u00a0<strong>relay host<\/strong>\u00a0as shown in this article is an essential skill that every system administrator must have, and represents the foundation to understand and install a more complex scenario such as a mail server hosting a live domain for several (even hundreds or thousands) of email accounts.<\/p>\n<p>(Please note that this kind of setup requires a DNS server, which is out of the scope of this guide), but you can use following article to setup\u00a0<strong>DNS Server<\/strong>:<\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/setup-dns-cache-server-in-centos-7\/\" target=\"_blank\" rel=\"noopener\">Setup Cache only DNS Server in CentOS\/RHEL 07<\/a><\/li>\n<\/ol>\n<p>Finally, I highly recommend you become familiar with Postfix\u2019s configuration file (<strong>main.cf<\/strong>) and the program\u2019s man page. If in doubt, don\u2019t hesitate to drop us a line using the form below or using our forum,\u00a0<strong>Linuxsay.com<\/strong>, where you will get almost immediate help from Linux experts from all around the world.<\/p>\n<h1 class=\"post-title\">Install and Configure Caching-Only DNS Server in RHEL\/CentOS 7 \u2013 Part 10<\/h1>\n<p>DNS servers comes in several types such as master, slave, forwarding and cache, to name a few examples, with cache-only DNS being the one that is easier to setup. Since DNS uses the UDP protocol, it improves the query time because it does not require an acknowledgement.<\/p>\n<div id=\"attachment_18196\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Setup-Cache-Only-DNS-in-CentOS-RHEL-7.png\" rel=\"attachment wp-att-18196\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18196\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Setup-Cache-Only-DNS-in-CentOS-RHEL-7.png\" alt=\"Setup Cache-Only DNS in RHEL and CentOS 7\" width=\"720\" height=\"345\" aria-describedby=\"caption-attachment-18196\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-18196\" class=\"wp-caption-text\">RHCE Series: Setup Cache-Only DNS in RHEL and CentOS 7 \u2013 Part 11<\/p>\n<\/div>\n<p>The cache-only DNS server is also known as resolver, which will query DNS records and fetch all the DNS details from other servers, and keep each query request in its cache for later use so that when we perform the same request in the future, it will serve from its cache, thus reducing the response time even more.<\/p>\n<p>If you\u2019re looking to setup DNS Caching-Only Server in\u00a0<strong>CentOS\/RHEL 6<\/strong>, follow this guide here:<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/install-caching-only-dns-server-in-centos\/\" target=\"_blank\" rel=\"noopener\">Setting Up Caching-Only DNS Name Server in CentOS\/RHEL 6<\/a><\/p>\n<h4>My Testing Environment<\/h4>\n<pre>DNS server\t\t:\tdns.tecmintlocal.com (Red Hat Enterprise Linux 7.1)\r\nServer IP Address\t:\t192.168.0.18\r\nClient\t\t\t:\tnode1.tecmintlocal.com (CentOS 7.1)\r\nClient IP Address\t:\t192.168.0.29\r\n<\/pre>\n<h3>Step 1: Installing Cache-Only DNS Server in RHEL\/CentOS 7<\/h3>\n<p><strong>1.<\/strong>\u00a0The Cache-Only DNS server, can be installed via the bind package. If you don\u2019t remember the package name, you can do a quick search for the package name using the command below.<\/p>\n<pre># yum search bind\r\n<\/pre>\n<div id=\"attachment_18185\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Search-DNS-Bind-Package.png\" rel=\"attachment wp-att-18185\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18185\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Search-DNS-Bind-Package.png\" alt=\"Search DNS Bind Package\" width=\"747\" height=\"117\" aria-describedby=\"caption-attachment-18185\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-18185\" class=\"wp-caption-text\">Search DNS Bind Package<\/p>\n<\/div>\n<p><strong>2.<\/strong>\u00a0In the above result, you will see several packages. From those, we need to choose and install only\u00a0<strong>bind<\/strong>\u00a0and\u00a0<strong>bind-utils<\/strong>\u00a0packages using following yum command.<\/p>\n<pre># yum install bind bind-utils -y\r\n<\/pre>\n<div id=\"attachment_18186\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Install-DNS-Bind-in-CentOs-7.png\" rel=\"attachment wp-att-18186\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18186\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Install-DNS-Bind-in-CentOs-7.png\" alt=\"Install DNS Bind in RHEL\/CentOS 7\" width=\"536\" height=\"76\" aria-describedby=\"caption-attachment-18186\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-18186\" class=\"wp-caption-text\">Install DNS Bind in RHEL\/CentOS 7<\/p>\n<\/div>\n<h3>Step 2: Configure Cache-Only DNS in RHEL\/CentOS 7<\/h3>\n<p><strong>3.<\/strong>\u00a0Once DNS packages are installed we can go ahead and configure DNS. Open and edit\u00a0<code>\/etc\/named.conf<\/code>using your preferred text editor. Make the changes suggested below (or you can use your settings as per your requirements).<\/p>\n<pre>listen-on port 53 { 127.0.0.1; any; };\r\nallow-query     { localhost; any; };\r\nallow-query-cache       { localhost; any; };\r\n<\/pre>\n<div id=\"attachment_18187\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Configure-Cache-Only-DNS.png\" rel=\"attachment wp-att-18187\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18187\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Configure-Cache-Only-DNS.png\" alt=\"Configure Cache-Only DNS in CentOS and RHEL 7\" width=\"534\" height=\"357\" aria-describedby=\"caption-attachment-18187\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-18187\" class=\"wp-caption-text\">Configure Cache-Only DNS in CentOS and RHEL 7<\/p>\n<\/div>\n<p>These directives instruct the DNS server to listen on\u00a0<strong>UDP<\/strong>\u00a0port\u00a0<strong>53<\/strong>, and to allow queries and caches responses from\u00a0<strong>localhost<\/strong>\u00a0and any other machine that reaches the server.<\/p>\n<p><strong>4.<\/strong>\u00a0It is important to note that the ownership of this file must be set to\u00a0<code>root:named<\/code>\u00a0and also if\u00a0<strong>SELinux<\/strong>\u00a0is enabled, after editing the configuration file we need to make sure that its context is set to\u00a0<code>named_conf_t<\/code>\u00a0as shown in Fig. 4 (same thing for the auxiliary file\u00a0<code>\/etc\/named.rfc1912.zones<\/code>):<\/p>\n<pre># ls -lZ \/etc\/named.conf\r\n# ls -lZ \/etc\/named.rfc1912.zones\r\n<\/pre>\n<p>Otherwise, configure the SELinux context before proceeding:<\/p>\n<pre># semanage fcontext -a -t named_conf_t \/etc\/named.conf\r\n# semanage fcontext -a -t named_conf_t \/etc\/named.rfc1912.zones\r\n<\/pre>\n<p><strong>5.<\/strong>\u00a0Additionally, we need to test the DNS configuration now for some syntax error before starting the bind service:<\/p>\n<pre># named-checkconf \/etc\/named.conf\r\n<\/pre>\n<p><strong>6.<\/strong>\u00a0After the syntax verification results seems perfect, restart the\u00a0<strong>named<\/strong>\u00a0service to take new changes into effect and also make the service to auto start across system boots, and then check its status:<\/p>\n<pre># systemctl restart named\r\n# systemctl enable named\r\n# systemctl status named\r\n<\/pre>\n<div id=\"attachment_18188\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Configure-and-Start-DNS-Named-Service.png\" rel=\"attachment wp-att-18188\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18188\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Configure-and-Start-DNS-Named-Service.png\" sizes=\"auto, (max-width: 846px) 100vw, 846px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Configure-and-Start-DNS-Named-Service.png 846w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Configure-and-Start-DNS-Named-Service-768x241.png 768w\" alt=\"Configure and Start DNS Named Service\" width=\"846\" height=\"266\" aria-describedby=\"caption-attachment-18188\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-18188\" class=\"wp-caption-text\">Configure and Start DNS Named Service<\/p>\n<\/div>\n<p><strong>7.<\/strong>\u00a0Next, open the port\u00a053\u00a0on the firewall.<\/p>\n<pre># firewall-cmd --add-port=53\/udp\r\n# firewall-cmd --add-port=53\/udp --permanent\r\n<\/pre>\n<div id=\"attachment_18189\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Open-DNS-Port-53-on-Firewall.png\" rel=\"attachment wp-att-18189\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18189\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Open-DNS-Port-53-on-Firewall.png\" alt=\"Open DNS Port 53 on Firewall\" width=\"458\" height=\"73\" aria-describedby=\"caption-attachment-18189\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-18189\" class=\"wp-caption-text\">Open DNS Port 53 on Firewall<\/p>\n<\/div>\n<h3>Step 3: Chroot Cache-Only DNS Server in RHEL and CentOS 7<\/h3>\n<p><strong>8.<\/strong>\u00a0If you wish to deploy the Cache-only DNS server within\u00a0<strong>chroot<\/strong>\u00a0environment, you need to have the package\u00a0<strong>chroot<\/strong>\u00a0installed on the system and no further configuration is needed as it by default hard-link to chroot.<\/p>\n<pre># yum install bind-chroot -y\r\n<\/pre>\n<p>Once\u00a0<strong>chroot<\/strong>\u00a0package has been installed, you can restart named to take the new changes into effect:<\/p>\n<pre># systemctl restart named\r\n<\/pre>\n<p><strong>9.<\/strong>\u00a0Next, create a symbolic link (also named\u00a0<code>\/etc\/named.conf<\/code>) inside\u00a0<code>\/var\/named\/chroot\/etc\/<\/code>:<\/p>\n<pre># ln -s \/etc\/named.conf \/var\/named\/chroot\/etc\/named.conf\r\n<\/pre>\n<h3>Step 4: Configure DNS on Client Machine<\/h3>\n<p><strong>10.<\/strong>\u00a0Add the DNS Cache servers\u00a0<strong>IP 192.168.0.18<\/strong>\u00a0as resolver to the client machine. Edit\u00a0<code>\/etc\/sysconfig\/network-scripts\/ifcfg-enp0s3<\/code>\u00a0as shown in the following figure:<\/p>\n<pre>DNS=192.168.0.18\r\n<\/pre>\n<div id=\"attachment_18190\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Configure-DNS-on-Client-Machine.png\" rel=\"attachment wp-att-18190\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18190\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Configure-DNS-on-Client-Machine.png\" alt=\"Configure DNS on Client Machine\" width=\"339\" height=\"360\" aria-describedby=\"caption-attachment-18190\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-18190\" class=\"wp-caption-text\">Configure DNS on Client Machine<\/p>\n<\/div>\n<p>And\u00a0<strong>\/etc\/resolv.conf<\/strong>\u00a0as follows:<\/p>\n<pre>nameserver 192.168.0.18\r\n<\/pre>\n<p><strong>11.<\/strong>\u00a0Finally it\u2019s time to check our cache server. To do this, you can use\u00a0<a href=\"https:\/\/www.tecmint.com\/10-linux-dig-domain-information-groper-commands-to-query-dns\/\" target=\"_blank\" rel=\"noopener\">dig utility<\/a>\u00a0or\u00a0<a href=\"https:\/\/www.tecmint.com\/8-linux-nslookup-commands-to-troubleshoot-dns-domain-name-server\/\" target=\"_blank\" rel=\"noopener\">nslookup command<\/a>.<\/p>\n<p>Choose any website and query it twice (we will use\u00a0<strong>facebook.com<\/strong>\u00a0as an example). Note that with dig the second time the query is completed much faster because it is being served from the cache.<\/p>\n<pre># dig facebook.com\r\n<\/pre>\n<div id=\"attachment_18191\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Check-Cache-only-DNS-Queries.png\" rel=\"attachment wp-att-18191\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18191\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Check-Cache-only-DNS-Queries.png\" sizes=\"auto, (max-width: 864px) 100vw, 864px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Check-Cache-only-DNS-Queries.png 864w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Check-Cache-only-DNS-Queries-768x438.png 768w\" alt=\"Check Cache only DNS Queries\" width=\"864\" height=\"493\" aria-describedby=\"caption-attachment-18191\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-18191\" class=\"wp-caption-text\">Check Cache only DNS Queries<\/p>\n<\/div>\n<p>You can also use\u00a0<strong>nslookup<\/strong>\u00a0to verify that the DNS server is working as expected.<\/p>\n<pre># nslookup facebook.com\r\n<\/pre>\n<div id=\"attachment_18192\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Checking-DNS-Query-with-nslookup.png\" rel=\"attachment wp-att-18192\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18192\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Checking-DNS-Query-with-nslookup.png\" alt=\"Checking DNS Query with nslookup\" width=\"303\" height=\"159\" aria-describedby=\"caption-attachment-18192\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-18192\" class=\"wp-caption-text\">Checking DNS Query with nslookup<\/p>\n<\/div>\n<h3>Summary<\/h3>\n<p>In this article we have explained how to set up a DNS Cache-only server in\u00a0<strong>Red Hat Enterprise Linux 7<\/strong>\u00a0and\u00a0<strong>CentOS 7<\/strong>, and tested it in a client machine. Feel free to let us know if you have any questions or suggestions using the form below.<\/p>\n<h1 class=\"post-title\">How to Setup and Configure Network Bonding or Teaming in RHEL\/CentOS 7 \u2013 Part 11<\/h1>\n<p>When a system administrator wants to increase the bandwidth available and provide redundancy and load balancing for data transfers, a kernel feature known as network\u00a0<strong>bonding<\/strong>\u00a0allows to get the job done in a cost-effective way.<\/p>\n<p>Read more about how to increase or bandwidth throttling in Linux<\/p>\n<div class=\"SandboxRoot env-bp-350\" data-twitter-event-id=\"0\">\n<div id=\"twitter-widget-0\" class=\"EmbeddedTweet EmbeddedTweet--cta EmbeddedTweet--mediaForward media-forward js-clickToOpenTarget js-tweetIdInfo tweet-InformationCircle-widgetParent\" lang=\"en\" data-click-to-open-target=\"https:\/\/twitter.com\/tecmint\/status\/644355842305687552\" data-iframe-title=\"Twitter Tweet\" data-scribe=\"page:tweet\" data-tweet-id=\"644355842305687552\" data-twitter-event-id=\"1\">\n<article class=\"MediaCard MediaCard--mediaForward customisable-border\" dir=\"ltr\" data-scribe=\"component:card\">\n<div class=\"MediaCard-media\" data-scribe=\"element:photo\">\n<div class=\"MediaCard-widthConstraint js-cspForcedStyle\" data-style=\"max-width: 720px\">\n<div class=\"MediaCard-mediaContainer js-cspForcedStyle\" data-style=\"padding-bottom: 47.9167%\"><a class=\"MediaCard-mediaAsset NaturalImage\" href=\"https:\/\/twitter.com\/tecmint\/status\/644355842305687552\/photo\/1\"><img loading=\"lazy\" decoding=\"async\" class=\"NaturalImage-image\" title=\"View image on Twitter\" src=\"https:\/\/pbs.twimg.com\/media\/CPE2OK3UYAI5eoz?format=jpg&amp;name=small\" alt=\"View image on Twitter\" width=\"720\" height=\"345\" data-image=\"https:\/\/pbs.twimg.com\/media\/CPE2OK3UYAI5eoz\" \/><\/a><\/div>\n<\/div>\n<\/div>\n<\/article>\n<div data-scribe=\"element:notice\"><\/div>\n<\/div>\n<\/div>\n<p>In simple words, bonding means aggregating two or more physical network interfaces (called slaves) into a single, logical one (called master). If a specific NIC (Network Interface Card) experiences a problem, communications are not affected significantly as long as the other(s) remain active.<\/p>\n<p>Read more about network bonding in Linux systems here:<\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/ethernet-channel-bonding-aka-nic-teaming-on-linux-systems\/\" target=\"_blank\" rel=\"noopener\">Network Teaming or NiC Bondin in RHEL\/CentOS 6\/5<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/network-nic-bonding-teaming-in-debian-linux\/\" target=\"_blank\" rel=\"noopener\">Network NIC Bonding or Teaming on Debian based Systems<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/configure-network-bonding-teaming-in-ubuntu\/\" target=\"_blank\" rel=\"noopener\">How to Configure Network Bonding or Teaming in Ubuntu<\/a><\/li>\n<\/ol>\n<h3>Enabling and Configuring Network Bonding or Teaming<\/h3>\n<p>By default, the bonding kernel module is not enabled. Thus, we will need to load it and ensure it is persistent across boots. When used with the\u00a0<code>--first-time<\/code>\u00a0option,\u00a0<strong>modprobe<\/strong>\u00a0will alert us if loading the module fails:<\/p>\n<pre># modprobe --first-time bonding\r\n<\/pre>\n<p>The above command will load the bonding module for the current session. In order to ensure persistency, create a\u00a0<code>.conf<\/code>\u00a0file inside\u00a0<code>\/etc\/modules-load.d<\/code>\u00a0with a descriptive name, such as\u00a0<code>\/etc\/modules-load.d\/bonding.conf<\/code>:<\/p>\n<pre># echo \"# Load the bonding kernel module at boot\" &gt; \/etc\/modules-load.d\/bonding.conf\r\n# echo \"bonding\" &gt;&gt; \/etc\/modules-load.d\/bonding.conf\r\n<\/pre>\n<p>Now reboot your server and once it restarts, make sure the bonding module is loaded automatically, as seen in\u00a0<strong>Fig. 1<\/strong>:<\/p>\n<div id=\"attachment_18741\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Check-Network-Bonding-Module.png\" rel=\"attachment wp-att-18741\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18741\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Check-Network-Bonding-Module.png\" alt=\"Check Network Bonding Module Loaded in Kernel\" width=\"280\" height=\"58\" aria-describedby=\"caption-attachment-18741\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-18741\" class=\"wp-caption-text\">Check Network Bonding Module Loaded in Kernel<\/p>\n<\/div>\n<p>In this article we will use 3 interfaces (<code>enp0s3<\/code>,\u00a0<code>enp0s8<\/code>, and\u00a0<code>enp0s9<\/code>) to create a bond, named conveniently\u00a0<code>bond0<\/code>.<\/p>\n<p>To create\u00a0<code>bond0<\/code>, we can either use\u00a0<strong>nmtui<\/strong>, the text interface for controlling\u00a0<strong>NetworkManager<\/strong>. When invoked without arguments from the command line,\u00a0<strong>nmtui<\/strong>\u00a0brings up a text interface that allows you to edit an existing connection, activate a connection, or set the system hostname.<\/p>\n<p>Choose\u00a0<strong>Edit connection<\/strong>\u00a0\u2013&gt;\u00a0<strong>Add<\/strong>\u00a0\u2013&gt;\u00a0<strong>Bond<\/strong>\u00a0as illustrated in\u00a0<strong>Fig. 2<\/strong>:<\/p>\n<div id=\"attachment_18742\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Create-Network-Bonding.png\" rel=\"attachment wp-att-18742\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18742\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Create-Network-Bonding.png\" alt=\"Create Network Bonding Channel\" width=\"677\" height=\"251\" aria-describedby=\"caption-attachment-18742\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-18742\" class=\"wp-caption-text\">Create Network Bonding Channel<\/p>\n<\/div>\n<p>In the\u00a0<strong>Edit Connection<\/strong>\u00a0screen, add the slave interfaces (<code>enp0s3<\/code>,\u00a0<code>enp0s8<\/code>, and\u00a0<code>enp0s9<\/code>\u00a0in our case) and give them a descriptive (Profile) name (for example,\u00a0<code>NIC #1<\/code>,\u00a0<code>NIC #2<\/code>, and\u00a0<code>NIC #3<\/code>, respectively).<\/p>\n<p>In addition, you will need to set a name and device for the bond (<code>TecmintBond<\/code>\u00a0and\u00a0<code>bond0<\/code>\u00a0in Fig. 3, respectively) and an IP address for\u00a0<code>bond0<\/code>, enter a gateway address, and the IPs of DNS servers.<\/p>\n<p><strong>Note<\/strong>\u00a0that you do not need to enter the MAC address of each interface since\u00a0<strong>nmtui<\/strong>\u00a0will do that for you. You can leave all other settings as default. See Fig. 3 for more details.<\/p>\n<div id=\"attachment_18743\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Network-Bonding-Teaming-Configuration.png\" rel=\"attachment wp-att-18743\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18743\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Network-Bonding-Teaming-Configuration.png\" alt=\"Network Bonding Teaming Configuration\" width=\"538\" height=\"554\" aria-describedby=\"caption-attachment-18743\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-18743\" class=\"wp-caption-text\">Network Bonding Teaming Configuration<\/p>\n<\/div>\n<p>When you\u2019re done, go to the bottom of the screen and choose\u00a0<strong>OK<\/strong>\u00a0(see Fig. 4):<\/p>\n<div id=\"attachment_18744\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Configuration-of-bond0.png\" rel=\"attachment wp-att-18744\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18744\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Configuration-of-bond0.png\" alt=\"Configuration of bond0\" width=\"394\" height=\"288\" aria-describedby=\"caption-attachment-18744\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-18744\" class=\"wp-caption-text\">Configuration of bond0<\/p>\n<\/div>\n<p>And you\u2019re done. Now you can exit the text interface and return to the command line, where you will enable the newly created interface using\u00a0<a href=\"https:\/\/www.tecmint.com\/ip-command-examples\/\" target=\"_blank\" rel=\"noopener\">ip command<\/a>:<\/p>\n<pre># ip link set dev bond0 up\r\n<\/pre>\n<p>After that, you can see that\u00a0<code>bond0<\/code>\u00a0is UP and is assigned\u00a0<strong>192.168.0.200<\/strong>, as seen in Fig. 5:<\/p>\n<pre># ip addr show bond0\r\n<\/pre>\n<div id=\"attachment_18745\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Check-Network-Bond-Interface.png\" rel=\"attachment wp-att-18745\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18745\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Check-Network-Bond-Interface.png\" alt=\"Check Network Bond Interface Status\" width=\"609\" height=\"131\" aria-describedby=\"caption-attachment-18745\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-18745\" class=\"wp-caption-text\">Check Network Bond Interface Status<\/p>\n<\/div>\n<h3>Testing Network Bonding or Teaming in Linux<\/h3>\n<p>To verify that\u00a0<code>bond0<\/code>\u00a0actually works, you can either ping its IP address from another machine, or what\u2019s even better, watch the kernel interface table in real time (well, the refresh time in seconds is given by the\u00a0<code>-n<\/code>\u00a0option) to see how network traffic is distributed between the three network interfaces, as shown in Fig. 6.<\/p>\n<p>The\u00a0<code>-d<\/code>\u00a0option is used to highlight changes when they occur:<\/p>\n<pre># watch -d -n1 netstat -i\r\n<\/pre>\n<div id=\"attachment_18746\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Check-Kernel-Interface-Table.png\" rel=\"attachment wp-att-18746\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18746\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Check-Kernel-Interface-Table.png\" alt=\"Check Kernel Interface Table\" width=\"603\" height=\"162\" aria-describedby=\"caption-attachment-18746\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-18746\" class=\"wp-caption-text\">Check Kernel Interface Table<\/p>\n<\/div>\n<p>It is important to note that there are several bonding modes, each with its distinguishing characteristics. They are documented in section 4.5 of the\u00a0<a href=\"https:\/\/access.redhat.com\/documentation\/en-US\/Red_Hat_Enterprise_Linux\/7\/html\/Networking_Guide\/sec-Using_Channel_Bonding.html#s3-modules-bonding-directives\" target=\"_blank\" rel=\"noopener\">Red Hat Enterprise Linux 7 Network Administration<\/a>\u00a0guide. Depending on your needs, you will choose one or the other.<\/p>\n<p>In our current setup, we chose the\u00a0<strong>Round-robin<\/strong>\u00a0mode (see Fig. 3), which ensures packets are transmitted beginning with the first slave in sequential order, ending with the last slave, and starting with the first again.<\/p>\n<p>The Round-robin alternative is also called\u00a0<code>mode 0<\/code>, and provides load balancing and fault tolerance. To change the bonding mode, you can use\u00a0<strong>nmtui<\/strong>\u00a0as explained before (see also Fig. 7):<\/p>\n<div id=\"attachment_18747\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Changing-Bonding-Mode-Using-nmtui.png\" rel=\"attachment wp-att-18747\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18747\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Changing-Bonding-Mode-Using-nmtui.png\" alt=\"Changing Bonding Mode Using nmtui\" width=\"484\" height=\"160\" aria-describedby=\"caption-attachment-18747\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-18747\" class=\"wp-caption-text\">Changing Bonding Mode Using nmtui<\/p>\n<\/div>\n<p>If we change it to\u00a0<strong>Active Backup<\/strong>, we will be prompted to choose a slave that will the only one active interface at a given time. If such card fails, one of the remaining slaves will take its place and becomes active.<\/p>\n<p>Let\u2019s choose\u00a0<code>enp0s3<\/code>\u00a0to be the primary slave, bring\u00a0<code>bond0<\/code>\u00a0down and up again, restart the network, and display the kernel interface table (see Fig. 8).<\/p>\n<p>Note how data transfers (<strong>TX-OK<\/strong>\u00a0and\u00a0<strong>RX-OK<\/strong>) are now being made over\u00a0<code>enp0s3<\/code>\u00a0only:<\/p>\n<pre># ip link set dev bond0 down\r\n# ip link set dev bond0 up\r\n# systemctl restart network\r\n<\/pre>\n<div id=\"attachment_18749\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Bond-Acting-in-Active-Backup-Mode.png\" rel=\"attachment wp-att-18749\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18749\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Bond-Acting-in-Active-Backup-Mode.png\" alt=\"Bond Acting in Active Backup Mode\" width=\"595\" height=\"319\" aria-describedby=\"caption-attachment-18749\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-18749\" class=\"wp-caption-text\">Bond Acting in Active Backup Mode<\/p>\n<\/div>\n<p>Alternatively, you can view the bond as the kernel sees it (see Fig. 9):<\/p>\n<pre># cat \/proc\/net\/bonding\/bond0\r\n<\/pre>\n<div id=\"attachment_18750\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Check-Network-Bond-as-Kernel.png\" rel=\"attachment wp-att-18750\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18750\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Check-Network-Bond-as-Kernel.png\" alt=\"Check Network Bond as Kernel\" width=\"420\" height=\"557\" aria-describedby=\"caption-attachment-18750\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-18750\" class=\"wp-caption-text\">Check Network Bond as Kernel<\/p>\n<\/div>\n<h3>Summary<\/h3>\n<p>In this chapter we have discussed how to set up and configure bonding in\u00a0<strong>Red Hat Enterprise Linux 7<\/strong>\u00a0(also works on\u00a0<strong>CentOS 7<\/strong>\u00a0and\u00a0<strong>Fedora 22+<\/strong>) in order to increase bandwidth along with load balancing and redundancy for data transfers.<\/p>\n<p>As you take the time to explore other bonding modes, you will come to master the concepts and practice related with this topic of the certification.<\/p>\n<p>If you have questions about this article, or suggestions to share with the rest of the community, feel free to let us know using the comment form below.<\/p>\n<h1 class=\"post-title\">Create Centralized Secure Storage using iSCSI Target \/ Initiator on RHEL\/CentOS 7 \u2013 Part 12<\/h1>\n<p><strong>iSCSI<\/strong>\u00a0is a block level Protocol for managing storage devices over TCP\/IP Networks, specially over long distances. iSCSI target is a remote hard disk presented from an remote iSCSI server (or) target. On the other hand, the iSCSI client is called the\u00a0<strong>Initiator<\/strong>, and will access the storage that is shared in the\u00a0<strong>Target<\/strong>\u00a0machine.<\/p>\n<p>The following machines have been used in this article:<\/p>\n<h4>Server (Target):<\/h4>\n<pre><strong>Operating System<\/strong> \u2013 Red Hat Enterprise Linux 7\r\n<strong>iSCSI Target IP<\/strong> \u2013 192.168.0.29\r\n<strong>Ports Used<\/strong> : TCP 860, 3260\r\n<\/pre>\n<h4>Client (Initiator):<\/h4>\n<pre><strong>Operating System<\/strong> \u2013 Red Hat Enterprise Linux 7\r\n<strong>iSCSI Target IP<\/strong> \u2013 192.168.0.30\r\n<strong>Ports Used<\/strong> : TCP 3260\r\n<\/pre>\n<h3>Step 1: Installing Packages on iSCSI Target<\/h3>\n<p>To install the packages needed for the target (we will deal with the client later), do:<\/p>\n<pre># yum install targetcli -y\r\n<\/pre>\n<p>When the installation completes, we will start and enable the service as follows:<\/p>\n<pre># systemctl start target\r\n# systemctl enable target\r\n<\/pre>\n<p>Finally, we need to allow the service in firewalld:<\/p>\n<pre># firewall-cmd --add-service=iscsi-target\r\n# firewall-cmd --add-service=iscsi-target --permanent\r\n<\/pre>\n<p>And last but not least, we must not forget to allow the iSCSI target discovery:<\/p>\n<pre># firewall-cmd --add-port=860\/tcp\r\n# firewall-cmd --add-port=860\/tcp --permanent\r\n# firewall-cmd --reload\r\n<\/pre>\n<h3>Step 2: Defining LUNs in Target Server<\/h3>\n<p>Before proceeding to defining\u00a0<strong>LUNs<\/strong>\u00a0in the\u00a0<strong>Target<\/strong>, we need to create two logical volumes as explained in Part 6 of\u00a0<strong>RHCSA<\/strong>\u00a0series (\u201c<a href=\"https:\/\/www.tecmint.com\/rhcsa-exam-create-format-resize-delete-and-encrypt-partitions-in-linux\/\" target=\"_blank\" rel=\"noopener\">Configuring system storage<\/a>\u201d).<\/p>\n<p>This time we will name them\u00a0<code>vol_projects<\/code>\u00a0and\u00a0<code>vol_backups<\/code>\u00a0and place them inside a volume group called\u00a0<code>vg00<\/code>, as shown in Fig. 1. Feel free to choose the space allocated to each LV:<\/p>\n<div id=\"attachment_19401\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/03\/Create-Two-Logical-Volumes.png\" rel=\"attachment wp-att-19401\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-19401\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/03\/Create-Two-Logical-Volumes.png\" alt=\"Two Logical Volumes Named vol_projects and vol_backups\" width=\"519\" height=\"620\" aria-describedby=\"caption-attachment-19401\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-19401\" class=\"wp-caption-text\">Fig 1: Two Logical Volumes Named vol_projects and vol_backups<\/p>\n<\/div>\n<p>After creating the\u00a0<strong>LVs<\/strong>, we are ready to define the\u00a0<strong>LUNs<\/strong>\u00a0in the\u00a0<strong>Target<\/strong>\u00a0in order to make them available for the client machine.<\/p>\n<p>As shown in\u00a0<strong>Fig. 2<\/strong>, we will open a\u00a0<code>targetcli<\/code>\u00a0shell and issue the following commands, which will create two block backstores (local storage resources that represent the LUN the initiator will actually use) and an\u00a0<strong>Iscsi Qualified Name<\/strong>\u00a0(<strong>IQN<\/strong>), a method of addressing the target server.<\/p>\n<p>Please refer to\u00a0<a href=\"https:\/\/tools.ietf.org\/html\/rfc3720#page-32\" target=\"_blank\" rel=\"nofollow noopener\">Page 32 of RFC 3720<\/a>\u00a0for more details on the structure of the IQN. In particular, the text after the colon character\u00a0<code>(:tgt1)<\/code>\u00a0specifies the name of the target, while the text before\u00a0<code>(server:)<\/code>\u00a0indicates the hostname of the target inside the domain.<\/p>\n<pre># targetcli\r\n# cd backstores\r\n# cd block\r\n# create server.backups \/dev\/vg00\/vol_backups\r\n# create server.projects \/dev\/vg00\/vol_projects\r\n# cd \/iscsi\r\n# create iqn.2016-02.com.tecmint.server:tgt1\r\n<\/pre>\n<div id=\"attachment_19402\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/03\/Define-LUNs-in-Target-Server.png\" rel=\"attachment wp-att-19402\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-19402\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/03\/Define-LUNs-in-Target-Server.png\" alt=\"Define LUNs in Target Server\" width=\"608\" height=\"321\" aria-describedby=\"caption-attachment-19402\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-19402\" class=\"wp-caption-text\">Fig 2: Define LUNs in Target Server<\/p>\n<\/div>\n<p>With the above step, a new\u00a0<strong>TPG<\/strong>\u00a0(<strong>Target Portal Group<\/strong>) was created along with the default portal (a pair consisting of an IP address and a port which is the way initiators can reach the target) listening on port\u00a0<strong>3260<\/strong>\u00a0of all IP addresses.<\/p>\n<p>If you want to bind your portal to a specific IP (the Target\u2019s main IP, for example), delete the default portal and create a new one as follows (otherwise, skip the following\u00a0<strong>targetcli<\/strong>\u00a0commands.\u00a0<strong>Note that for simplicity we have skipped them as well<\/strong>):<\/p>\n<pre># cd \/iscsi\/iqn.2016-02.com.tecmint.server:tgt1\/tpg1\/portals\r\n# delete 0.0.0.0 3260\r\n# create 192.168.0.29 3260\r\n<\/pre>\n<p>Now we are ready to proceed with the creation of LUNs. Note that we are using the backstores we previously created (<code>server.backups<\/code>\u00a0and\u00a0<code>server.projects<\/code>). This process is illustrated in Fig. 3:<\/p>\n<pre># cd iqn.2016-02.com.tecmint.server:tgt1\/tpg1\/luns\r\n# create \/backstores\/block\/server.backups\r\n# create \/backstores\/block\/server.projects\r\n<\/pre>\n<div id=\"attachment_19403\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/03\/Create-LUNs-in-iSCSI-Target-Server.png\" rel=\"attachment wp-att-19403\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-19403\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/03\/Create-LUNs-in-iSCSI-Target-Server.png\" alt=\"Create LUNs in iSCSI Target Server\" width=\"577\" height=\"113\" aria-describedby=\"caption-attachment-19403\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-19403\" class=\"wp-caption-text\">Fig 3: Create LUNs in iSCSI Target Server<\/p>\n<\/div>\n<p>The last part in the Target configuration consists of creating an\u00a0<a href=\"https:\/\/www.tecmint.com\/secure-files-using-acls-in-linux\/\" target=\"_blank\" rel=\"noopener\">Access Control List to restrict access<\/a>\u00a0on a per-initiator basis. Since our client machine is named\u00a0<strong>\u201cclient\u201d<\/strong>, we will append that text to the IQN. Refer to\u00a0<strong>Fig. 4<\/strong>\u00a0for details:<\/p>\n<pre># cd ..\/acls\r\n# create iqn.2016-02.com.tecmint.server:client\r\n<\/pre>\n<div id=\"attachment_19404\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/03\/Create-Access-Control-List-for-Initiator.png\" rel=\"attachment wp-att-19404\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-19404\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/03\/Create-Access-Control-List-for-Initiator.png\" alt=\"Create Access Control List for Initiator\" width=\"609\" height=\"89\" aria-describedby=\"caption-attachment-19404\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-19404\" class=\"wp-caption-text\">Fig 4: Create Access Control List for Initiator<\/p>\n<\/div>\n<p>At this point we can the\u00a0<strong>targetcli<\/strong>\u00a0shell to show all configured resources, as we can see in\u00a0<strong>Fig. 5<\/strong>:<\/p>\n<pre># targetcli\r\n# cd \/\r\n# ls\r\n<\/pre>\n<div id=\"attachment_19405\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/03\/Check-LUNs-Configured.png\" rel=\"attachment wp-att-19405\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-19405\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/03\/Check-LUNs-Configured.png\" sizes=\"auto, (max-width: 1068px) 100vw, 1068px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/03\/Check-LUNs-Configured.png 1068w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/03\/Check-LUNs-Configured-768x361.png 768w\" alt=\"User targetcli to Check Configured Resources\" width=\"1068\" height=\"502\" aria-describedby=\"caption-attachment-19405\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-19405\" class=\"wp-caption-text\">Fig 5: User targetcli to Check Configured Resources<\/p>\n<\/div>\n<p>To quit the\u00a0<strong>targetcli<\/strong>\u00a0shell, simply type\u00a0<strong>exit<\/strong>\u00a0and press\u00a0<strong>Enter<\/strong>. The configuration will be saved automatically to\u00a0<strong>\/etc\/target\/saveconfig.json<\/strong>.<\/p>\n<p>As you can see in\u00a0<strong>Fig. 5<\/strong>\u00a0above, we have a portal listening on port\u00a0<strong>3260<\/strong>\u00a0of all IP addresses as expected. We can verify that using\u00a0<a href=\"https:\/\/www.tecmint.com\/20-netstat-commands-for-linux-network-management\/\" target=\"_blank\" rel=\"noopener\">netstat command<\/a>\u00a0(see\u00a0<strong>Fig. 6<\/strong>):<\/p>\n<pre># netstat -npltu | grep 3260\r\n<\/pre>\n<div id=\"attachment_19406\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/03\/Verify-iSCSI-Target-Server-Port.png\" rel=\"attachment wp-att-19406\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-19406\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/03\/Verify-iSCSI-Target-Server-Port.png\" alt=\"Verify iSCSI Target Server Port Listening\" width=\"659\" height=\"56\" aria-describedby=\"caption-attachment-19406\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-19406\" class=\"wp-caption-text\">Fig 6: Verify iSCSI Target Server Port Listening<\/p>\n<\/div>\n<p>This concludes the\u00a0<strong>Target<\/strong>\u00a0configuration. Feel free to restart the system and verify that all settings survive a reboot. If not, make sure to open the necessary ports in the firewall configuration and to start the target service on boot. We are now ready to set up the Initiator and to connect to the client.<\/p>\n<h3>Step 3: Setting up the Client Initiator<\/h3>\n<p>In the client we will need to install the\u00a0<strong>iscsi-initiator-utils<\/strong>\u00a0package, which provides the server daemon for the iSCSI protocol (<strong>iscsid<\/strong>) as well as\u00a0<strong>iscsiadm<\/strong>, the administration utility:<\/p>\n<pre># yum update &amp;&amp; yum install iscsi-initiator-utils\r\n<\/pre>\n<p>Once the installation completes, open\u00a0<strong>\/etc\/iscsi\/initiatorname.iscsi<\/strong>\u00a0and replace the default initiator name (commented in\u00a0<strong>Fig. 7<\/strong>) with the name that was previously set in the\u00a0<strong>ACL<\/strong>\u00a0on the server (<strong>iqn.2016-02.com.tecmint.server:client<\/strong>).<\/p>\n<p>Then save the file and run\u00a0<strong>iscsiadm<\/strong>\u00a0in discovery mode pointing to the target. If successful, this command will return the target information as shown in\u00a0<strong>Fig. 7<\/strong>:<\/p>\n<pre># iscsiadm -m discovery -t st -p 192.168.0.29\r\n<\/pre>\n<div id=\"attachment_19407\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/03\/Setting-Up-Client-Initiator.png\" rel=\"attachment wp-att-19407\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-19407\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/03\/Setting-Up-Client-Initiator.png\" alt=\"Setting Up Client Initiator\" width=\"640\" height=\"142\" aria-describedby=\"caption-attachment-19407\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-19407\" class=\"wp-caption-text\">Fig 7: Setting Up Client Initiator<\/p>\n<\/div>\n<p>The next step consists in restarting and enabling the\u00a0<strong>iscsid<\/strong>\u00a0service:<\/p>\n<pre># systemctl start iscsid\r\n# systemctl enable iscsid\r\n<\/pre>\n<p>and contacting the target in node mode. This should result in\u00a0<strong>kernel-level<\/strong>\u00a0messages, which when captured through\u00a0<strong>dmesg show<\/strong>\u00a0the device identification that the remote LUNs have been given in the local system (<strong>sde<\/strong>and\u00a0<strong>sdf<\/strong>\u00a0in\u00a0<strong>Fig. 8<\/strong>):<\/p>\n<pre># iscsiadm -m node -T iqn.2016-02.com.tecmint.server:tgt1 -p 192.168.0.29 -l\r\n# dmesg | tail\r\n<\/pre>\n<div id=\"attachment_19408\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/03\/Connecting-to-iSCSCI-Target-Server-in-Node-Mode.png\" rel=\"attachment wp-att-19408\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-19408\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/03\/Connecting-to-iSCSCI-Target-Server-in-Node-Mode.png\" alt=\"Connecting to iSCSCI Target Server in Node Mode\" width=\"739\" height=\"280\" aria-describedby=\"caption-attachment-19408\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-19408\" class=\"wp-caption-text\">Fig 8: Connecting to iSCSCI Target Server in Node Mode<\/p>\n<\/div>\n<p>From this point on, you can create partitions, or even LVs (and filesystems on top of them) as you would do with any other storage device. For simplicity, we will create a primary partition on each disk that will occupy its entire available space, and format it with ext4.<\/p>\n<p>Finally, let\u2019s mount\u00a0<strong>\/dev\/sde1<\/strong>\u00a0and\u00a0<strong>\/dev\/sdf1<\/strong>\u00a0on\u00a0<strong>\/projects<\/strong>\u00a0and\u00a0<strong>\/backups<\/strong>, respectively (note that these directories must be created first):<\/p>\n<pre># mount \/dev\/sde1 \/projects\r\n# mount \/dev\/sdf1 \/backups\r\n<\/pre>\n<p>Additionally, you can add two entries in\u00a0<strong>\/etc\/fstab<\/strong>\u00a0in order for both filesystems to be mounted automatically at boot using each filesystem\u2019s\u00a0<strong>UUID<\/strong>\u00a0as returned by\u00a0<strong>blkid<\/strong>.<\/p>\n<p><strong>Note<\/strong>\u00a0that the\u00a0<strong>_netdev<\/strong>\u00a0mount option must be used in order to defer the mounting of these filesystems until the network service has been started:<\/p>\n<div id=\"attachment_19409\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/03\/Find-Filesystem-UUID.png\" rel=\"attachment wp-att-19409\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-19409\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/03\/Find-Filesystem-UUID.png\" alt=\"Find Filesystem UUID\" width=\"642\" height=\"200\" aria-describedby=\"caption-attachment-19409\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-19409\" class=\"wp-caption-text\">Fig 9: Find Filesystem UUID<\/p>\n<\/div>\n<p>You can now use these devices as you would with any other storage media.<\/p>\n<h3>Summary<\/h3>\n<p>In this article we have covered how to set up and configure an iSCSI Target and an Initiator in\u00a0<strong>RHEL\/CentOS 7<\/strong>disitributions. Although the first task is not part of the required competencies of the\u00a0<strong>EX300 (RHCE)<\/strong>\u00a0exam, it is needed in order to implement the second topic.<\/p>\n<p>Don\u2019t hesitate to let us know if you have any questions or comments about this article \u2013 feel free to drop us a line using the comment form below.<\/p>\n<p>Looking to setup iSCSI Target and Client Initiator on RHEL\/CentOS 6, follow this guide:\u00a0<a href=\"https:\/\/www.tecmint.com\/iscsi-initiator-client-setup\/\" target=\"_blank\" rel=\"noopener\">Setting Up Centralized iSCSI Storage with Client Initiator<\/a>.<\/p>\n<h1 class=\"post-title\">Setting Up \u201cNTP (Network Time Protocol) Server\u201d in RHEL\/CentOS 7<\/h1>\n<p><b>Network Time Protocol<\/b>\u00a0\u2013 NTP- is a protocol which runs over port 123 UDP at Transport Layer and allows computers to synchronize time over networks for an accurate time. While time is passing by, computers internal clocks tend to drift which can lead to inconsistent time issues, especially on servers and clients logs files or if you want to replicate servers resources or databases.<\/p>\n<div id=\"attachment_9009\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/NTP-Server-Install-in-CentOS.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-9009\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/NTP-Server-Install-in-CentOS.png\" alt=\"NTP Server Install in CentOS\" width=\"600\" height=\"400\" aria-describedby=\"caption-attachment-9009\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-9009\" class=\"wp-caption-text\">NTP Server Installation in CentOS and RHEL 7<\/p>\n<\/div>\n<h4>Requirements:<\/h4>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/centos-7-installation\/\" target=\"_blank\" rel=\"noopener\">CentOS 7 Installation Procedure<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/redhat-enterprise-linux-7-installation\/\" target=\"_blank\" rel=\"noopener\">RHEL 7 Installation Procedure<\/a><\/li>\n<\/ol>\n<h4>Additional Requirements:<\/h4>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/enable-redhat-subscription-reposiories-and-updates-for-rhel-7\/\" target=\"_blank\" rel=\"noopener\">Register and Enbale RHEL 7 Subscription for Updates<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/configure-network-interface-in-rhel-centos-7-0\/\" target=\"_blank\" rel=\"noopener\">Configure Static IP Address on CentOS\/Rhel 7<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/remove-unwanted-services-in-centos-7\/\" target=\"_blank\" rel=\"noopener\">Disable and Remove Unwanted Services in CentOS\/RHEL 7<\/a><\/li>\n<\/ol>\n<p>This tutorial will demonstrate how you can install and configure\u00a0<strong>NTP<\/strong>\u00a0server on\u00a0<strong>CentOS<\/strong>\/<strong>RHEL 7<\/strong>\u00a0and automatically synchronize time with the closest geographically peers available for your server location by using NTP Public Pool Time Servers list.<\/p>\n<h3>Step 1: Install and configure NTP daemon<\/h3>\n<p><strong>1.<\/strong>\u00a0NTP server package is provided by default from official\u00a0<strong>CentOS<\/strong>\u00a0\/<strong>RHEL 7<\/strong>\u00a0repositories and can be installed by issuing the following command.<\/p>\n<pre># yum install ntp\r\n<\/pre>\n<div id=\"attachment_8998\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/Install-NTP-in-CentOS.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-8998\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/Install-NTP-in-CentOS-620x372.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/Install-NTP-in-CentOS-620x372.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/Install-NTP-in-CentOS-1024x614.png 1024w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/Install-NTP-in-CentOS.png 1280w\" alt=\"Install NTP in CentOS\" width=\"620\" height=\"372\" aria-describedby=\"caption-attachment-8998\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-8998\" class=\"wp-caption-text\">Install NTP Server<\/p>\n<\/div>\n<p><strong>2.<\/strong>\u00a0After the server is installed, first go to official\u00a0<a href=\"http:\/\/www.pool.ntp.org\/en\/\" target=\"_blank\" rel=\"nofollow noopener\">NTP Public Pool Time Servers<\/a>, choose your\u00a0<b>Continent<\/b>\u00a0area where the server physically is located, then search for your\u00a0<b>Country<\/b>\u00a0location and a list of NTP servers should appear.<\/p>\n<div id=\"attachment_9000\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/NTP-Pool-Server.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-9000\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/NTP-Pool-Server-620x352.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/NTP-Pool-Server-620x352.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/NTP-Pool-Server-1024x583.png 1024w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/NTP-Pool-Server.png 1096w\" alt=\"NTP Pool Server\" width=\"620\" height=\"352\" aria-describedby=\"caption-attachment-9000\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-9000\" class=\"wp-caption-text\">NTP Pool Server<\/p>\n<\/div>\n<p><strong>3.<\/strong>\u00a0Then open NTP daemon main configuration file for editing, comment the default list of Public Servers from\u00a0<b>pool.ntp.org<\/b>\u00a0project and replace it with the list provided for your country like in the screenshot below.<\/p>\n<div id=\"attachment_9001\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/Configure-NTP-Server.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-9001\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/Configure-NTP-Server-620x180.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/Configure-NTP-Server-620x180.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/Configure-NTP-Server.png 924w\" alt=\"Configure NTP Server in CentOS\" width=\"620\" height=\"180\" aria-describedby=\"caption-attachment-9001\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-9001\" class=\"wp-caption-text\">Configure NTP Server<\/p>\n<\/div>\n<p><strong>4.<\/strong>\u00a0Further, you need to allow clients from your networks to synchronize time with this server. To accomplish this, add the following line to NTP configuration file, where\u00a0<b>restrict<\/b>\u00a0statement controls, what network is allowed to query and sync time \u2013 replace network IPs accordingly.<\/p>\n<pre>restrict 192.168.1.0 netmask 255.255.255.0 nomodify notrap\r\n<\/pre>\n<p>The\u00a0<b>nomodify notrap<\/b>\u00a0statements suggest that your clients are not allowed to configure the server or be used as peers for time sync.<\/p>\n<p><strong>5.<\/strong>\u00a0If you need additional information for troubleshooting in case there are problems with your NTP daemon add a log file statement which will record all NTP server issues into one dedicated log file.<\/p>\n<pre>logfile \/var\/log\/ntp.log\r\n<\/pre>\n<div id=\"attachment_9002\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/Enable-NTP-Log.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-9002\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/Enable-NTP-Log-620x423.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/Enable-NTP-Log-620x423.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/Enable-NTP-Log.png 993w\" alt=\"Enable NTP Logs in CentOS\" width=\"620\" height=\"423\" aria-describedby=\"caption-attachment-9002\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-9002\" class=\"wp-caption-text\">Enable NTP Logs<\/p>\n<\/div>\n<p><strong>6.<\/strong>\u00a0After you have edited the file with all configuration explained above save and close\u00a0<b>ntp.conf<\/b>\u00a0file. Your final configuration should look like in the screenshot below.<\/p>\n<div id=\"attachment_9003\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/NTP-Server-Configuration.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-9003\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/NTP-Server-Configuration-620x372.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/NTP-Server-Configuration-620x372.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/NTP-Server-Configuration-1024x614.png 1024w\" alt=\"NTP Server Configuration in CentOS\" width=\"620\" height=\"372\" aria-describedby=\"caption-attachment-9003\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-9003\" class=\"wp-caption-text\">NTP Server Configuration<\/p>\n<\/div>\n<h3>Step 2: Add Firewall Rules and Start NTP Daemon<\/h3>\n<p><strong>7.<\/strong>\u00a0NTP service uses UDP port\u00a0<b>123<\/b>\u00a0on OSI transport layer (layer 4). It is designed particularly to resist the effects of variable latency (jitter). To open this port on RHEL\/CentOS 7 run the following commands against Firewalld service.<\/p>\n<pre># firewall-cmd --add-service=ntp --permanent\r\n# firewall-cmd --reload\r\n<\/pre>\n<div id=\"attachment_9004\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/Open-NTP-Port.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-9004\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/Open-NTP-Port-620x151.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/Open-NTP-Port-620x151.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/Open-NTP-Port.png 864w\" alt=\"Open NTP Port in Firewall\" width=\"620\" height=\"151\" aria-describedby=\"caption-attachment-9004\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-9004\" class=\"wp-caption-text\">Open NTP Port in Firewall<\/p>\n<\/div>\n<p><strong>8.<\/strong>\u00a0After you have opened Firewall port 123, start NTP server and make sure you enable it system-wide. Use the following commands to manage the service.<\/p>\n<pre># systemctl start ntpd\r\n# systemctl enable ntpd\r\n# systemctl status ntpd\r\n<\/pre>\n<div id=\"attachment_9005\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/Start-NTP-Service.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-9005\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/Start-NTP-Service-620x331.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/Start-NTP-Service-620x331.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/Start-NTP-Service-1024x548.png 1024w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/Start-NTP-Service.png 1362w\" alt=\"Start NTP Service\" width=\"620\" height=\"331\" aria-describedby=\"caption-attachment-9005\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-9005\" class=\"wp-caption-text\">Start NTP Service<\/p>\n<\/div>\n<h3>Step 3: Verify Server Time Sync<\/h3>\n<p><strong>9.<\/strong>\u00a0After NTP daemon has been started, wait a few minutes for the server to synchronize time with its pool list servers, then run the following commands to verify NTP peers synchronization status and your system time.<\/p>\n<pre># ntpq -p\r\n# date -R\r\n<\/pre>\n<div id=\"attachment_9006\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/Verify-NTP-Time-Sync.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-9006\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/Verify-NTP-Time-Sync-620x168.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/Verify-NTP-Time-Sync-620x168.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/Verify-NTP-Time-Sync-1024x278.png 1024w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/Verify-NTP-Time-Sync.png 1039w\" alt=\"Verify NTP Server Time\" width=\"620\" height=\"168\" aria-describedby=\"caption-attachment-9006\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-9006\" class=\"wp-caption-text\">Verify NTP Time Sync<\/p>\n<\/div>\n<p><strong>10.<\/strong>\u00a0If you want to query and synchronize against a pool of your choice use\u00a0<b>ntpdate<\/b>\u00a0command, followed by the server or servers addresses, as suggested in the following command line example.<\/p>\n<pre># ntpdate -q  0.ro.pool.ntp.org  1.ro.pool.ntp.org\r\n<\/pre>\n<div id=\"attachment_9007\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/Synchronize-NTP-Time.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-9007\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/Synchronize-NTP-Time-620x221.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/Synchronize-NTP-Time-620x221.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/Synchronize-NTP-Time-1024x365.png 1024w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/Synchronize-NTP-Time.png 1052w\" alt=\"Synchronize NTP Time\" width=\"620\" height=\"221\" aria-describedby=\"caption-attachment-9007\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-9007\" class=\"wp-caption-text\">Synchronize NTP Time<\/p>\n<\/div>\n<h3>Step 4: Setup Windows NTP Client<\/h3>\n<p><strong>11.<\/strong>\u00a0If your windows machine is not a part of a Domain Controller you can configure Windows to synchronize time with your NTP server by going to Time from the right side of\u00a0<b>Taskbar<\/b>\u00a0-&gt;\u00a0<b>Change Date and Time Settings<\/b>\u00a0-&gt;\u00a0<b>Internet Time<\/b>\u00a0tab -&gt;\u00a0<b>Change Settings<\/b>\u00a0-&gt;\u00a0<b>Check Synchronize with an Internet time server<\/b>\u00a0-&gt; put your\u00a0<b>server\u2019s IP or FQDN<\/b>\u00a0on\u00a0<b>Server<\/b>\u00a0filed -&gt;\u00a0<b>Update<\/b>\u00a0now -&gt;\u00a0<b>OK<\/b>.<\/p>\n<div id=\"attachment_9008\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/Synchronize-Windows-Time-with-NTP.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-9008\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/Synchronize-Windows-Time-with-NTP-620x432.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/Synchronize-Windows-Time-with-NTP-620x432.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/09\/Synchronize-Windows-Time-with-NTP.png 760w\" alt=\"Synchronize Windows Time with NTP\" width=\"620\" height=\"432\" aria-describedby=\"caption-attachment-9008\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-9008\" class=\"wp-caption-text\">Synchronize Windows Time with NTP<\/p>\n<\/div>\n<p>That\u2019s all! Setting up a local NTP Server on your network ensures that all your servers and clients have the same time set in case of an Internet connectivity failure and they all are synchronized with each other.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/how-to-setup-and-configure-static-network-routing-in-rhel\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>RHCE Series: How to Setup and Test Static Network Routing \u2013 Part 1 RHCE\u00a0(Red Hat Certified Engineer) is a certification from Red Hat company, which gives an open source operating system and software to the enterprise community, It also gives training, support and consulting services for the companies. RHCE Exam Preparation Guide This\u00a0RHCE\u00a0(Red Hat Certified &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/03\/rhce-red-hat-certified-engineer\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;RHCE (Red Hat Certified Engineer)&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-13528","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13528","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=13528"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13528\/revisions"}],"predecessor-version":[{"id":13529,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13528\/revisions\/13529"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=13528"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=13528"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=13528"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}