Tuesday, 15 March 2016

Networking Concepts

What is a Service?
  • Service is a program in computer.
  • Service = Program = Application
  • Eg: Web Browser, Email program.
  • Each service has a unique port.
e.g SSH secure socket host is a service that runs on port 22
HTTP is a service that runs on port 80
likewise there are multiple services , each service runs on unique port number.

What is Web Service?
  • Service that runs on Web Server.
Example of port and service:

Computer A has application A running in it.
Computer B has application B running in it.

When a client process wants to a connect a server, the client must have a way of identifying the server that it wants to connect. If the client knows the 32-bit Internet address of the host on which the server resides, it can contact that host. But how does the client identify the particular server process running on that host?
To resolve the problem of identifying a particular server process running on a host, both TCP and UDP have defined a group of well-known ports.
For our purpose, a port will be defined as an integer number between 1024 and 65535. This is because all port numbers smaller than 1024 are considered well-known -- for example, telnet uses port 23, http uses 80, ftp uses 21, and so on.

Ports: 
  • Each service has a unique port.
  • It is an Integer number
  • Port numbers ranging from 0 to 1024 are default ports already assigned to specific services.
  • Although these default port numbers can be changed as per configuration
  • Port number between 1025 till 65535 can be used for any new service

Before connecting to my SSH service, that is port 22











Foreign IP 192.168.0.4 is connected to my IP 192.168.0.7 on port 22 i.e SSH service.
Foreign IP 192.168.0.4 has selected random port which is 54699 to connect with my SSH Service running on port 22

Foreign IP 192.168.0.4 was running putty client software which selected port 54699 i.e random port

As you can see in 2nd screenshot, there are 2 different ports (54699,54686) in Foreign Address 192.168.0.4,   which means there are two connections established from putty client on my port 22


Why Putty used?
  • Putty is a open source free client software that is used to connect remote computers on multiple ports.
How to use Putty?
  • Download Putty
  • Open Putty and enter ip address of remote host along with port number. 
  • There are 5 types of connections, so depending on service that you want to connect , you can select connection type.
  • There are 3 default connection types that we can use that is SSH(port 22), Telnet(port 23), Rlogin(port 513)
  • For any other ports you can use Raw as connection type and enter the port number.

How to open Command Prompt:
  • All system executables such as Command Prompt, telnet, calculator etc are stored in C:\Windows\System32
  • Open Command prompt:
    > Press start + r  (This will open run window)
    > Type cmd or cmd.exe (This will open command prompt)
Check reachability of IP using Ping command:
ping 192.168.2.5


Link for netstat commands usage:
http://www.tecmint.com/20-netstat-commands-for-linux-network-management/


How to transfer files from remote machin1e to local machine.?
In my case remote machine is Linux Ubuntu and local machine is windows.

  1. Use Winscp application
  2. put files in /var/www/html so that the file can be accessible from any browser.
1. Use Winscp application:
a. Download winscp, type host ip address and enter credential, Please refer below:
















b. Once you login to winscp , left window is your local window and right window is your remote window.
c. just navigate to the file location from where you want to copy file from remote machine and copy that to left window which is local machine, refer below.














2. put files in /var/www/html so that the file can be accessible from any browser.
a. Check if remote machine is reachable or not, for that type ping 192.168.0.4 (remote ip) in your local command prompt.
b. Open putty, enter details refer below:






















c. Once you logged in, type sudo su to switch user as root, for that you have to enter root password.

d. root@linux --> here root is username who is logged in, Linux is host name.
i.e username@hostname.
e. type hostname as Linux and you will be able to view host name as linux.
f. Type cp filename /var/www/html to copy the file, i.e deploy the file in /var/www/html so that it can be accessible via any browser.
g. Now start the apache2 service, this is important to access copied file in /var/www/html
h. Enter service apache2 start , this will start the apache3 service.
I. If you get below error i.e could not bind to address, meaning 80 port is already used by some different service.















j. Kill the process/service that is using port 80
k. Before that find out the services that are making use of port 80, for that type below command
l. netstat -nap | grep 80






netstat --> it is command line tool used to monitor network connections, i.e what are the services ports etc in use.
n--> ip number in integer
a--> all services
p--> process id
grep --> to reduce the output i.e to filter to specific input, in this case only filter port 80

m. now as you can see that python is the service that is running on port 80 with process id 1141, hence just kill the process id as below
kill 1141

now just start apache service and it will be executed without any error.
service apache2 start

apache2 is a webservice

n. now just enter remote ip 192.168.0.4 in browser and the files will be visible to you from any browser.






1 comment: