Thursday, December 15, 2016

Fix "No 3D support is available from the host" on VMware Workstation Pro or Player 12.5.2

To fix this issue, simple follow the steps below.

Open the VMware Preference File:

Run the following command to open the vmware preference file.

$ gedit $HOME/.vmware/preferences

Add 3D support in the Preference File:

Now in the end of this file, add the following line.

mks.gl.allowBlacklistedDrivers = "TRUE"

Save the file. Now close the VMware program and re-open it. It shouldn't complain "No 3D support is available from the host" anymore.


References:

askubuntu.com

Tested on: Ubuntu 16.04 LTS
Software Package: VMware Workstation Pro 12.5.2 build-4638234

Tuesday, December 13, 2016

Blocking/Unblocking an IPv4 IP Address using firewalld on Linux




You can block a host with a specific IPv4 address with firewalld firewall program. The firewalld program can be managed by the firewall-cmd command. By default the firewall-cmd command don't have any specific options to block an IP address. But we can use firewalld rich rules. Let's see how it's done.


Blocking an IPv4 Address with firewall-cmd command:

Suppose you want to block a host with the IPv4 address 192.168.17.112, so it can't connect to your computer. You can do that with the following command.

shovon@ubntu-lab$ sudo firewall-cmd --add-rich-rule='rule family=ipv4 source address=192.168.17.112 reject' --permanent success

The rich rule has been added permanently. Now we have to reload the firewalld program configuration for the changes to take effect. To do that, run the following command.

shovon@ubntu-lab$ sudo firewall-cmd --reload success

Now you can verify that the rule has been added and it's active with the following command.

shovon@ubntu-lab$ sudo firewall-cmd --list-all
public (default, active)
  interfaces: eno16777760
  sources: 
  services: dhcpv6-client ftp nfs ssh
  ports: 
  masquerade: no
  forward-ports: 
  icmp-blocks: 
  rich rules: 
 rule family="ipv4" source address="192.168.17.112" reject

Now you can try to ping from the host with the IPv4 address 192.168.17.112, and the request now should be denied by the server.



Unblocking the IPv4 address:

You can also unblock the blocked IPv4 address with the firewall-cmd command with the following command.

shovon@ubntu-lab$ sudo firewall-cmd --remove-rich-rule='rule family=ipv4 source address=192.168.17.112 reject' --permanent success

Now reload the firewalld program with the following command.

shovon@ubntu-lab$ sudo firewall-cmd --reload success

Now you should be able to ping from the host with the IPv4 address 192.168.17.112.



FAQ:

Do I have to use the same rule I added with '--add-rich-rule' option to remove with '--remove-rich-rule'?

Yes.

How do I remember several days or months after what rules I added while removing a rich rule?

You can get a list of active rich rules with firewall-cmd --list-all command. Just copy and paste the rich rule as shown in the list.



References:

access.redhat.com

Tested on: CentOS 7

Friday, December 9, 2016

How to Find the Blocksize of an Ext2/Ext3/Ext4 FileSystem on Linux



When we want to set up quotas on Linux, we need to specify the soft limit and hard limit on blocks unit. So the block size is very important here. This post is about how to find the block size of an ext2/ext3/ext4 filesystem.

To find the blocksize of an ext2/ext3/ext4 partition, we can use the tune2fs command.



Example 1

To find the block size of partition /dev/sda1, run the following command.

tune2fs -l /dev/sda1 | grep -i 'block size'
Block size:               1024

From the output of the command, you can see that, the block size is 1024 bytes or 1 KB.



Example 2

To find the block size of partition /dev/mapper/testvg-testlv1 LVM filesystem, run the following command.

tune2fs -l /dev/mapper/testvg-testlv1 | grep -i 'block size'
Block size:               4096

From the output of the command, you can see that, the block size is 4096 bytes or 4 KB.



References:

ServerFault.com(how-do-i-determine-the-block-size-of-an-ext3-partition-on-linux)

Tested on: Ubuntu 16.04 LTS

Monday, December 5, 2016

How to Count the Number of Words in a File from the Command Line on Linux

If you want to know how many words are there in a given file on Linux from the command line, you can use the 'wc' command.


The format of wc command for counting words:

You can use the long option or the short option for counting words using the wc command.


Short command format:

wc -w file_path

Long command format:

wc --words file_path

Example - Counting the number of words on the file /etc/apache2/apache2.conf

Remember that, this file is only available on Ubuntu or debian based operating systems in that location. If you're using other Linux distributions such as CentOS or RedHat, the file should be in /etc/httpd directory.

Now let's get back to where we were, Counting the number of words in a apache configuration file.

To count the number of words in apache configuration file, run the following command.

/etc/apache2/apache2.conf 1099 /etc/apache2/apache2.conf

You can see from the output that, the apache2.conf file on my Ubuntu system contains 1099 words in total.




Tested on: Ubuntu 16.04LTS

How to take weekly backups using crontab on Linux

If you want to take automatic backup and save the backup files according to today's date(year,month,day), the command to use is,

tar cvzf `date +"%Y%m%d.tar.gz"` directory_that_you_want_to_backup

Here the file will be saved as YYYYMMDD.tar.gz in the current directory.

