7 – Mohammed Wasay https://www.mowasay.com Wed, 15 Feb 2017 18:11:12 +0000 en-US hourly 1 https://wordpress.org/?v=7.1 https://www.mowasay.com/wp-content/uploads/2016/09/cropped-me-32x32.jpg 7 – Mohammed Wasay https://www.mowasay.com 32 32 How to Configure Time Server (NTP Server) on Centos 7? https://www.mowasay.com/how-to-configure-time-ntp-server-on-centos-7/ Wed, 15 Feb 2017 18:11:12 +0000 https://www.mowasay.com/?p=755 Prerequisites:

VM/ Physical – It is recommended to have the time server as a physical server, but VMs should be okay depending on your setup and requirement. My virtual lab environment is VMware based so here’s the guide for a VM. Once the CentOS Minimal is installed on the VM make sure to install open-vm-tools.

yum install open-vm-tools

If you are not conformable with Vi Editor please use install nano for editing.

yum install nano

Installing the time server:

  1. First we need to install NTPd . to do this open command line :
    [root@mytimesrv01 ~]# yum -y install ntp
  2. Then open NTP main configuration file for editing:[su_note note_color=”#fafae8″]If you are planning on hosting your time servers externally like time01.yourdomain.com, time02.yourdomain.com with ports 123 open on the firewall. Each of the time server will be talking to 0.us.pool.ntp.org, 0.us.pool.ntp.org, 0.us.pool.ntp.org, 0.us.pool.ntp.org. Later on you can probably add your time servers to the NTP.org by joining the pool. For my example, I am not using the centos default pool, but i am using the U.S. zone. For internal servers/workstations you can point it to the local ip/dns name for the local time servers.[/su_note]
    [root@mytimesrv01 ~]# vi /etc/ntp.conf
    # For more information about this file, see the man pages
    # ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).
    
    driftfile /var/lib/ntp/drift
    
    # Permit time synchronization with our time source, but do not
    # permit the source to query or modify the service on this system.
    restrict default nomodify notrap nopeer noquery
    
    # Permit all access over the loopback interface. This could
    # be tightened as well, but to do so would effect some of
    # the administrative functions.
    restrict 127.0.0.1
    restrict ::1
    
    # Hosts on local network are less restricted.
    #restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
    
    # Use public servers from the pool.ntp.org project.
    # Please consider joining the pool (http://www.pool.ntp.org/join.html).
    
    #Your time servers go here:
    server 0.us.pool.ntp.org iburst
    server 1.us.pool.ntp.org iburst
    server 2.us.pool.ntp.org iburst
    server 3.us.pool.ntp.org iburst
    
    #Default OOB time servers
    #server 0.centos.pool.ntp.org iburst
    #server 1.centos.pool.ntp.org iburst
    #server 2.centos.pool.ntp.org iburst
    #server 3.centos.pool.ntp.org iburst
    
    #broadcast 192.168.1.255 autokey # broadcast server
    #broadcastclient # broadcast client
    #broadcast 224.0.1.1 autokey # multicast server
    #multicastclient 224.0.1.1 # multicast client
    #manycastserver 239.255.254.254 # manycast server
    #manycastclient 239.255.254.254 autokey # manycast client
    
    # Enable public key cryptography.
    #crypto
    
    includefile /etc/ntp/crypto/pw
    
    # Key file containing the keys and key identifiers used when operating
    # with symmetric key cryptography.
    keys /etc/ntp/keys
    
    # Specify the key identifiers which are trusted.
    #trustedkey 4 8 42
    
    # Specify the key identifier to use with the ntpdc utility.
    #requestkey 8
    
    # Specify the key identifier to use with the ntpq utility.
    #controlkey 8
    
    # Enable writing of statistics records.
    #statistics clockstats cryptostats loopstats peerstats
    
    # Disable the monitoring facility to prevent amplification attacks using ntpdc
    # monlist command when default restrict does not include the noquery flag. See
    # CVE-2013-5211 for more details.
    # Note: Monitoring will not be disabled with the limited restriction flag.
    disable monitor
    
    logfile /var/log/ntp.log
  3. Then start and enable ntp server:
    [root@mytimesrv01 ~]# systemctl start ntpd
    [root@mytimesrv01 ~]# systemctl enable ntpd
  4. You need to allow ntp service on firewall(NTP service uses UDP port 123). So run next command:
    [root@mytimesrv01 ~]# firewall-cmd –add-service=ntp –permanent
    success
    [root@mytimesrv01 ~]# firewall-cmd –reload
    success
  5. Verify you ntp service with next command:
    [root@mytimesrv01 ~]# ntpq -p

Your output should be similar to:

]]>
Delete Files and Folders Older Than X Days https://www.mowasay.com/delete-files-and-folders-older-than-x-days/ Wed, 04 Jan 2017 22:05:43 +0000 https://www.mowasay.com/?p=721 Often times admin have to creates tasks like removing log files or some other files on a regular schedule. Here is an automated way of removing files / folders older than X days.

Create a Batch file or Powershell script and add it to scheduled task.

[su_tooltip position=”north” content=”Here’s what all of those funky switches do. The first two arguments are for the InstallShield application, setup.exe. /S requests a silent installer, and /v lets the application know that you’re going to pass switches directly to the MSI. This is why the command structure after the /v is enclosed in double quotes. The /qn portion is MSI-speak for no user interface, while the REBOOT=R portion is toReallySupress the reboot. ADDLOCAL is describing what features to install locally, while REMOVE states to toss out the HGFS (Shared Folders) feature. This way ensures that new features will be added without having to call them all out in a list.”]Please check permissions on the files and folders. If you have unique or specialized permission on the file or folders these wont work.[/su_tooltip]

Batch File:

@echo off
:: set folder path
set dump_path=c:\shares\dump

:: set min age of files and folders to delete
set max_days=7

:: remove files from %dump_path%
forfiles -p %dump_path% -m *.* -d -%max_days% -c "cmd  /c del /q @path"

:: remove sub directories from %dump_path%
forfiles -p %dump_path% -d -%max_days% -c "cmd /c IF @isdir == TRUE rd /S /Q @path"

Powershell:

# set folder path
$dump_path = "C:\shares\dump"

# set min age of files
$max_days = "-7"
 
# get the current date
$curr_date = Get-Date

# determine how far back we go based on current date
$del_date = $curr_date.AddDays($max_days)

# delete the files
Get-ChildItem $dump_path -Recurse | Where-Object { $_.LastWriteTime -lt $del_date } | Remove-Item

 

]]>
How to Start and Enable Firewalld on CentOS 7 https://www.mowasay.com/linux-how-to-start-and-enable-firewalld-on-centos-7/ Mon, 28 Mar 2016 16:09:56 +0000 http://www.mowasay.com/?p=477 It is highly recommended that you have a firewall protecting your server.

Pre-Flight Check

  • These instructions are intended specifically for enabling and starting firewalld CentOS 7.
  • I’ll be working from a Liquid Web Self Managed CentOS 7 server, and I’ll be logged in as root.

Check the Status of Firewalld

To check the status of firewalld, run the following command as root:

systemctl status firewalld

Enable Firewalld

To enable firewalld, run the following command as root:

systemctl enable firewalld

Start Firewalld

To start firewalld, run the following command as root:

systemctl start firewalld

]]>