24

With ifconfig, I am able to configure multiple IP addresses on a single network interface card. Why would I want to do that and how would I later utilize several addresses, e.g. how does software know which one to use?

I have only used network interfaces with a single IP address so far.

4 Answers 4

40

Some (but not all) reasons:

  • In order to host multiple SSL sites as already mentioned
  • Because you may be consolidating services from multiple hosts and you need to preserve the addresses
  • In order to use an IP address that can later be transferred to another host
  • To compensate for a host that's down at that moment by adding its IP address to another one
  • If you have multiple IP networks on the same physical/logical network/vlan it will prevent traffic from being exchanged via the gateway, speeding things up and reducing the load
  • In order to setup a device that has a default IP address and thus you need to add an address on the same network
  • In order to use different public IP addresses to avoid firewalls or to avoid being blacklisted in SPAM filters
  • In order to make things less obvious to external people. E.g. you may be running apache on IP address 1.2.3.4 and only allow SSH on 1.2.3.5. That way if someone attempts to attack the IP address behind a site they won't find SSH running.
  • In order to run the same service multiple times
  • In order to use different hostnames in reverse DNS lookups. E.g. if you're connecting from this host to something external and you want to be presented as two different domain/hostnames
  • In order not to expose commonality between services. E.g. if you host site1.example.com and site2.example.org and you map them on different IPs instead of using CNAMEs there won't be an obvious link between them
1
4

In the case of a web server, it depends. If you have multiple virtual hosts then in Apache for example, the server knows which IP to use from the VirtualHost block.

 <VirtualHost 10.10.10.1:80>
   ...
 </VirtualHost>

You can also have a VirtualHost listen on all available interfaces which Apache is currently listening on (via the Listen directive eg. Listen *:80

 <VirtualHost *:80>
   ...
 </VirtualHost>

In the event you have multiple sites running on a server where multiple sites are SSL enabled, it is good to have a separate IP for each site. This is because SSL certificates are exchanged before the HTTP headers are sent. If you have multiple vhosts on one IP, then Apache will not know which site you are trying to reach without the host header.

I'm sure there are many other use cases, this is a common one.

3
  • @0xC0000022L can you explain this a bit more, I'm trying to learn about this as I'm hosting multiple SSL websites on one VPS with 1 IP address.
    – ArchNoob
    Commented Mar 8, 2021 at 5:35
  • 1
    @ArchNoob sure, the explanation is easy. SNI was supported much less when I commented nearly seven years ago than it is these days. And so indeed this is much less of a problem. However, without SNI you'd still have the issue that you cannot host multiple HTTPS sites at one IP address. Sometimes context matters and in this case the timestamp on the comment would have provided said context 😉 Commented Mar 8, 2021 at 7:20
  • 1
    @ArchNoob another more important point would be to host multiple SSH sites, for example. In times when other protocols use SSH as transport, that's becoming sort of important. So for example you may have a dozen sites (different host names) on a single IPv4 address, but if you wanted several instances of SSH running (e.g. for Git/Hg) the only "dimension" in which you could expand with a single IP would be ports. Commented Mar 8, 2021 at 7:26
1

It's good idea to have separate ip for separate services, then when you'll have to migrate one of service to another hardware/location, there will be transparent for other components.

Some services use the same port number, then you have to have several ips to run this services on single server.

Also if you want to handle more simultanous connections than you have ephemeral port, you'll need more ip.

2
  • If I'm running a web server, how does it know which IP address to use? Does it install to use the main IP by default? Commented May 3, 2014 at 21:03
  • 3
    It's configurable. By default it Listen or Binds to every IP on host.
    – fazie
    Commented May 3, 2014 at 21:06
1

multiple IP Adresses allows to you having Service IPs, in other words you can match IP with a specific service, for example in sendmail you do :

DAEMON_OPTIONS(`Family=inet, Name=MTA-v4, Port=smtp, Addr=192.168.1.25')dnl

and so on. it can be used for High Availlability, for test and network routing ^^

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .