9

I'm trying to understand the relationship between:

  • A "networked" Linux device; and
  • The physical NIC card located on that device (giving it the ability to be "networked"); and
  • Various Ethernet/Wi-fi network interfaces (eth0, eth1, wlan0, etc.); and
  • IP addresses and ports

From what I've collected, it appears that each interface (again, eth0, eth1, wlan0, etc.) are assigned their own unique IP. Meaning on my machine eth0 would have a different IP than, say, wlan1.

But this contradicts my uderstanding that networked devices as a whole receive a single IP for the entire device.

So which is it? Does a device get 1 IP used by all interfaces, or does each interface in fact get its own IP? If each gets its own, then what determines how many ports are available on that interface?

  • how/where an interface is connected affects what ip address it should have, such as 3 different ethernet LANs, so different interfaces have different addresses. this address also becomes the default source address. – Skaperen Sep 30 '15 at 9:24
9

Each network interface will have it's own IP address if IP traffic is to flow through it.

Take for example, your router/modem device that most homes and/or small offices have.

There will a connection to your computers/laptops on the internal side of the router - whether that is WiFi or Ethernet. These are normally in the private address ranges of 191.168.0.0 - 192.168.255.254 or sometimes 10.0.0.0 - 10.255.255.254. Your desktop/laptop/tablet will connect to this side of the device and have itself and IP address in the same range (but not identical to the device).

On the external side of the router/modem you will have a completely separate IP address usually allocated to your device automatically by the service provider. This is a routable address such as 98.23.45.62 which is globally unique to your modem/router while it is connected.

Small modem/routers such as these can be confusing as they will seem to have just the one address - the one quoted in the user manual for administrating the device via a web browser (such as http://192.168.0.1) - while it has many Ethernet ports. This is because the device, in essence has a network switch tagged onto the router in order to split the router's single Ethernet port into many ports and in order to connect a WiFi bridge.

At the same time, the external side of the router/modem will have it's IP address automatically configured by the service provider so you may well never see it. (Type what's my IP address in Google to find out what it is).

A diagram may help:

                                                                 +--------+
                                                                 | laptop |
                                                                 +--------+
+-----+                +-------------+              +--------+       | 10.0.0.2
|     |98.23.45.61     |             |10.0.0.1      |        |-------+
| ISP |----------------+ modem/router|--------------| switch |
|     |     98.23.45.62|             |              |        |-------+
+-----+                +-------------+              +--------+       | 10.0.0.3
                                                                  +---------+
                                                                  | desktop |
                                                                  +---------+

As you can see, the modem/router has two IP addresses - one for each network interface. The desktop and laptops have one - on the networking device connected to your router. Most modem/routers have WiFi and Ethernet connections as do most laptops. If you were to connect the Ethernet cable to your laptop and also enable and configure your laptop's WiFi then that too would have two IP addresses - one for each device - both in the 10.0.0.x address range. That would just give you problems thought - don't do it.

A port is just a number that is attached to the destination IP address. It is similar to a telephone extension in an office switchboard and decides which service is to receive your traffic. It is a 16-bit number, which gives it a maximum possible 65535. Only a very small subset of these are used though. Some are pre-allocated as well known ports such as http traffic on port 80 and secure shell (ssh) on port 22. These ports are only open and listening for traffic if the relevant service is running on the device as installed by the device manufacturer.

In the case of the modem router above, port 80 will be listening on the internal side because a webserver is running so that you can administer the device using a web browser. Some routers also have a ssh service listening on port 22 so that you can manage the device using a ssh client. They'll probably have port 53 open as there will be a DNS server running on the router too.

Your laptop will probably (hopefully) have no ports listening, unless you've installed a service on that device. In the diagram above, you could install a ssh server server on the desktop PC at which point (and firewalls permitting) your desktop will have port 22 open. Your laptop can then ssh to port 22 of the desktop and login.

Therefore, the number of ports on a device is down to how many services are running on that device, the configuration of that service, and the configuration of the firewall.

If you want to make the ssh server running on your desktop in the example above, accessible from a remote user somewhere on the Internet you would hit a small problem as, although you have many internal addresses, you only have one external (98.23.45.62).

To resolve this you would have to configure a facility known as Port Forwarding on your router. This instructs the router to take all traffic arriving at a particular port and forward it to a specific internal host and port.

