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

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.

Related

network sniffer - detect subnet mask in non-DHCP network

I'm writting a simple network sniffer that should be able to reconstruct network structure.
When an interface has set up a DHCP, I can easily read interface settings such as client IP address, subnet mask, DNS server etc. by catching a DHCP packet and analysing it.
When an interface has a static IP, I'm catching ARP Announcement packet to get static IP address and then ARP request from the gateway, to get geteway IP address. I'm also saving MAC addresses.
My problem is: how to get subnet mask from one or more static IPs in the network and the gateway address. Or by caching some packets. I didn't see packets that could have such informations.
I also need DNS address, but it's less important.
The program should work in OpenWRT (C++).
My problem is: how to get subnet mask from one or more static IPs in the network and the gateway address.
Possibly, you can't.
If the sniffed network uses DHCP then you can monitor the DHCP requests (which should be broadcast) for their subnet mask and router fields which mirror the server's offer.
Without DHCP, all you can do is take an educated guess. If your passive sniffer registers broadcasts from addresses 192.168.1.1 through 192.168.1.29, you know that the prefix length is at most /27. It could also be anything shorter, down to /16, with potential addresses being (currently) absent or silent. The prefix could be even short than /16 if the network admin is ignoring RFC 1918. With public addresses you're mostly on your own.
If you can scan actively you could send ARP requests and see which ones get answered - you'd also see nodes that don't originate any traffic/broadcasts.
The gateway is also just a guess. In a network with mostly Internet-bound traffic, the default gateway is most likely the one being ARPed most often. If the network traffic is mostly server-centric, ARP requests for their addresses outnumber the ones for any gateway.
Your sniffer is severely limited when it is just attached to a switch and listening to broadcast packets only. If the sniffer manages to listen to all traffic on the network (via a monitoring/mirroring switch port) then you can easily identify the gateway by its MAC address that packets for arbitrary IP addresses is sent to and vice versa.
As above, if you can actively send probe packets you could test the gateway(s) with packets that they accept (and hopefully forward) and which ones they reject.

How does a computer know other computer's IP address on a local network?

