CentOS 7

How To Change Time/Date In Linux From Command Prompt

Share on LinkedIn

These commands work with CentOS 6.5. The commands for CentOS 7 are similar and you should be able to figure them out if you start with these commands.

Only change time not date:

To only set the time use like this:

# date -s hh:mm:ss

Update Hardware clock:

To sync the hardware clock to the current system clock:

# hwclock –systohc
OR
# hwclock –systohc –utc
***** use the second option if you use UTC.

Set Hardware clock manually:

To know the current time of the hardware clock:

# hwclock –show
Tue Nov  4 22:13:40 2003  -0.684660 seconds

To set the hw clock manually:

# hwclock –set –date=”09/21/2005 14:23:23″

 

We run into power issues from time to time and our servers have been known to lose their time. The hardware time may not have been changed and the system often synchronizes off of the hardware clock, especially following a power cycle.

Below are the steps I performed to 1. change the system clock to the correct time and then 2. synchronize the hardware clock up to the system clock.

[root@ ~]# date -s 16:30:00
Mon Jan 26 16:30:00 CST 2015
[root@ ~]# date
Mon Jan 26 16:30:05 CST 2015
[root@ ~]# hwclock –show
Mon 26 Jan 2015 03:09:58 PM CST -0.188457 seconds
[root@ ~]# hwclock –systohc –utc
[root@ ~]# hwclock –show
Mon 26 Jan 2015 04:35:40 PM CST -0.616988 seconds

Linux Gateway

How To Find Linux Gateway Address

This is NOT my work. I’ve just added it to my blog. The original post and author can be found here.

Find out Gateway / router IP address under Linux / UNIX using route command

You need to use route command. This command can manipulates the kernel’s IP routing tables. It can be also use to print gateway / router IP address. Type the following command to see default gateway:
$ route -n
Output:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 ra0
0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 ra0

192.168.1.1 is gateway IP address for our computer. The flag U indicates that route is up andG indicates that it is gateway. You can print gateway name, enter:
$ route
Output:

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     *               255.255.255.0   U     0      0        0 ra0
default         wrt             0.0.0.0         UG    0      0        0 ra0

Second column prints Gateway hostname / IP address. In our example wrt is gateway.

netstat command example to find out gateway/router IP

Open a terminal and type the following command:
# netstat -r -n
Sample outputs:

Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.1.254   0.0.0.0         UG        0 0          0 eth1
192.168.1.0     0.0.0.0         255.255.255.0   U         0 0          0 eth1
Nagios Logo

Install Nagios 4.0.4 on CentOS 6.5

Assumptions: This build document assumes you are on a local domain with a local DNS server. You need to identify the DNS server an add this server as a host if you’d like to browse to it in your address bar. For instance, we just go to http://nagios..com instead of the ip address.

Virtual Machine Resources
4Core, 8GB
100GB HDD
Local dns nagios.<yourdomain>.com
Minimal Install CentOS 6.5
Hostname: nagios
Local Domain: <yourdomain>.com
IP Address: <nagiosip>
Local DNS IP: <localdnsip>

Install nano
yum install nano

Add Hosts Entries
nano /etc/hosts

By default, this is what’s present:
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

Add the following:
<nagiosip> nagios.yourdomain.com nagios
<localdnsip> nagios.yourdomain.com

Add Nameserver
nano /etc/resolv.conf

Change default “nameserver ” to “nameserver <localdnsip>”
Press “Ctl+X” to exit
Select “Y” to save changes
Press “Enter” to get back to CL

Disable other services and firewall
service iptables stop
chkconfig iptables off

Disable SELINUX
change selinux=enforcing to selinux=disabled
nano /etc/selinux/config
Press “Ctl+X” to exit
Select “Y” to save changes
Press “Enter” to get back to CL

Install Prerequisites
yum install -y wget httpd php gcc glibc glibc-common gd gd-devel make net-snmp

Download Nagios Core and Nagios Plugins Tarballs
For all systems, run the following commands in your terminal:
cd /tmp
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.4.tar.gz
wget http://nagios-plugins.org/download/nagios-plugins-2.0.tar.gz

Adding the Nagios User and Group
Next add the appropriate user and group for the Nagios process to run:
useradd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios

Install Nagios Core
tar zxvf nagios-4.0.4.tar.gz
tar zxvf nagios-plugins-2.0.tar.gz
Change to the new Nagios directory and install the packages:
cd nagios-4.0.4
./configure –with-command-group=nagcmd

make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf
cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/
chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
/etc/init.d/nagios start/etc/init.d/httpd start
Create a Default User for Web Access. (may have to do this last)
Add a default user for Web Interface Access:
htpasswd –c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Monitoring Infrastructure Switch
htpasswd /usr/local/nagios/etc/htpasswd.users

For perl modules, need to install perl
yum install perl-LDAP

Dependencies
less /var/log/messages | grep perl
Aug 19 15:25:39 nagios yum[2062]: Installed: perl-DBI-1.609-4.el6.x86_64
Aug 19 15:25:39 nagios yum[2062]: Installed: perl-DBD-MySQL-4.013-3.el6.x86_64
Aug 19 15:25:39 nagios yum[2062]: Installed: mysql-5.1.73-3.el6_5.x86_64
Aug 19 15:25:41 nagios yum[2062]: Installed: mysql-server-5.1.73-3.el6_5.x86_64
Aug 19 15:46:41 nagios yum[21836]: Installed: perl-XML-NamespaceSupport-1.10-3.el6.noarch
Aug 19 15:46:42 nagios yum[21836]: Installed: perl-XML-SAX-0.96-7.el6.noarch
Aug 19 15:46:42 nagios yum[21836]: Installed: 1:perl-XML-LibXML-1.70-5.el6.x86_64
Aug 19 15:46:42 nagios yum[21836]: Installed: perl-XML-Filter-BufferText-1.01-8.el6.noarch
Aug 19 15:46:42 nagios yum[21836]: Installed: perl-Digest-SHA1-2.12-2.el6.x86_64
Aug 19 15:46:42 nagios yum[21836]: Installed: perl-Digest-HMAC-1.01-22.el6.noarch
Aug 19 15:46:43 nagios yum[21836]: Installed: perl-Convert-ASN1-0.22-1.el6.noarch
Aug 19 15:46:43 nagios yum[21836]: Installed: perl-Net-SSLeay-1.35-9.el6.x86_64
Aug 19 15:46:43 nagios yum[21836]: Installed: perl-GSSAPI-0.26-6.el6.x86_64
Aug 19 15:46:43 nagios yum[21836]: Installed: perl-Authen-SASL-2.13-2.el6.noarch
Aug 19 15:46:43 nagios yum[21836]: Installed: perl-Net-LibIDN-0.12-3.el6.x86_64
Aug 19 15:46:43 nagios yum[21836]: Installed: perl-IO-Socket-SSL-1.31-2.el6.noarch
Aug 19 15:46:43 nagios yum[21836]: Installed: perl-Text-Iconv-1.7-6.el6.x86_64
Aug 19 15:46:43 nagios yum[21836]: Installed: perl-XML-SAX-Writer-0.50-8.el6.noarch
Aug 19 15:46:43 nagios yum[21836]: Installed: 1:perl-LDAP-0.40-1.el6.noarch

Nagios Config File (tells nagios what config files to look at)
cd /usr/local/nagios/etc/nagios.cfg

Configuration files
cd /usr/local/nagios/etc/objects

If making changes to configuration files, restart service when finished
service nagios restart

We monitor multiple locations. Each location has its own config file in objects. Each location config file specifies its own host group, hosts, and services.