Thursday, October 23, 2014

Bash interpreting a Command

By default bash is the default shell in Linux. Lets see how bash shell interprets the command we type in.

It not as simple as checking the binaries in directories specified in the $PATH variable. It flows through the following steps:
  1. Redirection
  2. Aliases
  3. Expansion
  4. Shell Function
  5. Shell Built-in
  6. Hash table
  7. PATH variable
Lets go through the steps :

1. Redirection.
This comes into picture when you use redirection : ">" and ">>".


You can see that a file list.txt is automatically created before the "ls" command is executed with redirection ">". How does this happened ? Redirection is done and the o/p file is created before the command "ls" is executed.  

2. Alias.
Alias is actually shortcuts or easy to remember alternatives of a command.


Here we have defined alias "ls=cat", now when we type "ls list.txt" , ls is replaced with cat and contents of list.txt file is displayed.
Just FYI, we can make the shell ignore alias by preceding "\" with the command.
 
3. Expansion : 
Expansion stands for command substitution, variable and parameter expansion, tilde expansion, brace expansion, arithmetic expansion, word splitting, and path name expansion. 
 

Like this ~, *,? etc will be replaced accodingly.

4. Functions defined in the Shell
Shell also allows to define functions like other programming languages. After defining functions you can execute it just like any other commands.


As you can see, here I have shown you the order of interpretation. Alias has precedence over Functions!. When we first executed "ls" the alias /bin/ls is executed. Then ignored alias with "\" and function is executed. Then we deleted the alias "unalias" command. Now since there is no alias, text candidate to run is function.

5. Shell Builtin
The bash code contains some commands as well. These commands gets precedence over other binaries. The type command can be used to identify who the command is interpreted. 

Lets play a bit with this :

[jk@rhel1 ~]$ type echo
echo is a shell builtin

[jk@rhel1 ~]$ which echo
/bin/echo

[jk@rhel1 ~]$ type ls
ls is a function
ls ()
{
    echo "I am a Function"
}

