What is Difference between IP address and Port Number in Networking? - networking

What is Difference between IP address and Port Number in Networking?

IP address is address of the system in the Network.
Port is address of the service within the System.
So IP address + Port defines address of the particular service on the particular system.

Think about how many application layer protocols exist (HTTP, FTP,DNS, SSH, etc). Now think about how many task/process/programs exist within your device trying to communicate over the internet. Would it be possible just one address, the IP address, to be able to handle all these different assignments and types of protocols alone? The answer is no.
The IP address is a numerical label assigned to each device connected to a computer network that uses the Internet Protocol for communication. The port number is used so the data is directed to the correct location within this device.
The IP and the port number form the structure IP:port number, 192.168.1.1:8080 for example, and the port number can hold 65536 numbers, with the following division:
0 to 1023 - Well known port numbers. Only special companies like Apple QuickTime, MSN, SQL Services, Gopher Services and other prominent services have these port numbers.
1024 to 49151 - Registered ports; meaning they can be registered to specific protocols by software corporations.
49152 to 65536 - Dynamic or private ports; meaning that they can be used by just about anybody.

IP address is use to identify a host or a group of hosts in a network
while port number is used to identify a particular service running in a host

Port number is used to identify an application/services which you want to talk to on your system. Some predefined ports like 80 = HTTP server, 23 = Telnet.
You identify a host uniquely (globally) by its IP address. So if I ever wanted to access your laptop via telnet then I'd use the IP address given to you by your ISP and the port 23

A MAC address is a layer-2 address. It is used by some layer-2 protocols, e.g. ethernet and Wi-Fi. There are 48-bit and 64-bit MAC addresses. Some layer-2 protocols use different addressing.
An IP address is the address of the layer-3 IP protocol. Different layer-3 protocols use different addressing, e.g. IPv4, IPX, and IPv6 each have different addressing.
A port number is a layer-4 address used by some layer-4 protocols, e.g. TCP and UDP. Some layer-4 protocols use different addressing, or none at all.
TCP example: RFC 793, TRANSMISSION CONTROL PROTOCOL
Multiplexing:
To allow for many processes within a single Host to use TCP
communication facilities simultaneously, the TCP provides a set of
addresses or ports within each host. Concatenated with the network
and host addresses from the internet communication layer, this forms a
socket. A pair of sockets uniquely identifies each connection. That
is, a socket may be simultaneously used in multiple connections.
You may want to learn more about the network layers.

Simply:
A socket is like a telephone (i.e. end to end device for communication)
IP is like your telephone number (i.e. address of your socket)
Port is like the person you want to talk to (i.e. the service you want to order from that address)
In networking, generally a socket is (IP+Port)

IP address: Ip address is a address of your system, it assign when your system connects to internet.There are two types of ip address available here among first one is dynamic which invokes at your system in online. Second one is static, which assign when your system get in offline.
port address Port address is an Id of server such as your using apache server that get port number default 8080 is id of apache server,If you can change server port number.

IP address is your system domain name or socket address of specific system like 192.168.0.1
but the port number is the number of specific location or folder where to you want to write your file or any file transfer like: 3308

