{"id":1460,"date":"2022-09-11T22:27:00","date_gmt":"2022-09-12T04:27:00","guid":{"rendered":"http:\/\/blog.supportpro.com\/?p=1460"},"modified":"2026-03-25T23:56:46","modified_gmt":"2026-03-26T05:56:46","slug":"centos-7-commands-and-configuration-files","status":"publish","type":"post","link":"https:\/\/www.supportpro.com\/blog\/centos-7-commands-and-configuration-files\/","title":{"rendered":"CentOS-7 : Commands and Configuration files"},"content":{"rendered":"\n<p><strong>CentOS-7<\/strong> is now powered by version 3.10.0 of the Linux kernel, with advanced support for Linux Containers and XFS (is a high-performance 64-bit journaling file system) as the default file system. It&#8217;s also the first version of CentOS to include the systemd management engine, the firewalld dynamic firewall system, and the GRUB2 boot loader.<br> CentOS 7 supports 64 bit x86 machines. MySQL has been switched with <a href=\"https:\/\/www.supportpro.com\/blog\/comparison-between-mariadb-postgresql-and-mongodb\/\">MariaDB<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Systemd<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Systemd<\/strong> is a system and service manager for the Linux operating system.<\/li>\n\n\n\n<li>It uses the <strong><code>systemctl<\/code><\/strong> command to control services, replacing older utilities such as <code>service<\/code>, <code>chkconfig<\/code>, <code>runlevel<\/code>, and traditional power management commands used in CentOS 6.x.<\/li>\n\n\n\n<li>It is built to maintain backward compatibility with SysV init scripts that were used in CentOS 6.x.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Systemd units<\/strong> :<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Represented by unit configuration files in \/etc\/systemd\/system<\/li>\n\n\n\n<li>Encapsulate information about system service, listening sockets,saved system state snapshots.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><span style=\"text-decoration: underline;\"><strong>Systemd file locations:<\/strong><\/span><\/h3>\n\n\n\n<p><strong>Directory&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Description<\/strong><\/p>\n\n\n\n<p>\/usr\/lib\/systemd\/system\/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Systemd file distributed with installed RPM package<br>\n\/run\/systemd\/system\/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Systemd unit file created at run time.<br>\n\/etc\/systemd\/system\/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Systemd unit file created and managed by the system administrator<\/p>\n\n\n\n<p><strong>Comparison of the service utility with systemctl<\/strong><\/p>\n\n\n\n<style type=\"text\/css\"><!--td {border: 1px solid #ccc;}br {mso-data-placement:same-cell;}--><\/style>\n\n\n\n<figure class=\"wp-block-table\"><div class=\"pcrstb-wrap\"><table><tbody><tr><td><strong>service<\/strong><\/td><td><strong>systemctl<\/strong><\/td><td><strong>Description<\/strong><\/td><\/tr><tr><td>service name start<\/td><td>systemctl start name.service<\/td><td>Starts a service.<\/td><\/tr><tr><td>service name stop<\/td><td>systemctl stop name.service<\/td><td>Stops a service.<\/td><\/tr><tr><td>service name restart<\/td><td>systemctl restart name.service<\/td><td>Restarts a service.<\/td><\/tr><tr><td>service namecondrestart<\/td><td>systemctl try-restart name.service<\/td><td>Restarts a service only if it is running.<\/td><\/tr><tr><td>service name reload<\/td><td>systemctl reload name.service<\/td><td>Reloads configuration.<\/td><\/tr><tr><td>service name status<\/td><td>systemctl status name.service<br>\nsystemctl is-active name.service<\/td><td>Checks if a service is running.<\/td><\/tr><tr><td>service &#8211;status-all<\/td><td>systemctl list-units &#8211;type service &#8211;all<\/td><td>Displays the status of all services.<\/td><\/tr><\/tbody><\/table><\/div><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Comparison of chkconfig utility with systemd<\/strong><\/h3>\n\n\n\n<p><strong>1) Listing services<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#systemctl list-units --type service<br>\n#systemctl list-unit-files --type service<\/code><\/pre>\n\n\n\n<p><strong>2) Displaying service status:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#systemctl&nbsp; status httpd.service\n#systemctl is-active httpd.service\n#systemctl is-enable httpd.service<\/code><\/pre>\n\n\n\n<p><strong>3) Starting a service<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#systemctl start mysqld.service<\/code><\/pre>\n\n\n\n<p><strong>4) Stopping a service<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#systemctl&nbsp; stop named.service<\/code><\/pre>\n\n\n\n<p><strong>5) Restarting a service<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#systemctl restart vsftpd.service<br>#systemctl try-restart named.service<br>#systemctl reload httpd.service<\/code><\/pre>\n\n\n\n<p><strong>6) Enabling a service<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#systemctl enable mysqld.service\n#systemctl reenable httpd.service<\/code><\/pre>\n\n\n\n<p><strong>7) Disabling a service<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#systemctl disable vsftpd.service<\/code><\/pre>\n\n\n\n<p><strong>8) Preventing service from being started manually or by another service<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#systemctl mask vsftpd.service<br> #systemctl unmask vsftpd.service<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span style=\"text-decoration: underline;\"><strong>Working with Systemd Targets<\/strong><\/span><\/h3>\n\n\n\n<p>* Runlevels were numbered from 0 to 6 and were defined by a selection of system services to be run.<br> * In CentOS 7, the concept runlevels has been replaced with systemd targets.<\/p>\n\n\n\n<p><strong>Comparison of Power Management Commands with systemctl :<\/strong><\/p>\n\n\n\n<style type=\"text\/css\"><!--td {border: 1px solid #ccc;}br {mso-data-placement:same-cell;}--><\/style>\n\n\n\n<figure class=\"wp-block-table\"><div class=\"pcrstb-wrap\"><table><tbody><tr><td><strong>Old Command<\/strong><\/td><td><strong>New Command<\/strong><\/td><td><strong>Description<\/strong><\/td><\/tr><tr><td>halt<\/td><td>systemctl halt<\/td><td>Halts the system.<\/td><\/tr><tr><td>poweroff<\/td><td>systemctl poweroff<\/td><td>Powers off the system.<\/td><\/tr><tr><td>reboot<\/td><td>systemctl reboot<\/td><td>Restarts the system.<\/td><\/tr><tr><td>pm-suspend<\/td><td>systemctl suspend<\/td><td>Suspends the system.<\/td><\/tr><tr><td>pm-hibernate<\/td><td>systemctl hibernate<\/td><td>Hibernates the system.<\/td><\/tr><tr><td>pm-suspend-hybrid<\/td><td>systemctl hybrid-sleep<\/td><td>Hibernates and suspends the system.<\/td><\/tr><\/tbody><\/table><\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span style=\"text-decoration: underline;\"><strong>2. FIREWALLD SUITE<\/strong><\/span><\/h2>\n\n\n\n<p>The dynamic firewall daemon firewallD provides a dynamically managed firewall with support for network \u201czones\u201d to assign a level of trust to a network and its associated connections and interfaces. It has support for IPv4 and IPv6 firewall settings.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Comparison of firewalld to system-config-firewall and iptables :<\/strong><\/h3>\n\n\n\n<p>The essential differences between firewalld and the iptables service are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The iptables service stores configuration in \/etc\/sysconfig\/iptables, while firewalld stores it in various XML files in \/usr\/lib\/firewalld\/ and \/etc\/firewalld\/.<\/li>\n\n\n\n<li>With the iptables service, every single change means flushing all the old rules and reading all the new rules from \/etc\/sysconfig\/iptables while with firewalld there is no re-creating of all the rules; only the differences are applied. Consequently, firewalld can change the settings during runtime without existing connections being lost.<\/li>\n<\/ul>\n\n\n\n<p>The zone settings in <strong>\/etc\/firewalld\/<\/strong> :<\/p>\n\n\n\n<p><em>drop<\/em><br>\nAny incoming network packets are dropped, there is no reply. Only outgoing network connections are possible.<\/p>\n\n\n\n<p><em>block<\/em><br>\nAny incoming network connections are rejected with an icmp-host-prohibited message for IPv4 and icmp6-adm-prohibited for IPv6. Only network connections initiated from within the system are possible.<\/p>\n\n\n\n<p><em>public<\/em><br>\nFor use in public areas. You do not trust the other computers on the network to not harm your computer. Only selected incoming connections are accepted.<br>\nexternal<\/p>\n\n\n\n<p><em>trusted<\/em><br>\nAll network connections are accepted.<\/p>\n\n\n\n<p><em>internal<\/em><br>\nFor use on internal networks. You mostly trust the other computers on the networks to not harm your computer. Only selected incoming connections are accepted.<\/p>\n\n\n\n<p><em>home<\/em><br>\nFor use in home areas. You mostly trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.<\/p>\n\n\n\n<p><em>internal&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/em><br>\nFor use on internal networks. You mostly trust the other computers on the networks to not harm your computer. Only selected incoming connections are accepted.<\/p>\n\n\n\n<p>It is possible to designate one of these zones to be the default zone. When interface connections are added to NetworkManager, they are assigned to the default zone. On installation, the default zone in firewalld is set to be the public zone.<\/p>\n\n\n\n<p>You may refer our article at <em>http:\/\/blog.supportpro.com\/2015\/01\/an-introduction-to-firewalld-dynamic-firewall\/<\/em> for more details on the configuration settings of Firewalld<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Disabling firewalld<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code><em>#systemctl disable firewalld<\/em><br>\n<em>#systemctl stop firewalld<\/em><\/code><\/pre>\n\n\n\n<p><strong>Start firewalld<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> <em>#systemctl start firewalld<\/em><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span style=\"text-decoration: underline;\"><strong>&nbsp;3. Localectl Command<\/strong><\/span><\/h2>\n\n\n\n<p>The system locale is set in the file \/etc\/locale.conf but the setting are limited to the sort order, display language, time format etc. Other important setting include the keyboard layout for consoles and the GUI if the X Server is running. The command localectl can display and control many of these setting.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em>&nbsp;#localectl status&nbsp; &gt;&gt; to display locale settings<\/em><br>\n<em>&nbsp;#localectl set-locale LANG=en_GB.utf8&nbsp; &gt;&gt; to set the Language<\/em><br>\n<em>&nbsp;#localectl list-locales &gt;&gt; to lists locales<\/em><br>\n<em>&nbsp;#locale list-keymaps &gt;&gt; list keyboard mappings<\/em><br>\n<em>&nbsp;#locale set-keymap uk&nbsp; &gt;&gt; sets the key map<\/em><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span style=\"text-decoration: underline;\"><strong>4. Timedatectl Command<\/strong><\/span><\/h2>\n\n\n\n<p>In CentOS7, A new command used to set date and time is \u201ctimedatectl\u201c. this command is distributed as part of the systemd system and service manager. You can use this command to change the date and time, set the time zone, check the current date and time or others<\/p>\n\n\n\n<p>To find list of all available time zones,<br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em>#timedatectl list-timezones<\/em><\/code><\/pre>\n\n\n\n<p>To set timezone<br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em>#timedatectl set-timezone time_zone<\/em>\n<\/code><\/pre>\n\n\n\n<p>In this example, set timezone to America\/Chicago<br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em>#timedatectl set-timezone America\/Chicago<\/em><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><em>#timedatectl set-time YYYY-MM-DD<\/em> &gt;&gt; To set date<br>\ntimedatectl&nbsp; set-time 2014-07-19<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><em>#timedatectl set-time HH:MM:SS<\/em> &gt;&gt; To set time<br>\ntimedatectl&nbsp; set-time 15:12:00<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><em>#timedatectl set-ntp yes<\/em> &gt;&gt; enable ntp server<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span style=\"text-decoration: underline;\"><strong>5. Hostnamectl command<\/strong><\/span><\/h2>\n\n\n\n<p>We can change host name by modifying the \/etc\/sysconfig\/network in Centos and other Linux systems, but it did not take an effect of the modification. Even after multiple reboot of server.<br>\nThe procedure to change the host name in CentOS 7 is now totally different from the previous versions.<\/p>\n\n\n\n<p>In CentOS\/RHEL 7, there is a command line utility called <em>hostnamectl<\/em>, which allows you to view or modify hostname related configurations.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em>#hostnamectl status<\/em><\/code><\/pre>\n\n\n\n<p>To view static, transient or pretty hostname only, use &#8220;&#8211;static&#8221;, &#8220;&#8211;transient&#8221; or &#8220;&#8211;pretty&#8221; option, respectively<br>\n<em>#hostnamectl status [&#8211;static|&#8211;transient|&#8211;pretty]<\/em><\/p>\n\n\n\n<p>To change all three hostnames: static, transient, and pretty, simultaneously:<br>\n<em>#hostnamectl set-hostname &lt;host-name&gt;<\/em><\/p>\n\n\n\n<p>Used to set hostname remotely(-H option using )<br>\n<em>#hostnamectl set-hostname -H username@hostname<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span style=\"text-decoration: underline;\"><strong>6. Root file system change<\/strong><\/span><\/h2>\n\n\n\n<p>* The \/bin, \/sbin, \/lib and \/lib64 directories are now under the \/usr directory.<br>\n* The \/tmp directory can now be used as a temporary file storage system (tmpfs).<br>\n* The \/run directory is now used as a temporary file storage system (tmpfs). Applications can now use \/run the same way they use the \/var\/run directory.<\/p>\n\n\n\n<p>&gt;&gt; \/tmp and \/run directory<\/p>\n\n\n\n<p>Offers the ability to use \/tmp as a mount point for a temporary file storage system (tmpfs).<br>\nWhen enabled, this temporary storage appears as a mounted file system, but stores its content in volatile memory instead of on a persistent storage device. No files in \/tmp are stored on the hard drive except when memory is low, in which case swap space is used. This means that the contents of \/tmp are not persisted across a reboot.<\/p>\n\n\n\n<p>To enable and disable this service<br>\n<em># systemctl enable\/disable tmp.mount<\/em><\/p>\n\n\n\n<p>Files stored in \/run and \/run\/lock are no longer persistent and do not survive a reboot.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span style=\"text-decoration: underline;\"><strong>7. Httpd package<\/strong><\/span><\/h2>\n\n\n\n<p>Configuration file contain less configuration compared to previous version of the htpd, it is hard copied to manuals installed in \/usr\/share\/httpd.<br>\nUses a single binary and provides these Multi-Processing Models as loadable modules: worker, prefork (default), and event. Edit the \/etc\/httpd\/conf.modules.d\/00-mpm.conf file to select which module is loaded.<br>\nContent previously installed in \/var\/cache\/mod_proxy has moved to \/var\/cache\/httpd under either the proxy or the ssl subdirectory.<br>\nContent previously installed in \/var\/www has moved to \/usr\/share\/httpd including icons, error and and noindex(new)<br>\nModule for the previous versions not supported<br>\nConfiguration files that load modules are now placed in the \/etc\/httpd\/conf.modules.d directory. Packages that provide additional loadable modules for httpd (like the php package) are added to this&nbsp; directory. Any configuration files in the conf.modules.d directory are processed before the main body of httpd.conf. Configuration files in the \/etc\/httpd\/conf.d directory are now processed after the main body of httpd.conf.<br>\n\/etc\/httpd\/conf.d\/autoindex.conf configures mod_autoindex directory indexing<\/p>\n\n\n\n<p>If you require help, <a href=\"https:\/\/www.supportpro.com\/requestquote.php\">contact SupportPRO server Admin<\/a> or do a server checkup:<\/p>\n\n\n\n<div class=\"wp-block-media-text alignwide has-media-on-the-right is-stacked-on-mobile is-vertically-aligned-center has-white-background-color has-background\"><div class=\"wp-block-media-text__content\">\n<p class=\"has-large-font-size\">Partner with <strong>SupportPRO<\/strong> for 24\/7 proactive cloud support that keeps your business secure, scalable, and ahead of the curve.<\/p>\n\n\n\n<!--HubSpot Call-to-Action Code --><span class=\"hs-cta-wrapper\" id=\"hs-cta-wrapper-3350a795-db50-482f-9911-301930d1b1be\"><span class=\"hs-cta-node hs-cta-3350a795-db50-482f-9911-301930d1b1be\" id=\"hs-cta-3350a795-db50-482f-9911-301930d1b1be\"><!--[if lte IE 8]><div id=\"hs-cta-ie-element\"><\/div><![endif]--><a href=\"https:\/\/cta-redirect.hubspot.com\/cta\/redirect\/2725694\/3350a795-db50-482f-9911-301930d1b1be\" ><img decoding=\"async\" class=\"hs-cta-img\" id=\"hs-cta-img-3350a795-db50-482f-9911-301930d1b1be\" style=\"border-width:0px;\" src=\"https:\/\/no-cache.hubspot.com\/cta\/default\/2725694\/3350a795-db50-482f-9911-301930d1b1be.png\"  alt=\"Contact Us today!\"\/><\/a><\/span><script charset=\"utf-8\" src=\"https:\/\/js.hscta.net\/cta\/current.js\"><\/script><script type=\"text\/javascript\"> hbspt.cta.load(2725694, '3350a795-db50-482f-9911-301930d1b1be', {\"useNewLoader\":\"true\",\"region\":\"na1\"}); <\/script><\/span><!-- end HubSpot Call-to-Action Code -->\n<\/div><figure class=\"wp-block-media-text__media\"><img fetchpriority=\"high\" decoding=\"async\" width=\"904\" height=\"931\" src=\"https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2022\/09\/Free-server-checkup.png\" alt=\"guy server checkup\" class=\"wp-image-12943 size-full\" srcset=\"https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2022\/09\/Free-server-checkup.png 904w, https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2022\/09\/Free-server-checkup-291x300.png 291w, https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2022\/09\/Free-server-checkup-768x791.png 768w, https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2022\/09\/Free-server-checkup-585x602.png 585w\" sizes=\"(max-width: 904px) 100vw, 904px\" \/><\/figure><\/div>\n","protected":false},"excerpt":{"rendered":"<p>CentOS-7 is now powered by version 3.10.0 of the Linux kernel, with advanced support for Linux Containers and XFS (is a high-performance 64-bit journaling file system) as the default file&hellip;<\/p>\n","protected":false},"author":5,"featured_media":12949,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[6],"tags":[102,106],"class_list":["post-1460","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux-basics","tag-devops","tag-server"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/posts\/1460","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/comments?post=1460"}],"version-history":[{"count":15,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/posts\/1460\/revisions"}],"predecessor-version":[{"id":16623,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/posts\/1460\/revisions\/16623"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/media\/12949"}],"wp:attachment":[{"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/media?parent=1460"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/categories?post=1460"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/tags?post=1460"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}