Monday 24 December 2012

Configuration of LINUX Gateway Machine

Check two network devices attach properly or not.

Follow the steps to configure the Linux machine(CentOS, Fedora) gateway.

i )  Check the Device eth0, eth1 are available on the machine by running command.

   [root@Xhost ]# ifconfig 

It will display eth0 and eth1 two network card details (ip, mac and etc).

ii)  Configure eth0 as the Public Network ip address. (/etc/sysconfig/networking-scripts/ifconfig-eth0)

# cat ifcfg-eth0
IPADDR=xx.xx.xx.xx  # IP ADDRESS of Public Network
NETMASK= # Provided by the ISP
GATEWAY=xx.xx.xx.1 # Provided by the ISP

iii)  Configure  eth1 as the Private Network ip address (/etc/sysconfig/networking-scripts/ifconfig-eth1)

# cat ifcfg-eth1

NETMASK= # Specify based on your requirement
IPADDR= # Gateway of the LAN
NETWORK= # Optional

iv) Check each eth0 and eth1 separte like.

 [root@Xhost ]# service network restart
 [root@Xhost ]# ifconfig eth1 down
 [root@Xhost ]# ping  xx.xx.xx.xx  # Ping any public ip
if it works fine. other wise check the configuration of eth1

simmillarly for eth1

 [root@Xhost ]# service network restart
 [root@Xhost ]# ifconfig eth0 down
 [root@Xhost ]# ping  192.168.0.xx  # Ping any private ip

if both working means continue this fifth step

V)  Host Configuration (Optional)

# cat /etc/hosts nat localhost.localdomain localhost

vi)  Gateway Configuration

# cat /etc/sysconfig/network

GATEWAY=xx.xx.xx.1 # Internet Gateway, provided by the ISP

Vii)  DNS Configuration

# cat /etc/resolv.conf

nameserver xx.xx.xx.xx # Primary DNS Server provided by ISP
nameserver xx.xx.xx.xx # Secondary DNS Server provided by ISP

viii) NAT with iptables:

[root@Xhost ]# iptables -F  # Flush iptables 
[root@Xhost ]# iptables -t nat -F # Flush nat table
[root@Xhost ]# iptables -t mangle -F # Flush mangle table

setup forwarding rule in the iptables

[root@Xhost ]# iptables -t nat -A PREROUTING -o eth0 -j MASQUERADE
[root@Xhost ]# iptables -A FORWARDING -i eth1 -j ACCEPT

iX) Enabling the Kernel ip forwarding

Check kernel ip forwading enable or not

[root@Xhost ]# sysctl -a | grep  net.ipv4.ip_forward
net.ipv4.ip_forward = 0

if 0 is there set it to 1 by

[root@Xhost ]# echo 1 > /proc/sys/net/ipv4/ip_forward

and edit to make the change permanent

[root@Xhost ]#vi /etc/sysctl.conf

net.ipv4.ip_forward=1 # modify this 0 to 1

X) Apply configurations

[root@Xhost ]# service iptables save
[root@Xhost ]# service iptables restart
[root@Xhost ]#  chkconfig --list iptables  # on 3,5 runlevel

Finally Gateway is setuped ..

Now we need to test this gateway from any client system(private network).
login into client system.

ping  xx.xx.xx.xx # Any public IP

Read More

Friday 21 December 2012

Guide to Install VServer in Fedora and Install MYPLC in VServer

This Guide will explain how to install Vserver in Fedora and then How to Install MyPLC in Vserver

Step 1 : Install Fedora 12 without GUI (do not Install Any X11 packages Because in GUI mode vserver not Installing Properly)

Option 1 :
Download Fedora Net Install ISO and Install while Installing Choose Minimal as Installation Option  Because It is Not Going to Install Any GUI Component.
Download Link for Fedora 12 Net Install ISO 

Option 2:
Download Fedora 12 DVD and while Installing Choose Minimal as Installation Option Because It is Not Going to Install Any GUI Component, And Coustamize packages and remove all GUI packages and Multimedia Packages and all Applications which contain GUI.
Download Link for Fedora 12 DVD

Goto Step 2 If you Installed Fedora With Out GUI

Step 2:
Check this 

Step 3:
Stop IPTable ( Firewall )
Check this 

Step 4:
If you did not restart system after step2, step3 then restart your System now.

