EPEL Repo: CentOS 8/7/6 – Install & Enable – Yum

The EPEL repository (Extra Packages for Enterprise Linux) is an open source and free community based repository project from Fedora team, which provides 100% high quality add-on software packages for Linux distributions.

The following article describes how to install and enable the EPEL repository on CentOS-8/7/6, how to verify the EPEL installation and how to remove it, if needed. (more…)

Nginx Web-Server Installation and Initial Configuration on CentOS/RHEL

Nginx is an open source web server and a reverse proxy server for HTTP, SMTP, POP3 and IMAP protocols, with a strong focus on high concurrency, performance and low memory usage.

This guide explains how to install and perform the initial configuration of Nginx Web Server on CentOS/RHEL based systems.

Adding Nginx Repository

If you want the latest version of nginx with all features and bugfixes, it’s recommended to use packages directly from the nginx yum repository.

Packages from the usual repositories are often somewhat out-of-date.

To add the nginx yum repository, create a file named /etc/yum.repos.d/nginx.repo, and paste one of the configurations below.

For CentOS:

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

For RHEL:

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/rhel/$releasever/$basearch/
gpgcheck=0
enabled=1

Manually replace $releasever with either “5” (for 5.x) or “6” (for 6.x), depending upon your OS version.

Nginx Installation

Install the nginx web server with yum:

# yum install nginx

Set the nginx to start at boot:

# chkconfig nginx on

Basic Nginx Configuration

Backup the configuration files:

# cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.back
# cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.back

Edit the nginx configuration file /etc/nginx/nginx.conf. Change the worker_processes value. It should be equal to the number of CPUs in your server.

worker_processes 1;

To list the number of CPUs, you can use the following command:

# lscpu | grep '^CPU(s)'

Enable compression by uncommenting the following line:

gzip on;

Save and close the file.

Edit the file /etc/nginx/conf.d/default.conf. Set the server’s name:

server_name  example.com;

Save and close the file. Start Nginx:

# service nginx start

Firewall opening for Nginx

Edit the file /etc/sysconfig/iptables, if you use the firewall. Append the following line before the REJECT line, to open http port 80:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

Save and close the file. Restart the firewall.

# service iptables restart

Confirming the installation

To confirm that the Nginx has been successfully installed, you can enter your server’s name or IP address in your web-browser.

You should see “Welcome to Nginx!” page.

If you see this page, the Nginx Web Server is successfully installed and working.

Additional information

Default Nginx configuration files and ports

  • /etc/nginx/ – Nginx server configuration directory;
  • /etc/nginx/conf.d/ – SSL and vhost configuration directory;
  • /etc/nginx/nginx.conf – main configuration file;
  • /var/log/nginx/error.log – error logs;
  • /var/log/nginx/access.log – access logs;
  • /usr/share/nginx/html/ – Nginx default document root directory;
  • TCP 80 – Nginx HTTP default port;
  • TCP 443 – Nginx HTTPS default port.

Nginx commands

# /etc/init.d/nginx start
# /etc/init.d/nginx stop
# /etc/init.d/nginx restart
# /etc/init.d/nginx condrestart
# /etc/init.d/nginx try-restart
# /etc/init.d/nginx force-reload
# /etc/init.d/nginx upgrade
# /etc/init.d/nginx reload
# /etc/init.d/nginx status
# /etc/init.d/nginx help
# /etc/init.d/nginx configtest

Setting Up Reverse DNS — PTR Record

What is the reverse DNS?

Reverse DNS is an IP address to domain name mapping – the opposite of Forward DNS which maps domain names to IP addresses.

Comparison:

## FORWARD LOOKUP ##

# host centos.org
centos.org has address 72.232.194.162

## REVERSE LOOKUP ##

# host 72.232.194.162
162.194.232.72.in-addr.arpa domain name pointer www.centos.org.

What does the Reverse DNS serve for?

The Reverse DNS is one of the basic requirements for running some Internet protocols. It is also often used as a spam filter to determine whether the IP address of the incoming message matches an authenticated domain name and to block the message if it doesn’t.

Who controls the reverse DNS?

