Wednesday, February 19, 2014

Linix tips & tricks

[Softlinks and hardlinks in Linux ]

Hardlink vs Softlink in Linux
Hard links: a hard link is a pointer to the file's i-node.

Create a hard link using :
ln a-file.txt b-file.txt

Soft links (symbolic links): a soft link, also called symbolic link, is a file that contains the name of another file
We can then access the contents of the other file through that name. That is, a symbolic link is like a pointer to the pointer to the file's contents.

Create a soft-link using :
root# : ln -s a-file.txt b-file.txt

The most significant drawback is that hard links cannot be created to link a file from one file system to another file on another file system

What will happen if orginal file of hardlink or softlink is deleted?
In case of hard link even if original file is deleted data second file is accesible

In case of softlink if orginal file is deleted,the file contents will not be accessible


[Command to view memory usage in Linux]

cat /proc/meminfo

free command

To display free memory size in MB (megabytes):
$ free -m

[Mount command]

cifs mount
 mount -t cifs -o username=qauser,password=qawzsx\!3 //backupserver/Builds /mnt/win

nfs mount :
mount -t nfs /dev/sdb /mnt/Store
where /mnt/Store is the mount directory

This file contains these default limits:
fsize = 2097151
core = 2097151
cpu = -1
data = 262144
rss = 65536
stack = 65536
nofiles = 2000
threads = -1
nproc = -1
ulimit -a #list all current resource limits

time(seconds)        unlimited
file(blocks)         2097151
data(kbytes)         131072
stack(kbytes)        32768
memory(kbytes)       65536
coredump(blocks)     2097151
nofiles(descriptors) 2000
threads(per process) unlimited
processes(per user)  unlimited
-u Specifies the limit on the number of a process a user can create.


cat /etc/sysconfig/network

NETWORKING=yes
HOSTNAME=server1.parag.com
GATEWAY=192.168.1.254

# cat /etc/sysconfig/network-scripts/ifcfg-eth0

Sample static ip configuration:


# Intel Corporation 82573E Gigabit Ethernet Controller (Copper)
DEVICE=eth0
BOOTPROTO=static
DHCPCLASS=
HWADDR=00:30:48:56:A6:2E
IPADDR=192.168.1.10
NETMASK=255.255.255.0
ONBOOT=yes
# cat /etc/resolv.conf
BOOTPROTO=dynamic for dynamic ip addresses


Sample static IP configurations:


search cyberciti.biz
nameserver 192.168.1.254
nameserver 8.8.8.8
nameserver 202.54.2.1

To verify new static ip configuration for eth0, enter:
# ifconfig eth0
# route -n
# ping 192.168.1.254
# ping google.com

First, you have to install the DHCP on a server, as shown in the following steps:

Install the DHCP server:
up2date -i dhcp
Create the /etc/dhcpd.conf file and enter the following information:
option routers 192.168.1.254;
shared-network YOUR.NET {
 subnet 192.168.1.0 netmask 255.255.255.0 {
 range 192.168.1.40 192.168.1.50;
 }
 }
The first section describes the range of IP addresses, within the class C subnet 192.168.1.0, that the DHCP clients are going to use.

Create the /etc/dhcpd.leases file:
touch /etc/dhcpd.leases
You don't need to put anything into this file. The dhcpd daemon dynamically puts information here about the computers that are getting their IP addresses from DHCP. Those addresses are called leases.

Start the dhcpd server:
/sbin/service dhcp start
#starts the service now
/sbin/chkconfig dhcpd on
#makes sure it starts next time

Your dhcpd server is now ready for client computers to get their IP addresses and routing information.


The primary network configuration files are as follows:
/etc/hosts
The main purpose of this file is to resolve host names that cannot be resolved any other way. It can also be used to resolve host names on small networks with no DNS server. Regardless of the type of network the computer is on, this file should contain a line specifying the IP address of the loopback device (127.0.0.1) as localhost.localdomain.
/etc/resolv.conf
This file specifies the IP addresses of DNS servers and the search domain. Unless configured to do otherwise, the network initialization scripts populate this file.
/etc/sysconfig/network
This file specifies routing and host information for all network interfaces. It is used to contain directives which are to have global effect and not to be interface specific.
/etc/sysconfig/network-scripts/ifcfg-interface-name
For each network interface, there is a corresponding interface configuration script. Each of these files provide information specific to a particular network interface.
chmod user,group,others
read=4
write=2
execute=2
examples:
chmod 777 abc.txt
chmod 744 xyz.txt
Deny execute permission to everyone:  chmod a-x file Allow read permission to everyone: chmod a+r file Make a file readable and writable by the group and others:  chmod go+rw file


Password less ssh login

First, on the local machine you will want to generate a secure SSH key:
ssh-keygen
Walk through the key generator and set a password, the key file by default goes into ~/.ssh/id_rsa
ext, you need to copy the generated key to the remote server you want to setup passwordless logins with, this is easily done with the following command string but you can use scp if you’d prefer:
cat ~/.ssh/id_dsa.pub | ssh user@remotehost 'cat >> ~/.ssh/authorized_keys'
This command takes the generated SSH key from the local machine, connects to the remote host via SSH, and then uses cat to append the key file to the remote users authorized key list. Because this connects with SSH to the remote machine you will need to enter the password to use this command.

how to find run level on which os is running
root#who -r
YUM:
yum uses a configuration file at /etc/yum.conf.
reposdir A list of directories where yum should look for .repo files which define repositories to use. Default is '/etc/yum.repos.d'. Each file in this directory should contain one or more repository sections as documented in [repository] options below. These will be merged with the repositories defined in /etc/yum.conf to form the complete set of repositories that yum will use.


debuglevel Debug message output level. Practical range is 0-10. Default is '2'.


errorlevel Error message output level. Practical range is 0-10. Default is '2'.

UMASK
To calculate permissions that will result from specific umask values, subtract the umask from 777. Note, however, that files are not usually created with the execute permission by default, so the final permissions for files will omit the “x” permission.

For example, if the user wants all files created with permissions of 666, he/she should set the umask to 000. Alternatively, for all files to be created with permissions of 000, the user should set the umask to 777 or 666 (which works since files do not normally have the execute permission).

A reasonable value for umask is 022, which will cause files to be created with permissions of 644 (rw-r–r–) and directories to be created with permissions of 755 (rwxr-xr-x).

Ulimit command:

The ulimit command sets or reports user process resource limits, as defined in the /etc/security/limits file


Swap space in Linux is used when the amount of physical memory (RAM) is full. If the system needs more memory resources and the RAM is full, inactive pages in memory are moved to the swap space