如何在Linux里搭建ddns(动态DNS服务器)?
发布网友
发布时间:2022-04-19 14:03
我来回答
共2个回答
热心网友
时间:2023-07-07 09:48
linux系统下搭建DDNS服务
记住把 dhcp 和 bind, bind-utils 装上就行了。
配置:
一 生成密钥
# dnssec-keygen -a HMAC-MD5 -b 128 -n USER DHCP_UPDATER
这时当前目录下会生成Kdhcp_updater.+xxx+xxxxx.key及.private两个文件
# cat Kdhcp_updater.+xxx+xxxxx.key
DHCP_UPDATER. IN KEY 0 2 157 qSSpjerAuaPE/X3JJyxSww==
其中qSSpjerAuaPE/X3JJyxSww==下面要用到的。
参数说明:
上述dnssec-keygen命令的功能就是生成更新密钥,其中参数-a HMAC-MD5是指密钥的生成算法采用HMAC-MD5;参数-b 128是指密钥的位数为128位;参数-n USER DHCP_UPDATER是指密钥的用户为DHCP_UPDATER
二、DHCP的配置:
配置DHCP server 时很简单,可以参考 /usr/share/doc/dhcp-x.xx/dhcpd.conf.sample来做。也可以先把这个文件cp 到 /etc/dhcpd.conf,然后根据自己的需要做适当修改。下面贴出我的一个/etc/dhcpd.conf,供大家参考:
ddns-update-style interim;
ignore client-updates;
max-lease-time 604800;
default-lease-time 86400;
key DHCP_UPDATER {
algorithm HMAC-MD5;
secret qSSpjerAuaPE/X3JJyxSww==;
};
zone shcto.com. {
primary 127.0.0.1;
key DHCP_UPDATER;
}
zone 160.230.10.in-addr.arpa. {
primary 127.0.0.1;
key DHCP_UPDATER;
}
subnet 10.230.160.0 netmask 255.255.255.0 {
range 10.230.160.30 10.230.160.230;
# --- default gateway
option routers 10.230.160.254;
option subnet-mask 255.255.255.0;
option broadcast-address 10.230.160.255;
# --- option nis-domain "domain.org";
option domain-name "shcto.com";
option domain-name-servers 10.230.128.33,10.230.128.34;
}
几个要注意的地方:
1. 'ddns-update-style'
这个就是动态DNS的更新方式,有几个选项,我用的是interim,可以用 man dhcpd.conf找到另外的几个选项。
2. 'ignore client-updates'
这个选项是不允许客户机更新DNS记录。当然,也可能允许,但会有一点问题。
3. 'key DHCP_UPDATER'
这个是更新DNS的KEY,是必须的。其中algorithm 后的是生成key的算法,key的生成是用 'dnssec-keygen -a HMAC-MD5 -b 128 -n USER DHCP_UPDATER'。
4. 'zone'
要更新的zone,如果是本机就是DNS server,primay 就写127.0.0.1,要是其它机器是DNS server, 就写那台机器的IP。
别的都是一般DNS该有的了,要注意的是一定要有 range 那一行,不然就分不了IP啦。
配好以后,可以启动一下试试, service dhcpd start,如果没问题,把dhcpd改成开机就启动,chkconfig --level 2345 dhcpd on。
三、bind(named)的配置。
# rpm -qa | gerp bind
看有没有bind-xx及bind-chroot-xx理论上chroot可以提高安全性但设置时繁琐一点
# rpm -qa | gerp caching-name
看caching-nameserver是否也已经装了,这个不装的话就要自己写named.ca等几个文件了
######################3named.conf参考范例:
// generated by named-bootconf.pl
options {
directory "/var/named";
/*
* If there is a firewall between you and nameservers you want
* to talk to, you might need to uncomment the query-source
* directive below. Previous versions of BIND always asked
* questions using port 53, but BIND 8.1 uses an unprivileged
* port by default.
*/
forward first;
forwarders { 202.99.224.8; 202.99.224.67; 202.106.0.20; };
// query-source address * port 53;
};
//
// a caching only nameserver config
//
controls {
inet 127.0.0.1 allow { localhost; } keys { rndckey; };
};
key DHCP_UPDATER {
algorithm HMAC-MD5;
secret qSSpjerAuaPE/X3JJyxSww==;
};
zone "." IN {
type hint;
file "named.ca";
};
zone "localhost" IN {
type master;
file "localhost.zone";
allow-update { none; };
};
zone "0.0.127.in-addr.arpa" IN {
type master;
file "named.local";
allow-update { none; };
};
zone "160.230.10.in-addr.arpa" IN {
type master;
file "named.160.230.10";
allow-update { key DHCP_UPDATER; };
};
zone "shcto.com" IN {
type master;
file "named.shcto.com";
allow-update { key DHCP_UPDATER; };
};
include "/etc/rndc.key";
/var/named/
区域文件
$TTL 86400
$ORIGIN shcto.com.
@ IN SOA NS1.shcto.com. root.NS1.shcto.com. (
2007121001;
28800;
14400;
3600000;
86400);
IN NS NS1.shcto.com.
IN MX 0 mail.shcto.com.
mail IN A 10.230.129.40
webserver IN A 10.230.128.36
www IN CNAME webserver
smbserver IN A 10.230.128.33
ftp IN CNAME smbserver
named.128.230.10
$TTL 86400
@ IN SOA NS1.shcto.com. root.mail.shcto.com.(
2007121001;
28800;
14400;
3600000;
86400);
IN NS NS1.shcto.com.
40 IN PTR mail.shcto.com.
33 IN PTR smbserver.shcto.com.
80 IN PTR webserver.shcto.com.
其中多了的是
key DHCP_UPDATER {
algorithm HMAC-MD5;
secret qhB++OR5yWo8BTXwk/m4ng;
};
这就是更新dns要用的key,必须和dhcpd.conf里的一样。
还有就是每个 zone 都可以用 key 来update了。
这样就行了。然后启动一下试试吧。
你就可以ping 机器名来找你同事的机器了。
四。测试(主要讲讲LINUX)
在客户机上加入一个文件/etc/dhclient.conf内容如下
send fqdn.fqdn "test"; //test为本机的hostname
send fqdn.encoded on;
send fqdn.server-update off;
运行dhclient或重新启动
正常的话DNS服务器主机的/var/named/chroot/var/named下会多出一个以jnl结尾的
热心网友
时间:2023-07-07 09:49
linux下创建DDNS服务器(在一个Blog中找到的)1、先创建一个用户myddns
#useradd myddns
2、生成密码
#dnssec-keygen -a HMAC-MD5 -b 128 -n USER myddns
在当前目录下生成了两个文件:
Kmyddns.+157+59363.key
Kmyddns.+157+59363.private
3、配置DNS
#vi /etc/named.conf
添加以下内容:
key myddns {
algorithm HMAC-MD5.SIG-ALG.REG.INT;
secret xEGzMJVu7aT81lC5QRzIg==;
};
其中secrect后的内容是用vi打开Kmyddns.+157+59363.private后,拷贝里面的密码文件得来的!
4、配置DHCP
#vi /etc/dhcpd.conf
先将第二行前面的“#”去掉,再在subnet 上面添加下面一行内容:
ddns-updates on;
在option domain-name 后,改成DNS的域名,例如“sunman.com”
在option domain-name-servers 后,填写好DNS服务器的IP地址,例如:192.168.1.112
然后在里面添加下面几行内容:
key myddns {
algorithm HMAC-MD5.SIG-ALG.REG.INT;
secret xEGzMJVu7aT81lC5QRzIg==;
}
zone sunman.com. {
primary 192.168.1.2;
key myddns;
}
zone 1.168.192.in-addr.arpa. {
primary 192.168.1.2;
key myddns;
}
保存退出!
5、开启DNS和DHCP服务器
#service named start
#service dhcpd start
6、通过下面的命令排错
#tail -n 20 /var/log/messages | grep named (指定显示靠后的20行内容)
#tail /var/log/messages | grep dhcpd (全部显示所有内容)
7、linux客户端通过dhclient命令动态获取到IP,这时在DNS服务器的/var/named/chroot/var/named/下会生成两个扩展名是.jnl的文件。
还有一点要注意,linux客户端还必须执行下面的工作
#cp /usr/share/doc/dhclient-3.0pl2/dhclient.conf.sample /etc/dhclient.conf
生成一个dhclient.conf配置文件
#vi /etc/dhclient.conf
修改第一行内容,将双引号里的内容删掉,添加上自己的主机名。
最后再执行dhclient命令来获取IP。
/etc/named.conf文件内容:
options {
directory "/var/named";
listen-on ports 53 {
127.0.0.1;
192.168.1.112;
};
forward first;
forwarders {202.38.64.1;202.96.199.133;};
};
zone "." IN {
type hint;
file "named.ca";
};
zone "localhost" IN {
type master;
file "localhost.zone";
};
zone "0.0.127.in-addr.arpa" IN {
type master;
file "localhost.arpa";
};
key myddns {
algorithm HMAC-MD5.SIG-ALG.REG.INT;
secret xEGzMJVu7aT81lC5QRzIg==;
};
zone "sunman.com" IN {
type master;
file "sunman.zone";
allow-update { key myddns; };
};
zone "1.168.192.in-addr.arpa" IN {
type master;
file "sunman.arpa";
allow-update { key myddns; };
};
key "rndc-key" {
algorithm hmac-md5;
secret "pq18UO7rODLStf5XVdg17Q==";
};
controls {
inet 127.0.0.1 port 953
allow { 127.0.0.1; } keys { "rndc-key"; };
};
/etc/dhcpd.conf配置文件内容:
ddns-update-style interim;
#ignore client-updates;
ddns-updates on;
subnet 192.168.1.0 netmask 255.255.255.0 {
# --- default gateway
option routers 192.168.1.1;
option subnet-mask 255.255.255.0;
option nis-domain "domain.org";
option domain-name "sunman.com";
option domain-name-servers 192.168.1.112;
option time-offset -18000;
# Eastern Standard Time
# option ntp-servers 192.168.1.1;
# option netbios-name-servers 192.168.1.1;
# --- Selects point-to-point node (default is hybrid). Don't change this unless
# -- you understand Netbios very well
# option netbios-node-type 2;
range 192.168.1.128 192.168.1.255;
range 192.168.1.10 192.168.1.100;
default-lease-time 21600;
max-lease-time 43200;
# we want the nameserver to appear at a fixed address
host ns {
next-server marvin.redhat.com;
hardware ethernet 12:34:56:78:AB:CD;
fixed-address 207.175.42.254;
}
}
key myddns {
algorithm HMAC-MD5.SIG-ALG.REG.INT;
secret xEGzMJVu7aT81lC5QRzIg==;
}
zone sunman.com. {
primary 192.168.1.2;
key myddns;
}
zone 1.168.192.in-addr.arpa. {
primary 192.168.1.2;
key myddns;
}