Step 5:
Add Vserver repo
[root@xyz~]# cd /etc/yum.repos.d/
[root@xyz yum.repos.d]# vim vserver.repo

#Add Only One based on 32 bit or 64 bit

#for 32 bit Fedora
#Add Following Lines to vserever.repo 
name=Linux-VServer related packages for Fedora $releasever - $basearch

#for 64 bit Fedora
#Add Following Lines to vserever.repo 
name=Linux-VServer related packages for Fedora $releasever - $basearch

Step 6:
Add this Line : exclude=kernel* util-vserver* yum in fedora.repo the location is before 
[fedora-debuginfo] line Like below
[root@xyz~]# cd /etc/yum.repos.d/
[root@xyz yum.repos.d]# vim fedora.repo
exclude=kernel* util-vserver* yum


Step 7:
Add this Line : exclude=kernel* util-vserver* yum in fedora-update.repo the location is before 
[fedora-debuginfo] line Like below
[root@xyz~]# cd /etc/yum.repos.d/
[root@xyz yum.repos.d]# vim fedora.repo
exclude=kernel* util-vserver* yum


Step 8:
yum install kernel 
It will Install Kernel like kernel- [this kernel will support Vserver with out any Problem)

step 9:
Open Grub file and set timeout to 10 seconds or any value And Default to 0 because it 
will select latest installed kernal as default kernel
[root@xyz~]# vi /etc/grub.conf

Restart So System will boot into Newly Installed Kernel
Check which kernel is selected by typing uname -a in terminal
[root@xyz~]# uname -a
Linux #1 SMP Thu Dec 2 19:34:22 CET 2010 i686 i686 i386 GNU/Linux

Step 10:
Install kernel-firmware version which is related to our installed kernel
For 32 bit
[root@xyz~]# rpm -U --force
for 64 bit
[root@xyz~]# rpm -U --force

Step 11:
Install yum which support chroot
[root@xyz~]# rpm -qa | grep yum
#Remove yum
[root@xyz~]# rpm -e --nodeps yum-3.2.28-5.fc12.noarch
Success, Now

For 32 bit
[root@xyz~]# rpm -ivh
For 64 bit
[root@xyz~]# rpm -ivh

Step 11:
Install Necessary Packages
[root@xyz~]# yum install util-vserver util-vserver-build
[root@xyz~]# yum install subversion
[root@xyz~]# yum install httpd
[root@xyz~]# yum install createrepo
[root@xyz~]# yum install qemu
[root@xyz~]# yum install bridge-utils
[root@xyz~]# yum install emacs
[root@xyz~]# yum install ntp

Step 12:
Download Necessary Files to Setup Vserver Properly
[root@xyz~]# cd
[root@xyz~]# svn co svn-build
If SVN showning unknown host error set proxy for SVN like below
[root@xyz~]# vi /etc/subversion/servers
Edit the file Like below

Step 13:
Copy Distribution files to /etc/vservers/.distributions
[root@xyz~]#  cd 
[root@xyz~]# cd svn-build
[root@xyz  svn-build]#  cd mirroring
[root@xyz  mirroring]# cp -r * /etc/vservers/.distributions

Step 14:
Initializing Vserver Distributions 
[root@xyz  mirroring]# sh -a
[root@xyz  mirroring]# sh init

Step 15: Verifying the setup
Going to install Fedora 12 in Vserver
Go to /etc/vservers/.distributions
[root@xyz~]# cd /etc/vservers/.distributions
[root@xyz .distributions]# ls
centos5  f10  f12  f13  f7  f8  fc1  fc2  fc3  fc4  fc5  fc6  rh9  suse91
[root@xyz .distributions]# cd f12
[root@xyz f12]# cd yum.repos.d/
[root@xyz yum.repos.d]# ls
IF building.repo not there then
[root@xyz yum.repos.d]# cp building.repo

Step 16: Adding MYPLC repository to Vserver repository
Going to install MyPLC in Vserver of Fedora 12
[root@xyz~]# cd /etc/vservers/.distributions/f12/yum.repos.d
#Note to create vserver Successfully we need to change gpgcheck=1 to gpgcheck=0 in .repo file
[root@xyz yum.repos.d]# vim building.repo
name=Fedora 12 - $basearch

name=Fedora 12 - $basearch - Updates

Add MYPLC Repository location in building.repo file