[jk@rhel1 ~]$ alias ls="echo GNU/Linux"
[jk@rhel1 ~]$ type ls
ls is aliased to `echo GNU/Linux'
[jk@rhel1 ~]$ ls
GNU/Linux

[jk@rhel1 ~]$ unalias ls
[jk@rhel1 ~]$ ls
I am a Function

[jk@rhel1 ~]$ unset ls
[jk@rhel1 ~]$ type ls
ls is hashed (/bin/ls)
[jk@rhel1 ~]$

I shall explain why "hashed" is displayed in the last command.


6. Hash Table 
The concept of hash table is similar to cashing in Linux, shell store the full path of all the executed commands to speed things up. 
Lets see how hast table works. We have started a new shell and executed "ls", "cat" and "echo" commands. Then we checked the hash table entries. The hash table, as already mentioned, contains two columns, first column contains the cache hits and the 2nd column contains the full path of the command. Also note that the shell built in command "echo" is not listed in the hash table. Remember the purpose the hash table is to speed up the execution. 


You can see that when the command "ls" is executed the second time, the hits value is increased.

7. Path Variable
After all the above steps are over or not available, shell searches for the given command in the directories specified in the PATH variable. 

[jk@rhel1 ~]$ echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/jk/bin
[jk@rhel1 ~]$


Tuesday, October 7, 2014

Disk Metadata : Superblock, Directory and Inodes

Metadata
Filesystem blocks are user for 2 purposes : To store User data and Metadata
  • User data - stores actual data contained in files
  • Metadata - stores file system structural information such as superblock, inodes, directories
Metadata describes the structure of the file system. Most common metadata structure are superblock, inode and directories.

Superblocks
Every FS has a superblock which contains info about filesystems such as :
  • File system type
  • Size
  • Status
  • Information about other metadata structures
    • For filesystems with 1k blocksizes, a backup superblock can be found at block 8193
    • For filesystems with 2k blocksizes, at block 16384
    • For 4k blocksizes, at block 32768.
List backup superblocks:
# dumpe2fs /dev/hda3 | grep -i superblock

If Superblock  is corrupted, restore with backup :
# e2fsck -f -b 8193 /dev/sda3
 
Inode
 
 An inode is a data structure on a Linux Unix FS which stores stores basic information about a regular file, directory, or other file system objects.  

Monday, April 28, 2014

Recover deleted files used by any process in Linux from RAM memory.


Every thing in Linux is a File. A file in turn is actually a pointer to inode which contain the actual data on the disk, permissions, ownership. Now what happens when a file is deleted ? Only the link is removed by not the inode or the actual data. if a process is using the file, or if the file is open , the inode is not released for overwriting util the process is done with the file. Such files will remain in the server memory (RAM). 

Lets discuss how to recover such deleted files which is being used by a process.

Lets do it with an example.

Create a test file.
# touch testfile.txt

Echo some random data on it.
# cat /dev/random > testfile.txt

Open the file using some command like below.
# less  testfile.txt

# ps -ef | grep -i less
less 4607 root  4r  REG 254,4   21  
           8880214 /root/testing.txt (deleted)

All the open files remain in the memory and hence in the /proc filesystem. The important columns in the above output are the second one, which gives you the PID of the process that has the file open (4607), and the fourth one, which gives you the file descriptor (4). Now, we go look in /proc, where there will still be a reference to the inode, from which you can copy the file back.

# ls -l /proc/4607/fd/4
lr-x------ 1 root root 64 Apr  7 03:19 
             /proc/4607/fd/4 -> /root/testing.txt (deleted)
  
To recover the deleted file in memory, just copy as below.
 #cp /proc/4607/fd/4 testing.txt.bk


Hurray you got your file back. Just make sure not to use "-a" switch while copying the file as this will copy the broken softlink.

JK

 

Tuesday, April 8, 2014

Sendmail Error : NOQUEUE: SYSERR(root): No local mailer defined NOQUEUE: SYSERR(root): QueueDirectory (Q) option must be set

Error using m4 macro while building sendmail.cf from sendmail.mc on RHEL 6 / CentOS 6 flavors?

[root@cent1]# m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
m4:/etc/mail/sendmail.mc:10: cannot open `/usr/share/sendmail-cf/m4/cf.m4': No such file or directory
[root@cent1]#

The above error is because the package sendmail-cf is not installed.


You will have the below error messages on the /var/log/maillog file also. 

sendmail[3215]: gethostbyaddr(10.0.3.15) failed: 2
sendmail[3215]: NOQUEUE: SYSERR(root): No local mailer defined
sendmail[3215]: NOQUEUE: SYSERR(root): QueueDirectory (Q) option must be set

The above error is because the sendmail.cf is not configured properly. 

Fix is to install the package sendmail-cf, build sendmail.cf from sendmail.mc and restart sendmail service.

Install the sendmail-cf

# yum install -y sendmail-cf


Comment the entry which makes the sendmail listens only to loopback address as below by adding "dnl" on /etc/mail/sendmail.mc

# vi /etc/mail/sendmail.mc
dnl # DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl

# m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

# service sendmail restart

Check if sendmail is started properly.

[root@cent1 ~]# netstat -tulnp |  grep -i :25
tcp        0      0 0.0.0.0:25                  0.0.0.0:*                   LISTEN      3748/sendmail
[root@cent1 ~]#

Hope this helps.
Jk


Change Default MTA in RHEL 6 / Cent OS 6

By default Postfix is set as the default mail transfer agent in Redhat Enterprise Linux 6 and Cent OS 6 flavors.

However you can change the default Mail transfer Agent in RHEL 6 using the below commands.

* Install Sendmail if not yet installed.

# yum install sendmail -y

Change the default MTA.

# alternatives --config mta

There are 2 programs which provide 'mta'.
  Selection    Command
-----------------------------------------------
 + 1           /usr/sbin/sendmail.postfix
*  2           /usr/sbin/sendmail.sendmail
Enter to keep the current selection[+], or type selection number: 2
#

