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

Apache 2.4: Allow access to directory only for ip address range

· 52CE 我爱测

I want allow access to /htdocs/reserved/ directory only for ip addresses from 192.168.1.193 to 192.168.1.254 (.193 --> .254). I have written this code in httpd.conf : <Directory /htdocs/reserved/> Order Deny, Allow Deny from all …

问题原文

原帖链接 · Simone Nigro · CC BY-SA 3.0

I want allow access to /htdocs/reserved/ directory only for ip addresses from 192.168.1.193 to 192.168.1.254 (.193 --> .254).

I have written this code in httpd.conf:

<Directory /htdocs/reserved/>
    Order Deny, Allow
    Deny from all
    Allow from 192.168.1.193/254
</Directory>

After stop, Apache won't restarts and raises this exception:

The Apache service named reported the following error: The specified network mask is invalid.

the problem seem the mask 192.168.1.193/254.

I have also tried:

<Directory /htdocs/reserved/>
    Order Deny, Allow
    Deny from all
    Allow from 192.168.1.193 192.168.1.254
</Directory>

it works! apache start, but i'm not sure if all ip addresses in the range are allowed to access to directory or only 192.168.1.193 and 192.168.1.254 are allowed.

The official docs lacks of clear information (or i'm too stupid to understand it).

The question is: what is the right way for allow a ip address range to access in a directory?

side note: i have used private range only for example.

Thanks at all and sorry for my english.

已采纳解答

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

Your netmask is wrong. The closest you'll be able to do in a single line is 192.168.1.192/26. Note that that includes the address that ends in 192, not starting at 193. Otherwise, according to https://ip2cidr.com/, you need

192.168.1.193/32
192.168.1.194/31
192.168.1.196/30
192.168.1.200/29
192.168.1.208/28
192.168.1.224/28
192.168.1.240/29
192.168.1.248/30
192.168.1.252/31
192.168.1.254/32

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

资料来源与适用范围

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

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

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