[root@xyz yum.repos.d]# vim building.repo
#For 32 bit
name= MyPLC

#For 64 bit
name= MyPLC
Step 17:
Some times while creating Vserver we get error /proc/uptime can not be accessed
to Avoid this before creating Vserver Start vprocunhide script
[root@xyz~]# cd /etc/init.d/
[root@xyz init.d]# ./vprocunhide start

Step 18:
Create Vserver
[root@xyz svn-build]# cd ~/svn-build

For 32 bit System

[root@xyz svn-build]# ./ -f f12 -d onelab -p linux32 vtest32 -- --interface eth0: --hostname &> vtest32.log&

For 64 bit System

[root@xyz svn-build]# ./ -f f12 -d onelab -p linux64 vtest64 -- --interface eth0: --hostname &> vtest64.log&

Check RPM packages location connecting or not other wise change location, currently link is working properly

Step 19:
Start Vserver and Install MYPLC
[root@xyz~]# vserver vtest32 start
[root@xyz~]# vserver vtest32 enter
[vtest32 ] /# yum install plc
Install myplc
[vtest32 ] /# yum install myplc
make myplc start at system startup 
[vtest32 ] /# chkconfig plc on
Start MYPLC if you done all steps correctly then you will see text like below
[vtest32 ] /# service plc start
PLC: Generating network files:                             [  OK  ]
PLC: Generating SSL certificates for: PLC: WWW: PLC: API: P[  OK  ]:
PLC: Generating GPG keys:                                  [  OK  ]
PLC: Generating SSH keys:                                  [  OK  ]
PLC: Starting web server: PLC: Setting PHP timezone to GMT:[  OK  ]
PLC: Starting PostgreSQL server:                           [  OK  ]
PLC: Configuring the API:                                  [  OK  ]
PLC: Bootstrapping the database: PLC:  - 101-up-leases.sql (dbdumped): PLC:  - 102-up-isvalid.sql (dbdumped): PLC:  - 103-up-extensions.sql (dbdumped): PLC:  - 104-up-noderole.sql (dbdumped): PLC:  - 105-up-timespent.sq[  OK  ]ped):
PLC: Starting DNS server: PLC: Configuring resolv.conf:    [  OK  ]
PLC: Creating BootCD variants:                             [  OK  ]
PLC: Rebuilding Boot CD:                                   [  OK  ]
                                                           [  OK  ]
PLC: Signing and indexing node packages:                   [  OK  ]

MyPLC Installation Completed

Read More

Tuesday 18 December 2012

Uninstall or Remove Any Application or Package in Fedora

Hi I already installed yum-3.2.28-5.fc12.noarch package now i want to remove that package and
Install lower version yum-3.2.25-2chroot.noarch

[root@server1]#rpm -Uvh yum-3.2.25-2chroot.noarch.rpm 
Preparing...                ########################################### [100%]
package yum-3.2.28-5.fc12.noarch (which is newer than yum-3.2.25-2chroot.noarch) is already installed

1 st time Fail
[root@server1]#yum remove yum

Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package yum.noarch 0:3.2.28-5.fc12 set to be erased
--> Processing Dependency: yum >= 3.2.24 for package: yum-utils-1.1.26-1.fc12.noarch
--> Running transaction check
---> Package yum-utils.noarch 0:1.1.26-1.fc12 set to be erased
--> Finished Dependency Resolution
Error: Trying to remove "yum", which is protected
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest

2 nd time Success
[root@server1]#rpm -qa | grep yum

Note the package need to remove

[root@server1]#rpm -e yum-3.2.28-5.fc12.noarch
error: Failed dependencies:
yum >= 3.2.24 is needed by (installed) yum-utils-1.1.26-1.fc12.noarch

For me no need to remove dependence packages So

[root@server1]#rpm -e --nodeps yum-3.2.28-5.fc12.noarch
Success, Now
[root@server1]#rpm -ivh yum-3.2.25-2chroot.noarch.rpm Preparing...                ########################################### [100%]
   1:yum                    ########################################### [100%]

Read More

Thursday 13 December 2012

Find Size of table and Size of Index in MySQL Command Prompt

To find Size of table in MySQL command prompt use below command

mysql > SELECT table_name AS "Table", round(((data_length + index_length) / 1024 / 1024), 2) "Size in MB" FROM information_schema.TABLES WHERE table_schema = "database_name" AND table_name = "table_name";

