0

I need to add specific IPs to access my magento website. How can I do that

2
  • got any solution? Commented Oct 18, 2019 at 10:47
  • Ask your hosting provider to look into it (they can restrict IP address (specific, in range, etc)) Commented Oct 26, 2023 at 6:38

4 Answers 4

0

You can do this via your web server https://www.getastra.com/blog/cms/magento-security/restrict-access-magento-admin-area-ip-address-htaccess-nginx/ this is an example for admin area only but you can do this for / as well.

2
  • I have access for admin panel only, so I need to do that through admin panel Commented Nov 13, 2018 at 15:36
  • try to add js script to head, you can do this in admin, Admin > Stores > Configuration > General > Design > HTML head in that js check client ip and redirect client to some page window.location.href="some page".
    – mygir
    Commented Nov 13, 2018 at 20:34
0

Through admin panel you cannot restrict access to the site. You have two options

  • htacess

    open your root htaccess

order deny,allow allow from 111.222.333.444

replace Directory with your root directory and IP with your IP

  • magento CLI

go to magento root and run this command (php bin/magento maintenance:enable –ip=XXX.XXX.X.XXX) replace -ip with your IP.

1
  • may I do so through the htaccess of the server? Commented Nov 14, 2018 at 8:57
0

The easiest way to restrict a Magento system to specific IP addresses when you're developing or doing maintenance work is to use the maintenance mode like this:

# get your ip adress:
curl ifconfig.me
17.18.19.20

# go to your Magento webroot directory
cd /var/www/yourshop/webroot

# execute this command as your magento user
sudo -u magento php bin/magento maintenance:enable --ip 17.18.19.20

To add further IP addresses redo this command with the other IP address.

Have a look at the Magento docs for further information.

0

There are different ways to restrict access to your Magento site or admin panel by IP addresses, depending on your server configuration and preference. Here are some possible methods that you can use or modify as you wish:

Using .htaccess file: You can edit the .htaccess file in your Magento root directory and add some rules to allow or deny access to your site or admin panel by IP addresses. For example, if you want to allow only your IP address (111.222.333.444) to access the admin panel, you can add the following lines to your .htaccess file

RewriteCond %{REQUEST_URI} ^/(index.php/)?admin/ [NC]
RewriteCond %{REMOTE_ADDR} !^111.222.333.444
RewriteRule ^(.*)$ http://%{HTTP_HOST}/ [R=302,L]

This will redirect any request to the admin panel from other IP addresses to the home page of your site. You can also use a range of IP addresses or a subnet mask to allow or deny access.

Using Magento CLI: You can use the Magento command-line interface (CLI) to enable the maintenance mode and specify the IP addresses that are allowed to access your site while it is in maintenance mode. For example, if you want to allow your IP address (111.222.333.444) and another IP address (222.333.444.555) to access your site, you can run the following command in your Magento root directory

php bin/magento maintenance:enable --ip=111.222.333.444 --ip=222.333.444.555

This will create a .maintenance.flag file in your var directory and a .maintenance.ip file in your var directory with the list of allowed IP addresses. You can also use the --exclude-url option to specify a URL that can be accessed by anyone, such as a custom maintenance page.

Using a Magento extension: You can also use a Magento extension that provides the functionality to block or allow IP addresses or countries to access your site or admin panel. There are many extensions available in the Magento Marketplace that offer this feature, such as Magento 2 Advanced Admin Login Security. From automated admin lockouts on failed attempts to customizable IP whitelisting and blacklisting, this extension provides a robust suite of features. Receive real-time email notifications, country-wise blacklist, and maintain detailed logs for a secure and stress-free admin experience. Elevate your security measures and fortify your Magento 2 store with confidence.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.