极客工坊知识库_极客学校:学习Windows 7 – IP地址基础知识
极客工坊知识库
In this edition of Geek School, we are going to look at how IP addressing works. We will also cover some advanced topics like how your PC determines if the device you are communicating with is on the same network as you. We will then finish with a brief look at two name resolution protocols: LLMNR and DNS.
在此版本的Geek School中,我们将研究IP寻址的工作原理。 我们还将介绍一些高级主题,例如您的PC如何确定与之通信的设备是否与您在同一网络上。 然后,我们将简要介绍两个名称解析协议:LLMNR和DNS。
Be sure to check out the previous articles in this Geek School series on Windows 7:
请务必查看Windows 7上此Geek School系列中的先前文章:
And stay tuned for the rest of the series all week long.
并请整周关注本系列的其余部分。
知识产权基础 (IP Fundamentals)
When you send a letter via snail mail you have to specify the address of the person you would like to receive the mail. Similarly, when one computer sends a message to another computer it needs to specify the address that the message should be sent to. These addresses are called IP addresses and typically look something like this:
通过蜗牛邮件发送信件时,您必须指定要接收邮件的人的地址。 同样,当一台计算机将消息发送到另一台计算机时,它需要指定该消息应发送到的地址。 这些地址称为IP地址,通常看起来像这样:
192.168.0.1
192.168.0.1
These addresses are IPv4 (Internet Protocol Version 4) addresses and like most things these days they are a simple abstraction as to what the computer actually sees. IPv4 addresses are 32-bit, which mean they contain a combination of 32 ones and zeros. The computer would see the address listed above as:
这些地址是IPv4(Internet协议版本4)地址,如今,像大多数事情一样,它们是计算机实际所见内容的简单抽象。 IPv4地址是32位的,这意味着它们包含32个1和0的组合。 计算机将看到上面列出的地址为:
11000000 10101000 00000000 00000001
11000000 10101000 00000000 00000001
Note: Each decimal octet has a maximum value of (2^8) – 1 which is 255. This is the maximum number of combinations that can be expressed using 8 bits.
注意:每个十进制八位位组的最大值(2 ^ 8)– 1为255。这是可以使用8位表示的最大组合数。
If you wanted to convert an IP address to its binary equivalent you could create a simple table, like below. Then take one section of the IP address (technically called an octet), for example 192, and move from left to right checking if you can subtract the number in the header of the table from your decimal number. There are two rules:
如果要将IP地址转换为其等效的二进制地址,可以创建一个简单的表,如下所示。 然后以IP地址的一部分(技术上称为八位字节)为例,例如192,并从左向右移动,检查是否可以从十进制数字中减去表标题中的数字。 有两个规则:
- If the number in the header of the table is smaller than or equal to your number, mark the column with a 1. Your new number then becomes the number you had subtract the number in the header of the column. For example, 128 is smaller than 192 so I mark the 128s column with a 1. I am then left with 192 – 128, which is 64. 如果表标题中的数字小于或等于您的数字,请将该列标记为1。新数字将成为您减去该列标题中的数字的数字。 例如,128小于192,因此我将128s列标记为1。然后剩下192 – 128,即64。
- If the number is larger than the number you have, mark it with a 0 and move on. 如果该数字大于您的数字,则将其标记为0并继续。
Here is how it would look using our example address of 192.168.0.1
使用我们的示例地址192.168.0.1,结果如下所示
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
1 | 0 | 1 | 0 | 1 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1个 |
1个 | 1个 | 0 | 0 | 0 | 0 | 0 | 0 |
1个 | 0 | 1个 | 0 | 1个 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | 0 | 0 | 0 | 1个 |
In the above example, I took our first octet of 192 and marked the 128s column with a 1. I was then left with 64 which is the same as the number as the second column so I marked it with a 1 as well. I was now left with 0 since 64 – 64 = 0. That meant that the rest of the row was all zeros.
在上面的示例中,我采用了第一个八位位组192,并用1标记了128s列。然后,我留下了64,它与第二列的编号相同,所以我也用了1。 因为64 – 64 = 0,所以我现在剩下0。这意味着该行的其余部分全为零。
In the second row, I took the second octet, 168. 128 is smaller than 168 so I marked it with a 1 and was left with 40. 64 was then greater than 40 so I marked it with a 0. When I moved into the third column, 32 was less than 40 so I marked it with a 1 and was left with 8. 16 is greater than 8 so I marked it with a 0. When I got to the 8s column I marked it with 1 which left me with 0 so the rest of the columns were marked with 0.
在第二行中,我取了第二个八位位组168。128小于168,所以我用1标记了它,剩下了40。然后64大于40,所以用0标记了它。第三列,32小于40,所以我用1标记,剩下8。16大于8,所以用0标记。当到达8s列时,我用1标记,这使我0,因此其余列均标记为0。
The third octet was 0, and nothing can go into 0 so we marked all columns with a zero.
第三个八位位组为0,并且任何东西都不能为0,因此我们将所有列标记为零。
The last octet was 1 and nothing can go into 1 except 1, so I marked all columns with 0 until we got to the 1s column where I marked it with a 1.
最后一个八位位组是1,除了1之外,其他任何东西都不能进入1,因此我将所有列都标记为0,直到到达1s列,然后在其中将其标记为1。
子网掩码 (Subnet Masks)
Note: Subnet masking can get very complex, so for the scope of this article we are only going to discuss classful subnet masks.
注意:子网掩码可能会变得非常复杂,因此在本文的范围内,我们将仅讨论有类别的子网掩码。
An IP address is made up of two components, a network address and a host address. The subnet mask is what is used by your computer to separate your IP address into the network address and host address. A subnet mask typically looks something like this.
IP地址由两个部分组成,即网络地址和主机地址。 子网掩码是计算机用来将IP地址分为网络地址和主机地址的掩码。 子网掩码通常看起来像这样。
255.255.255.0
255.255.255.0
Which in binary looks like this.
用二进制形式看起来像这样。
11111111.11111111.11111111.00000000
11111111.11111111.11111111.00000000
In a subnet mask the network bits are denoted by the 1s and the host bits are denoted by the 0s. You can see from the above binary representation that the first three octets of the IP address are used to identify the network that the device belongs to and the last octet is used for the host address.
在子网掩码中,网络位用1表示,主机位用0表示。 从上面的二进制表示中可以看到,IP地址的前三个八位位组用于标识设备所属的网络,而最后一个八位位组用于主机地址。
Given an IP address and subnet mask, our computers can tell if the device is on the same network by performing a bitwise AND operation. For example, say:
在给定IP地址和子网掩码的情况下,我们的计算机可以通过执行按位与操作来判断设备是否在同一网络中。 例如,说:
- computerOne wants to send a message to computerTwo. computerOne想要向computerTwo发送消息。
- computerOne has an IP of 192.168.0.1 with a subnet mask of 255.255.255.0 computerOne的IP地址为192.168.0.1,子网掩码为255.255.255.0
- computerTwo has an IP of 192.168.0.2 with a subnet mask of 255.255.255.0 computerTwo的IP为192.168.0.2,子网掩码为255.255.255.0
computerOne will first calculate the bitwise AND of its own IP and subnet mask.
computerOne将首先计算其自己的IP和子网掩码的按位与。
Note: When using a bitwise AND operation, if the corresponding bits are both 1 the result is a 1, otherwise it’s a 0.
注意:使用按位与运算时,如果相应的位均为1,则结果为1,否则为0。
11000000 10101000 00000000 00000001 11111111 11111111 11111111 00000000
11000000 10101000 00000000 00000001 11111111 11111111 11111111 00000000
11000000 10101000 00000000 00000000
11000000 10101000 00000000 00000000
It will then calculate the bitwise AND for computerTwo.
然后它将为computerTwo计算按位与。
11000000 10101000 00000000 00000010 11111111 11111111 11111111 00000000
11000000 10101000 00000000 00000010 11111111 11111111 11111111 00000000
11000000 10101000 00000000 00000000
11000000 10101000 00000000 00000000
As you can see, the results of the bitwise operations are they same, so that means that the devices are on the same network.
如您所见,按位运算的结果是相同的,这意味着设备位于同一网络上。
班级 (Classes)
As you probably have guessed by now, the more networks (1s) you have in you subnet mask the less host (0s) you can have. The number of hosts and networks you can have is divided up into 3 classes.
您可能已经猜到了,子网中的更多网络(1s)掩盖的主机(0s)越少。 您可以拥有的主机和网络数量分为3类。
Networks | Subnet Mask | Networks | Hosts | |
Class A | 1-126.0.0.0 | 255.0.0.0 | 126 | 16 777 214 |
Class B | 128-191.0.0.0 | 255.255.0.0 | 16 384 | 65 534 |
Class C | 192-223.0.0.0 | 255.255.255.0 | 2 097 152 | 254 |
网路 | 子网掩码 | 网路 | 主持人 | |
A级 | 1-126.0.0.0 | 255.0.0.0 | 126 | 16777214 |
B级 | 128-191.0.0.0 | 255.255.0.0 | 16384 | 65534 |
C级 | 192-223.0.0.0 | 255.255.255.0 | 2097152 | 254 |
保留范围 (Reserved Ranges)
You will notice that the 127.x.x.x range has been left out. This is because the entire range is reserved for something called your loopback address. Your loopback address always points to your own PC.
您会注意到127.xxx范围已被忽略。 这是因为整个范围是为称为环回地址的内容保留的。 您的环回地址始终指向您自己的PC。
The 169.254.0.x range was also reserved for something called APIPA which we will discuss later on in the series.
169.254.0.x范围也保留给APIPA,我们将在本系列的后面部分讨论。
专用IP范围 (Private IP Ranges)
Up until a few years ago every device on the internet had a unique IP address. When IP addresses began to run out, a concept called NAT was introduced which added another layer between our networks and the internet. IANA decided that they would reserve a range of addresses from each class of IPs:
直到几年前,互联网上的每个设备都有一个唯一的IP地址。 当IP地址开始用尽时,引入了一种称为NAT的概念,这在我们的网络和Internet之间增加了另一层。 IANA决定从每种IP类别中保留一系列地址:
- 10.0.0.1 – 10.255.255.254 from Class A A类10.0.0.1 – 10.255.255.254
- 172.16.0.1 – 172.31.255.254 from Class B B类的172.16.0.1 – 172.31.255.254
- 192.168.0.1 – 192.168.255.254 from Class C C类的192.168.0.1 – 192.168.255.254
Then instead of assigning each device in the world an IP address, your ISP provides you with a device called a NAT Router which is assigned a single IP address. You can then assign your devices IP addresses from the most suitable private IP range. The NAT Router then maintains a NAT table and proxies your connection to the internet.
然后,您的ISP不会为世界上的每个设备分配IP地址,而是为您提供了一个称为NAT路由器的设备,该设备被分配了一个IP地址。 然后,您可以从最合适的专用IP范围分配设备IP地址。 然后,NAT路由器会维护NAT表并代理您与Internet的连接。
Note: The IP of your NAT Router is usually assigned dynamically via DHCP so it normally changes depending on the constraints your ISP has in place.
注意:NAT路由器的IP通常是通过DHCP动态分配的,因此它通常会根据ISP的限制而变化。
名称解析 (Name Resolution)
It is way easier for us to remember human readable names like FileServer1 than it is to remember an IP address like 89.53.234.2. On small networks, where other name resolution solutions like DNS don’t exist, when you try to open a connection to FileServer1 you computer can send a multicast message (which is a fancy way of saying send a message to each device on the network) asking who FileServer1 is. This method of name resolution is called LLMNR (Link-lock Multicast Name Resolution), and while it’s a perfect solution for a home or small business network it doesn’t scale well, firstly because broadcasting to thousands of clients will take too long and secondly because broadcasts don’t typically traverse routers.
对于我们来说,记住诸如FileServer1之类的可读名称比记住IP地址(如89.53.234.2)要容易得多。 在不存在其他名称解析解决方案(例如DNS)的小型网络上,当您尝试打开与FileServer1的连接时,计算机可以发送多播消息(这是一种向网络上的每个设备发送消息的一种奇特的方式)问谁是FileServer1。 这种名称解析方法称为LLMNR(链接锁定多播名称解析),虽然它是家庭或小型企业网络的理想解决方案,但扩展性不佳,首先是因为广播到成千上万的客户端将花费很长时间,其次是因为广播通常不会遍历路由器。
DNS(域名系统) (DNS (Domain Name System))
The most common method to solve the scalability issue is to use DNS. The Domain Name System is the phonebook of any given network. It maps human readable machine names to their underlying IP addresses using a giant database. When you try to open a connection to FileServer1 your PC asks your DNS Server, which you specify, who FileServer1 is. The DNS Server will then respond with an IP address which your PC can in turn make a connection to. This is also the name resolution method used by the largest network in the world: the internet.
解决可伸缩性问题的最常见方法是使用DNS。 域名系统是任何给定网络的电话簿。 它使用一个巨型数据库将人类可读的机器名称映射到其底层IP地址。 当您尝试打开与FileServer1的连接时,PC会询问您指定的DNS服务器,FileServer1是谁。 然后,DNS服务器将使用您的PC可以与之建立连接的IP地址进行响应。 这也是世界上最大的网络:互联网使用的名称解析方法。
更改网络设置 (Changing Your Network Settings)
Right click on the network settings icon and select Open Network and Sharing Center from the context menu.
右键单击网络设置图标,然后从上下文菜单中选择“打开网络和共享中心”。
Now click on the Change adapter settings hyperlink on the left hand side.
现在,单击左侧的“更改适配器设置”超链接。
Then right click on your network adapter and select Properties from the context menu.
然后右键单击您的网络适配器,然后从上下文菜单中选择“属性”。
Now select Internet Protocol Version 4 and then click on the properties button.
现在选择Internet协议版本4,然后单击属性按钮。
Here you can configure a static IP address by selecting the radio button for “Use the following IP address”. Armed with the information above, you can fill in an IP address and subnet mask. The default gateway, for all intents and purposes, is the IP address of your router.
在这里,您可以通过选择“使用以下IP地址”单选按钮来配置静态IP地址。 有了以上信息,您可以填写IP地址和子网掩码。 出于所有目的和目的,默认网关是路由器的IP地址。
Near the bottom of the dialog you can set the address of your DNS server. At home you probably don’t have a DNS server, but your router often has a small DNS cache and forwards queries to your ISP. Alternatively, you could use Google’s public DNS server, 8.8.8.8.
在对话框底部附近,您可以设置DNS服务器的地址。 在家里,您可能没有DNS服务器,但是您的路由器通常具有较小的DNS缓存,并将查询转发到ISP。 或者,您可以使用Google的公共DNS服务器8.8.8.8。
家庭作业 (Homework)
-
There is no homework for today, but this has been a long one, so read over it again. If you are still hungry for more information you can read up on an advanced networking subject called CIDR (Classless Interdomain Routing).
今天没有作业,但是这已经很长了,因此请仔细阅读。 如果您仍然想获取更多信息,可以阅读称为CIDR (无类域间路由)的高级网络主题。
If you have any questions you can tweet me @taybgibb, or just leave a comment.
如果您有任何疑问,可以发给我@taybgibb ,或发表评论。
翻译自: https://www.howtogeek.com/133943/geek-school-learning-windows-7-ip-addressing-fundamentals/
极客工坊知识库