To find Size of  Index of a table in MySQL command prompt use below command

mysql > SELECT table_name AS "Table", round(((index_length) / 1024 / 1024), 2) "Size in MB" FROM information_schema.TABLES WHERE table_schema = "database_name" AND table_name = "table_name";
Read More

Thursday 6 December 2012

Add new Line while Appending two files in Linux

If two files containing following content

After append : cat file2>>file1 
output in file1:

to Add new Line while Appending two files
Command : sed -i -e '$a\' file2 | cat file2 >> file1

From Above
sed -i -e '$a\' file2
This adds \n at the end of the file only if it doesn't already end in a newline. So if you run it twice it will not add another newline.

Read More

Wednesday 28 November 2012

Solution: After Exception Catch in Python What will happen?

Exception Handling :
After Exception Catch Python will execute remaining code, See below Example 

# reading sitemap xml file


def diverror(a):
    a = a/0

print("Division Error")
a = a+10


Division Error

Read More

Break out of the function in Python

In Python if Any function return any thing or return none means the function is completed ie Break out of the function 


def test(a,b):
      return "HI Closed"
      a = b+10

HI Closed

Read More

Catch all exception in Python3

to catch all exceptions in python3 simple do like bellow

    print("Unknown Exception found")

Read More

Sunday 25 November 2012

Python current timestamp

To get current time with date in python