Congrats, now your default MTS is changed from postfix to Sendmail.

Regards,
Jk

Thursday, October 10, 2013

How to configure Veritas Volume Manager VxVM 6.0.2

The disks should be discovered by OS before it can be added to Veritas Volume Manager.


1. List the disks detected by VxVM.

# vxdisk -o alldgs list


Eg :

[root@rhel61 ~]# vxdisk -o alldgs list
DEVICE       TYPE            DISK         GROUP        STATUS
sda          auto:none       -            -            online invalid
sdb          auto:none       -            -            online invalid
sdc          auto:cdsdisk    mydg01       mydg         online
sdd          auto:cdsdisk    mydg02       mydg         online
[root@rhel61 ~]#

sda and sbd are not configured / initialized for VxVM; where as sdc and sdd are initialized and added to a disk group.


2. Initialize disks.

vxdisksetup -i [attributes]

# vxdisksetup -i sdc
# vxdisksetup -i emc0_dd1

Initializing a disk will create Privae and Public regions in the disks, Meta data is stored in private region and public reagion is available for general purpose data usage. 32 MB is reserved for private region.

Friday, July 5, 2013

Configure DNS Client in Solaris 11.1

Solaris 11.1 saw a lot of changes. A number of configurations has been moved from config files to Service Management Framework , SMF.

To enable DNS client you should be come an Administrator.

1. List the current DNS Client configuration.

root@solaris11.1:~# svccfg -s network/dns/client listprop config
config                      application
config/value_authorization astring     solaris.smf.value.name-service.dns.client
config/domain              astring     Home
config/nameserver          net_address
root@solaris11.1:~#


2. Update the SMF repository with the DNS server name. Let 192.168.1.1 and 192.168.1.2 be the primary and secondary DNS server.

root@solaris11.1:~# svccfg -s network/dns/client setprop config/nameserver = net_address: "(192.168.1.1 192.168.1.2)"
root@solaris11.1:~#

3. change the Domain name.
root@solaris11.1:~# svccfg -s network/dns/client setprop config/domain = astring: '("solaris.local")'
root@solaris11.1:~#

4. Change the search domains.
root@solaris11.1:~# svccfg -s network/dns/client setprop config/search = astring: '("solaris.local" test.solaris.local)'
root@solaris11.1:~#

5. Update the Name resolution order.
root@solaris11.1:~# svccfg -s name-service/switch setprop config/host = astring: '("files dns mdns")'
root@solaris11.1:~#

6. Review the modified DNS client configuration
root@solaris11.1:~# svccfg -s network/dns/client listprop config
config                      application
config/value_authorization astring     solaris.smf.value.name-service.dns.client
config/domain              astring     solaris.local test.solaris.local
config/nameserver          net_address 192.168.1.1 192.168.1.2
root@solaris11.1:~#

root@sol1:~# svccfg -s name-service/switch listprop config
config                      application
config/default             astring     files
config/value_authorization astring     solaris.smf.value.name-service.switch
config/host                astring     "files dns mdns"
config/printer             astring     "user files"
root@sol1:~#

Jayakrishnan

Wednesday, June 12, 2013

Cut command reference

Cut is a simpler alternative to the sed command. Cut is also very efficient and flexible..

The examples specified below is from Solaris 11.1 and  RedHat Enterprise Linux 6.4, however most of the Linux / Unix distributions supports the cut command.

We shall use the below file for our examples.

root@sol1:~/jk# cat testfile.txt
This is a test file to demonstrate "cut" command.
Cut can be used for line filtering.
Cut is simpler than awk and sed commands.
root@sol1:~/jk#


1. Select a field from a file.
You can combine -f and -d to print required field. -f specifies the field and -d specified the delimiter to be used to find the filed.

root@sol1:~/jk# cut -d':' -f1 /etc/passwd | head -5
root
daemon
bin
sys
adm
root@sol1:~/jk#


2. Select multiple fields from a file.
To select multiple fields use comma separated numbers with -f.

root@sol1:~/jk# cut -d' ' -f 1,5 testfile.txt
This file
Cut for
Cut awk
root@sol1:~/jk#
Here 'space' is the delimiter.


3. Select Column of characters.
To print selected column or character from a file use -c option.

root@sol1:~/jk# cut -c2 testfile.txt
h
u
u
root@sol1:~/jk#
 
As you can see, h,u,u are the 2nd character on each line.


4.  Select column of characters using range.
 
To print from 3rd character to the end :

root@sol1:~/jk# cut -c3- testfile.txt
is is a test file to demonstrate "cut" command.
t can be used for line filtering.
t is simpler than awk and sed commands.
root@sol1:~/jk#

To print till 5th character :

root@sol1:~/jk# cut -c-5 testfile.txt
This
Cut c
Cut i
root@sol1:~/jk#

To print from 5th character to 10th character.
 
root@sol1:~/jk# cut -c5-10 testfile.txt
 is a
can be
is sim
root@sol1:~/jk#

Whole lines will be print if no number is specified before or after '-'.

root@sol1:~/jk# cut -c- testfile.txt
This is a test file to demonstrate "cut" command.
Cut can be used for line filtering.
Cut is simpler than awk and sed commands.
root@sol1:~/jk#

5. Print fields only when the delimiter specified is present.

If the delimiter specified is not present in the file, cut will print the whole lines.

root@sol1:~/jk# cut -d'|' -f1 /etc/passwd | head -5
root:x:0:0:Super-User:/root:/usr/bin/bash
daemon:x:1:1::/:
bin:x:2:2::/usr/bin:
sys:x:3:3::/:
adm:x:4:4:Admin:/var/adm:
root@sol1:~/jk#

Use '-s' to prevent this behaviour.

root@sol1:~/jk# cut -d'|' -s -f1 /etc/passwd | head -5
root@sol1:~/jk#

6. To select all fields except the ones specified.
Use --complement to invert cut's behavior. Note '--complement' is not available in Solaris.

root@sol1:~/jk# cut -d' ' --complement -f1,3 testfile.txt
is test file to demonstrate "cut" command.
can used for line filtering.
is than awk and sed commands.
root@sol1:~/jk#


7. Change output delimiter for ease of reading.
You can use '--output-delimiter' to custom specify the delimiter to print. Note : --output-delimiter is not available in Solaris.

root@rhel:~/jk# grep "/bin/bash" /etc/passwd | cut -d':'  -s -f1,6,7 --output-delimiter='#'
root#/root#/usr/bin/bash
root@rhel:~/jk#

You can also use the escape characters as follows. For changing the delimiter to "new line":

root@sol1:~/jk# grep "/bin/bash" /etc/passwd | cut -d':'  -s -f1,6,7 --output-delimiter=$'\n'
root
/root
/usr/bin/bash
root@sol1:~/jk#

Remember to use "$" as the escape character.

Cut is a very cool and simple utility. Master it !!

JK.

Thursday, April 25, 2013

Set Setuid, Setgid and Sticky bit in Linux

Special permissions on files and directories in linux are : SetUID, SetGID and Sticky bit.

With the help of “chmod” command  we can implement the special permissions on file and directories.

SUID / Set User ID : A program is executed with the file owner's permissions (rather than with the permissions of the user who executes it).

SGID / Set Group ID : Files created in the directory inherit its GID, i.e When a directory is shared between the users , and sgid is implemented on that shared directory , when these users creates  directory, then the created directory has the same gid or group owner of its parent directory.

Sticky Bit :  It is used mainly used on folders in order to avoid deletion of a folder and its content by other user though he/she is having write permissions. If Sticky bit is enabled on a folder, the folder is deleted by only owner of the folder and super user(root). This is a security measure to suppress deletion of critical folders where it is having full permissions by others.

Assign IP Address and Gateway in Linux from Command Line

if config command is used to assign the ip address to a lan card from the command or from the terminal.

