Redirect or block traffic based on country geographical location using Apache mod_geoip

In this config you will learn how to block or redirect web traffic based on the visitor’s country geographical location using Apache’s geoip mod.

Apache mod_geoip installation

Assuming that you already have Apache webserver installed and running we start by the installation of mod_geoip:

UBUNTU/DEBIAN
# apt-get install libapache2-mod-geoip
CENTOS/REDHAT/FEDORA ( epel enabled only )
# yum install mod_geoip.x86_64

Read more

An easy way to encrypt and decrypt large files using OpenSSL and Linux

Below is a quick config on how to to encrypt and decrypt large files using OpenSSL and Linux such as Redhat, Ubuntu, Debian, CentOS, Fedora etc. First, what you will need is a some sort of arbitrary file. Let’s create 1GB file now:

$ fallocate -l 1G large_file.img
$ ls -lh large_file.img
-rw-r--r--. 1 lrendek lrendek 1.0G Jan  2 16:40 large_file.img

Read more

How to transfer data over the network with nc (netcat) command on Linux

The nc ( netcat ) command can be used to transfer arbitrary data over the network. It represents a quick way for Linux administrators to transfer data without the need for an additional data transfer services such as FTP, HTTP, SCP etc. This config will show you an example on how to transfer data between to network hosts. We will be transferring data myfile.txt file from a localhost to a destination host with an IP address 10.1.1.2.

Destination host

The nc command first needs to be started on the network host to which we need to transfer data. We will instruct nc to listen for an incoming request on user defined port number and once the client request comes receive the desired data. Pick the port number of your choice to ensure that it is not blocked by firewall and it is accessible from the source host.

$ nc -l -p 7555 > myfile.txt

Read more

How to obtain a laptop battery information and charging state on Linux

The following linux commands will help you to obtain the information about your laptop battery such as manufacturer, part type, capacity, voltage etc. First, tool which can be used for this job is dmidecode command. If you currently do not have dmidecode available on your Linux system you can install it by:

UBUNTU/DEBIAN
# apt-get install dmidecode
CENTOS/FEDORA
# yum install dmidecode

next, using dmidecode we can obtain some hardware information about our battery:

# dmidecode -t 22
# dmidecode 2.12
SMBIOS 2.6 present.

Handle 0x002E, DMI type 22, 26 bytes
Portable Battery
        Location: Rear
        Manufacturer: LGC
        Name: 42T4942
        Design Capacity: 93240 mWh
        Design Voltage: 11100 mV
        SBDS Version: 03.01
        Maximum Error: Unknown
        SBDS Serial Number: 073C
        SBDS Manufacture Date: 2012-03-23
        SBDS Chemistry: LION
        OEM-specific Information: 0x00000000

Read more

How to convert documents between LibreOffice and Microsoft Office file formats on Linux

In this config you can learn how to convert documents format between LibreOffice and Microsoft Office file formats on Linux. The preferred tool to use for a file format conversion between LibreOffice and Microsoft Office is unoconv. Let’s start with the installation of unoconv package:

FEDORA/REDHAT/CENTOS
# yum install unoconv
DEBIAN/UBUNTU
# apt-get install unoconv

and create some LibreOffice document document.odt and spreadsheet spreadsheet.ods to play with:

$ file document.odt 
document.odt: OpenDocument Text
$ file spreadsheet.ods 
spreadsheet.ods: OpenDocument Spreadsheet

Read more

Remove all containners based on docker image name

Questions:
How can I remove all docker containers based on a docker image name. I do not wish to remove all available containers, only the those which are based on particular image. For example I would like to remove all containers based on image centos:7.

Answer:
To remove all docker containers based on centos:7 run the following linux command:

# docker ps -a | awk '{ print $1,$2 }' | grep centos:7 | awk '{print $1 }' | xargs -I {} docker rm {}

Read more

convert ebook to amazon kindle mobi using calibre - linux

How to convert various eBook formats for Amazon Kindle on Linux

Amazon currently accepts limited number of ebook formats that you can directly send to your Amazon Kindle. In this config we are going to show few Linux tools which may assist you with the conversion between various Document and eBook formats.

Based on your amazon Kindle type the supported formats may include:

  • Microsoft Word (.doc, .docx)
  • Rich Text Format (.rtf)
  • HTML (.htm, .html)
  • Text (.txt) documents
  • Archived documents (zip , x-zip) and compressed archived documents
  • Mobi book
  • Portable Document Format PDF
  • JPEGs (.jpg)
  • GIFs (.gif)
  • Bitmaps (.bmp)
  • PNG images (.png)

ebook-convert

The first tool you might consider is ebook-convert. This tool is available on Fedora , CentOS, Redhat Linux under the package named ebook-tools. To install ebook-tools package run the command below:

# yum install ebook-tools

Read more