from datetime import datetime
curtime = str(

output : '2012-11-25 14:58:30.465213'

Read More

Friday 23 November 2012

Solution: Extract tar.bz2 files in Linux

To Extract tar.bz2 files in linux use below command

root@system1~# tar -xjvf filename.tar.bz2
Read More

Wednesday 21 November 2012

Delete duplicate rows in mysql table

It is Possible to DELETE duplicate rows in MYSQL table based on Particular Field (Coloumn)

the SQL Query is

ALTER IGNORE TABLE table_name ADD UNIQUE INDEX(coloumn_name); 
Read More

Thursday 15 November 2012

IPtables: Saving firewall rules to /etc/sysconfig/iptables: /etc/init.d/iptables: line 268: restorecon: command not found

Solution to : IPtables: Saving firewall rules to /etc/sysconfig/iptables: /etc/init.d/iptables: line 268: restorecon: command not found

root@server1:~# ls -l /sbin/ | grep restore
lrwxrwxrwx 1 root root     14 May 23 17:52 iptables-restore -> iptables-multi

Means policycoreutils not Installed
So Install policycoreutils to get restorecon save Iptables

root@server1:~# yum install policycoreutils
root@server1:~# ls -l /sbin/ | grep restore

lrwxrwxrwx 1 root root     14 May 23 17:52 iptables-restore -> iptables-multi
lrwxrwxrwx 1 root root      8 Nov 15 17:00 restorecon -> setfiles

Read More

Tuesday 13 November 2012

Read Large Files Line by Line in Python - Best Way

The readlines() function loads the entire file into memory as it runs. A better approach for large files is to use the fileinput module, as follows:

import fileinput
for line in fileinput.input(['myfile']):
Read More

Monday 12 November 2012

Solution: Dovecot error : Unknown database driver mysql

Dovecot error : Unknown database driver mysql because Dovecot requires the dovecot-mysql package to run mysql authentication. So Install  dovecot-mysql
yum install dovecot-mysql
Read More

Friday 9 November 2012

Load Kernel Module in Linux Example Load IP table module

Below Instructions shows How to Load Kernel module in Linux

check whether module is Loaded or Not

if you don't know Exact Module Name then Check All Loaded Modules

root@system1:~# lsmod

Module                  Size  Used by
nf_conntrack_ipv4      18850  1 
nf_defrag_ipv4         12601  1 nf_conntrack_ipv4
xt_state               12514  1 
nf_conntrack_ftp       13039  0 
nf_conntrack           65203  3 nf_conntrack_ipv4,xt_state,nf_conntrack_ftp
xt_tcpudp              12531  1 
x_tables               20679  4 xt_state,xt_tcpudp,iptable_filter,ip_tables
sctp                  165508  2 
libcrc32c              12510  1 sctp
nls_iso8859_1          12617  0 
nls_cp437              12751  0 
vfat                   17166  0 
fat                    54411  1 vfat
snd_seq_dummy          12686  0 
usb_storage            42478  0 
uas                    17476  0 
i915                  395739  1 
drm_kms_helper         30737  1 i915
drm                   183453  3 i915,drm_kms_helper
i2c_algo_bit           12980  1 i915
video                  18434  1 i915
dm_crypt               22236  0 
snd_intel8x0           33017  2 
snd_ac97_codec        104623  1 snd_intel8x0
ac97_bus               12602  1 snd_ac97_codec
snd_pcm                72878  2 snd_intel8x0,snd_ac97_codec
snd_seq_midi           13132  0 
snd_rawmidi            24215  1 snd_seq_midi
snd_seq_midi_event     14076  1 snd_seq_midi
snd_seq                50403  3 snd_seq_dummy,snd_seq_midi,snd_seq_midi_event
snd_timer              23911  2 snd_pcm,snd_seq
snd_seq_device         13817  4 snd_seq_dummy,snd_seq_midi,snd_rawmidi,snd_seq
ppdev                  12840  0 
lp                     13321  0 
parport_pc             31867  1 
shpchp                 32187  0 
snd                    52787  11 snd_intel8x0,snd_ac97_codec,snd_pcm,snd_rawmidi,snd_seq,snd_timer,snd_seq_device
psmouse                72465  0 
parport                34960  3 ppdev,lp,parport_pc
soundcore              12534  1 snd
mac_hid                13037  0 
serio_raw              13027  0 
snd_page_alloc         13709  2 snd_intel8x0,snd_pcm
dm_mirror              21585  0 
dm_region_hash         15035  1 dm_mirror
dm_log                 17871  2 dm_mirror,dm_region_hash
aufs                  162169  0 
usbhid                 41119  0 
hid                    79842  1 usbhid
tg3                   133921  0 
floppy                 59430  0 

if you know what module you are Looking ex:ip_tables then Check whether that module loaded or not by below command

root@system1:~# lsmod | grep ip_tables

Not Loaded then Load Module

root@system1:~# modprobe ip_tables

Now check

root@bt:~# lsmod | grep ip_tables
ip_tables              17634  1 iptable_filter
x_tables               20679  4 xt_state,xt_tcpudp,iptable_filter,ip_tables


Read More

Tuesday 6 November 2012

Solution to g++: Command not found in Fedora Problem

g++ command not found means gcc-c++ package not 

installed so install gcc-c++ package


root@system1:# yum install gcc-c++
Read More

Install deb packages

To install .deb packages use following command

root@system1:~# dpkg -i package.deb
Read More

SSH login without password in Linux

Hi to login into Linux System through SSH with out password Follow Below Steps
two systems (Below IP addresses are for Example)
system1 ip :
system2 ip :

Note: For Below Command don't type any thing Simply press Enter

root@system1:~# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): (Press Enter)
Enter passphrase (empty for no passphrase): (Press Enter)
Enter same passphrase again: (Press Enter)
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/
The key fingerprint is:
d8:b7:3b:d8:12:19:47:de:43:e9:8b:54:ba:b4:af:c4 root@system1
The key's randomart image is:
+--[ RSA 2048]----+
|           ..    |
|          ...o   |
|          .+* .  |
|       o oo* .   |
|      . S ....    |
|         + +.+.   |
|         oE.o    |
|        ..oo     |
|          o.     |

root@system1:~# ssh-copy-id
root@'s password: 

Now try logging into the machine, with "ssh ''", and check in:


to make sure we haven't added extra keys that you weren't expecting.

root@system1:~# ssh
(If Login success OK,if Login Fail and Got Below Error )

Agent admitted failure to sign using the key.
root@'s password: 

root@system1:~# ssh-add
Identity added: /root/.ssh/id_rsa (/root/.ssh/id_rsa)

root@system1:~# ssh
Last login: Wed Nov  7 10:27:23 2012 from


Read More

Monday 5 November 2012

convert to binary in PHP

In PHP decbin function is used to convert anything to binary

$a = "3";
$b = 4;
echo decbin($a)."<br>";
echo decbin($b);

Read More

Monday 22 October 2012

Setup domain nagix etc usefull urls

Read More

Change linux root password

Change linux root password

user# su
password :
root# passwd
Enter New Password:
Re type password:
Read More

After Copying Mysql table data files manually mysql service not running

If you got the problem After Copying Mysql table data files manually MySQL service not running then check owner of copied files, to work MySQL the owner must be MySQL

mysql data folder in linux /var/lib/mysql

root/backup# cp databasefolder /var/lib/mysql
root# chown mysql.mysql  databasefolder
root# cd  databasefolder
root/databasefolder# chown mysql.mysql *

Read More

Sunday 21 October 2012

Solution to : XML::SAX::Base.3pm.gz conflicts between Problem

Some time if you got Problem like below while yum update

file /usr/share/man/man3/XML::SAX::Base.3pm.gz conflicts between
attempted installs of perl-XML-SAX-Base-1.04-3.el6.noarch and
file /usr/share/man/man3/XML::SAX::Exception.3pm.gz conflicts between
attempted installs of perl-XML-SAX-Base-1.04-3.el6.noarch and

to Avoid these type of problem update yum by excluding those packages

yum update -y --exclude=perl-XML-SAX-Base --skip-broken

Read More

Solution to : Error: rpmdb open failed

Error: rpmdb open failed will occur while trying to use you update to solve this problem use following commands

yum clean all
rm -f /var/lib/rpm/__db*
rpm --rebuilddb
yum update
Read More

Thursday 18 October 2012

Shell script execute command and store in variable

This Post shows how to execute command in .sh files ie shell script files


cmd=$(ps -ef | grep tcpdump | awk '{print $3}')
echo $cmd

in .sh files need to use like this variable=$(command)
Read More

Wednesday 17 October 2012

Set PHP execution time in Code Itself

It is possible to Set PHP execution time in code No need to changing php.ini file

Add Below line to your PHP code
ini_set('max_execution_time', 1919);
where 1919 means PHP script will execute 1919 seconds

ini_set('max_execution_time', 1919);

Read More

Tuesday 9 October 2012

Get SVN files and Folders with WGET

By Using WGET it is possible to get all files and folders of a url 

wget -r -i
Read More

Wednesday 3 October 2012

Add Route Between Two Systems

Type ifconfig in terminal (command Prompt) to know IP
Type route -n in terminal (command Prompt) to know GateWay

First System IP :
Second System IP :

First System Gateway :
Second System Gateway :

You can add route in any One System is Enough for example

Add route in First System
route add -host gw

Add route in Second System
route add -host gw

Read More

Saturday 29 September 2012

Show error message if Java run-time not installed in client mechine through JavaScript

By using Follow code, it is possible to show error message if java run-time not installed in client mechine

<!DOCTYPE html>

if (navigator.javaEnabled()) {
    //Java is enabled
document.write("Error:Java is Disabled or Java Not Installed<br>Download and Insatall java from <a href=\"\"></a>");


Read More

Wednesday 26 September 2012

Solution SSH Connection Refused Problem in Linux - Backtrack

If your system unable to SSH from another System means

1. SSH server Not Running. So start SSH Server
    To start SSH server goto Applications->Backtrack->Services->SSHD->sshd start

If It is Running, and unable to SSH go to step 2

2. root@bt:~# sshd-generate
Generating public/private rsa1 key pair.
Your identification has been saved in /etc/ssh/ssh_host_key.
Your public key has been saved in /etc/ssh/
The key fingerprint is:
d3:c3:ee:61:70:81:fa:06:44:18:a5:1c:49:25:70:d4 root@bt
The key's randomart image is:
+--[RSA1 2048]----+
|         .oo*B=. |
|        .  ..=  E|
|        ....o    |
|     o ..o.      |
|      = .S.o.     |
|       o o...    |.
|          ..  .   |
|                 |
|                 |


Now Check Again , I think it will work.

Read More

Monday 24 September 2012

Solution to Endianness Problems in Linux Networking

There are two types of Endians

In real world Networks generally use Big-Endian

Ethernet is Big-endian

IP's byte order also is Big-endian

A common solution to the endianness problem associated with networking can be handled by below functions

htons(): Convert 16-bit unsigned value from processor order (machine order) to network order. (htons-host to network short)
htonl(): Convert 32-bit unsigned value from processor order (machine order) to network order. (htonl-host to network long)
ntohs(): Convert 16-bit unsigned value from network order to processor order (machine order). (ntohs-network to host short)
ntohl(): Convert 32-bit unsigned value from network order to processor order (machine order). (ntohl-network to host long)
Read More
Here We Write The Problems we face at different situations and Solutions to those problems.