Syntax :

 # ifconfig [-v] [-a] [-s]  [interface]

Options :
  • -a :    display all interfaces which are currently available, even if down
  • -s :    display a short list (like netstat -i)
  • -v :   be more verbose for some error conditions
interface : The name of the interface.  This is usually a driver name followed by a unit number, for example eth0 for  the  first Ethernet interface. If your kernel supports alias interfaces, you can specify them with eth0:0 for the first alias of eth0. One can use them to assign a second address. To delete an alias interface use ifconfig eth0:0 down.

Sunday, February 10, 2013

Grub Re-install for SUSE Linux


The below steps can be used to fix un-bootable SUSE Linux OS due to Grub corruption or any damage to GRUB boot loader.

Boot to the SLED or SLES 11 DVD (the SP1 DVD is also fine), select "Rescue System" and login as root.  At the command line enter "grub" and follow this example:

******************
linux:~ # grub

    GNU GRUB  version 0.97  (640K lower / 3072K upper memory)
 [ Minimal BASH-like line editing is supported.  For the first word, TAB
   lists possible command completions.  Anywhere else TAB lists the possible
   completions of a device/filename. ]

grub> find /boot/grub/stage1
 (hd0,0)

grub> root (hd0,0)
 Filesystem type is reiserfs, partition type 0xfd

grub> setup (hd0)
 Checking if "/boot/grub/stage1" exists... yes
 Checking if "/boot/grub/stage2" exists... yes
 Checking if "/boot/grub/reiserfs_stage1_5" exists... yes
 Running "embed /boot/grub/reiserfs_stage1_5 (hd0)"...  18 sectors are embedded.
succeeded
 Running "install /boot/grub/stage1 (hd0) (hd0)1+18 p (hd0,0)/boot/grub/stage2 /boot/
grub/menu.lst"... succeeded
Done.

grub> quit
******************

In this example the root partition is (hd0,0) as returned by the "find /boot/grub/stage1" command.  Use the correct root partition for your system as indicated by this command for the two commands that follow the first one.

Reboot the system and GRUB should come up appropriately.

This Doc is for SUSE Linux Enterprise Server 11 or SUSE Linux Enterprise Desktop 11 but it should work for all SLES and OpenSUSE editons with little and obvious modifications. 





Wednesday, January 16, 2013

Network Bonding / NIC Teaming in Linux


Network Bonding :- NIC teaming or network bonding is nothing but combining or aggregating multiple network connections in parallel. This is done to increase throughput, and to provide redundancy in case one of the links fails or Ethernet card fails. The Linux kernel comes with the bounding driver for aggregating multiple network interfaces into a single logical interface called bond0.

Bonding is nothing but Linux kernel feature that allows to aggregate multiple like interfaces (such as eth0, eth1) into a single virtual link such as bond0. The idea is pretty simple get higher data rates and as well as link failover. Steps To Configure Bonding in Linux



Step #1: Create a Bond0 Configuration File:
CentOS stores network configuration in /etc/sysconfig/network-scripts/ directory. First, we need to create a bond0 config file as follows:

# vi /etc/sysconfig/network-scripts/ifcfg-bond0
Append the following lines:
DEVICE=bond0
IPADDR=192.168.1.20
NETWORK=192.168.1.0
NETMASK=255.255.255.0
USERCTL=no
BOOTPROTO=none
ONBOOT=yes

You need to replace IP address with your actual setup. Save and close the file.


Tuesday, October 30, 2012

The XARGS command


The xargs Command.


Xargs' power lies in the fact that it can take the output of one command, and use that output as arguments to another command. So, using the basic find command below, let us pass the output of find to xargs and get xargs to issue multiple 'ls -l' commands.

# find ~ -type f -mmin -90 | xargs ls -l

Sample output: 
-rw-rw-r--    1 linux    lunux    10209032 Jun 30 13:28 /home/linux/dns/mysql-outfile/dnsx.doc
-rw-rw-rw-    1 mysql    mysql    10209032 Jun 30 12:53 /home/linux/dns/mysql-outfile/dnsx.txt

