My original intentions were to make this sort of a how to
blog for Linux technologies; however, all I seem to want to write about are the
ways technology impact lives, the relationships between real and virtual
worlds, and my curiosity. While some of
that may be interesting, most tech gurus read to learn. Unfortunately at this point in time our lives
are finite and my opinions on technology sometimes may not be logical or relevant. With that being said….let the learning begin!
Saturday, April 26, 2014
Monday, March 17, 2014
Ports...
Recently I was asked about ports and it made me realize how
little I knew about them….not only that but what I did know I wasn't exactly
confident about. In Linux there are
65536 standard ports. This is actually a
packet limitation not Linux. Within a packet
there is a space allocated for Source Port and Destination Port each space is
16 bit. So the result is 2^16 = 65536 or
0 through 65535. So that means there are
65536 places for a remote application to communicate. Now it is important to note these are not
physical ports, they are 100% software and are bound by the limitations of the
protocols that utilize them (Primarily UDP/TCP). The physical component would be the network
interface card better known as a NIC.
Each NIC can have one or more physical ports associated with it….not to
be confused with the software ports previously mentioned.
So…why all the fuss over ports?
Well the questions I was asked involved port
limitations. For instance can more than
one connection exist on a port at any given time?
I guess to start with it is important to realize that a port
is nothing more than a construct with which an application can utilize for a specific
type of communication. Can a physical
port receive more than one packet at a time?
No. So how can a software port
maintain more than one connection? See
this is where things get interesting….because while we like to think of a port
as a place to dock and stay a while it really isn't. It is more or less just a number with which
an application binds to in order to receive packets…a filtering mechanism more
or less for network traffic at the application layer.
So how are connections made then? The socket! A socket is a connection between two sources
usually defined by the source IP/Port and destination IP/Port. In the client server model typically the
server listens on a specific port for incoming connections while the client
picks from a range of ports to connect with.
Example:
Server A:
IP: 5.6.7.8
PORT:3000
IP: 5.6.7.8
PORT:3000
CLIENT A:
IP: 9.6.7.1
PORT:5000
IP: 9.6.7.1
PORT:5000
CLIENT A:
IP: 9.6.7.1
PORT:5001
IP: 9.6.7.1
PORT:5001
CLIENT B:
IP: 9.6.7.2
PORT:5000
IP: 9.6.7.2
PORT:5000
So CLIENT A has two connections to the server identified as:
Connection 1: 5.6.7.8:3000-9.6.7.1:5000
Connection 2: 5.6.7.8:3000-9.6.7.1:5001
Connection 1: 5.6.7.8:3000-9.6.7.1:5000
Connection 2: 5.6.7.8:3000-9.6.7.1:5001
And CLIENT B has one connection as:
Connection 1: 5.6.7.8:3000-9.6.7.2:5000
Connection 1: 5.6.7.8:3000-9.6.7.2:5000
So can a port have multiple connections at the same
time? Yes.
Friday, January 24, 2014
The Simple Stuff
Every
so often I will stumble across a new command that is incredibly useful or just
really cool. It is in those moments I realize how little I actually know
about this operating system and how incredibly powerful it actually is. Linux is easily molded into whatever we need
it to be. If you break it down and learn
the tools used to model it you can literally get it to do pretty much
anything. Obviously there are going to
be computational limitations, but within those limits the capabilities are
still quite amazing.
So
let’s start with a simple command.
[myprompt]$
ls
The
ls command allows a user to list the contents of a directory. A simple command by itself, but when coupled
with other scripting commands you begin to create dynamic tools within scripts.
For
instance let’s say the linux machine is used for maintaining characters. Each character has configuration data
associated with it. We will give each
character configuration a name in the form of <CharacterName>.chcfg
We
have a program that creates deletes and stores these files in /Data/Characters
directory. Let’s say we have another
program that needs to list all the characters.
This is one method:
#!/bin/bash
#!/bin/bash
##Char
list script
CHAR_CONF_DIR=/Data/Characters
MY_CHARACTERS=(
`ls ${ CHAR_CONF_DIR}\*.chcfg` )
echo
${ MY_CHARACTERS[@]}
MY_CHARACTERS
is a bash array. The bash array just
stores each individual .chcfg file within one variable. The ls command allowed
us to easily access the .chcfg data and store it into the variable. So now each time we add or remove a .chcfg
file and run the script it will automatically update the MY_CHARACTERS variable
without any modifications to the script.
Subscribe to:
Posts (Atom)