Monday, August 12

Install mod_rpaf with apache-2.4

Apache-2.4 has own module mod_remoteip

"This module is used to treat the useragent which initiated the request as the originating useragent as identified by httpd for the purposes of authorization and logging, even where that useragent is behind a load balancer, front end server, or proxy server."

you may use it with nginx such:

....
    RemoteIPHeader X-Forwarded-For
....

but I found 2 issues for me:

1. I must change LogFormat ( replace %h with %a) to show original IP in logs
2.  /server-status/ page show nginx ip address instead original

So, i deside to use mod_rpaf. Defaut veriosn does not compile with aapche-2.4.
To solve the issue:

 replace  “remote_” with “client_” in “mod_rpaf-2.0.c” 

Tuesday, April 9

Linux TOP Command

Top command options:
Line 1: Gives System present time, up time of the machine, number of users logged in, Load average on system at 1, 5, 15 min interval. Please ignore the values which mention load average as 5,10 and 15 mins.
Line 2: Gives total number of process on the machine, number of running process, number of sleeping process, number of stopped process, number of Zombie process.
Line 3: Gives you CPU details
Line 4 &  5: Gives RAM and SWAP details.
Line 6: To execute top command shortcuts(See below for the list of top command shortcuts ).
From Line 7: dynamically displayed top process results.
 top commands shortcuts:

The Runlevels in Linux

Many Windows users are familiar with different modes of execution of their operating system:
a. Safe mode
b. Command prompt only
c. Safe mode with network support
d. Safe mode with vga


And other such options that are presented during the boot-up process. Similarly, Linux has different modes of executing as well, which are known as runlevels. But unlike Windows, we can change runlevels on a fly.
Definition for runlevel : The term runlevel refers to a mode of operation in one of the computer operating system that implement Unix System V-style initialization. This system replaces the traditional /etc/rc and /etc/rc.local scripts used in BSD UNIX. Conventionally, seven runlevels exist, numbered from zero to six, plus an alias runlevel named ‘S’ and/or ‘s’.
Runlevels control services started by the initialization process. The number of runlevels and services started on those runlevels varies with Linux distributions. Information about the runlevels of a particular distribution is listed in file /etc/inittab.
The contents of the file include the following:
DNameDescription
0HaltShuts down the system.
1Single-user ModeMode for administrative tasks.
2Multi-user ModeDoes not configure network interfaces and does not export networks services.
3Multi-user Mode with NetworkingStarts the system normally.
4Not used/User-definableFor special purposes.
5Start the system normally with appropriate display manager. ( with GUI )As runlevel 3 + display manager.
6RebootReboots the system.

Linux Booting Process

Knowing Linux booting process is an essential part of every Linux user/administration which will give you a clear picture of how Linux Operating system works. In this post we will see what happens when a Linux OS boots i.e. after powering on the machine to the user log-in prompt. Below image will give you clear idea what will happen in Linux booting process.

Linux Booting process

A quick view of booting sequence:
Power on
CPU jumps to BIOS
BIOS runs POST
Finds first bootable device
Load and execute MBR
Load OS
User prompt
This a rough idea what happens in Linux booting. Below are the detailed stages in Linux Booting process.
Stages of Booting:
1)System startup(Hardware )
2)Boot loader Stage 1 (MBR loading)
3)Boot loader Stage 2 (GRUB loader)
4)Kernel
5)INIT
6)User prompt

Monday, April 1

Building a Apache Web Server

If you have not yet installed your Linux OS, or just for future reference, do not choose to install Apache  during the system installation. Then you can immediately proceed with the source-based install listed here.

Note: to install applications from source code, you will need a C++ compiler (gcc++) installed. This is generally taken care of, but I've had enough queries about it that I've added this note to avoid getting more! You can use your distribution's install CDs to get the proper version of the compiler.

yum install gcc gcc-c++

If you do not have direct access (via keyboard) to the server, PLEASE use Secure Shell (SSH) to access the server and not telnet!! Whenever you use telnet (or plain FTP for that matter), you are transmitting your username, password, and all session information in "plain text". This means that anyone who can access a machine someplace between your PC and your server can snoop your session and get your info. Use encryption wherever possible!

Get the Source Code for all Applications
We want to put all our source code someplace central, so it's not getting mixed up in someone's home directory, etc.

cd /usr/local/src

Monday, December 3

Activate NIC or network card at boot time for Redhat/CentOS


In recent RHEL6/CentOS6 NIC is not getting up by default. So once you login we have to up the network interface to make it work properly. To make the interface available at the time of boot we have to set ONBOOT option in ifcfg-eth0 file.
Open the file In file /etc/sysconfig/network-scripts/devices/ifcfg-eth0 and change ONBOOT value to yes
Before editing the file.
DEVICE=eth0
HWADDR=52:54:00:60:af:6d
NM_CONTROLLED=yes
ONBOOT=no
BOOTPROTO=dhcp
TYPE=Ethernet
USERCTL=no
PEERDNS=yes
IPV6INIT=no
After editing the file
DEVICE=eth0
HWADDR=52:54:00:60:af:6d
NM_CONTROLLED=yes
ONBOOT=yes
BOOTPROTO=dhcp
TYPE=Ethernet
USERCTL=no
PEERDNS=yes
IPV6INIT=no
Reboot the machine and your NIC interface will be activated at the time of booting.

