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

Size Limit of /etc/hosts (Linux)

· 52CE 我爱测

Does anyone happen to know what the theoretical size limit of /etc/hosts is on a Linux system before you might start to see degradation in performance? Furthermore, can anyone point me towards some official source that states wha…

问题原文

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

Does anyone happen to know what the theoretical size limit of /etc/hosts is on a Linux system before you might start to see degradation in performance?

Furthermore, can anyone point me towards some official source that states what the expected limit is?

已采纳解答

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

Use the source, Mike.

The resolver uses a linear search through the text file to locate entries. It's a database with no indexes. So, in the absence of additonal caching capability, the cost for lookups will be O(n). As to when that will result in a degradation in performance, thats an impossible question to answer - it gets slower with every record.

If you talk to a database programmer or admin you'll get different figures for the point at which an index lookup (O(log2(n)) is cheaper than a full table scan, but generally the answer will be in the region of 20 to 100 records.

Any linux system needing to resolve a lot of names (not just hostnames). Should be running nscd or similar. Most such caches will index data themselves which would nullify the performance question, however...

It provides no means for managing complex/large datasets - if you have a host with more than one IP address, lookups via the hosts file will always return the first entry.

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

资料来源与适用范围

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

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

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