Reverse DNS is controlled by the owner of the IP address (probably your SIP).

How to check the reverse DNS?

Using one of the following commands, you can get the reverse DNS.

Using the ‘host’ command:

# host 72.232.194.162
162.194.232.72.in-addr.arpa domain name pointer www.centos.org.

Using the ‘nslookup’ command:

# nslookup 208.80.152.201
162.194.232.72.in-addr.arpa     name = www.centos.org.

Using the ‘dig’ command:

# dig -x 208.80.152.201
162.194.232.72.in-addr.arpa. 859 IN     PTR     www.centos.org.

Configuring the reverse DNS

Lets setup PTR record for the IP address ‘192.168.0.5’. It should be pointed to ‘your.site.name’.

Add the new zone to the ‘named.conf’ file as follows:

zone "0.168.192.in-addr.arpa" {
type master;
file "/var/named/0.168.192.in-addr.arpa";
};

Create the zone file ‘/var/named/0.168.192.in-addr.arpa’, and add the the following content:

$TTL 3600
@          IN SOA ns0.name.server. root.ns0.name.server. (
              2012020801       ; Serial
              21600             ; refresh
              3600              ; retry
              3600000           ; expire
              86400 )           ; minimum

           IN  NS ns0.name.server.
           IN  NS ns1.name.server.

; ----------- ENREGISTREMENTS -----------
$ORIGIN 0.168.192.in-addr.arpa.
5                      IN PTR                  your.site.name.
; ----------- ENREGISTREMENTS SPECIAUX -----------

Where ‘ns0.name.server’ and ‘ns1.name.server’ are your DNS servers.

Save the changes and reconfig ‘named’:

# rndc reconfig

Check the PTR:

# dig -x  192.168.0.5 @ns0.name.server +short
your.site.name.

HowTo: Get a List of All Sub-Domains of a Domain Name

If you need to find out all the sub-domains of a given domain name, you can try AXFR request.

This hint works only if the NS that you are querying is configured to allow AXFR requests.

Not all name servers allow AXFR protocol queries. Most of them return “Transfer failed”.

The first thing that you have to do, is to find out the AUTHORITY NAME SERVER(s) for the required DOMAIN NAME e.g zonetransfer.me:

$ dig zonetransfer.me

Look under the AUTHORITY SECTION:

;; AUTHORITY SECTION:
zonetransfer.me.	7122	IN	NS	ns16.zoneedit.com.
zonetransfer.me.	7122	IN	NS	ns12.zoneedit.com.

In this case zonetransfer.me has 2 name servers: ns12.zoneedit.com and ns16.zoneedit.com.

Now you can query one of these servers for the sub-domains of zonetransfer.me:

$ dig @ns12.zoneedit.com zonetransfer.me AXFR

Here is the result:

; <<>> DiG 9.9.2-P1 <<>> @ns12.zoneedit.com zonetransfer.me AXFR
; (1 server found)
;; global options: +cmd
***
zonetransfer.me.	7200	IN	NS	ns16.zoneedit.com.
zonetransfer.me.	7200	IN	NS	ns12.zoneedit.com.
zonetransfer.me.	7200	IN	A	217.147.180.162
zonetransfer.me.	7200	IN	MX	0 ASPMX.L.GOOGLE.COM.
***

HowTo: TEST Internet Speed via Linux Command Line

If you need to troubleshoot an issue with slow Internet access on your Linux system, it would be a good idea to measure the current Internet speed.

In this article you’ll find how to test Internet speed from the Linux terminal, using speedtest_cli – a simple command-line client written in Python for measuring Internet bandwidth by using Speedtest.net infrastructure.

I’ll show how to simply check download/upload Internet speed to the geographically closest server, how to measure the network speed to specific server and how to share the results of speed test via Speedtest.net.

All these tasks can be performed using the Linux command line only.

Test Download/Upload Internet Speed in Linux

Use the following command to Test Internet Download and Upload Speed from the Linux Command Line:

$ wget -O - https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py | python

Sample output:

Retrieving speedtest.net configuration...
Retrieving speedtest.net server list...
Testing from ******* (xxx.xxx.xxx.xxx)...
Selecting best server based on latency...
Hosted by ******* [1.24 km]: 2.458 ms
Testing download speed...
Download: 84.35 Mbits/s
Testing upload speed...
Upload: 77.32 Mbits/s

Test Internet Speed From the Linux Command Line

If you are planing to measure Internet bandwidth often, you can install speedtest script on your system:

$ wget https://raw.github.com/sivel/speedtest-cli/master/speedtest.py
$ chmod a+rx speedtest.py
$ sudo mv speedtest.py /usr/local/bin/speedtest
$ sudo chown root:root /usr/local/bin/speedtest

After installation, you will be able to test Internet speed from the terminal by simply running speedtest command, as follows:

$ speedtest
Retrieving speedtest.net configuration...
Retrieving speedtest.net server list...
Testing from ******* (xxx.xxx.xxx.xxx)...
Selecting best server based on latency...
Hosted by ******* [1.24 km]: 2.458 ms
Testing download speed...
Download: 84.35 Mbits/s
Testing upload speed...
Upload: 77.32 Mbits/s

Share the Result Of Speed Test via Speedtest.net

If you want to share the result of speed test, run speedtest command, as follows:

$ speedtest --share
Share results: http://www.speedtest.net/result/3690948322.png

Get the List Of Available Speedtest.net Servers

Run the following command to get the list of all available Speedtest.net servers around the world:

$ speedtest --list | more
Retrieving speedtest.net configuration...
Retrieving speedtest.net server list...
3464) Vodafone España (Alicante, Spain) [3047.78 km]
 804) ServiHosting Networks (Elda, Spain) [3063.22 km]
4845) du (Dubai, United Arab Emirates) [3069.72 km]
4844) Etisalat (Dubai, United Arab Emirates) [3069.72 km]

Measure the Network Speed to Specific Server

You can manually specify server ID during testing, instead of using the geographically closest one.

Let’s test the link to “1746) Vodafone DE (Frankfurt, Germany) [1937.90 km]”:

$ speedtest --server 1746

Bash Colors

You can make your BASH script more pretty, by colorizing its output.

Use ANSI escape sequences to set text properties like foreground and background colors.

Colorizing Shell

Use the following template for writing colored text:

echo -e "\e[COLORmSample Text\e[0m"
Option Description
-e Enable interpretation of backslash escapes
\e[ Begin the color modifications
COLORm Color Code + ‘m’ at the end
\e[0m End the color modifications

Examples:

$ echo -e "\e[31mRed Text\e[0m"
Red Text
$ echo -e "\e[42mGreen Background\e[0m"
Green Background

ANSI — Color Escape Codes

Shell scripts commonly use ANSI escape codes for color output:

Color Foreground Code Background Code Sample
Black 30 40
Red 31 41
Green 32 42
Brown 33 43
Blue 34 44
Purple 35 45
Cyan 36 46
Light Gray 37 47

Escape sequence also allows to control the manner in which characters are displayed on the screen:

ANSI Code Description
0 Normal Characters
1 Bold Characters
4 Underlined Characters
5 Blinking Characters
7 Reverse video Characters

Examples:

$ echo -e "\e[1mBold Text\e[0m"
Bold Text
$ echo -e "\e[3mUnderlined Text\e[0m"
Underlined Text

By combining all these escape sequences, we can get more fancy effect.

echo -e "\e[COLOR1;COLOR2mSample Text\e[0m"

There are some differences between colors when combining colors with bold text attribute:

Color Foreground Code Background Code Sample
Dark Gray 1;30 1;40
Light Red 1;31 1;41
Light Green 1;32 1;42
Yellow 1;33 1;43
Light Blue 1;34 1;44
Light Purple 1;35 1;45
Light Cyan 1;36 1;46
White 1;37 1;47

Examples:

$ echo -e "\e[1;34mLight Blue Text\e[0m"
Light Blue Text
$ echo -e "\e[1;33;4;44mYellow Underlined Text on Blue Background\e[0m"
Yellow Underlined Text on Blue Background

HowTo: Install VMware Tools on CentOS/RHEL

Don’t Forget VMware Tools!

VMware Tools is a suite of utilities that enhances the performance of the virtual machine’s guest operating system and improves management of the virtual machine.

Without VMware Tools installed in your guest operating system, guest performance lacks important functionality.

Installing VMware Tools

Open Vmware Worstation or ESX console and Locate the VM you need to install VMware Tools to.

Right click the VM and choose “Tools”, then select “Install VMware Tools”.

It will connect the virtual CD-ROM device to the appropriate CD image containing the tools for your virtual machine.

Log into VMware Guest you need to install VMware Tools to.

Install the kernel-devel, gcc, dracut, make, perl and eject packages using yum:

$ yum -y install kernel-devel gcc dracut make perl eject

Mount CD image with VMware Tools:

$ mount /dev/cdrom /media

Uncompress the archive with VMware Tools:

$ tar -zxf /media/VMwareTools-*.tar.gz -C /tmp

Run the installer (exclude the --default option if you prefer to control the installation process):

$ /tmp/vmware-tools-distrib/vmware-install.pl --default

Remove the temporary files after installation:

$ rm -rf /tmp/vmware-tools-distrib

Validating VMware Tools Installation

Use the command as follows to validate that VMware Tools is running:

$ initctl list | grep vmware-tools
vmware-tools start/running

To determine the vmware-tools version, run the command:

$ vmware-toolbox-cmd -v

Grep OR – Grep AND – Grep NOT – Match Multiple Patterns

The grep, egrep, sed and awk are the most common Linux command line tools for parsing files.

From the following article you’ll learn how to match multiple patterns with the OR, AND, NOT operators, using grep, egrep, sed and awk commands from the Linux command line.

I’ll show the examples of how to find the lines, that match any of multiple patterns, how to print the lines of a file, that match each of provided patterns and how to find and print the lines, that do not match a pattern (negative matching). (more…)

TSM Client Configuration File

The client options file is an editable file that identifies the server and communication method. It provides the configuration for backup, archiving, hierarchical storage management, and scheduling.

The configuration for the TSM client is defined in the following files depending on your OS:

Client OS Default configuration location Purpose
Windows C:\Program Files\Tivoli\TSM\baclient\dsm.opt Main TSM configuration file
Unix/Linux /opt/tivoli/tsm/client/ba/bin/dsm.sys Main TSM configuration file
Unix/Linux /opt/tivoli/tsm/client/ba/bin/dsm.opt Secondary TSM configuration file (used for dsmcad)

The Main TSM configuration file – Example

These are the minimum options required to get started using TSM:

$ cat /opt/tivoli/tsm/client/ba/bin/dsm.sys
   Servername                server_a
   COMMMethod                TCPip
   TCPPort                   1500
   TCPServeraddress          node.domain.company.com

The Secondary TSM configuration file – Example

We mainly need it if we use several TSM servers:

$ cat /opt/tivoli/tsm/client/ba/bin/dsm.opt
   Servername                server_a

Client Configuration File Options

Typical configuration options look like:

The SERVERNAME option specifies the name you want to use to identify a server.

SERVERNAME TSM-SERVER-1

The COMMMethod option specifies the communication method you use to provide connectivity for client-server communication.

COMMMethod         TCPip

The TCPPort option specifies a TCP/IP port address for a Tivoli Storage Manager server.

TCPPort            1500

The TCPServeraddress option specifies the TCP/IP address for a Tivoli Storage Manager server.

TCPServeraddress   192.168.0.5

The TCPCLIENTAddress option specifies a TCP/IP address if your client node has more than one address, and you want the server to contact an address other than the one that was used to make the first server contact.

TCPCLIENTAddress   192.168.0.200

The TCPCLIENTPort option specifies a different TCP/IP port number for the server to contact than the one that was used to make the first server contact.

TCPCLIENTPort      1501

The PASSWORDAccess option specifies whether you want to generate your password automatically or set as a user prompt.

PASSWORDAccess     generate

Use the NODename option in your client options file dsm.opt to identify your workstation to the server.

NODename           CLIENT-SERV-123456

The SCHEDMODe option specifies whether you want to use the polling mode (your client node periodically queries the server for scheduled work), or the prompted mode (the server contacts your client node when it is time to start a scheduled operation).

SCHEDMODe          PROMPTED

The INCLExcl option specifies the path and file name of an include-exclude options file.

INCLExcl           /opt/tivoli/tsm/client/ba/bin/inclexcl.def

The MANAGEDServices option specifies whether the Tivoli Storage Manager Client Acceptor service (CAD) manages the scheduler, the Web client, or both.

MANAGEDServices    schedule

The ERRORLOGName option specifies the fully qualified path and file name of the file in which to store information about errors that occur during processing.

ERRORLOGName       /opt/tivoli/tsm/client/ba/bin/dsmerror.log

The ERRORLOGRetention option specifies how many days to maintain error log entries before pruning, and whether to save the pruned entries.

ERRORLOGRetention  7 D

The SCHEDLOGName option specifies the path and file name where you want to store schedule log information.

SCHEDLOGName       /opt/tivoli/tsm/client/ba/bin/dsmsched.log

The SCHEDLOGRetention option specifies the number of days to keep entries in the schedule log, and whether to save the pruned entries.

SCHEDLOGRetention  7 D

The DEDUPLICATION option configures the client so that you can use data deduplication.

DEDUPLICATION YES

Displaying All Options

You can use the ‘query options’ command to display all or part of your options and their current settings relevant to the command-line client.

Display all options:

tsm> query options

Display only options beginning with sched:

tsm> query options sched*

My typical Configuration Files

Here are the typical configuration files that i use for deploying new TSM clients:

$ cat /opt/tivoli/tsm/client/ba/bin/dsm.sys
SErvername  TSM-SERVER-1
  COMMMethod         TCPip
  TCPPort            1500
  TCPServeraddress   192.168.0.5
  PASSWORDAccess     generate
  NODename           CLIENT-NODE-12345
  SCHEDMODe          PROMPTED
  MANAGEDServices    schedule
  ERRORLOGName       /opt/tivoli/tsm/client/ba/bin/dsmerror.log
  ERRORLOGRetention  7 D
  SCHEDLOGName       /opt/tivoli/tsm/client/ba/bin/dsmsched.log
  SCHEDLOGRetention  7 D
  DEDUPLICATION yes
$ cat /opt/tivoli/tsm/client/ba/bin/dsm.opt
SErvername  TSM-SERVER-1

Free Fast Public DNS Servers

There are several reasons why you may want to use alternative DNS servers:

  • Speed up your web browsing;
  • Improving your security;
  • Backup solution when your ISP servers are down.

Here is a list of Free public DNS servers.

Google Public DNS

Google Public DNS – Free DNS server list.

# For IPv4:
nameserver 8.8.8.8
nameserver 8.8.4.4
# For IPv6:
nameserver 2001:4860:4860::8888
nameserver 2001:4860:4860::8844

OpenDNS

OpenDNS – Free Public DNS IP address.

nameserver 208.67.220.220
nameserver 208.67.222.222

Norton ConnectSafe

Norton ConnectSafe – Free DNS server list.

nameserver 198.153.192.1
nameserver 198.153.194.1
# A - Security (malware, phishing sites and scam sites):
nameserver 198.153.192.40
nameserver 198.153.194.40
# B - Security + Pornography:
nameserver 198.153.192.50
nameserver 198.153.194.50
# C - Security + Pornography + Non-Family Friendly:
nameserver 198.153.192.60
nameserver 198.153.194.60

Comodo Secure DNS

Comodo Secure DNS – Free Public DNS IP address.

nameserver 8.26.56.26
nameserver 8.20.247.20

DNS Advantage

DNS Advantage – Free Public DNS IP address.

nameserver 156.154.70.1
nameserver 156.154.71.1

ScrubIT

ScrubIT – Free Public DNS IP address.

nameserver 67.138.54.100
nameserver 207.225.209.66

Level 3 Communications

Verizon (Level 3 Communications) – Free Public DNS IP address.

nameserver 4.2.2.1
nameserver 4.2.2.2
nameserver 4.2.2.3
nameserver 4.2.2.4
nameserver 4.2.2.5
nameserver 4.2.2.6