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
188.8.131.52 - 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
184.108.40.206 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
| |220.127.116.11 | |10.0.0.1 | |-------+
| ISP |----------------+ modem/router|--------------| switch |
| | 18.104.22.168| | | |-------+
+-----+ +-------------+ +--------+ | 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 (
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 22.214.171.124 to access the desktop and
ssh -p 2022 126.96.36.199 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.