IP address, MAC address and port

Overview:

  • IP address, a positioning function (communication network and network) (logically uniquely identifies a computer) (network layer)
  • MAC ID is no positioning function (work in a subnet) (physically uniquely identifies a computer) (link layer)

The first is how to view the ip address the problem:

Windows:ipconfig

Linux:ifconfig 、ip addr

Copy the code
#Linux下ip addr的内容
root@test:~# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether fa:16:3e:c7:79:75 brd ff:ff:ff:ff:ff:ff # MAC地址
    inet 10.100.122.2/24 brd 10.100.122.255 scope global eth0  #10.100.122.2就是一个IP地址
valid_lft forever preferred_lft forever inet6 fe80::f816:3eff:fec7:7975/64 scope link valid_lft forever preferred_lft forever
Copy the code

When using TCP / IP protocol suite for communication, there are three more critical information to confirm the identity of: mac address, IP address and port number.

  • IP Address: (based computer or router) in the network layer where the IP header is used to identify network hosts and routers interconnected, it is mainly to confirm subnets, subnet an IP address belongs confirmed by the subnet mask , and then confirm the mac address in the internal subnet will be able to find the correct user.
  • MAC address: (or a router-based network) in the package data link layer in the Ethernet header, which is mainly used to identify the same link in a different computer. Mac address is card numbers, each card when manufactured, has a worldwide unique MAC address length is 48 bits, generally represented by 12 hexadecimal numbers.
  • Port Number: the transport layer comprises a TCP / UDP header for identifying the application. On one host can run multiple programs, then the received message in the end is which program it? We need to confirm that the port number.
  • Port Number Two:
    •   Port number http, telnet, ftp, etc. widely used application protocol to use fixed port number, is shaped like a fixed
    •   Dynamically assigned port numbers, this time to determine the server listening port number, serviced clients do not need to determine the port number

port

Port concept is the application layer, each application (communication network) occupies its own port

It is determined by the transport layer protocol port numbers, and therefore can not use the same transport protocol port numbers, TCP and UDP use the same port number

Sent to the application via port

 

16-bit port number is represented in binary. In the range 0 to 65535, it is divided into two ports:

Well-known ports : 0 to 1023 (System Application service occupied)

FTP service: 21

HTTP services: 80,443

Dynamic Port : 1024 to 65535 (install their own applications / services occupancy)

MySQL:3306

Redis: 6379

FeiQ: 2425

Question: Now a lot of tools can change the MAC address of the machine, which is present on many network MAC address is changed to the same, but there has been no communication error or confusion this is why?
Answer: MAC conflict within a local area network that can affect communications, is outside the LAN via IP positioning, so that different devices on LAN MAC will not have the same communication problems.


IP detailed supplement

The first several different network number, the IP address is divided into five categories:

Currently IP address IP technology that may be used with up to 4,294,967,296 (i.e., 2 32 ).

n  indicates that the network bit is bit     H  indicates that the bit position is the host     X  represents a non-specific effect that the bit

Copy the code
Class A addresses: the first bit is 0, the length of the network number is 8-1 = 7, host number address length is 24 bits. Address range: 0.0.0.0 ~ 127.255.255.255 
  of 0. The of 0. The 00000000.00000000.00000000.00000000 of 0. The 0 = 
127.255.255.255 = 01111111.11111111.11111111.11111111 
                  0nnnnnnn.HHHHHHHH.HHHHHHHH.HHHHHHHH 
Class B addresses: the first two 10, 16 is the network number length = 14 -2, 16-bit length host number. Address range: ~ 191.255.255.255 128.0.0.0 
128. of 0. The 10000000.00000000.00000000.00000000 of 0. The 0 = 
191.255.255.255 = 10111111.11111111.11111111.11111111 
                  10nnnnnn.nnnnnnnn.HHHHHHHH.HHHHHHHH 

Class C addresses: 110 as the top three, a length of network number 24 = 21 -3, a length of eight host number. Address range: ~ 223.255.255.255 192.0.0.0 
192. of 0. The 11000000.00000000.00000000.00000000 of 0. The 0 = 
223.255.255.255 = 11011111.11111111.11111111.11111111 
                  110nnnnn.nnnnnnnn.nnnnnnnn.HHHHHHHH

Class D Address: 1110 first four bits, the back does not distinguish between network number and host number. For the multicast or broadcast 
224. of 0. The 11100000.00000000.00000000.00000000 of 0. The 0 = 
239.255.255.255 = 11101111.11111111.11111111.11111111 
                  1110XXXX.XXXXXXXX.XXXXXXXX.XXXXXXXX 

E Class Address: back does not distinguish between network number and host number, reserved, now no used (an IPV6) 
240. of 0. the 11110000.00000000.00000000.00000000 of 0. the 0 = 
255.255.255.255 = 11111111.11111111.11111111.11111111 
                  1111XXXX.XXXXXXXX.XXXXXXXX.XXXXXXXX
Copy the code


 

C类地址中,在一个局域网(网络号相同)内,最多能同时存在多少台机器?256台
B类地址中,在一个局域网(网络号相同)内,最多能同时存在多少天机器?65536台
A类地址中,……
另外,在A、B、C地址中,有一个小范围:
10.0.0.0~10.255.255.255
172.16.0.0~172.16.255.255
192.168.0.0~192.168.255.255
这个范围之内的IP地址用来做私有IP
这些地址是不能联网的,能上网的IP叫公有IP
 
还有一个127.0.0.1~127.255.255.255,用于回路测试。以确保自己的电脑身上的网络相关的功能是正常的。

 

 

 

学习参考资料:

IP地址和MAC地址的本质区别

mac地址、ip地址和端口号

集线器、交换机、路由器的区别

