11

Why do we need to give IP addresses to each interface? Wouldn't giving one to each device be enough?

  • 3
    Some devices do only get an IP for management that it isn't tied to any particular interface. Others work in the way you described. It varies by device, model, and software/firmware. In addition, you may need to assign different IP address per interface depending on a task's requirements. – Jesse P. Jan 16 at 14:35
  • 3
    Short answer - to make routers possible. A router is just a computer (these days most likely Linux) that needs to connect to different networks - thus must have the ability to have multiple IP addresses. The multiple IP per device thing came about at roughly the same time as the invention of the router. – slebetman Jan 16 at 17:57
  • No answer with historical information? Disappointed :-) – DanFromGermany Jan 17 at 11:33
  • This question makes no sense, or isn't concrete or complete logical statement. It's just a combination of words. An ip address is a integer used in the internet protocol defined in various requests for comments. I don't believe a notion of "device" or "interface are ever defined. – marshal craft Jan 17 at 12:14
  • For example two windows application running on the same physical machine can utilize a network which uses ip protocol to communicate. There are pros and cons to this. That said, again the ip protocol is an abstract logical thing which runs on top of the underlying layers which them selves can be abstract the same as IP. – marshal craft Jan 17 at 12:19
26

Connecting an interface to a network makes it a part of that network. Therefore, the IP address is a property of the connection, not the host.

Likewise, a host can have many network connections and accordingly, IP addresses. Different interfaces often have different functions, so it's important to distinguish between them (e.g. internal console, public services, iSCSI).

Routers require multiple IP addresses for their interfaces.

14

No.

That said, let's see a simplified example:

I have a computer with three interfaces: eth0 (wired Ethernet), wlan0 (wifi), and vboxnet0 (virtualbox). One of the interfaces is connected to an internal network, one is connected to the internet, and the last one is connected to a network of virtual computers. Let's say I have just one address, 10.1.2.3, and wish to send a whole lot of packets to 192.168.1.2, reachable on one of those networks - where do I send them to? Can't just send them Everywhere, such behavior would flood all the networks in short order.

But if the eth0 interface has 192.168.1.3, wlan0 has 10.1.2.3, and vboxnet0 has 172.0.0.1, then the default routing table will probably say "send it out eth0". (This can obviously get far more complicated with more complex routing rules).

And conversely, I may wish to run a service only on the interface that's open to the private network - so when a request comes in on a different interface, it's not handled at all.

  • 1
    Why couldn't you know what is reachable at each interface without those having different IP addresses? – Paŭlo Ebermann Jan 17 at 0:17
  • You could (and it is indeed possible to have such routing rules), but then you're going to a lower level of abstraction, instead of saying "send anything non-matching to 10.1.2.1" and be done with it (OSI layer 3), now you need to handle "which of the interfaces do I want (layer 2)". It is also possible, but the abstraction simplifies matters. – Piskvor Jan 17 at 9:45
  • 2
    And another thing - the IP addresses are assigned for others to contact you as well. Say you're connected via wifi and via ethernet; each of the interfaces goes into a different network, but both networks can reach the internet. Now you send out a packet to 1.2.3.4 from your 10.1.2.3 - what's the return route? Wifi or wired? You can guess, but if you guess wrong, the packet comes back through the wrong interface and could be discarded. (Yes, there are cases where you want multiple interfaces with same IP addr, or an iface with more IP addrs, or an iface with no addr at all - unusual) – Piskvor Jan 17 at 9:50
5

Case 1: Routers

Theoretically this would be possible.

However, normally an IP packet is sent "directly" to the destination when the IP address "matches" a certain network mask (e.g. 10.0.0.0/28); otherwise the packet is sent over a router.

This means:

  • A router connects two networks; each of the two networks has a network mask
  • Packets being sent from one computer to another within one of the two networks do not pass a router.

    This means that the IP addresses of each computer match the network mask of the network they are connected to.

  • Packets being sent to the router (this includes packets being routed by the router!) are not sent from a computer to the router via a second router.

    This means that the IP address of the router must match the network masks of both networks.

  • IP packets being sent from one computer in one network to a computer in the other network however are sent over the router.

    This means that the IP addresses of the computers in one network must not match the network mask of the other network.

It is nearly impossible to choose an IP address and two network masks in a way that one IP address matches both network masks but a lot of IP addresses only match one network mask.

Case 2: Different private networks

We could have the case that a computer is connected to two private networks which cannot exchange data between each other.

In this case a computer may have the same IP address in both networks.

In the case of IPv4 most OSs won't support this because the OSs use the network masks of the two networks to distinguish between them. The networks need to have different network masks...

In the case of IPv6 (using "link-local" addresses) a computer can have the same (link-local) IP address in two different networks - and therefore two network cards can have the same IP address!

  • In one specific case, TSN specifications for ethernet do allow multiple interfaces with the same IP, mask, and MAC Address in order to support seamless redundant paths for deterministic ethernet (802.1cb). The redundancy is handled at the MAC level (detection of duplicate packed and ignoring redundant information) so from the hosts perspective it is one interface. – crasic Jan 16 at 22:35
3

I was wondering, why do we need to give IP addresses to each interface? Wouldn't giving to each device enough?

Let me start by challenging your assumption. Why do you say this isn't how machines behave? Say I assign 192.168.1.1/24 to eth1 and 192.168.2.1/24 to eth2. Other than installing a route for 192.168.1.0/24 out eth1 and 192.168.2.0/24 out eth2 and determining the preferred source IP address for packets sent along that route, how much does it really matter which interface I assign the IP address to? What really changes? In what sense does the machine not behave as if all IP addresses assigned to interfaces on the machine belong to the machine?

Both approaches are used. The most common approach is actually a hybrid of these two approaches.

On the "give a device an IP address" extreme, you could imagine a device that behaved as if all of its interfaces were connected to a filtering bridge with one IP address assigned to the bridge.

On the "give each interface an IP address" extreme, you could imagine a device that behaved as if each interface it had was like a separate machine. (See here if you think that's how devices currently work or think about someone who connects to an IP address assigned to one interface but the packets arrive on and are sent out another one.)

In practice, most machines operate somewhere in-between. They do act as if all IP addresses were owned by the machine. The assignment of an IP to a particular device doesn't really do all that much beyond telling the OS to install a default route out that interface and to set the default source IP address for packets sent out that interface where the source IP address isn't forced.

Otherwise, they do behave as if all IP addresses belonged to the machine. The way a packet is processed doesn't depend much on what interface it is received on -- packets with a source IP address assigned to one interface received on another are routine. Which interface an address is assigned to has no direct effect on which interface a packet is sent out, the routing table determines that.

3

A device that has an IP address exists within a network.

A Router is a device who's primary purpose is to pass traffic between networks.

For a Router to pass packets between two networks, it must exist within both networks.

The Router will have an "arm" inside each network -- or as we call it, an interface. And the way an interface exists within a network is by assigning it an IP address within the network.

Hence, when configuring a router, each interface receives an IP address to identify the networks which that Router belongs within.

Disclaimer: The link above is to my blog. My blog is not monetized. I make no profit from you reading it. I am providing a link simply for your (and any other reader's) benefit.

  • 1
    Nice and concise answer, very clear way of explaining why. – Stilez Jan 16 at 19:56
2

In the general case, you do need one IP per local network you connect to, and this is just how TCP/IP was defined: each host on a given local network has an IP address, which allows:

  • to route traffic to the appropriate local network, based on the destination IP address
  • to direct traffic to the appopriate device on that local network (after an ARP lookup on 802.x local networks, for instance).

As long as you have local networks with multiple devices connected to it (most 802.x local networks, including Ethernet, Wi-Fi), it's quite difficult to go around that unless you fundamentally change the way TCP/IP works.

However, it is actually possible to avoid that, though it is quite specific.

Consider a network that only has point-to-point links (point-to-point Ethernet between two devices without a switch or hub, DSL links, SONET/SDH links, Frame Relay or ATM VCs...).

The usual convention is to use a /30 for each link, so the device at each end has an IP address on that link.

But you can use "IP unnumbered", and not associate any IP addresses to those links. Now, you assign an IP to the device's loopback interface (any interface really, but loopback is the easiest one for this purpose), and you use a dynamic routing protocol (IS-IS, OSPF, EIGRP...). This routing protocol will advertise how to route traffic to that IP address via the various unnumbered links.

0

IP addresses include routing information. An IP address is split up into two components, the network number and the host number, based on an assigned prefix length (which was originally expressed as a network mask, and this is still often how it's implemented internally in network stacks).

For routing to work properly, all the devices connected to a particular network must have addresses with the same network number. Senders determine whether the receiver is on the same or a different network by comparing their own network number with the receiver's address. If they're in the same network, they send directly; otherwise, they send to a router whose job is to get the message closer to the destination.

So if a device is connected to multiple networks, it needs an address on each of those networks so it can be reached by devices on that network.

That said, it isn't really necessary for the addresses to be assigned specifically to particular network interfaces. The device could just have a list of all the IPs that it owns in a single table. But the interfaces still need information about which network they're connected to. By assigning an IP and network mask to each interface we put this information in one place, simplifying the design. There's no need for extra code to keep the list of IPs consistent with the list of networks that interfaces are connected to.

0

It might be enough to have one IP in the standard case, but as highlighted by other answers, there are many cases where it's not.

Other answers have already mentioned the case of a router. One mentions virtualbox, which is the case of virtual machines: you may be running on a single physical device several virtual ones. Another case is VLANs, you might have actually, connected to a single network card, several different virtual LANs, with different IP addresses. And you could even for some reasons have an interface with multiple IPs, for instance because you want to run several web servers on TCP port 80. Such a configuration isn't uncommon for servers, the hardware you rent may have a single network interface card, but you will have several IP addresses configured.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.