Important Switches

-r --> Tells xargs to quit; when the its i/p doesn't contain any non-zero files.
# find ~ -type f -mtime +1825 |xargs -r ls -l

-0, --null --> Expect filenames to be terminated by NULL instead of whitespace. Do not treat quotes or backslashes specially.
Used with print0 command (at first set), so the args are terminated with a null.

$ find /share/media/mp3/ -type f -name "*.mp3" -print0 | xargs -0 -r -I {} cp -v -p {} --target-directory=/bakup/iscsi/mp3/

-n args, --max-args=args --> Max number or args to pass to the 2nd command at a time.
$ echo 1 2 3 4 | xargs -n 2

-I [string] --> Replace all occurrences of { }, or string, with the names read from standard input. Unquoted blanks are not considered argument terminators. Implies -x and -L 1.

-L [lines] , --max-lines[=lines] --> Allow no more than lines nonblank input lines on the command line (default is 1). Implies -x.
-x, --exit --> If the maximum size (as specified by -s) is exceeded, exit.
-s max, --max-chars=max --> Allow no more than max characters per command line.


Most used while deleting/copying a large number of files which can't by default, handled by rm or cp or any other commands.

Xargs examples.

# ls |xargs -I {} cp -v {} /mnt/import_log/


The above command will copy all the files from the current location to /mnt/import_log/ irrespective of number of files.


# ls |xargs -n10 -I {} tar -cvf /mnt/import_log_file.tar {}

The above command will tar the entire contents of the current directory to /mnt/import_log_file.tar.


Similarly you will find the xargs command to be useful in many cases.

An example error if you try to delete contents a directory with a lot of files.

/bin/rm: Argument list too long.

Just use the xargs as above to solve this.

Saturday, April 28, 2012

Mounting iSCSI Luns on Linux Hosts

Adding iSCSI Storage to a Linux Computer
 
This article describes mounting iSCSI luns from SAN iSCSI targets to Linux hosts. Please make sure that an iSCSI Target has been created and ready for use in theSAN / NAS targets. 


Step 1: Install the iSCSI Initiator Software

[root@test.com /]# yum install iscsi-initiator-utils
Loaded plugins: presto, refresh-packagekit
Setting up Install Process
Resolving Dependencies
Running transaction check
Package iscsi-initiator-utils.i686 0:6.2.0.872-7.fc13 set to be installed
Finished Dependency Resolution
...
Installed:
  iscsi-initiator-utils.i686 0:6.2.0.872-7.fc13                                

Complete!

Things you need to have before setting up the iSCSI mounts.
  1. iSCSI startup using the init script or manual startup. You need to edit and configure iSCSI via /etc/iscsi/iscsid.conf file
  2. Discover targets.
  3. Automate target logins for future system reboots.
  4. You also need to obtain iSCSI username, password and storage server IP address (target host)
 Step 2: Edit the iscsi.conf file

Setup username and password:
node.session.auth.username = My_ISCSI_USR_NAME
node.session.auth.password = MyPassword
discovery.sendtargets.auth.username = My_ISCSI_USR_NAME
discovery.sendtargets.auth.password = MyPassword


Where,
  • node.session.* is used to set a CHAP username and password for initiator authentication by the target(s).
  • discovery.sendtargets.* is used to set a discovery session CHAP username and password for the initiator authentication by the target(s)
Make sure iscsi.conf 'node' parameter is set for Automatic
[root@test.com /]# vi /etc/iscsi/iscsid.conf
node.startup = automatic

Now start the iscsi service:
# /etc/init.d/iscsi start

Friday, March 30, 2012

The Find command cheat sheet


The Find Command Cheat Sheet


1. Basic find command
# find -name "TestFile"

2. Find Files Using Name and Ignoring Case
# find -iname "TestFile"

3. Limit Search To Specific Directory Level Using mindepth and maxdepth
# find / -maxdepth 3 -name passwd
-maxdepth --> will go 3 directories below -- / 1st; /etc 2nd; /usr/bin 3rd

