当前位置:网站首页>IP, subnet mask, gateway, default gateway
IP, subnet mask, gateway, default gateway
2022-07-06 17:53:00 【TABE_】
Here's the catalog title
ip
ip Address = network address + The host address ( also called : Network number and host number ), We call the host with the same network number as the host in the local network , Hosts with different network numbers are called hosts in the remote network . Hosts in the local network can communicate with each other directly , In order to communicate with each other, the hosts in the remote network must pass through the local gateway (Gateway) To deliver forwarding data .
ip The main addresses are A、B、C、D、E Five types of address :
- A class : from 1 Byte network address and 3 Byte host address composition , The highest bit of the network address must be “0”( All network addresses are 0 The address of is reserved for use ). The address range is 1.0.0.0 To 127.255.255.255, It is mainly allocated to large-scale networks with a large number of hosts and a small number of LAN networks ;
- B class : from 2 Byte network address and 2 Byte host address composition , The top two digits of the network address must be “10”. The address range is 128.0.0.0 To 191.255.255.255, Generally used in large international companies and government agencies ;
- C class : from 3 Byte network address and 1 Byte host address composition , The highest bit of the network address must be “110”. The address range is 192.0.0.0 To 223.255.255.255, For general small company campus network research institutions, etc ;
- D class : The first byte consists of “1110” Start . All zeros (“0.0.0.0”) The address corresponds to the current host . whole “1” Of IP Address (“255.255.255.255”) Is the broadcast address of the current subnet . The address range is 224.0.0.0 To 239.255.255.255, Also known as broadcast address , So any first byte is greater than 223 Less than 240 Of IP The address is the multicast address .
- E class : from “11110” Start , The address range is 240.0.0.0 To 255.255.255.255, For the time being .
network address
Calculating the network address is to determine whether the computers in the network are on the same network , You can get through , You can't get through without , Need the help of local gateway .
take IP The address and subnet mask are all converted to binary form , Then the result of the phase by phase sum of the two is the network address .
IP Decimal system :192.168.1.1
IP Binary system :11000000 10101000 00000001 00000001
Subnet mask decimal :255.255.255.0
Subnet mask binary :11111111 11111111 11111111 00000000
network address = IP & Subnet mask
Network address binary :11000000 10101000 00000001 00000000
Network address decimal :192.168.1.0
The host address
IP The result of not matching the subnet mask is the host address .
IP Decimal system :192.168.1.1
IP Binary system :11000000 10101000 00000001 00000001
Subnet mask decimal :255.255.255.0
Subnet mask binary :11111111 11111111 11111111 00000000
The host address = IP & (~ Subnet mask )
Host address binary :00000000 00000000 00000000 00000001
Host address decimal :0.0.0.1
Subnet mask
The representation of subnet mask
(1) Dotted decimal notation
Binary to decimal , Every time 8 The places are separated by dots .
for example : Subnet mask binary 11111111.11111111.11111111.00000000, Expressed as 255.255.255.0
(2)CIDR slash notation
IP Address /n
example 1:192.168.1.100/24, Its subnet mask is expressed as 255.255.255.0, Binary representation as 11111111.11111111.11111111.00000000
example 2:172.16.198.12/20, Its subnet mask is expressed as 255.255.240.0, Binary representation as 11111111.11111111.11110000.00000000
It's not hard to find out , example 1 The Communist Party of China has 24 individual 1, example 2 The Communist Party of China has 20 individual 1, therefore n It's like this . Operator, ISP This method is often used to assign... To customers IP Address .
notes :n by 1 To 32 The number of , Indicates the length of the network number in the subnet mask , adopt n Determine the number of hosts in the subnet =2^(32-n)-2(-2 Why : All hosts are 0 Indicates the network address of the network , All hosts are 1 Indicates the broadcast address of the network , These are two special addresses ).
Why use a subnet mask ?
Said before , The subnet mask can be separated IP Network address and host address in the address , Then why separate ? Because the two hosts need to communicate , First of all, it is necessary to judge whether they are in the same network segment , Whether the network address is the same . If the same , Then you can send the packet directly to the target host , Otherwise, the routing gateway is required to forward the data packet to the destination .
It's easy to understand :A The host should be connected with B Host communication ,A and B Respective IP Address and A The subnet mask of the host And And operation , The visible result :
- If the results are the same , It means that the two hosts are in the same network segment , such A Can pass ARP Broadcast discovery B Of MAC Address ,B It can also be found A Of MAC Address to achieve normal communication .
- If the results are different ,ARP The broadcast will end at the local gateway , Now A Will send to B The packet is sent to the local gateway first , The gateway is then based on B The host IP Address to query the routing table , Then continue to deliver and forward the packet , Finally sent to the destination B.
Classification of subnet masks
(1) The default subnet mask
Also known as the default subnet mask , That is, there is no subnet , The corresponding network number is set to 1 , All the host numbers are set 0 .
Not divided into subnets IP Address : network number + Host number , be :
- A Class network default subnet mask : 255.0.0.0, use CIDR Expressed as /8
- B Class network default subnet mask : 255.255.0.0, use CIDR Expressed as /16
- C Class network default subnet mask : 255.255.255.0, use CIDR Expressed as /24
(2) Custom subnet mask
After dividing a network into subnets , Give a part of the original host number location to the subnet number , The rest is the host number of the subnet . Its form is as follows :
After the subnet division IP Address : network number + Subnet number + Subnet host number , for instance :
- 192.168.1.100/25, Its subnet mask indicates :255.255.255.128, It means that you will 192.168.1.0 The highest host bit of this network segment 1 The bits are divided into subnets .
gateway
Computer gateway (Gateway) Is the exit to other network segments , That is, the router interface IP Address . The router interface uses IP The address can be any address in this network segment , However, the first available address or the last available address of the network segment is usually used , This is to avoid conflicts with the host addresses in this network segment as much as possible .
In the following topology illustration example ,A And B,C And D, Can communicate directly with each other ( All belong to the same network segment , You don't have to go through the router ), however A And C,A And D,B And C,B And D They do not belong to the same network segment , So they communicate through the local gateway , Then the router according to each other IP Address , Find the exact match in the routing table IP Direct routing of addresses , So it is forwarded from the gateway interface on the other side to realize interconnection .
The default gateway
The default gateway address is set to all except the last host bit 1 Later obtained .
Let's say there's a ip The address is 193.6.7.0/24, According to the network prefix 24 Before we know 24 Bit is network bit , after 8 Bit is host bit , Therefore, the default gateway address of the network is IP Address 193.6.7.11111110( The bold part is the host bit ), Convert to decimal number, that is 193.6.7.254/24.
A host can have multiple gateways . The default gateway means that if a host cannot find an available gateway , Send the packet to the default gateway , This gateway handles packets . Now the gateway used by the host , It generally refers to the default gateway . The default gateway of a computer can't be specified casually , Must specify... Correctly , Otherwise, a computer will send packets to a host that is not a gateway , Therefore, it is impossible to communicate with the host of other networks . The default gateway can be set manually or automatically .
(1) Manual settings
The manual setting is suitable for a small number of computers 、TCP/IP When the parameters are basically the same , For example, there are only a few to a dozen computers . Because this method needs to be set up on every computer connected to the network “ The default gateway ”, It's very hard , Once the default gateway has to be modified due to migration and other reasons IP Address , Will bring a lot of trouble to the network management , So... Is not recommended .
stay Windows 9x in , Set the default gateway in “ Online neighbors ” Right click on , Click... In the pop-up menu “ attribute ”, In the network properties dialog box, select “TCP/IP agreement ”, Click on “ attribute ”, stay “ The default gateway ” Tab, fill in the name of the new default gateway IP The address will do .
Here's the thing to watch out for : The default gateway must be in the network segment of the computer itself IP Address , You can't fill in IP Address .
(2) Automatic setting
Automatic setting is to use DHCP(Dynamic Host Configuration Protocol, Dynamic Host Configuration Protocol ) Server to automatically assign computers in the network IP Address 、 Subnet mask and default gateway . The advantage of this is that once the default gateway of the network changes , Just change DHCP The default gateway settings in the server , Then all the computers in the network get the new default gateway IP Address . This method is suitable for large scale networks 、TCP/IP Parameters may change in the network . Another way to get the gateway automatically is by installing the proxy server software ( Such as MS Proxy) The client program to automatically get , Its principle and method and DHCP There are similarities . Limited space , Let's not go into details .
边栏推荐
- How to use scroll bars to dynamically adjust parameters in opencv
- The integrated real-time HTAP database stonedb, how to replace MySQL and achieve nearly a hundredfold performance improvement
- Interview assault 63: how to remove duplication in MySQL?
- 面试突击62:group by 有哪些注意事项?
- Zen integration nails, bugs, needs, etc. are reminded by nails
- C语言指针*p++、*(p++)、*++p、*(++p)、(*p)++、++(*p)对比实例
- 【ASM】字节码操作 ClassWriter 类介绍与使用
- Remote code execution penetration test - B module test
- Debug xv6
- Reppoints: advanced order of deformable convolution
猜你喜欢
[ASM] introduction and use of bytecode operation classwriter class
偷窃他人漏洞报告变卖成副业,漏洞赏金平台出“内鬼”
8位MCU跑RTOS有没有意义?
What is the reason why the video cannot be played normally after the easycvr access device turns on the audio?
Why should Li Shufu personally take charge of building mobile phones?
There is a gap in traditional home decoration. VR panoramic home decoration allows you to experience the completion effect of your new house
Easy introduction to SQL (1): addition, deletion, modification and simple query
[introduction to MySQL] the first sentence · first time in the "database" Mainland
SQL statement optimization, order by desc speed optimization
Zen integration nails, bugs, needs, etc. are reminded by nails
随机推荐
Solution qui ne peut pas être retournée après la mise à jour du navigateur Web flutter
[getting started with MySQL] fourth, explore operators in MySQL with Kiko
Debug and run the first xv6 program
ASEMI整流桥DB207的导通时间与参数选择
Basic configuration and use of spark
EasyCVR平台通过接口编辑通道出现报错“ID不能为空”,是什么原因?
中移动、蚂蚁、顺丰、兴盛优选技术专家,带你了解架构稳定性保障
重磅硬核 | 一文聊透对象在 JVM 中的内存布局,以及内存对齐和压缩指针的原理及应用
远程代码执行渗透测试——B模块测试
[ASM] introduction and use of bytecode operation classwriter class
Pyspark operator processing spatial data full parsing (4): let's talk about spatial operations first
Mysqlimport imports data files into the database
Spark calculation operator and some small details in liunx
Manifest of SAP ui5 framework json
Kivy tutorial: support Chinese in Kivy to build cross platform applications (tutorial includes source code)
How to submit data through post
The easycvr platform reports an error "ID cannot be empty" through the interface editing channel. What is the reason?
OpenEuler 会长久吗
Pytorch extract middle layer features?
It doesn't make sense without a distributed gateway