The IP address of your computer (host) is the mix of the network ID of the ISP/any other provider (uniquely provided by the ICANN group) and the host name (provided by the Network administrator). The Network ID is unique for all the network and among two networks, we can have same host names but on the same network, the host names can not be the same. So, this is how the host can be identified on the network and data can be transferred. But on the same host multiple applications will be running and once the data reach to the host, we need an identifier to recognize which application data is this TCP Segment/UDP datagram.
The Port number is 16 bits (possibly 65K application can run) and assigned by the Network operating system when the application process creates the sockets. On the Server side, the port numbers are well defined numbers (HTTP- Port #80, SMTP- Port#25). The port number is transport layer addressing (L4) and goes in the header of TCP/UDP.

Related

Difference between Default gateway and a Router

Actually i have three Questions in this regard
IP ADDRESS:- Does router and default gateway same? if same , then why router (internet IP) address is public and Gateway IP address is local (i mean why both are different)
MAC ADDRESS:- what is the difference between WAN MAC address and ROUTER MAC address and Default Gateway MAC address , why are they different?
Difference between Data packets and IP packets? are data packets travel from a host to a remote server present in some other country through submarine cables or through router to router by hop-by-hop transport?
I am a new learner , please don't get angry if i asked something silly
Router and gateway are essentially the same - a gateway provides access to remote subnets. The hardware for that is called router. Routers route between networks.
A default gateway is a gateway to provide access to all subnets that are not specifically configured. At a minimum, a host requires a default gateway to connect to the Internet.
IP addresses are configured on (logical) interfaces. A router usually requires at least two interfaces, each configured with an IP address from the connected subnet.
Likewise, a MAC address is required for a physical interface - specifically for the data link layer to work (OSI layer 2). It uniquely identifies interfaces within a network segment and is used by network switches for forwarding.
A data packet can be many things. An IP packet is a packet (also protocol data unit PDU) on the network layer (OSI layer 3). IP packets travel between hosts around the globe and transport user data (payload) between them.
User data is actually transported by an application-layer protocol (e.g. HTTP) that in turn uses a transport-layer protocol (e.g. TCP) between processes/applications. The transport layer uses the network layer (IPv4 or IPv6) which in turn uses the data link layer (e.g. Ethernet) which in turn uses the physical layer (physical interfaces and cables).

NAT on TCP connections

When we establish a TCP connection from PC1 to Server and send data through this connection, how does the Router know to which of the two PCs (PC1 and PC2) should it communicate on the way back from Server to PC1?
And
How does ping (ICMP) know to which internal node it should send the answer?
NAT (Network Address Translation) is stateful. It creates a translation table that has the layer-3 and layer-4 protocols and addresses. By looking up the return traffic addresses in the translation table, the NAT process can determine which inside addresses should be placed in the packet.
Edit:
Per the edit to your question, asking about ICMP (it is very bad form to change the question in order to ask a different question because it can invalidate the perfectly acceptable answers already given):
It is all the same as TCP or UDP. NAT creates a state table that is dynamically built as traffic passes from inside to outside. NAPT will allow you to overload a single IP address with traffic from multiple inside addresses, and it will translate the return traffic by looking up where to send it in its state table.
With NAPT, besides looking at and translating the IP address, NAPT looks at the layer-4 protocol (TCP, UDP, ICMP) and translates the layer-4 addresses (TCP or UDP port numbers or ICMP identifies), too, storing the translations in its translation table. When return traffic is destined to a particular layer-3 and layer-4 address combination, from a particular layer-3 and layer-4 address combination, the NAPT process finds that in its translation table, and it can see where to send the traffic on the inside.
NAT is very resource intensive, and it breaks the IP paradigm of end-to-end connectivity, where every host is uniquely identified by its own IP address, which is why it is called a kludge (or worse). NAT was developed to extend the life of IPv4 until IPv6, with its nearly unlimited addressing, can become ubiquitous.
RFC 2663, IP Network Address Translator (NAT) Terminology and Considerations:
4.1.2. Network Address Port Translation (NAPT)
NAPT extends the notion of translation one step further by also
translating transport identifier (e.g., TCP and UDP port numbers, ICMP
query identifiers). This allows the transport identifiers of a number
of private hosts to be multiplexed into the transport identifiers of a
single external address. NAPT allows a set of hosts to share a single
external address. Note that NAPT can be combined with Basic NAT so
that a pool of external addresses are used in conjunction with port
translation.
For packets outbound from the private network, NAPT would translate
the source IP address, source transport identifier and related fields
such as IP, TCP, UDP and ICMP header checksums. Transport identifier
can be one of TCP/UDP port or ICMP query ID. For inbound packets, the
destination IP address, destination transport identifier and the IP
and transport header checksums are translated.
A NAPT router in figure 2 may be configured to translate sessions
originated from N-Pri into a single external address, say Addr-i.
Very often, the external interface address Addr-Nx of NAPT router is
used as the address to map N-Pri to.
There is a large pool of resources describing NAT (Network Address Translation), which is available if you search "nat explained". A great resource is What is NAT and how it work tutorial.
The most important detail is that commonly we use NAPT (commonly used as PAT - Port Address Translation) (Network Address and Port Translation), alongside NAT.
When a device needs to use the Internet, it must open a local (source port) and send the IP request to the other end. For example, a notepad with source IP address 192.168.1.2 needs to communicate with a web server at 216.58.212.35.
It fires up random source port 1234 and requests information from target port 80 (HTTP - Web page).
This goes through the networks NAT device, which stores the information 192.168.1.2/1234 with the next information that it computes, and sends the request as 46.103.93.105 (its own IP public IP) and a new source port, for example 2345.
The web server responds to the NAT device, which in turn finds the correlated information (source port 2345 targets 192.168.1.2/1234). The notepad receives the information and displays it to the user.
The router adds information to the request header sent to the server that allows it to look up the sender when the reply is received. This is usually accomplished by using a table stored in the router's memory that maps the PC's address to the token added to the header.

Do TCP Ports belong to the Host or the IP Address?

I understand TCP/IP addresses, and I understand ports, but I don't know whether the ports are tied to the Host (and hence one host gets one port 80), or whether the ports are tied to the IP Address (and hence one host with 2 NICs/IP-Addresses gets 2 port 80s)?
A port belongs to an IP address. If a host has two NICs , and a program binds to only one IP address, the same port can still be used by another program(given that it binds to another IP address).
The answer is 'both'.
If you bind to a specific IP:port, you can have as many bindings using the same port number as you have IP addresses.
If you bind to 0.0.0.0:port, or ::port in IPv6, the port is global to all possible IP addresses of the host, including those that don't exist yet.
But I agree with #DavidShwartz, the question is a bit ill-formed. The fact is that the endpoint is defined by IP:port, not just by port. A port isn't a real thing that you can actually count. It's just a 16-bit number.

How do two PCs communicate on an isolated LAN disconnected form the internet? Do they have IP adresses?

I am given to understand that in order to send data using the TCP/IP protocol suite you need two IP addresses (sender and receiver). My question is, how does communication happen on an isolated LAN. Say I have two PCs connected with an ethernet cable (There is no DHCP sever and IP addresses weren't set manually), do they choose random IP addresses (to please the TCP/IP suite), or do they send IP packets with emtpy TO and FROM fields? or something else?
If you want to use IP, you must have an IP address. Most devices will auto-assign themselves an address in the 169.254.0.0/16 block if a DHCP server is unavailable.
You should also note though that there are many other protocols available, such as IPX/SPX, but most of them are not used these days.

Networks vs Subnetworks

Can a computer with an IP address of class C like 192.168.0.1 and subnet mask 255.255.255.0 communicate and share resources with another computer having the IP 192.168.1.1 and the same subnet mask 255.255.255.0 ? I'm asking this because the first 3 octets in this case tell us that these IPs are running on different networks (network 192.168.0.0 and network 192.168.1.0).
Also, does "network" mean the same thing as "subnetwork" (or "subnet") in this context?
Thank you!
To fully understand how computer networks work, you need to take a look at OSI model (or in practice - TCP/IP or DoD model. For your question you need to look at first three layers: physical, data link and network.
Physical connection is self explanatory, and represents direct connection via some medium (copper, glass, air).
When a host A tries to send a packet to host B first thing it will do is look at the destination IP address and based on it's own IP configuration determine if host B is in the same subnet as a host A. This is done as Eugen Rieck explained to you already: subnet mask bits are used to mask the bits of the IP address (logical AND operation). Now, we have two cases:
Host A and B are in the same subnet.
Host A and B are not in the same subnet.
You should note that on layer 2, which network adapters use to send and receive frames, there is no IP addresses (which are present on layer 3) but instead the communication between devices is done by using MAC addresses. Because of that, host can directly communicate only with hosts in their subnet (1st scenario). For sending a frame host A needs the MAC address of host B. So host A first looks up the MAC address mapped to the IP address of host B in his ARP table. If he can't find it, it sends broadcast ARP request asking all host on the subnet who has that specific IP. If he gets a response it adds the MAC address of the host he got the reply from and builds a packet with destination MAC address of that host and IP address of that host.
If both hosts are not in the same subnet (2nd scenario) the packet is sent to default gateway which is responsible for finding a route to the destination. The crucial point to make here is that even if the destination MAC address in this case is the MAC address of the router (default gateway), the destination IP address is still the IP address of host B as in the first scenario. As the packet flows from router to router the source and destination MAC addresses will change, as they are locally significant, but the source and destination IP address will stay the same. This is how every layer provides a service (so to speak) to upper layers, and upper layers use it transparently without needing to know what is happening below.
So you have:
1st scenario.
----------------
L2:
Src MAC: host A
Dst MAC: host B
----------------
L3:
Src IP: host A
Dst IP: host B
----------------
2nd scenario:
----------------
L2:
Src MAC: host A
Dst MAC: router
----------------
L3:
Src IP: host A
Dst IP: host B
----------------
To sum it up (the answer #Eugen Rieck already gave you):
Two hosts which are not in the same subnet as in your example (192.168.0.1/24 and 192.168.1.1/24) will not be able to communicate on layer 2, and will require a L3 capable device such as router to act as a default gateway and to route the traffic between two networks (broadcast domains) for layer 3 connectivity.
Yes and no:
Yes: Those two computers can communicate, if there is a (properly set up) router in between and both sides have knowledge of it.
No: Those two computers can not communicate, if simply wired to the same dumb switch.
Rule of thumb: IP & SNM must be identical for all participants to allow direct communication.
You'd need to change the subnet mask to 255.255.254.0, or use a router or layer-3 switch to communicate.
Network generally means the whole network you're referring to, while subnet refers to a specific separate portion of it. However, the terminology is pretty loose.

Resources