My server has two network interfaces, so two IPs, one Internet IP, and one private address.
I added the following script to the /etc/iproute2/rt_tables
:
252 enp0s3
251 enp0s8
And added the following script to the /etc/rc.local
:
ip route add default via 172.17.171.151 dev enp0s3 table enp0s3
ip rule add from 172.17.171.151 table enp0s3
ip route add default via 172.17.168.121 dev enp0s8 table enp0s8
ip rule add from 172.17.168.121 table enp0s8
Now, everything worked fine.
I can ping these two ips, so icmp has been working normally. I can also SSH to the server through any IP, so port 22 also works well.
However, when I use the following docker-compose to start an nginx, I found that only the port 80 of any one of the 2 IPs can be accessed by the client browser, and the port 80 of the other IP is unresponsive.
version: "3"
services:
nginx:
restart: always
container_name: nginx
image: nginx
ports:
- 0.0.0.0:80:80
volumes:
- ./log:/var/log/nginx
What caused this? How can I get out of this situation?
Note: The above configuration file is a test environment I built with a virtual machine, so the IP addresses are all private addresses.
Steps to reproduce:
- Use
Oracle VM VirtualBox
to start a ubuntu 16.04 with two bridge network interfaces.
- Log in to the virtual machine.
- Refer to the above script to modify
/etc/iproute2/rt_tables
and /etc/rc.local
.
- Install docker and docker-compose.
- Use the docker-compose above to start an Nginx.
- No matter which network interface is opened, the host can access port 80 of the corresponding IP address of the virtual machine.
- If two network interfaces are opened at the same time, only port 80 of one of the network interfaces can be opened, and the other has no response.
Supplementary information: If I start Nginx directly on the virtual machine, port 80 of the two IPs can be accessed by the host machine.