问题原文
原帖链接 · Adelin · CC BY-SA 4.0
On a typical linux machine you can change kernel configuration by modifying the files located at /proc/*.
For example, for the IPv6 accept_dad parameter of a specific network interface (say, eth0), you'd modify the following file:
/proc/sys/net/ipv6/conf/eth0/accept_dad
But, as I recently discovered, there is the widely spread tool, sysctl, which has the same purpose, and works like so:
sysctl -w net.ipv6.conf.eth0.accept_dad=1
My question is, when should we use which tool? My instinct says that if you know what you're doing, you should write to file directly but, if you would like validations and what not, you should use sysctl.
Since sysctl is yet another layer over something that we can control directly, I think by using it we're exposing ourselves to potential bugs that are otherwise avoided by writing to files directly.
已采纳解答
原帖链接 · Grodriguez · CC BY-SA 4.0
sysctl is a tool for reading and modifying various kernel attributes. It is available in many Unix-like operating systems, including not only Linux, but also OpenBSD and FreeBSD, for example. sysctl is typically available both as a shell command and as a system call.
In Linux, the sysctl mechanism is additionally exposed as part of the procfs virtual filesystem, under /proc/sys.
Note that the sysctl syscall is deprecated in Linux; it is recommended to use /proc/sys instead (either directly or via the sysctl shell command).
References:
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
