编写了一个脚本,运行后可以关闭Linux下基于nscd的DNS缓存。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| #!/bin/bash
NSCD_CONF="/etc/nscd.conf"
if [ ! -f "$NSCD_CONF" ]; then echo "no file: $NSCD_CONF" exit 1 fi
cp $NSCD_CONF{,.bak}
sed -i '/enable-cache\s*hosts\s*yes/s/yes/no/' $NSCD_CONF
if [ $? -ne 0 ]; then echo "Failed to edit /etc/nscd.conf, no su I guess" exit 1 fi
systemctl restart nscd
if systemctl status nscd | grep -q "active (running)"; then echo "Success" else echo "restart nscd failed" fi
|
如果要开启DNS缓存,只需要将备份文件/etc/nscd.conf.bak
覆盖/etc/nscd.conf
即可。
1
| cp /etc/nscd.conf{.bak,}
|