Now you (hopefully) know a bit more what is an IP network, but what can you do with it? The purpose of a network is to allow machines to communicate, so the purpose of an IP network is to transport data between its hosts. To understand how hosts can communicate over an IP network, let's take the usual analogy of the post office. Let's say you want to send a letter from New York to your cousin in Paris. You write your letter, put it in an envelope, write your cousin's address on the envelope, and if you expect a reply, you also write your own address on it. Then you drop your letter in a mailbox at the post office, and thanks to the recipient's address on the envelope, your letter first goes to New York airport (probably by car), then flies to Paris by plane, and then arrives to your cousin's mailbox by car again.
This is exactly how data is transported on an IP network: the data is first split into IP packets (or datagrams), which correspond to letters, and the envelope is called the IP header. Like on a real envelope, the IP header contains the (IP) address of the sender, and the one of the recipient. In the IP world, the mailbox is called a gateway, the post office a router, and the road from the post office to the airport, or the flight from New York to Paris are different networks.
Now let's imagine an IP network 192.168.1.0/24 (called "network A"), with two computers: computer C with the IP address 192.168.1.2, and computer D with the IP address 192.168.1.3. These computers can be linked together thanks to an Ethernet connection, for instance. Ethernet is a low-level network protocol called "link protocol", and is used to link devices (computers, phones, etc.) which can be physically connected together. By "physically", I mean with a network cable, an optical fiber, or a WiFi link for instance. Each device on an Ethernet network has an address called "MAC address", which is a 48-bit number usually represented in hexadecimal (for instance: "00:19:e3:ff:fe:8d:f5:08"). Unlike the IP address, the MAC address is a characteristics of the network card of your computer; it should be unique in the world and is not supposed to be changed. When several computers are connected through an Ethernet network, each computer "learns" (thanks to a protocol called "ARP": Address Resolution Protocol) the MAC address of each other computer on the network, and the associated IP addresses. Like for the IP protocol, data is sent inside Ethernet packets, which start with a header containing the source and destination MAC address. The communication on an Ethernet network is very simple: when a computer wants to send an Ethernet packet to another one, this packet is actually sent to all the computers on the network (this mechanism is called "broadcast"), but only the one whose MAC address is equal to the destination address of the packet will read it; the other computers will just ignore the packet. As this broadcast mechanism is not very efficient if there are many computers in the network (it causes a problem called "packet collision"), there is actually another mechanism called bridging (or switching), which allows to divide an Ethernet network into smaller segments, and limit the broadcast mechanism to these segments; as it is a bit out of the topic I will not enter into details now.
The thing to remember is that hosts which are connected to the same Ethernet network (computers C and D in the example) can be part of the same IP network, and can talk directly to each other. On Linux, you can see which other hosts are on the same Ethernet network(s) as your computer, thanks to the command "arp" ("arp -a" on Windows or Mac OS X). It shows the ARP table, which makes the correspondence between IP addresses and MAC addresses:
By the way, a computer can have several network interfaces (network cards), and in that case each interface has its own MAC address, and (usually) its own IP address. On Linux or Mac OS X you can see all your network interfaces with the command "ifconfig -a" (use "ipconfig /all" on Windows):
Here there are two interfaces: "eth0" (an Ethernet card) and "wl0" (a WiFi interface).
On each "inet" line, you can see 3 addresses: "addr" is the IP address of the interface. "Bcast" is the broadcast address, i.e. is the destination address used when the computer wants to send a message to all the hosts of this network; the broadcast address is always the last IP address of the address range of the network. The third one, "Mask", is the network mask; the mask is another way to represent the number of bits of the network part of an address: it is the address obtained with all the bits of the network part set to "1", and all the bits of the host part set to "0". For instance, a network mask of 255.255.255.0 can be written "11111111 11111111 11111111 00000000" in binary, which means the network part of the address has 24 bits (so here the network is 192.168.1.0/24)
This is exactly how data is transported on an IP network: the data is first split into IP packets (or datagrams), which correspond to letters, and the envelope is called the IP header. Like on a real envelope, the IP header contains the (IP) address of the sender, and the one of the recipient. In the IP world, the mailbox is called a gateway, the post office a router, and the road from the post office to the airport, or the flight from New York to Paris are different networks.
Now let's imagine an IP network 192.168.1.0/24 (called "network A"), with two computers: computer C with the IP address 192.168.1.2, and computer D with the IP address 192.168.1.3. These computers can be linked together thanks to an Ethernet connection, for instance. Ethernet is a low-level network protocol called "link protocol", and is used to link devices (computers, phones, etc.) which can be physically connected together. By "physically", I mean with a network cable, an optical fiber, or a WiFi link for instance. Each device on an Ethernet network has an address called "MAC address", which is a 48-bit number usually represented in hexadecimal (for instance: "00:19:e3:ff:fe:8d:f5:08"). Unlike the IP address, the MAC address is a characteristics of the network card of your computer; it should be unique in the world and is not supposed to be changed. When several computers are connected through an Ethernet network, each computer "learns" (thanks to a protocol called "ARP": Address Resolution Protocol) the MAC address of each other computer on the network, and the associated IP addresses. Like for the IP protocol, data is sent inside Ethernet packets, which start with a header containing the source and destination MAC address. The communication on an Ethernet network is very simple: when a computer wants to send an Ethernet packet to another one, this packet is actually sent to all the computers on the network (this mechanism is called "broadcast"), but only the one whose MAC address is equal to the destination address of the packet will read it; the other computers will just ignore the packet. As this broadcast mechanism is not very efficient if there are many computers in the network (it causes a problem called "packet collision"), there is actually another mechanism called bridging (or switching), which allows to divide an Ethernet network into smaller segments, and limit the broadcast mechanism to these segments; as it is a bit out of the topic I will not enter into details now.
The thing to remember is that hosts which are connected to the same Ethernet network (computers C and D in the example) can be part of the same IP network, and can talk directly to each other. On Linux, you can see which other hosts are on the same Ethernet network(s) as your computer, thanks to the command "arp" ("arp -a" on Windows or Mac OS X). It shows the ARP table, which makes the correspondence between IP addresses and MAC addresses:
# arp
IP address HW address Iface
192.168.1.1 00:18:39:C1:A8:A2 eth0
192.168.1.4 00:19:E3:02:2A:03 wl0
By the way, a computer can have several network interfaces (network cards), and in that case each interface has its own MAC address, and (usually) its own IP address. On Linux or Mac OS X you can see all your network interfaces with the command "ifconfig -a" (use "ipconfig /all" on Windows):
# ifconfig -a
eth0 Link encap:Ethernet HWaddr 00:18:39:C9:A4:A6
inet addr:192.168.1.2 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
wl0 Link encap:Ethernet HWaddr 00:18:39:C9:A1:A2
inet addr:192.168.1.3 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Here there are two interfaces: "eth0" (an Ethernet card) and "wl0" (a WiFi interface).
On each "inet" line, you can see 3 addresses: "addr" is the IP address of the interface. "Bcast" is the broadcast address, i.e. is the destination address used when the computer wants to send a message to all the hosts of this network; the broadcast address is always the last IP address of the address range of the network. The third one, "Mask", is the network mask; the mask is another way to represent the number of bits of the network part of an address: it is the address obtained with all the bits of the network part set to "1", and all the bits of the host part set to "0". For instance, a network mask of 255.255.255.0 can be written "11111111 11111111 11111111 00000000" in binary, which means the network part of the address has 24 bits (so here the network is 192.168.1.0/24)
Aucun commentaire:
Enregistrer un commentaire