How to unlock an user account in Linux?


How to unlock a user account in Linux?

Some times on Linux boxes the user account will be locked due to issues such as wrong password entry, account expiry etc. In this post we will see how to unlock user account with different commands.
Example1: Check if the password is disabled by viewing /etc/shadow file for user entry.
grep ‘username’ /etc/shadow
if you are able to see ! in the second field starting that indicates that password is disabled, you have to enable it back by using passwd with -u option
passwd -u username
Example:
passwd -u ram
Unlocking password for user temp.
passwd: Success

How to delete user account in Linux?


How to delete user account in Redhat/Ubuntu Linux?

Deleting user account in Linux is as a task to remove user login credentials from system configuration files such as /etc/passwd, /etc/shadow and files which are owned by that particular user  from the Linux server. Here we are going to see on how to delete a user and precautions to be taken when deleting users. Lets start deleting user with examples.

What is lost+found directory in Linux/Unix?

This is an important directory which is useful for recovering files which are not properly closed due to many reason such as power failure. Lost+Found is created by system at the time of Linux OS installation for each partition we create. In other words we can say the mounted folder contains this lost+found folder. This folder contains the files with no links and files to be recovered. Any file to be recovered is kept in this folder. fsck command is used to recover these files.

Lost the Root password


Lost the Root password
When you lost root password how you can recover and login back in to the system?
To login in to system there are so many ways to get root access depending on security level of the system.
Method1: When there is no password set to access runlevel 1.
Here are the steps to change your root password the most esiest way is as follows..
1. Start your computer when you see Redhat Linux boot loader(GRUB menu where you can see all the Operating system’s in the system) select the redhat linux and press “e”, and select second line where you can set the temporary runlevel for the system to boot
2. You will notice that now you can edit boot loader command arguments now again press “e” and edit the line to add single or 1 without quots at the end of line.
3. Press enter to return to previous screen
4. Press b to boot with this new argument which will run Linux into single user mode. Please make sure that you see single at the end of line.
5. Now you will get root login with out asking for a password in single user mode.
6. Use “passwd” command to change your password.
#passwd
here it will not ask previous password so you can just enter new password.
7. When updateing the password in runlevel1 if the server is not allowing you to change password giving you error, this is due to /etc/shadow file issue.
In order to resolve this issue execute the following command and then try to change the password
#pwunconv
7.After changing the password just type exit command which will take you to default runlevel of the system or just Reboot and use the new password.

Wednesday, October 17

8 Ways To Mount SMBfs (SAMBA FILE SYSTEM) In Linux.


How to Mount smbfs (SAMBA file system) permanently in Linux.In this post I am going to give some examples how to do SMB (Server Message Block) mounts..
Type: Listing SMB shared folder through command prompt
#smbclient –L ipadd –U username
Here –L will specify listing of SMB share for the server with ipadd
Or
#smbclient //192.168.0.1/share1 –U username
Example :
#smbclient –L 192.168.0.1 –U root

How to find command location in Linux


This is a small how to on finding your command location. Some times its required to find command location to use it as path is not set properly to /bin or /sbin or some other folder. And some times we install packages through scripts where the commands will be installed in a defined path other than /usr/bin or /usr/sbin etc.
command to check where the particular command is installed?
which command-name
Example:
which ls
Output:
root@surendra:/home/surendra# which ls
/bin/ls
root@surendra:/home/surendra#

Linux Directory Structure explained: /bin folder


 /bin is one more important folder. Bin stands for binary which means an executable file. This folder contains commands or scripts or executable which can be executed to accomplish a task. We have some cousins to this folder as given below along with bin folder.
/bin
/sbin
/usr/bin
/usr/sbin
/usr/local/bin
/usr/local/sbin

Wednesday, September 5

System Logging

What is System Logging ?
n  An important part of maintaining a secure system is keeping track of the activities that take place on the system. If you know what usually happens, such as understanding when users log into your system, you can use log files to spot unusual activity
n  Two main logging daemons
l  klogd                           :The kernel log daemon service logs kernel messages                                                  and events
l  syslogd                        :The syslog daemon logs all other process activity. You can use the log files that syslogd generates to track activities on your system
Log Files
n  /var/log/dmesg                        : Kernel log messages
n  /var/log/messages                   : Standard system error messages
n  /var/log/maillog                      : Mail System messages
n  /var/log/secure                        : Security, authentication, and xinetd messages

utmpdump /var/log/wtmp

YUM Server configuration steps


To solve the problem of dependency resolution and package location, volunteer programmers at Duke University developed Yellow dog Update, Modified or short for YUM. The system is based on repositories that hold RPMs and repodata file list. Yum server is the centralized server through which you can install all servers’ package. The data of Yum server is stored in /var/ftp/pub to install Yum server you should have minimum 7 GB  in /Var partition. If you don’t have var partition then you should create a new partition and mount with /var by using vi /etc/fstab.