Now if you want to automate this command on a regular basis, you need to add it as a cron job on Linux.



Objectives:

The objectives of the example I'm writing on this post is simple. I want to make backups of the webroot of Apache HTTP server every week. I want to put the backup files under /backups/web directory. Let's see how it's done.

Note: Run all the commands as root.


Adding the command to cronjob:

To add the command to the cron job, run the following command as root.

crontab -e

A text editor should show up. Now add the following line to the end of the file.

@weekly /etc/cronscripts/weekly_web_backup.sh

Save the file and quit the editor.


Creating the script file:

There's a reason you should create script of everything you add on crontab file. Crontab file might throw some errors even when the command is correct. It happened to me once. So I always add a script file on crontab ever since. There's another advantage. You can put multi-line commands on a script file.

To create the script file, run the following commands.

mkdir -p /etc/cronscripts

It should create a new directory /etc/cronscripts. This is where I will put all my crontab scripts.

Now we should put the commands on the weekly_web_backup.sh file. To do that, open it as root with your favorite text editor and add the following lines.

#!/bin/bash

tar cvzf `date +"/backups/web/%Y%m%d.tar.gz"` /var/www &> /dev/null && echo "Backup taken"

What I am doing here is, I am taking backups of /var/www folder, archiving the folder with tar and putting it under /backups/web directory. The name of the file should be YYYYMMDD.tar.gz

Once you're done, save it.


Making the script executable:

Now we have to make it executable. So the crontab daemon can run it. To do that, run the following command.

chmod +x /etc/cronscripts/weekly_web_backup.sh

Making the directory where backups will be kept:

We also need the directory where backups will be kept. Without the directory, we won't be seeing any backups. But we should see lots of errors.

To create the directory, run the following commands.

mkdir -p /backups/web

Result:

Backup of /var/www directory should be taken every week and saved on a file YYYYMMDD.tar.gz in /backups/web directory.


References:

help.ubuntu.com



Tested on: Ubuntu 16.04 LTS

Remove root Password on Linux and Disable root Login

We set up root password for making our Linux administration life easier. But enabling root login is a security risk. So after we're done setting up our Linux system, we should/can remove root password and disable root login. This is the topic of this post.

Disable root Login

To disable root login or removing root password, run the following command. sudo passwd -l root
passwd: password expiry information changed.

Testing:

Now if you try to login as root, you shouldn't be able to login.

su -
su: Authentication failure

References:

Ubuntu Forums (https://ubuntuforums.org/showthread.php?t=1204751)


Tested on: Ubuntu 16.04 LTS

Sunday, December 4, 2016

How to Find the UUID of a Partition on Linux for Mounting Partitions Using /etc/fstab

You can mount a partition by it's partition identifier such as /dev/sdb1, /dev/sda1 etc. But that's not flexible.

Imagine a situation where you plugged out your first hard drive and turn on your computer. Now your second hard drive will act as the first hard drive. The operating system will try to mount the second hard drive in a directory but sadly there's no second hard drive.

Imagine another situation where you have three hard drives in your system, and you switched the second hard drive with the third one. If you specify mount points on /etc/fstab file as /dev/sdb1 /dev/sdc1 and so on. That will also mount wrong partitions in the wrong directory.


To avoid this type of situation, we can mount a partition by it's UUID(Universally Unique Identifier). It's an unique identifier that is assigned to every partition of your hard drive when you format it.


How to find the UUID of the partitions available on your system?

The answer is simple. We use the command 'blkid' to find the UUID of the available partitions of our system.

sudo blkid
/dev/sda1: UUID="845b9fe2-63b2-49cf-bc05-5fd5db4c25a7" TYPE="ext2" PARTUUID="c3fd0be8-01"
/dev/sda5: UUID="avjGaH-RAOc-nq0e-mxXJ-qpeD-4mfw-3qufR1" TYPE="LVM2_member" PARTUUID="c3fd0be8-05"
/dev/sr0: UUID="2016-04-20-22-45-29-00" LABEL="Ubuntu-Server 16.04 LTS amd64" TYPE="iso9660" PTUUID="4cbe268b" PTTYPE="dos"
/dev/mapper/ubuntu--vg-root: UUID="35a51703-9aa3-471d-a199-5e8d45082ec4" TYPE="ext4"
/dev/mapper/ubuntu--vg-swap_1: UUID="8396b26a-6031-4d80-b5e1-3daad2338ac7" TYPE="swap"
/dev/sdb1: LABEL="test" UUID="cabe72aa-d932-49d7-9299-f2e01ba91cce" TYPE="xfs" PARTUUID="d3ae0bfa-01"

From the output of this command, you can find the UUIDs. I want to mount the /dev/sdb1 partition. /dev/sdb1 has UUID cabe72aa-d932-49d7-9299-f2e01ba91cce.


Mounting a partition on boot using UUID and /etc/fstab file:

To mount the partition /dev/sdb1 using /etc/fstab file, open the file /etc/fstab with your favorite text editor and add the following line to the end of it. Note that, I formatted the partition as XFS.

UUID=cabe72aa-d932-49d7-9299-f2e01ba91cce /testmount xfs defaults 0 0

Tested on: Ubuntu 16.04.1 LTS