Simply put: The IP address is the service provider to you, the MAC address is the physical address of your network card. IP address for IP address, I believe everyone is very familiar with, that is, the use of TCPThe 32-bit address assigned to the host by the/IP protocol. An IP address consists of 4 88-bit groups separated by dots, such as 192.168.0. 1 is an IP address, which is called dotted decimal format. The IP address consists of the network address and the host address, and the number of bits assigned to the two parts varies with the address class (Class A, Class B, Class C, and so on). The network address is used for routing, and the host address is used to find a separate host within the network or subnet. An IP address makes it possible for future data from source addresses to be routed to the destination address. Second, MAC address for MAC address, because we do not directly contact with it, so people are not necessarily familiar. In the OSI (Open System interconnection, open systems interconnect) 7-Layer Network Protocol (physical layer, Data link layer, network layer, transport layer, Session layer, presentation layer, Application layer) Reference Model, the second layer is the data link layer. It contains two sub-layers, the previous layer is the logical link control (llc:logical link controls), the next layer is the MAC (media access control) layer we mentioned earlier, that is, the media access controls layer. The so-called medium (Media), refers to the transmission of the signal through a variety of physical environment. Commonly used network media including cables (such as: twisted pair, coaxial cable, optical fiber), as well as microwave, laser, infrared, etc., sometimes referred to as physical media. The MAC address is also called the physical address, hardware address, or link address, which is written by the network device manufacturer when it is produced inside the hardware. This address is not related to the network, that is, regardless of the hardware with this address (such as network cards, hubs, routers, etc.) access to the network where, it has the same MAC address, MAC address is generally immutable, can not be set by the user. Third, the length of the MAC address, the method of representation, the method of allocation and its uniqueness the length of the MAC address is 48 bits (6 bytes), usually expressed as 12 16 binary numbers, separated by a colon for every 2 16 digits, such as: ,:xx: -: 0A:8C:6D is a MAC address where the first 6 bits 16 binary number 08:xx: 20 represents the network hardware manufacturer's number, which is assigned by the IEEE (Istitute of Electrical and Electronics Engineers, Institute of Electrical and Electronics Engineers) and then 3 bits 16 binary 0a:8c 6D represents the serial number of a network product (such as a NIC) manufactured by the manufacturer. Each network manufacturer must ensure that each Ethernet device it manufactures has the same first three bytes and a different last three bytes. This ensures that every Ethernet device in the world has a unique MAC address. Four, the role of IP address and MAC address in the interconnection network since each Ethernet device has a unique MAC address at the factory, why do you need to allocate an IP address for each host? Or why is it that every host is assigned a unique IP address, and why should a unique MAC address be embedded in the production of network devices such as NICs, hubs, routers, etc.? The main reasons are as follows: (1The allocation of IP addresses is based on the topology of the network, not on who created the network settings. It is not feasible to build efficient routing schemes on the basis of equipment manufacturers rather than on the topological locations where the network is located. (2The device is easier to move and repair when there is an additional layer of address addressing. For example, if an Ethernet card is broken, it can be replaced without having to obtain a new IP address. If an IP host moves from one network to another, it can give it a new IP address without having to change a new network card. (3The communication between the local area network and the computers in the WAN ultimately manifests itself as starting from the initial node on some form of link, passing from one node to another and eventually to the destination node. The movement of packets between these nodes is done by the ARP (address Resolution Protocol: Addresses resolution Protocol) that maps the IP address to the MAC address. Let's look at an example of how IP addresses and MAC addresses are combined to transmit packets. Suppose the network is going to send a packet (named PAC) to a host in Beijing (called the A,ip address of the Ip_a,mac address of mac_a) to one of the hosts in Washington (with the name B,IP address Ip_b,mac address mac_b). The two hosts can not be directly connected, so the packet is passed through a lot of intermediate nodes (such as routers, servers, etc.), we assume in the transmission process through C1, C2, C3 (its MAC address is m1,m2,m3) three nodes. A before the PAC is emitted, send an ARP request to find the MAC address M1 of the First intermediate node C1 that it must go through to reach ip_b, and then encapsulate (encapsulation) These addresses in their packets: ip_a, Ip_b,mac_a, and M1. When the PAC is passed to C1, it is ip_b by ARP according to its destination IP address, finds the MAC address M2 of the Second intermediate node C2 it is going through, and then transmits the packet with M2 to C2. So and so on, until finally found the address of the Host B with the IP address of ip_b Mac_b, eventually transmitted to host B. During transmission, ip_a, ip_b, and mac_a are unchanged, while the MAC address of the intermediate node is constantly changing through ARP (M1,M2,M3) until the destination address is mac_b. As described above, we can conclude that the IP address and MAC address are the same point is they are unique, different features are mainly:1. For a device on a network, such as a computer or a router, its IP address is variable (but must be unique), and the MAC address is immutable. We can assign an arbitrary IP address to a host as needed, for example, we can allocate an IP address of 192 to a computer on a local area network.168.0. the, or you can change it to 192.168.0. $. and any network device (such as network card, router) once produced, its MAC address is always unique and can not be changed by the user. 2. length is different. The IP address is 32 bits and the MAC address is 48 bits. 3. The distribution is based on different. The allocation of IP addresses is based on network topology, and the allocation of MAC addresses is based on the manufacturer.4. The addressing protocol layer is different. The IP address is applied to the third layer of the OSI, the network layer, while the MAC address is applied to the second layer of the OSI, the data link layer. The Data Link layer protocol enables data to be passed from one node to another on the same link (via MAC address), while the Network layer protocol enables data to be passed from one network to another (ARP locates the MAC address of the intermediate node based on the destination IP address, transmits through the intermediary node, So that the destination network is eventually reached). Leo Chin Source: http://www.cnblogs.com/hnrainll/
Network Programming Learning Note the relationship between-MAC address and IP address