Support > About cybersecurity > How to configure multiple IP access on web server?
How to configure multiple IP access on web server?
Time : 2025-02-24 15:17:38
Edit : Jtti

Configuring multi-IP access on a web server means enabling the server to use multiple IP addresses to respond to different requests. This configuration is usually used in the following situations:

Virtual host: assign different IP addresses to different domain names or subdomains.

Load balancing: distribute the load through multiple IP addresses to improve access performance.

Security isolation: bind different services or applications to different IP addresses to improve security.

Here are the steps to configure multi-IP access on common web servers such as Apache and Nginx:

1. Configure multiple IP addresses for the server

Before configuring the web server, you first need to ensure that the server has multiple IP addresses. If you are using a cloud server, you can assign multiple public IP addresses to the server on the cloud platform. For local servers, you can manually configure multiple IP addresses.

Configure multiple IP addresses on Ubuntu

View the current network interface configuration:

ip addr show

Configure multiple IP addresses for a network interface

Assuming your network interface is named eth0. You can edit the network configuration file in /etc/netplan/ (for example, 00-installer-config.yaml, the specific file name varies depending on your system configuration).

Open the configuration file and add multiple IP addresses:

sudo nano /etc/netplan/00-installer-config.yaml

Add multiple IP addresses (make sure to change to your network configuration):

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      dhcp4: false
      addresses:
        - 192.168.1.10/24
        - 192.168.1.11/24  # Add the second IP address

Apply the changes:

sudo netplan apply

Verify the new IP configuration:

ip addr show

2. Configure Apache Web Server to Support Multiple IP Access

Apache configures multiple virtual hosts through the NameVirtualHost and VirtualHost directives, which can bind different Web sites according to different IP addresses or domain names.

Open the Apache configuration file:

Apache's main configuration file is usually located in /etc/apache2/apache2.conf, or each virtual host configuration file is usually located in the /etc/apache2/sites-available/ directory.

Configure virtual hosts for each IP address

Suppose you have two IP addresses: 192.168.1.10 and 192.168.1.11. You can create different virtual host configurations for each IP address:

<VirtualHost 192.168.1.10:80>
    ServerName www.example1.com
    DocumentRoot /var/www/html/example1
</VirtualHost>

<VirtualHost 192.168.1.11:80>
    ServerName www.example2.com
    DocumentRoot /var/www/html/example2
</VirtualHost>

Enable configuration and reload Apache

Make sure the configuration file is correct and enable virtual hosts, then reload the Apache service:

sudo systemctl reload apache2

3. Configure Nginx Web Server to Support Multiple IP Access

Nginx configuration is also very flexible, and different virtual hosts can be configured for different IP addresses.

Open the Nginx configuration file:

The default Nginx configuration file is usually located in /etc/nginx/nginx.conf, and the virtual host configuration file is usually located in the /etc/nginx/sites-available/ directory.

Configure virtual hosts for each IP address

Suppose you have two IP addresses: 192.168.1.10 and 192.168.1.11. You can configure a separate server block for each IP:

server {
    listen 192.168.1.10:80;
    server_name www.example1.com;
    root /var/www/html/example1;
}

server {
    listen 192.168.1.11:80;
    server_name www.example2.com;
    root /var/www/html/example2;
}

Check if the configuration is correct

Before reloading Nginx, check if there are any errors in the configuration file:

sudo nginx -t

Reload Nginx configuration

If there are no errors in the configuration file, you can reload Nginx:

sudo systemctl reload nginx

4. Verify multiple IPs Configuration

After completing the above configuration, you can verify whether the web server can respond to different requests correctly by visiting different IP addresses. For example:

Visiting http://192.168.1.10 should display the first site example1.

Visiting http://192.168.1.11 should display the second site example2.

5. Configure firewall and port forwarding (if necessary)

If your server uses a firewall (such as ufw or iptables), you need to make sure that the corresponding ports (usually 80 and 443 for HTTP and HTTPS) are opened for different IP addresses.

Open ports using ufw

sudo ufw allow from 192.168.1.10 to any port 80

sudo ufw allow from 192.168.1.11 to any port 80

Open ports using iptables

sudo iptables -A INPUT -p tcp --dport 80 -s 192.168.1.10 -j ACCEPT

sudo iptables -A INPUT -p tcp --dport 80 -s 192.168.1.11 -j ACCEPT

Configuring multiple IP access to a web server involves the following steps:

Configuring multiple IP addresses, first ensure that the server has multiple available IP addresses.

Web server configuration, configure virtual hosts or server blocks in Apache or Nginx to associate different IP addresses with different websites or services.

Test and verify, verify that the configuration is successful by accessing different IP addresses.

Firewall and port management, make sure the firewall is properly configured to allow access to the corresponding ports through different IP addresses.

In this way, you can easily configure the web server to support access from multiple IP addresses.

Relevant contents

Comparison of a single-processor server with a dual-processor server How to copy local files to a cloud server: A Comprehensive Guide A complete guide to upgrading Git to the latest version for Windows systems How to modify Ubuntu software source detailed method What is an IP address and how does it work Detail the protection principle of the American high defense server: the cutting-edge technology of guarding network security Troubleshooting and repairing SQL Server backup restoration failure A detailed tutorial for setting up a personal WordPress site on Linux Specific scenarios for installing and configuring Samba in Ubuntu Linux mount command usage tutorial
Go back

24/7/365 support.We work when you work

Support