大网数据广告活动
服务器运维问答

How do I require an IP range instead of 1 IP?

· 52CE 我爱测

My IP changes do a different D class, so I want to set a range: 123.123.123.xxx where the last segment can be 0-255. Right now, Apache says: <RequireAny> Require ip 127.0.0.1 Require ip ::1 </RequireAny>

问题原文

原帖链接 · user281497 · CC BY-SA 3.0

My IP changes do a different D class, so I want to set a range:

123.123.123.xxx where the last segment can be 0-255.

Right now, Apache says:

<RequireAny>
   Require ip 127.0.0.1
   Require ip ::1
</RequireAny>

社区高分解答

原帖链接 · Frank N · CC BY-SA 4.0

In Apache 2.2 and below, you could work with:

Order deny,allow
Deny from all
Allow from 24.18    # allow access from home
Allow from 162.12   # allow access from work

in your .htaccess, directly on base level (not within any <directive>).

As of Apache 2.4 and above, here you go:

<RequireAny>
    #IPv4 range at my work
    Require ip 207.100
    #IPv4 range I usually get through my mobile provider
    Require ip 29.11
    #IPv6 from home
    Require ip 2a02:4126:2aa4::/48
</RequireAny>

(all numbers fictional, no worries ;-).

I have been using this for many years now to shield my back end folders against 99% of potential users. (Working very well, unless you are an avid blogger while traveling. If you are a gmail user: “last account activity” Link at the very bottom is a comfy way to figure out your own “IP habits”).

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2015-04-14)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。