Linux dns安装脚本
时间: 2023-11-30 20:03:41 浏览: 196
以下是一个简单的Linux DNS安装脚本,可以在CentOS或Ubuntu等Linux发行版上运行:
```bash
#!/bin/bash
# 安装bind-utils和bind软件包
if [ $EUID -ne 0 ]; then
echo "请使用root用户运行此脚本"
exit 1
fi
if [ -f /etc/redhat-release ]; then
yum install -y bind-utils bind
elif [ -f /etc/lsb-release ]; then
apt-get update
apt-get install -y bind9 bind9utils
else
echo "不支持的操作系统"
exit 1
fi
# 配置DNS服务器
echo "请输入DNS服务器IP地址:"
read dns_ip
echo "请输入DNS域名:"
read domain_name
echo "正在配置DNS服务器..."
cat <<EOF > /etc/named.conf
options {
listen-on port 53 { any; };
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
allow-query { any; };
recursion yes;
dnssec-enable yes;
dnssec-validation yes;
dnssec-lookaside auto;
/* Path to ISC DLV key */
bindkeys-file "/etc/named.iscdlv.key";
managed-keys-directory "/var/named/dynamic";
};
zone "$domain_name" IN {
type master;
file "$domain_name.zone";
allow-update { none; };
};
zone "0.0.127.in-addr.arpa" IN {
type master;
file "named.local";
allow-update { none; };
};
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
EOF
cat <<EOF > /var/named/$domain_name.zone
\$TTL 86400
@ IN SOA ns1.$domain_name. root.$domain_name. (
2011041322 ; serial
3600 ; refresh
1800 ; retry
604800 ; expire
86400 ; minimum TTL
)
@ IN NS ns1.$domain_name.
@ IN A $dns_ip
ns1 IN A $dns_ip
EOF
echo "正在启动DNS服务器..."
if [ -f /etc/redhat-release ]; then
systemctl start named
systemctl enable named
elif [ -f /etc/lsb-release ]; then
service bind9 start
update-rc.d bind9 defaults
fi
echo "DNS服务器已成功配置!"
exit 0
```
注意,在运行此脚本之前,请确保您以root用户身份登录,并且您已经安装了bind-utils和bind(CentOS)或bind9和bind9utils(Ubuntu)。
阅读全文