Categories
Red Hat Linux

How can i install and use iptables on RHEL 7.2

RHKFirstly, stop and mask the firewalld service:
systemctl stop firewalld
systemctl mask firewalld

Then, install the iptables-services package:
yum install iptables-services

After that, enable the service at boot-time:
systemctl enable iptables

Managing the service;
systemctl stop|start|restart iptables

Saving your firewall rules can be done as follows:
service iptables save

Categories
Red Hat Linux

Configuring the number of allowable open files in Redhat Enterprise Linux

RHKEdit the /etc/security/limits.conf file then set the limit for open files from 1024 to 65536.

“username” hard nofiles 65536

“username” soft nofiles 65536

Categories
Red Hat Linux

Linux Swap Space

RHKLinux swap space is normally configured either on a dedicated partition or a logical volume. Such space is used to extend the amount of effective RAM on a system, as virtual memory for currently running programs. But you can’t just buy extra RAM and eliminate swap space.

Linux moves infrequently used programs and data to swap space even if you have gigabytes of RAM. As such, RAID arrays of swap space make little sense, as why would anyone back up fragments of data from RAM? The way Red Hat assigns default swap space is based on the amount of RAM on a system and the space available in local hard drives. For systems of up to 2GB, the default swap space size is twice the amount of installed RAM. Above 2GB, it’s the
amount of RAM + 2GB. But those are not “hard and fast” rules. Workstations with several GB of RAM frequently use very little swap space.

On my home server, I have 8GB of RAM and 4GB of swap space. That swap space is rarely used, but it may be
used more frequently on systems that aren’t rebooted for months at a time or have heavy demand from certain services. In any case, the default installation configures swap space not in a dedicated partition, but as a logical volume

Resources : Michael Jang-RHCSA RHCE Guide

Categories
Red Hat Linux

How to find files that are modified in the last x number of days?

RHKThe following command will list all the files that were modified in the last two days under the current directory.

find . -mtime -2

Resources : Linux 101 Hacks

Categories
Red Hat Linux

How to find files that are not modified in the last x number of days?

RHKThe following command will list all the files that were modified more than 60 days ago under the current directory.

find . -mtime +60

Resources : Linux 101 Hacks

Categories
Red Hat Linux

Working with Links in Linux

RHKIn a Linux file system, it is very useful to be able to access a single file from different locations. This discourages you from copying a file to different locations, where subsequently different versions of the file may come to exist. In a Linux file system, you can use links for this purpose. A link appears to be a regular file, but it’s more like a pointer that exists in one location to show you how to get to another location.

In Linux, there are two different types of links. A symbolic link is the most fl exible link type you can use. It points to any other file and any other directory, no matter where it is. A hard link can be used only to point to a file that exists on the same device.
With symbolic links, there is a difference between the original file and the link. If you remove the original file, the symbolic link won’t work anymore and thus is invalid.
A hard link is more like an additional name you’d give to a file. To understand hard links, you have to appreciate how Linux file systems work with inodes. The inode is the administration of a file. To get to a file, the file system reads the file’s inode in the file system metadata, and from there it learns how to access the block where the actual data of the file is stored. To get to the inode, the file system uses the file name that exists somewhere in a directory. A hard link is an additional file name that you can create anywhere in a directory on the same device that gives access to the same file system metadata. With hard links, you only need the original file name to create the hard link. Once it has been created, it isn’t
needed anymore, and the original file name can be removed. In general, you’ll use symbolic links, not hard links, because hard links have some serious limitations.

To create a link, you need the ln command. Use the option -s to create a symbolic link. Without this option, you’ll automatically create a hard link. First you’ll put the name of the original file directly after the ln command. Next you’ll specify the name of the link you want to create. For instance, the command ln -s /etc/passwd ~/users creates a symbolic link with the name users in your home directory. This link points to the original file /etc/
passwd.

Resources : Red Hat® Enterprise Linux® 6 Administration
Real World Skills for Red Hat Administrators

Categories
Red Hat Linux

Practical examples where shell scripting actively used

RHK

• Monitoring your Linux system.
• Data backup and creating snapshots.
• Dumping Oracle or MySQL database for backup.
• Creating email based alert system.
• Find out what processes are eating up your system resources.
• Find out available and free memory.
• Find out all logged in users and what they are doing.
• Find out if all necessary network services are running or not. For example if web server failed then send an alert
to system administrator via a pager or an email.
• Find out all failed login attempt, if login attempt are continue repeatedly from same network IP automatically
block all those IPs accessing your network/service via firewall.
• User administration as per your own security policies.
• Find out information about local or remote servers.
• Configure server such as BIND (DNS server) to add zone entries.
Shell scripting is fun. It is useful to create nice (perhaps ugly) things in shell scripting. Here are few script example I
use everyday:
• Find out today’s weather (useful when you are busy in a chat room).
• Find out what that site is running (just like netcraft).
• Download RSS feeds and display them as you login or in your email.
• Find out the name of the MP3 file you are listening to.
• Monitor your domain expiry date every day.

Resources : Linux Shell Scripting Tutorial
v2.0 Written by Vivek Gite