# find / -mindepth 3 -maxdepth 5 -name passwd
will go 3 depths first and upto 5 -- so will not disply under /; /usr; /usr/bin

4. Executing Commands on the Files Found by the Find Command.
user -exec {} /;
# find -iname "TestFile" -exec md5sum {} \;

5. Inverting the match.
To inver the match use the "-not" switch
# find / -not -iname "TestFile"

6. List inodes of the files
# ls -i1 test*
16187429 test-file-name
16187430 test-file-name

# find -inum 16187430 -exec mv {} new-test-file-name \;
# ls -i1 *test*
16187430 new-test-file-name
16187429 test-file-name

7. Find file based on the File-Permissions
You can :
    * Find files that match exact permission
    * Check whether the given permission matches, irrespective of other permission bits
    * Search by giving octal / symbolic representation

# find . -perm -g=r -type f -exec ls -l {} \;
Will display all files with group permission read. Not files with readonly group permission

# find . -perm g=r -type f -exec ls -l {} \;
Will dispay files with 040 permission. i.e files with group read only permisison

# find . -perm 040 -type f -exec ls -l {} \;
Will dispay files with 040 permission. i.e files with group read only permisison

Tuesday, March 29, 2011

Download RPM packages from a YUM repo without installing in RHEL

Download RPM packages using YUM


This how-to will explain how to download rpm packages from a yum repository without installing them. This will work on Redhat Enterprise Linux 5.x, Fedora and CentOS 5.x.

You need to install yum plugin called yum-downloadonly. This plugin adds a --downloadonly flag to yum so that yum can download the packages without installing/updating them. Following options supported by this plugin:

  • --downloadonly : don't update, just download a rpm file to default yum cache directory /var/cache/yum/.
  • --downloaddir=/path/to/dir : specifies an alternate directory to store packages such as /tmp
Install the yum-downloadonly plugin:

Type the following command to install plugin, enter:

        # yum install yum-downloadonly

Now for downloading rpm packages from an already configured yum repository use the following command:

      # yum update httpd -y --downloadonly

Friday, February 4, 2011

TCP Wrappers: Securing Linux


This how-to describes configuring TCP Wrappers for providing Access Control for the supported services in a Linux box.TCP wrappers are supported by most of the Linux distributions such as Redhat Enterprise Linux, Ubuntu, SUSE, Debian, BSD and UNIX. TCP Wrappers work in the manner of a host-based Access Control List. They will allow host or network addresses to be used as indicators to filter and implement a layer of access control. They additionally extend the capabilities of xinetd-controlled daemons. By using this technique, connection attempts can be logged, restricted, and messages returned. This can add an extra layer of security in your environment. TCP Wrappers also allow run-time reconfiguration without restarting or reloading the services they protect.

Mount NTFS partition in Linux

Mount NTFS partition in Redhat Enterpris Linux / Ubuntu Linux


Enterprise Linux distributions like Redhat Enterprise Linux ( RHEL ) does not provide native support to Windows NTFS partitions. However you may wand to mount a NTFS formated partiiton in your RHEL box. Here is a simple howto to mount NTFS partitions in your RHEL box.

First of all you need to install a couple of packages. You can use YUM for installing the packages. The rpmforge yum repo contains required rpm packages for mounting NTFS partitions on Linux server. The packages are fuse and fuse-ntfs-3g.

              # yum install fuse fuse-ntfs-3g
Yes, you are done now you can mount ntfs partitions on your rhel server using the mount commandas follows.

             # mount -t ntfs-3g /dev/device-name /mount-point

For example:
           # mount -t ntfs-3g /dev/sdb1 /media

This one also works!!!!!

          # mount.ntfs-3g /dev/sdb1 /media
Newer Ubuntu distributions like Ubuntu 10.04 LTS natively supports NTFS partiitons, so in a Ubuntu server you can mount NTFS partition by just using the above mount commnad.