Github地址:https://github.com/kumataahh
 
  • IP 是地址,有定位功能(网与网的通讯)     (在逻辑上唯一标识一台电脑)(网络层)
  • MAC 是身份证,无定位功能(在子网干活)(在物理上唯一标识一台电脑) (链路层)

首先是如何查看ip地址的问题:

Windows:ipconfig

Linux:ifconfig 、ip addr

Copy the code
#Linux下ip addr的内容
root@test:~# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether fa:16:3e:c7:79:75 brd ff:ff:ff:ff:ff:ff # MAC地址
    inet 10.100.122.2/24 brd 10.100.122.255 scope global eth0  #10.100.122.2就是一个IP地址
valid_lft forever preferred_lft forever inet6 fe80::f816:3eff:fec7:7975/64 scope link valid_lft forever preferred_lft forever
Copy the code

在利用TCP/IP协议族进行通信的时候,有三个比较关键的确认身份的信息:mac地址、IP地址和端口号。

  • IP地址:(基于计算机或路由器)在网络层的IP头部里,用于识别网络中互联的主机和路由器,其实主要是确认子网,通过子网掩码确认某个IP地址所在的子网,而后再在子网内部确认mac地址就能找到准确的用户了。
  • MAC地址:(基于网卡或路由器)在数据链路层包裹在以太网头部中的,它主要用来识别同一个链路中的不同计算机。Mac地址即网卡号,每块网卡出厂的时候,都有一个全世界独一无二的 MAC 地址,长度是 48 个二进制位,通常用 12 个十六进制数表示。
  • 端口号:在传输层包含在TCP/UDP头部中的,用于识别应用程序。一台主机上能运行多个程序,那么接收到的消息到底是哪个程序的呢?就需要端口号来确认。
  • 端口号有两种:
    •   固定的端口号,是形如http,telnet,ftp等广为使用的应用协议所使用的端口号是固定的
    •   动态分配的端口号,这个时候服务端要确定监听端口号,接受服务的客户端没必要确定端口号

端口

端口是应用层的概念,每个应用程序(进行网络通信)都占用自己的端口

端口号由传输层协议决定,因此不容传输协议可以使用相同的端口号,所以TCP和UDP可以使用同一个端口号

通过端口发送给应用程序

 

端口号用16位2进制数来表示。取值范围0~65535,分为两种端口:

知名端口:0~1023(系统应用程序服务所占用)

FTP服务:21

HTTP服务:80、443

动态端口:1024~65535(自己安装的应用程序/服务占用)

MySQL:3306

Redis:6379

FeiQ:2425

问题:现在很多工具都可以更改本机的MAC地址,也就是网络上存在很多MAC地址被更改成一样的,然而并没有出现通讯异常或者混乱这是为什么?
回答:MAC在一个局域网内冲突才会影响网络通讯,局域网外是通过IP定位,所以不同局域网的网络设备MAC一样是不会有通讯问题的。


IP详细补充

根据网络号的前几位不同,把IP地址分为5类:

目前IP技术可能使用的IP地址最多可有4,294,967,296个(即232)。

n 表示该二进制位是网络位    H 表示该二进制位是主机位    X 表示该二进制位无特定作用

Copy the code
A类地址:第一位为0,网络号长度是8-1=7位,主机号地址长度是24位。地址范围:0.0.0.0~127.255.255.255
  0.  0.  0.  0 = 00000000.00000000.00000000.00000000
127.255.255.255 = 01111111.11111111.11111111.11111111
                  0nnnnnnn.HHHHHHHH.HHHHHHHH.HHHHHHHH
B类地址:前两位为10,网络号长度是16-2=14位,主机号长度16位。地址范围:128.0.0.0~191.255.255.255
128.  0.  0.  0 = 10000000.00000000.00000000.00000000
191.255.255.255 = 10111111.11111111.11111111.11111111
                  10nnnnnn.nnnnnnnn.HHHHHHHH.HHHHHHHH

C类地址:前三位为110,网络号长度为24-3=21位,主机号长度8位。地址范围:192.0.0.0~223.255.255.255
192.  0.  0.  0 = 11000000.00000000.00000000.00000000
223.255.255.255 = 11011111.11111111.11111111.11111111
                  110nnnnn.nnnnnnnn.nnnnnnnn.HHHHHHHH

D类地址:前四位为1110,后面不区分网络号和主机号。用于进行多播或广播
224.  0.  0.  0 = 11100000.00000000.00000000.00000000
239.255.255.255 = 11101111.11111111.11111111.11111111
                  1110XXXX.XXXXXXXX.XXXXXXXX.XXXXXXXX

E类地址:后面不区分网络号和主机号,预留,现在没用了(出了IPV6)
240.  0.  0.  0 = 11110000.00000000.00000000.00000000
255.255.255.255 = 11111111.11111111.11111111.11111111
                  1111XXXX.XXXXXXXX.XXXXXXXX.XXXXXXXX
Copy the code


 

Class C addresses, in a local area network (same network number) within a maximum of how many machines can exist simultaneously? 256
Class B address, the (same network number) within a local area network, up to the number of days the machine exist? 65,536
Class A addresses, ......
In addition, A, B, C address, there is a small range:
10.0.0.0 ~ 10.255.255.255
172.16.0.0 ~ 172.16.255.255
192.168.0.0 ~ 192.168.255.255
within this range the IP address used for private IP
addresses are not networked, access to the Internet is called IP public IP
 
and a 127.0.0.1 ~ 127.255.255.255, for loop testing. To ensure that their computer network-related functions of the body is normal.

 

 

 

Learning Resources:

Essential difference between IP address and MAC address

mac address, ip address and port number

The difference between hubs, switches, routers

Guess you like

Origin www.cnblogs.com/WayneKhouTech/p/11488760.html