I might be late for this topic, but today I've had the same issue for Magento 2.3.6, served by an Apache2 server.
Even if @TA3 does not specify which web server software he's using, my post here will bring a answer to do it with Apache2 servers.
As @Marcel said, the reverse proxy in front of your Magento app must forward a HTTP header revealing the real client IP address. It can be X-Forwarded-For or X-Real-IP, depending on the configuration of the reverse proxy. It is the only way for the final web server to know which is the IP address of the visitor.
For my part, I have 2 HAProxy instances in front of my Apache2 servers & each instance is setup on a different machine for a HA setup, all of them on Debian 10.
- On the web servers, I've enabled the remoteip module in apache2 :
root@web-server01:~# a2enmod remoteip
- Then, I've declared which HTTP header I'm using (
X-Forwarded-For
in my case) & added the IP address of my reverse proxies in /etc/apache2/apache2.conf
, just before the end of the file :
RemoteIPHeader X-Forwarded-For
RemoteIPInternalProxy <IP_OF_HAPROXY-01> <IP_OF_HAPROXY-02>
(Replace <IP_OF_HAPROXY-0x> by the real IP addresses of your reverse proxies ;-) )
- Finally, restart apache2 service
root@web-server01:~# systemctl restart apache2
And don't forget to repeat this config on each web server you have.
Now, the maintenance mode should exempt the IP address you want :
php bin/magento maintenance:enable --ip=123.45.67.89
Hope this helps.