In this case, all traffic arriving at port 22 is forwarded to 10.0.0.2 port 22. As you may have gathered, this means that you can only have port 22 forwarded to one internal server.

If you wanted to be able to ssh to both the desktop and the laptop, you'd have to configure the router to listen on an alternate external port (such as 2022) and forward that to your laptop at 10.0.0.2 port 22. The remote user would have to ssh 98.23.45.62 to access the desktop and ssh -p 2022 98.23.45.62 to access your laptop.

Of course, it's not always as simple as this as the external IP address can change unless you specifically request/purchase a static IP address.

  • Thanks @garethTheRed (I'd upvote you if I had the rep to do so). A few quick followups if you don't mind: Can you confirm that, using your excellent example above, if I went to Google "What's my IP" on both the laptop and the desktop, they would both see their IP as 98.23.45.62 (basically, their common router's external IP)? If so, then if I stood up a server running on my laptop, and wanted it to be reachable from the outside world, how would external/remote clients make requests to that server if it has the same IP as all other devices behind the router?!? Thanks again so much! – Zac Sep 30 '15 at 9:42
  • Yes, all internal devices would show the same IP address on Google - your only IP address :-) I've edited my answer to cover your other question. – garethTheRed Sep 30 '15 at 10:15
  • Thanks again @garethTheRed! So is it fair to say that port forwarding is doing the same thing from external-to-internal as NAT does from internal-to-external? – Zac Sep 30 '15 at 10:38
  • Vaguely - NAT is more dynamic in that it "just works". Port Forwarding has to be configured by the router admin, but in essence both gets traffic through the router. – garethTheRed Sep 30 '15 at 11:59
1

“Device” is an overloaded word. It's sometimes used to mean a machine, and sometimes to mean a peripheral or interface of a machine.

Each network interface has its own address.

Each machine has zero, one or more addresses depending on how many network interfaces it has.

In simple cases, each physical network interface has one IP address, and your system also has a loopback interface which programs use to talk to programs running on the same machine. Each interface has a distinct IP address. Many, many complex setups are possible (bonding, aliasing, local addresses, etc.) but the basic intuition is that each IP address corresponds with one interface.

When you access a machine over the network, you use an IP address, so you're in fact accessing a specific network interface of that machine. In most cases, the distinction is moot, because only one interface is reachable from the remote machine, and it wouldn't make any difference anyway, because programs accept connections on all interfaces. However it is possible for a server to listen only on a single interface.

0

A device is a physical item which is represented by a label inside the system. This way the system can make different action such as setting/query/use of the physical device. The label is created by the driver which manage the physical hardware at kernel system.

So you can have multiple network devices, each of them identified with a uniq label (let's not complicate too much an talk about bonding).

Your problem is about ip address.

There are several different IP address class. You have the public one, which are able to be reached from everywhere on Internet and private address which are usually restricted to private area (home/business network for exemple).

Usually an home network or office network has a few public ip address and a lot of private address (between laptop/mobile/tablet/fridge/toaster/ of all member of familly).

You can assign as many ip address to a physical hardware, but you have to do it nicely and respect the underlying tcp/ip logic, if you don't want to face inextricable issue :)

For exemple in local network (lan) you cannot have two hardware with the same IP address. This is mostly due to Ethernet protocol which is base on the MAC address (uniq identifier of hardware), and there is a one to one relation between MAC address and ip address on local network.

You can also have one machine, with two hardware one with a public address from your provider, and one inside your local network. This machine will usually be used like a gateway to the external world for all the machine in your local network.

0

Your device may have several network interfaces. Those can correspond to real devices (NICs) or be virtual.

In order to be usable (i.e. initiate or listen for connections), each interface should have an IP address. Usually there will be one IP per interface, but it's possible to have several via IP aliasing.

Individual connections on each IP address are identified by port number. There is a limit of 65536 ports per IP address imposed by the IP protocol. One reason behind IP aliasing is to overcome this limitation.

So in the end your device can have as many IPs as you want (within reason - I suppose there are limits imposed by kernel on the number of interfaces and IPs it is able to manage), which is totally independent of the number of network interface adapters you have. On the other hand, your device will have at least as many IPs as there are network interfaces being used.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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