[#4] 增加读取dns.conf更新容器内nameserver
This commit is contained in:
parent
23a92d7e9c
commit
2faa13c567
31
src/bind/scripts/update-dns.sh
Executable file
31
src/bind/scripts/update-dns.sh
Executable file
@ -0,0 +1,31 @@
|
||||
#!/bin/sh
|
||||
# update-dns.sh
|
||||
# 从 /private/argus/etc/dns.conf 读取 IP,写入 /etc/resolv.conf
|
||||
|
||||
DNS_CONF="/private/argus/etc/dns.conf"
|
||||
RESOLV_CONF="/etc/resolv.conf"
|
||||
|
||||
# 检查配置文件是否存在
|
||||
if [ ! -f "$DNS_CONF" ]; then
|
||||
echo "配置文件不存在: $DNS_CONF" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 生成 resolv.conf 内容
|
||||
{
|
||||
while IFS= read -r ip; do
|
||||
# 跳过空行和注释
|
||||
case "$ip" in
|
||||
\#*) continue ;;
|
||||
"") continue ;;
|
||||
esac
|
||||
echo "nameserver $ip"
|
||||
done < "$DNS_CONF"
|
||||
} > "$RESOLV_CONF".tmp
|
||||
|
||||
# 替换写入 /etc/resolv.conf
|
||||
cat "$RESOLV_CONF".tmp > "$RESOLV_CONF"
|
||||
rm -f "$RESOLV_CONF".tmp
|
||||
|
||||
echo "已更新 $RESOLV_CONF"
|
||||
|
Loading…
x
Reference in New Issue
Block a user