什么是NIC,MAC和ARP
计算机网络基础:什么是NIC, MAC和ARP?
"Avast! Belay the port jib, and scupper the mains'l on the poop deck!"
“停住!把绳拴在港口上,用排水管排掉甲板和船尾的水!”
This means something important to pirates. (Possibly.) It also illustrates how every industry has its own jargon, rich in technical meaning to insiders, but often impenetrable to outsiders. And the first time you hear a network geek tell you, "Of course the device can't be found, because its MAC address isn't in the ARP table," well, you just wanna keelhaul that bilge rat on the lee side of a mizzenmast.
这些话对海盗来说(或许)至关重要。它还说明了每个行业自己的行话对业内人士如何拥有丰富的技术含义,但对门外汉却十分费解。当你第一次听见一个网络极客对你说:“你的机子当然不会被到,因为它的MAC地址不在ARP映射表里”时,你只有羞愧得恨不得个洞钻进去。
A more effective and less violent response would be to learn these important terms. Devices on a network don't immediately become aware of the existence and location of other devices on the same network. If you've ever wondered how they discover one another, then you're ready to enter the not-reall
y-that-mysterious world of NIC, MAC, and ARP (pronounced as words, not as spelled-out letters). Full speed ahead, matey!适配器字符串是什么
在学习了本文的这些重要东西后,你就可以做出更有效而温和的回击了。在网络中的设备并不会马上检测到相同网络中其他设备的存在及其位置。如果你想知道他们之间是如何发现彼此的,那你就要准备好进入网络适配器(NIC, 也称网卡), 媒体访问控制(MAC)和地址解析协议(ARP)的虚幻而神秘的世界。
Two addresses in one
一台计算机中的两个地址
To explain NIC, MAC, and ARP, we'll start with one computer: yours. We'll call this desktop system Redbeard, one of several computers on a LAN.
为了解释NIC, MAC和ARP,我们将从你的计算机开始。我们将你计算机的桌面操作系统称作Redbeard,一个局域网里众多计算机中的一台。
You're probably aware that Redbeard has an Internet Protocol (IP) address. (If this concept is new to you, first read Foundations: Understanding IP Addresses and Binary.) An IP address acts like a mailing address to help other computers deliver network traffic to Redbeard. But IP addresses also present co
mplications. Some addresses are static, meaning, more or less permanent. But other IP addresses are dynamic, meaning, assigned on the fly from (and returned to) a range of IP addresses (for example, 192.168.0.1 - 192.168.0.254). Dynamic IP addressing is part of what enables you to take your laptop somewhere new, connect to the Internet, and receive IP traffic. When you do so,
somewhere a DHCP server has dynamically alloca
ted a temporary IP address to your laptop.
你可能知道Redbeard有一个IP地址。一个IP地址就像一个邮箱地址,它帮助其他计算机将网络信息传给Redbeard。但IP地址却更加复杂。一些IP地址是静态的,这就是说,它们多半是永久的。但是其他的IP地址是动态的,也就是说,将被分配自(也将被回收到)一个范围的IP地址(例如,192.168.0.1 - 192.168.0.254)。动态分配IP地址是你能带着你的笔记本走到某个新地方却依然联着网和接受IP数据的必要条件。当你带着你的笔记本到处乱逛的时候,处于某处的一台DHCP服务器已经动态地分配了一个临时IP地址给你的笔记本了。
So with machines coming and going on networks, and IP addresses ever changing, how do other computers on your network find Redbeard? The secret (well, not really a secret; just a fact that veteran administrators know so well, they forgot to tell you) is this: every networked device actually has two ad
dresses. One is the IP address, which might or might not change. The other is the MAC address, which typically does not change.
那么随着你的计算机在网络中不断地移动,IP地址不断地改变,在局域网中的其他计算机是如何到Redbeard的呢?秘密在于(好吧,其实也不是什么秘密;只是一个经验丰富的管理员了解得很清楚但却忘了告诉你的一个事实):每一台网络设备都有两个地址。一个是IP地址,可能是静态也可能是动态。另一个是MAC地址,一个通常不会改变的地址。
MAC is just my NIC name
MAC仅仅是我网卡的名字
When you connect a computer to your Ethernet LAN, do you know what you're plugging the Ethernet cable into? From the outside, it looks like you're plugging it into a metal case, but you're not. Inside the case is a Network Interface Card (NIC). A NIC is a special hardware card within any networked device (computer, printer, router, etc.) that handles all the technical aspects of sending and receiving data packets over a computer network.
当你连接计算机到你的以太局域网时,你知道你的网线正在插进什么东西么?从外面来看,你在将网线
头插进一个金属孔(译者注:就是你计算机上的网口)中,但是事实并非这样。在这个孔的里面是一个网络适配器(网卡)。网卡是每个网络设备(计算机,打印机,路由器,等等)中都有的硬件,它们处理一个计算机网络中所有收发数据包的技术方面的工作。
Like your mailing address at home, your computer's NIC has a unique address. This address must be unique in all the world. Otherwise, network traffic couldn't find its way to the right computer.
就像你家里的邮箱地址,你的计算机的网卡也有一个唯一的地址。这个地址必须
在全球都是唯一的。否则,网络数据不能到到达
正确计算机的路径。
The distinctive address that identifies a NIC is called the Media Access Control (MAC) address. A MAC address is a unique character string, and since it identifies a specific physical device -- one individual NIC -- the MAC address, by convention, never changes for the life of the NIC. Two NICs never have the same MAC address (unless some manufacturer screws up royally [which has happened]). Because your NIC's MAC address is permanent, it's often referred to as the "real," or physical, address of a computer.
这个识别网卡的独特地址就是所谓的媒体访问控制(MAC)地址。一个MAC地址是一个独一无二的字符串。由于它标识一个独特的物理设备——一个唯一的网卡——MAC地址,按照约定,在网卡中将永不会改变。任何两块网卡都不会有相同的MAC地址(除非人为地改变)。因为你的网卡MAC地址是不变的,它常常被认为是“真”的,物理的,计算机地址。
A MAC address is formatted as a six-byte, hexadecimal number, like this:
一个标准的MAC地址是6字节,16进制表示,就像这样:
00:90:7F:12:DE:7F
00:90:7F:12:DE:7F
In hexadecimal notation, it takes merely two characters to represent a byte. Each byte in a MAC address is separated by either a colon (:) or a hyphen (-).
在16进制记法里,仅仅用两个字符就能表示一个字节。MAC地址里每个字节都用冒号(:)或连字号(-)分开。
You don't get to assign MAC addresses the way you do IP addresses. Instead, manufacturers pre-prog
ram a chip on each NIC with its exclusive MAC address. The IEEE Standards Association assigns each NIC manufacturer a special three-byte code, called an Organizationally Unique Identifier (OUI, which you should not confuse with the men's magazine of the same name -- trust us), which identifies that particular manufacturer. The first half (three bytes) of any MAC address expresses this manufacturer code. For example, taking the OUI in the MAC address shown above, you can look up 00:90:7F on IEEE's OUI registry and find that 00:90:7F indicates a NIC from WatchGuard.
你不用像获得IP地址那样获得MAC地址,而是制造商在每一个网卡里都预先编号了一个带有唯一MAC地址的芯片。IEEE标准协会给每个网卡制造商分配了一个唯一的3字节代码,即所谓的组织唯一标识符(OUI,Organizationally Unique Identifier),它用来识别制造商。任何一个MAC地址的前半部分(3字节)表示这种制造商代码。例如,到上面提到的MAC地址的OUI,你可以再IEEE的OUI注册表中查00:90:7E,最后你将发现00:90:7E代表来自WatchGuard的网卡。
The second half of a MAC address differentiates one NIC from another. The NIC manufacturers ensure that the MAC address for each NIC the
y ship ends with a unique three-byte number. This is feasible because a three-byte hexadecimal address offers over sixteen million
possible variations.
MAC地址的后半部分不同于其前半部分。网卡制造商确保他们生产的每一块网卡的MAC地址都以唯一的3字节数结尾。由于一个3字节的16进制数至少能表示一千六百万个地址,因此这样做是可行的。
The yin and yang of MAC and IP
MAC地址和IP地址的优缺点
MAC addresses seem pretty cool, right? But you have no control over what MAC addresses will be in the devices you purchase, and you normally can't alter them, so it's impossible to organize anything by MAC address. MAC addresses are not routable, either; in other words, Internet protocols will not accept a MAC address as a destination (for one thing, it's two bytes longer than an IP address). The MAC concept doesn't scale. So you only utilize MAC addresses locally, not across a router.
MAC地址似乎相当酷,是不是?但当你买到一块网卡时却无法控制其MAC地址的值,而且通常你还不能修改它,这就会由它引出一些事情。同时MAC地址是不能被路由的,换句话说,网络层协议将不会把MAC地址作为目的地址(而且,它还比IP地址多了两字节)。MAC并不能构成网络拓扑。所以你仅仅在局域网内部用MAC地址,而不会经过路由器。
IP addresses, on the other hand, scale extremely well. On your private network, you can slice 'em into ranges that make sense to you (known as subnetworking, or subnetting). You can decide at a whim what IP address any device or group of devices should have.
相反,IP地址的网络拓扑结构相当好。在你的私有网络中,你可以随心所欲地将其分为很多分支(即所谓的子网或分网)。你可以按你所愿给任何一台或一组设备分配IP地址。
So what we have is yin and yang. The malleable IP address gives your network some flexible manageability. The never-changing MAC provides a specific, reliable address for a physical device.
我们说事情都是优劣互补的。具有延展性的IP地址让你的网络拥有了灵活的管理。而永不变化的MAC地址给物理设备提供了一个独特可靠的地址。
Or you could say, we have the long and the short of it. IP addresses route a packet across the whole global Internet, while MAC addresses help the packet make the small, local hop between hardware devices. Sophisticated networking is possible because each of your networked devices has both a MAC and an IP address.
或者你也可以说,我们取长补短。IP地址在整个全球因特网中路由数据包,而MAC地址则帮助数据包在
两个硬件设备间做狭小的局部的传递。正是由于你的网络设备拥有MAC地址和IP地址才让这复杂的网络传输变得可能。
Network Roll Call: ARP
网络中的
点名:ARP
We began by wondering, "How do devices on a local network become aware of one another?"
NICs and MACs are important pieces of the answer, but your network must learn to pair a MAC address with the IP address for the same machine. It does so using a technique called Address Resolution Protocol (ARP, pronounced like a pirate with the hiccups).
我们开始想知道,“在局域网中的设备如何才知道彼此的存在呢?”网卡和MAC地址只是这个答案中重要的部分,你的网络还必须知道如何匹配同一台设备的MAC地址和其IP地址。这就是所谓的地址解析协议(ARP, Address Resolution Protocol, 可以想象海盗边打嗝边读出它的情景)。
Think of ARP as network roll call. Remember the first day of fourth grade? At the beginning of class, th
e teacher called from a list of names, expecting you to reply when she called yours. She did this to associate your name with your face. Every kid heard every name, but answered only to his or her own name. ARP uses a similar technique to associate an IP address to the MAC address.
把ARP想像成网络中的点名。还记得你四年级时入学的第一天么?在开始上课时,老师按照点名册开始点名,希望点到你时你能够答“到”。她这是为了能将你的名字和你的脸联系起来。每一个小孩都听到了所有的名字,但是却只回答他(她)自己的名字。ARP运用了相似的技术来将IP地址和MAC地址联系起来。
Let's assign Redbeard the IP address, 192.168.39.101, and suppose its NIC has the MAC address, 00:A0:24:30:2E:13. And suppose you need to send a file to Larry in Accounting -- or more literally, to his computer, Beancounter. When Redbeard attempts to send Beancounter a file, Redbeard first obtains Beancounter's IP address. Upon seeing that the IP address is local (on the same subnetwork), Redbeard knows he is capable of sending the file to its destination, if he learns the "real" (MAC) address associated with that IP address. To learn the MAC address, Redbeard does what your teacher did on the first day of school. He calls out to the entire local network asking that the computer with the IP in question reply "Here!" with a MAC address.
我们给Redbeard分配的IP地址为192.168.39.101,并且假设它的网卡的MAC地址为00:A0:24:30:2E:13.然后假设你需要发送一个文件给Larry——更具体点,给他的电脑,Beancounter。当Redbeard尝试给Beancounter发送一个文件时,Redbeard首先获得Beancounter的IP地址。发现其IP地址是局域网内的(在同一个子网中),如果Redbeard知道“真的”对方的MAC地址和对应的IP地址,那么他能够将文件送到目的地。为了获得对方的MAC地址,Redbeard做出了和你开学第一天老师做的同样事情。他在整个局域网内点名,让是这个IP地址的计算机
用它的MAC地址答“到”。
Let's say that Beancounter has the IP, 192.168.39.148. To find the MAC address for Beancounter, Redbeard would send the following (simplifi
ed) ARP request:
我们假设Beancounter的IP地址是192.168.39.148。为了到Beancounter的MAC地址,Redbeard将发送下面的ARP请求:
From(Redbeard's MAC address):    00:A0:24:30:2E:13
To(Broadcast address)            FF:FF:FF:FF:FF:FF
Packet content              Who has 192.168.39.148? Tell 192.168.39.101
来自(Redbeard的MAC地址):  00:A0:24:30:2E:13
去往(广播地址):          FF:FF:FF:FF:FF:FF
数据包的内容            Who has 192.168.39.148? Tell 192.168.39.101(谁的IP地址是192.168.39.148? 请告诉192.168.39.101,译者注)
Notice the special address in the "To" field above. That special address (all Fs) is the MAC broadcast address. Anything sent to that address goes to every computer on Redbeard's LAN segment. All those computers receive the message, but ignore it, because it doesn't pertain to them -- with the exception of Beancounter. Because Beancounter is 192.168.39.148, it replies with its MAC address, like this:
注意到上面的“去往”分栏里的特殊地址。这个特殊地址(全是F)就是MAC广播地址。任何发送至这个地址的包都会到达Redbeard所在局域网段里的每一个计算机。所有这些计算机(除了Beancounter,译者注)都会收到这个报文,但是都忽略它,因为这个报文并不属于它们——它属于Beancounter。因为Beancounter的IP地址是192.168.39.148,所以它会像这样响应这个报文:
From(Beancounter's MAC address):          00:A0:24:30:4C:23
To(Redbeard's address)                    00:A0:24:30:2E:13
Packet content                  I have192.168.39.148
来自(Beancounter的MAC地址):                00:A0:24:30:4C:23
去往(Redbeard的MAC地址):                  00:A0:24:30:2E:13
数据包内容                        I have192.168.39.148(我是192.168.39.148,译者注)
Now Redbeard has "resolved" the IP address 192.168.39.148 to its MAC address, 00:A0:24:30:4C:23. Redbeard can send files directly to the correct piece of hardware that accepts network traffic on behalf of Beancounter (Beancounter's NIC). Bonus: Beancounter also remembers Redbeard's IP address and MAC address, because they were part of Redbeard's initial ARP request.
现在Redbeard将IP地址192.168.39.148和它的MAC地址00:A0:24:30:4C:23“关联”起来了。Redbeard现在能偶直接发送文件到网络中代表Beancounter的硬件(Beancounter的网卡)了。注意:Beancounter也记住了Redbeard的IP地址和MAC地址,因为这些也是Redbeard的最初ARP请求里的内容。
This entire process we've just described is what geeks mean when they say "it's ARPing for a MAC address."

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。