Menu

Tuesday, March 13, 2012

Linux Command - ln


ln command - It is used to create a link between files. There are two types of links available in the Linux system.

  1. Hard Link
  2. Symbolic Link

Hard Link – It points the exact location of the specific file on the system.
Syntax: # ln target_file hardlink_name

Create a file named "file1"
# echo "This is file1" > file1

List the information of the current directory with inode value. Inode has the information of where the data is stored on the disk.
# ll –i
total 8
656011 -rw-r--r-- 1 root root 14 Mar 13 14:23 file1

Create a hard link “file2” for file1
# ln file1 file2

If you check the content of these two files, it will be same.
# cat file1 file2
This is file1
This is file1

If you check the inode value of both files, it will be same.
# ll -i
total 16
656011 -rw-r--r-- 2 root root 14 Mar 13 14:23 file1
656011 -rw-r--r-- 2 root root 14 Mar 13 14:23 file2

Even though we remove file1, the file2 is still accessible as the hard link directly points to location of the data.
# rm -f file1

# ll -i
total 8
656011 -rw-r--r-- 1 root root 14 Mar 13 14:23 file2
# cat file2
This is file1



Symbolic Link


Syntax: # ln –s file1 file2

Create a file
# echo "This is file1" > file1

Check the content of the file1
# cat file1
This is file1

Create a symbolic link for the file and list the information. The inode for these two files will be different. The file2 get the content through the file1 in the name of symbolic link. It is similar to short cut in windows.
# ln -s file1 file2
# ll -i

total 12
656013 -rw-r--r-- 1 root root 14 Mar 13 15:07 file1
656014 lrwxrwxrwx 1 root root  5 Mar 13 15:07 file2 -> file1

Check the type of the file2.
# file file2
file2: symbolic link to `file1'

If we remove the file1, the symbolic link file2 will not work.
# rm -f file1

#cat file2
cat: file2: No such file or directory

# file file2
file2: broken symbolic link to `file1'




Linux Command - File


File Command


This command is used to find the data type contained in a file

Syntax:
# file file_name

Example: 
# file test.txt



Thursday, March 8, 2012

Network Related Linux Commands


All the network related files and information are in

/etc/sysconfig/network-scripts/ifcfg-eth0
/etc/sysconfig/network
/etc/resolv.conf

Here is the list of network related comments
How to start and stop the network service?
# network service start
# network service stop
# network service restart


IP Address:
A unique address used to identify the computer or a device which is on the TCP/IP network.

Format of IP Address:
xxx.xxx.xxx.xxx   32 bit numeric address. Ex: 192.168.90.23

IP Address Classes:
A, B, C, D and E
Class A 1.0.0.0 to 127.255.255.255
Class B 128.0.0.0 to 191.255.255.255
Class C 191.0.0.0 to 223.255.255.255
Class D 224.0.0.0 to 239.255.255.255
Class E  240.0.0.0 to 255.255.255.255

Private IP address:
An IP address which is visible only to the private network (LAN).
    From 10.0.0.0 to 10.255.255.255
    From 172.16.0.0 to 172.31.255.255
    From 192.168.0.0 to 192.168.255.255

Linux commands - traceroute


traceroute

This command is used track the path of the packets which travels across the network from the starting location to the target host.

Example:
# traceroute [options] [target-host]
# traceroute learnjavajee.blogspot.com


Linux command - whois


whois

This command is used to query the information of the specific domain

Example:
# whois yahoo.com
# whois google.com


Linux command - nmap


nmap

It is a networking exploration tool and security scanner. This is very useful tool to determine the running services on a specific host and its status.

# nmap [taget-host]
# nmap localhost

Linux Command - ping


Ping

This command is used to check the specific host is reachable or not.

# ping 192.168.0.92
# ping yahoo.com

Linux Command - netstat


netstat – Network Statistics

This command is used to display all the network connections, routing tables and number of network interface.

Example:  The below command list all the java instance running on the system
# netstat --all --programs --numeric | grep java
# netstat –apn | grep java


How to check whether the specific port is listening on the system?
# netstat --listening  --numeric –programs | grep port_number

Example: To check whether 8080 port is listening
# netstat --listening --numeric –programs | grep 8080
# nestat –lnp | grep 8080


Some important options in netstat command
# netstat --all                  
# netstat --route          
# netstat --interfaces


Wednesday, March 7, 2012

Linux Command - ifconfig


Ifconfig 
This command is used to configure the network interfaces on the Linux system. The configuration files for each Ethernet Interfaces will be in the below location

/etc/sysconfig/network-scripts/

Syntax:  
# ifconfig [interface]

Example: The below command will display the information of the first “Ethernet Interface”.
# ifconfig eth0



"ifconfig" command without any option will list all the active Ethernet connections.
# ifconfig


This command with "-a" option list all the interfaces including interfaces which are down.
# ifconfig –a


Eth0 – First Ethernet Interface
Lo – Lookback Interface
Sit0 – First Simple interface Traslation


How to bring the specific network interface up and down?
Syntax: 
# ifconfig [interface] down/up

Example: 
# ifconfig eth0 down
# ifconfig eth0 up


# ifdown [OPTIONS] interface-card

Example:
# ifdown eth0
# ifdown eth0:1


# ifup [OPTIONS] interface-card

Example:
# ifup eth0
# ifup eth0:1


Type "man ifconfig" for more information about the this command.

Tuesday, March 6, 2012

How to assign multiple IP addresses to a single Network Card Interface


Step 1: Find out how many physical NIC on the system
# ll /etc/sysconfig/network-scripts


Consider you have one Ethernet device "eth0" and would like to add more IP addresses (alias) for the same.

In this example, I have assigned "192.168.0.90" and "192.168.0.88" to my primary (physical) Ethernet device.
192.168.0.91 eth0    primary (Physical NIC)
192.168.0.90 eth0:1 alias1     (Virtual NIC)
192.168.0.88 eth0:2 alias2     (Virtual NIC)


Step 2: Copy the eth0 file

# cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:1
# cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:2



Step 3: Edit the ifcfg-eth0:1 and ifcfg-eth0:2. Change the device name and the IP address.

# vim /etc/sysconfig/network-scripts/ifcfg-eth0:1

# vim /etc/sysconfig/network-scripts/ifcfg-eth0:2


Step 4: restart the network service

# service network restart








Step 5: Type ifconfig command to verify the network interface configuration and to check the all the IP addresses are running.

# ifconfig




Assign an IP address to the Linux system



How to assign an IP address to the Linux system?

Step 1: Edit the network scripts file. All the network related script files are in the below location
# ls /etc/sysconfig/network-scripts




 My system has only one Ethernet card. The file that need to be edited to assign the IP address is “ifcfg-eth0”.

If system has multiple Ethernet devices, the files will be like “ifcfg-eth0, ifcfg-eth1, ifcfg-eth2…”.

Step 2: Edit the Ethernet device file and add the IPADDR, GATEWAY, PREFIX/NETMASK…etc. as mentioned below.
# vi /etc/sysconfig/network-scripts/ifcfg-eth0



Step 3:  Bring down the network interface device and then start it.

# ifdown eth0
# ifup eth0

Or else just simply restart the network device.
# network service restart

Step 4:  Type ifconfig to view the available network interface card.

# ifconfig


Step 5: Try to ping this IP address from the other system.