Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: OpenID Connect / OAuth client 3.0.0-alpha9 New alpha version released for module openid_connect (3.0.0-alpha9). Release: Opensolr Search 4.5.0 Minor update available for module opensolr_search (4.5.0). Release: Timelinr 1.0.1 Minor update available for module timelinr (1.0.1). Usage Milestone: Simplify Module simplify crossed 10,000 active installs. Usage Milestone: Views Reference Filter Module entityreference_filter crossed 10,000 active installs. Usage Milestone: Dropdown Language Module dropdown_language crossed 10,000 active installs. Usage Milestone: Paragraphs Browser Module paragraphs_browser crossed 10,000 active installs. Usage Milestone: OpenAPI Module openapi crossed 10,000 active installs. Usage Milestone: Decoupled Router Module decoupled_router crossed 10,000 active installs. Module Revived: Entityqueue Buttons 1.1.2 Module entityqueue_buttons updated after 8 months of inactivity (1.1.2).

This module restricts access to Drupal features, such as logins and role assignments, based on IP addresses or IP ranges. It allows administrators to define which users can log in and which roles are available from specific IP locations.

This module restricts Drupal features to certain IP addresses or IP address ranges, entered in CIDR notation. It can restrict logins and/or role access.

Restrict login by IP

  • Global ranges apply to ALL users, including user 1.
  • Individual accounts can also be given their own allowed ranges on their user form, and a login is allowed when either list matches, so a personal range acts as a per-account exception to the global restriction.
  • A denied attempt fails on the login form with a configurable message.
  • If an already signed-in user's IP address stops matching, they are signed out and sent to a configurable page (the login page by default).

Restrict role by IP

When a role is restricted, that role is not available to users outside its allowed ranges: choose whether an out-of-range user loses the role for the duration of the request or is signed out entirely, with a configurable message either way. Role restriction on its own does not affect the ability to log in.
All roles can be restricted except the built-in "anonymous user" and "authenticated user".

The client IP address is resolved through Drupal core's request handling. If your site is behind a reverse proxy or CDN, you must configure the reverse_proxy settings in settings.php; the module's settings pages show the address it currently detects.

Locked out?

If a restriction locks you out and you have shell access, drush restrict_by_ip:status reports what is configured and whether an address may log in, and drush restrict_by_ip:allow adds an allowed range. See the README for more detail and other options.

For developers

There are hooks so you can alter the allowed ranges before they are applied, for example adding ranges kept in settings.php or an external service. See restrict_by_ip.api.php for the hooks and examples.

Versions

9.x requires Drupal 11.3 or later and is where new features land. 8.x-4.x is in maintenance mode and receives security/bug fixes only.

Any other suggestions are welcome, and please report any problems.

Thanks.

Related modules

  • Restrict Login Page by IP: hides the login page itself (403) from IPs outside an allowed range, rather than letting the login fail. Works together with this module, but note it makes the login page uncacheable by design.
  • Restrict IP: restricts access to the entire site by IP allowlist, with path and role exceptions and country-level rules. Use it when the whole site is private, not just authentication.
  • Advanced Ban: the opposite direction, a denylist for known-bad IPs with ranges and expiring bans. Successor to core's Ban module, which is deprecated in Drupal 11.3 and removed in 12.
  • Login Security: brute-force hardening for the login form, including attempt limits, soft/hard IP blocking and notification emails.

Module Sponsors

6.x-3.x version sponsored by UNC Charlotte.

6.x-2.x, restrict by role addition, sponsored by panthar.

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
5
Tracked since
May 2025
Latest release
4 weeks ago
Releases (12 mo)
3 ▲ from 2
Maintenance
Active

Release Timeline

Releases

Version Type Core Release date
9.0.0-beta1 Pre-release 11 Aug 3, 2026
8.x-4.0-beta4 Pre-release 10–11 Jul 10, 2026
9.x-dev Dev 11 Jun 21, 2026
8.x-4.0-beta3 Pre-release 10–11 Jul 8, 2025
8.x-4.0-beta2 Pre-release 9–10 May 22, 2025