LAB: - ---------------------------------------------------------------------------------------------

~] # create a drive like mkdir /popo
~] # mount /dev/cdrom /popo
~] # cd /popo/
Popo] # cd Server
Server] # rpm –ivh vsftpd (press tab key to complete the command)
Server] # rpm –ivh createrepo (press tab key to complete the command)
Server] # cp –rvf /popo/* /var/ftp/pub
Server] # cd /var/ftp/pub
Server] # cd Server
Server] # createrepo –v /var/ftp/pub/Server/
Server] # service vsftpd restart;chkconfig vsftpd on
Server] # service portmap restart;chkconfig portmap on
Server] # service iptables stop

Sunday, July 29

Introduction of Linux FTP Server


The File Transfer Protocol (FTP) is used as one of the most common means of copying files between servers over the Internet. Most web based download sites use the built in FTP capabilities of most web browsers and therefore server oriented operating systems usually include an FTP server application as part of the software suite. Linux is no exception.
Here we will show you how to convert your Linux Machine into an FTP server using the default Very Secure FTP Daemon (VSFTPD) package. 

FTP Overview

FTP relies on a pair of TCP ports to get the job done. It operates in two connection channels as I'll explain:
FTP Control Channel, TCP Port 21: All commands you send and the ftp server's responses to those commands will go over the control connection, but any data sent back (such as "ls" directory lists or actual file data in either direction) will go over the data connection.
FTP Data Channel, TCP Port 20: This port is used for all subsequent data transfers between the client and server.
In addition to these channels, there are several varieties of FTP.

FTP frequently fails when the data has to pass through a firewall, because firewalls are designed to limit data flows to predictable TCP ports and FTP uses a wide range of unpredictable TCP ports. You have a choice of methods to overcome this. 

Package Required: vsftpd

Introduction Of IPTABLES


Iptables is used to set up, maintain, and inspect the tables of IP packet filter rules in the Linux kernel. Several different tables may be defined. Each table contains a number of built-in chains and may also contain user-defined chains.
Each chain is a list of rules which can match a set of packets. Each rule specifies what to do with a packet that matches. This is called a 'target', which may be a

Targets

A firewall rule specifies criteria for a packet and a target. If the packet does not match, the next rule in the chain is the examined; if it does match, then the next rule is specified by the value of the target, which can be the name of a user-defined chain or one of the special values ACCEPT, DROP, QUEUE or RETURN.

ACCEPT means to let the packet through. DROP means to drop the packet on the floor. QUEUE means to pass the packet to user space. (How the packet can be received by a user space process differs by the particular queue handler. 2.4.x and 2.6.x kernels up to 2.6.13 include the ip_queue queue handler. Kernels 2.6.14 and later additionally include the nfnetlink_queue queue handler. Packets with a target of QUEUE will be sent to queue number '0' in this case. Please also see the NFQUEUE target as described later in this man page.) RETURN means stop traversing this chain and resume at the next rule in the previous (calling) chain. If the end of a built-in chain is reached or a rule in a built-in chain with target RETURN is matched, the target specified by the chain policy determines the fate of the packet.

Set Default Chain Policies

Saturday, July 21

How to Extend and Reduce Logical Volume


The biggest advantage of logical volume manager is that you can extend your logical volumes any time you are running out of the space. To increase the size of a logical volume by another 800 MB you can run this command:

1. How to Extend

# lvextend -L +800M/G <LV path>
The command above does not actually increase the physical size of volume, to do that you need to:
# resize2fs  <LV path>
The above method we use for online resizing and below is by unmounting.

Wednesday, July 18

Linux/Unix sort command examples

This is a small tutorial on how to use sort command to sort a file. Sorting is very useful when dealing with DB files, CSV, xls, log files in fact a text file too. By default sort command will sort according to alphabets. First sort tries to sort according to single character, if it finds the first character same in two lines, then it moves to sort second character. Suppose I have a following word list in a file
cat filename.txt
abc
cde
hij
klm
kle
ble
This will be sorted first with first char. When it finds both the char same in this example klm and kle start with same characters, so it tries to sort with third character which is different in them. The output of sort  as below
sort filename.txt
abc
ble
cde
hij
kle
klm

How to setup More Than One IP address on single NIC in Linux

Setting up two IP address on single NIC
There are some times we require two IP address to set up so that we can make a Linux box as a router. It can be possible without even having two NIC cards. We can configure more than two different IP address on single Network Card as shown below:
This example is on Ethernet.
STEP 1: Setting up first IP address. Edit /etc/sysconfig/network-scripts/ifcfg-eth0 on Red-hat Linux box and give the following entries as shown.
vi /etc/sysconfig/network-scripts/ifcfg-eth0
  • DEVICE=eth0
  • BOOTPROTO=static
  • IPADDR=192.168.1.10
  • NETMASK=255.255.255.0
  • NETWORK=192.168.1.0
  • ONBOOT=yes