I'm currently learning about ARP and L2/L3 networking - would someone be able to help out? If I use an ethernet cable to connect my laptop (A) to another laptop (B), it could use ARP to find out B's MAC address based on B's IP address. Then, any ethernet frames could be sent and accepted by B.
But how does A know B's IP address in the first place? What if there is a switch (L2 device) in between A and B? Does this change the answer? What if there was a router in between (an L3 device)?
Usually, a switch/Router will assign an IP.
The question is unclear -
find out B's MAC address based on B's IP address.
B's MAC address is not based on B's IP.
A MAC is associated to the hardware (but somewhat assignable/cloneable) where as an IP is assigned. Either by DHCP or statically by an admin.
Effectively, you need a switch/router to make what you're defining work.
EDIT:
you can connect two computers direct, but you still need to give each a static IP address so they can find each other - this would likely not be ona network so the IP sub-network doesn't matter.
It still has very little to do with MAC.
If two PC's hand-shake, they'll see each others MAC.
It sends out a broadcast packet to the broadcast MAC address asking "who has the IP address x.x.x.x" which goes to all computers on that broadcast domain. If a computer sees that packet that owns the IP address "x.x.x.x" it will send a unicast reply back to the MAC address of the original requestor with its MAC address which will then be cached for further communication.
It doesn't know the IP unless you tell it. You say "the default gateway is 192.168.1.1" and it will start trying to talk to 192.168.1.1 etc.
If there is a router in between, all traffic to the remote device would go to the MAC of the router and your computer wouldn't be doing any ARP lookups other than that router.
Switches wouldn't matter for this, all they do is make the broadcast domain bigger. With a cable the broadcast domain is just you and the remote device. With a switch, it expands that to all devices connected to the same switch (or VLAN in the switch)
But how does A know B's IP address in the first place?
It doesn't know. At least there's no general method to find out.
The IP address of any resource needs to be supplied by "something else". You need to either provide the address yourself, resolve it from a (also provided) DNS name, read it from a file, ... Alternatively, you need to provide some kind of auto discovery between the nodes (broadcast, multicast, LLDP, ...) or provide a commonly known discovery service, registration server or similar.
What if there is a switch (L2 device) in between A and B?
That changes nothing but excludes link-level discovery (unless it's a "dumb" switch that simply forwards those frames).
What if there was a router in between (an L3 device)?
That eliminates broadcast and multicast from the picture. (Multicast could be routed but that is unlikely for discovery and I won't dive into that.)

What is Difference between IP address and Port Number in 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.

Difference in Ethernet and Wireless IP addresses?

This is probably a pretty basic question with a fairly simple answer, but I was just wondering if anyone could clarify why there is a different IP address for my Ethernet connection and my Wireless LAN connection, rather than just one IP address for the actual machine?
It's because they are different connections. Each interface, hard wired or wired, will have its own IP address. The IP itself is assigned by your router. If you are concerned with what pool your IP is assigned from, you need to go into your setup utility and see what is allocated for wireless, and what is wired.
This same thing would happen if you had 2 ethernet cards in your machine. Each one would have it's own IP.
In other words, the IP is a unique identifier as per device, not each machine. You will have as many IPs as you have devices.

How are MAC addresses used in routing packets?

I recently found that packets are encapsulated within ethernet frames. Packets use IP addresses, frames use MAC addresses.
Why aren't IP addresses used in ethernet frames for routing? I understand that when trying to access a basic website, the computer goes to a DNS to find the IP address relevant to the user-entered domain name. How do computers find the correct MAC address?
Really, how are MAC addresses used in routing internet traffic?
Thanks
IP packets aren't always encapsulated in Ethernet frames. There are other physical media such as ISDN, etc. When packets are routed, IP addresses are used to determine the next hop and the physical address is used to physically identify the interface serving as the next hop. Only the former (determining next-hop) is usually called routing.
To answer your second part, MAC addresses are discovered through ARP (Address Resolution Protocol) in IPv4 & ND6 (Neighbor Discovery) in IPv6.
Update:
The destination IP address in the IP header is the final destination. In the process of routing (at each hop), you get the next hop's IP address to (eventually) reach the final destination from the routing table (this could be a default gateway's IP address). To send the packet to the next hop, you need its MAC address. While hopping through intermediate links, the IP address in the IP header don't change - only the MAC addresses change.
Bit late but still here is my answer :) ...
To send data you need two address, the MAC address and the IP address.
Basically the sending host will ARP for a MAC address, this occurs when the local host doesn't know the MAC address of the host it has an IP address for or it will ARP for the default gateway MAC address (if it doesn't already know it) if the IP address in on a different subnet/ network. Once it obtains a MAC address the IP packet is encapsulated in a L2 frame and sent across the media. If the IP packet is meant for a host on a different subnet/ network, it will be sent to the default gateway, this router will de-encapsulate the L2 frame (remove and discard it) check the IP address and will forward it. For the router to do this it needs a MAC address to send it over the media, It will look up the next hop in it's routing table, encapsulate the IP packet with the same source and destination IP address that was sent from the original host into a new L2 frame. This time the MAC address for the source address will be that of the forwarding interface of the router, and the receiving interface of the next hop will be the destination MAC address. This will continue from hop to hop until it reaches the final host, each time the MAC addresses will change, but the original IP address will remain the same.
Here's the key point -- there can be more types of packets than INTERNET traffic. You could be using IPX, which is non-routable. How do clients identify each other? By the MAC address.
Routing != Addressing, which is really where the MAC comes into play.
In order to be routed, the OSI model adds a layer to allow for path discovery to the next gateway. This layer is responsible for routing, but knows nothing about the MAC address.
As a side note, at the hardware level, MAC addresses ARE used by switches, but not for routing. From How Stuff Works:
The switch gets the first packet of data from Node A. It reads the MAC
address and saves it to the lookup table for Segment A. The switch now
knows where to find Node A anytime a packet is addressed to it. This
process is called learning.
In this way, a switch can make sure that traffic is only outputted to the correct port. This isn't accomplishing routing so much as reducing network congestion. Only broadcasts and traffic destined specifically for that MAC address should be sent out the port.
Recently I have been thinking about the same and came upon this question. Here is my answer to this question. Actually MAC address is needed for correctly sending the packet to right destination. This is specially true when packet is needed to sent over a VLAN. There can be multiple switches/routes connected on that VLAN over multiple physical interfaces. However IP Routing is unaware of these physical interface. It only knows about the logical connectivity. For example, route 10.10.10.0/24 is reachable via VE/VIF0.10(logical VLAN interface) and/or nexthop neighbor is 20.20.20.1. There could be multiple interfaces under VLAN 10. Then to which interface packet is sent out? This is where ARP comes in the picture. ARP helps to discover the MAC address associated with the next-hop IP address. When switch/router learns the nexthop MAC. along with that it learns the physical interface also via which that MAC is reachable. Hence while routing packet, firstly MAC corresponding to the destination IP is searched and then the physical interface associated with that MAC is searched. Finally packet is sent out via that physical interface. The MAC corresponding to that destination IP is used as destination MAC. In absence of this, routed packets will always be flooded in the outgoing VLAN.
Hope this helps.
Thanks.
Answer: MAC addresses are not used in the process of routing of a packet.
segment -> transport layer (TCP ports)
packets -> network layer (IP addresses)
frame -> data link layer (MAC addresses)
bits -> physical layer (electric/optical signals)
Create your own packet/segment visit http://wirefloss.com/wireit/
There are 2 models (TCP/IP and ISO/OSI)
In detail:
Your app has some data. This is encapsulated by mentioned layers. Encapsulation means that a header with fields is added at each layer. If your data never leave the local network the MAC address will be the same. Once your data needs to be delivered outside your network the frame header is stripped by router and is replaced by router fields.
UPDATE 2021: Some people seems never heard of ISO OSI model and put this answer as incorrect.

Resources