2.使用Cloudxns接替管理
3.拥有自己VPS
1.安装Docker
可以参考 https://www.gitbook.com/book/yeasy/docker_practice/details
或者按照以下安装
使用脚本自动安装
curl -sSL https://get.docker.com/ | sh
执行这个命令后,脚本就会自动的将一切准备工作做好,并且把 Docker 安装在系统中。
阿里云的安装脚本
curl -sSL http://acs-public-mirror.oss-cn-hangzhou.aliyuncs.com/docker-engine/internet | sh
DaoCloud 的安装脚本
curl -sSL https://get.daocloud.io/docker | sh
2.安装动态域名客户端
这里使用zwh8800的客户端
https://github.com/zwh8800/cloudxns-ddns
首先,拉取镜像:
docker pull zwh8800/cloudxns-ddns
然后,编写一个很简单的配置文件,文件名必须为 cloudxns-ddns.gcfg,把它放到某个文件夹中(如/home/zzz/cloudxns-ddns/config,下面以此为例子)
[CloudXNS]
APIKey="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
SecureKey="xxxxxxxxxxxxxx"
[Domain]
Data="home.lengzzz.com"
Data="haha.lengzzz.com"
上面 APIKey 是你在 CloudXNS https://www.cloudxns.net/AccountManage/apimanage.html 申请的 key,填进去即可。下面是你想要动态的域名,可以写很多。
然后,启动镜像即可。
docker run --name cloudxns-ddns -d -v /home/zzz/cloudxns-ddns/log:/app/log -v /home/zzz/cloudxns-ddns/config:/app/config zwh8800/cloudxns-ddns
依葫芦画瓢就可以运行了
为防止后台停止运行加入restart参数
docker run --name cloudxns-ddns --restart=always -d -v /home/zzz/cloudxns-ddns/log:/app/log -v /home/zzz/cloudxns-ddns/config:/app/config zwh8800/cloudxns-ddns
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.8202.99.224.67202.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结尾的
环境OS: Red Hat Enterprise Linux 5 update 4
Network: 192.168.122.0/24
前言
在baidu上搜DDNS,很多地方把DDNS解释为DHCP + DNS,其实这是牵强附会。DDNS是
Dynamic Domain Name Server的简称。DHCP分配IP的时候更新DNS服务器域名解析记录,这
就是DDNS所做的事情,而是否更新客户端的hostname显示倒是其次。
操作
这是DNS服务器的环境:
[root@server ~]# cat /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=server.afang.org
[root@server ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# Realtek Semiconductor Co., Ltd. RTL-8139/8139C/8139C+
DEVICE=eth0
BOOTPROTO=static
IPADDR=192.168.122.254
NETMASK=255.255.255.0
HWADDR=54:52:00:4F:D5:68
ONBOOT=yes
[root@server ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 54:52:00:4F:D5:68
inet addr:192.168.122.254 Bcast:192.168.122.255 Mask:255.255.255.0
inet6 addr: fe80::5652:ff:fe4f:d568/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:280 errors:0 dropped:0 overruns:0 frame:0
TX packets:232 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:24404 (23.8 KiB) TX bytes:31850 (31.1 KiB)
Interrupt:10
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:180 errors:0 dropped:0 overruns:0 frame:0
TX packets:180 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:14680 (14.3 KiB) TX bytes:14680 (14.3 KiB)
[root@server ~]#
安装配置DNS服务器
[root@server ~]# cd /misc/cd/Server
[root@server Server]# rpm -ivh bind-9.3.6-4.P1.el5.i386.rpm bind-chroot-9.3.6-4.P1.el5.i386.rpm
caching-nameserver-9.3.6-4.P1.el5.i386.rpm
warning: bind-9.3.6-4.P1.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing... ########################################### [100%]
1:bind ########################################### [ 33%]
2:bind-chroot ########################################### [ 67%]
3:caching-nameserver ########################################### [100%]
[root@server Server]# cd /var/named/chroot/etc/
[root@server etc]# ls
localtime named.caching-nameserver.conf named.rfc1912.zones rndc.key
[root@server etc]# mv named.caching-nameserver.conf named.conf
[root@server etc]# mv named.rfc1912.zones named.zones
[root@server etc]# ln -s /var/named/chroot/etc/named.conf /etc/named.conf
[root@server etc]# ln -s /var/named/chroot/etc/named.zones /etc/named.zones
[root@server etc]#
这是我的named.conf和named.zones配置
named.conf
[root@server etc]# cat named.conf
acl afang.org { 192.168.122.0/24}
options {
listen-on port 53 { 127.0.0.1afang.org}
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 { localhostafang.org}
allow-query-cache { localhostafang.org}
}
logging {
channel default_debug {
file "data/named.run"
severity dynamic
}
}
view afang.org {
match-clients { localhostafang.org}
match-destinations { localhost}
recursion yes
include "/etc/named.zones"
}
[root@server etc]#
named.zones
[root@server etc]# cat named.zones
zone "." IN {
type hint
file "named.ca"
}
zone "localdomain" IN {
type master
file "localdomain.zone"
allow-update { none}
}
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 "0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN {
type master
file "named.ip6.local"
allow-update { none}
}
zone "255.in-addr.arpa" IN {
type master
file "named.broadcast"
allow-update { none}
}
zone "0.in-addr.arpa" IN {
type master
file "named.zero"
allow-update { none}
}
zone "afang.org" IN {
type master
file "afang.org.zone"
allow-update { localhost}
}
zone "122.168.192.in-addr.arpa" IN {
type master
file "122.168.192.in-addr.arpa.rzone"
allow-update { localhost}
}
[root@server etc]#
对named.zones的一些解释
zone "afang.org" IN {
type master
file "afang.org.zone"
allow-update { localhost}
}
zone "122.168.192.in-addr.arpa" IN {
type master
file "122.168.192.in-addr.arpa.rzone"
allow-update { localhost}
}
这里allow-update允许DHCP服务器从本地IP来更新DNS的解析记录。如果你的DNS和
DHCP服务不在同一台机器上,你也可以在allow-update里面指定DHCP服务器的IP。但是这
样是不安全的。如果有人恶意把自己的IP设置为该IP,则DNS服务器就很容易给入侵。
这是我的域名解析记录
[root@server named]# pwd
/var/named/chroot/var/named
[root@server named]# ls
data localhost.zone named.ca named.local slaves
localdomain.zone named.broadcast named.ip6.local named.zero
[root@server named]# cp localdomain.zone afang.org.zone
[root@server named]# cp named.local 122.168.192.in-addr.arpa.rzone
这是afang.org.zone和122.168.192.in-addr.arpa.rzone 的内容
afang.org.zone
[root@server named]# cat afang.org.zone
$TTL 86400
@ IN SOA localhost root (
42 serial (d. adams)
3H refresh
15M retry
1W expiry
1D ) minimum
IN NS localhost
server IN A 192.168.122.254
[root@server named]#
122.168.192.in-addr.arpa.rzone
[root@server named]# cat 122.168.192.in-addr.arpa.rzone
$TTL 86400
@ IN SOA localhost. root.localhost. (
1997022700 Serial
28800 Refresh
14400 Retry
3600000 Expire
86400 ) Minimum
IN NS localhost.
254 IN PTR server.afang.org.
[root@server named]#
此外对目录和文件设置合适的权限
欢迎分享,转载请注明来源:夏雨云
评论列表(0条)