ubuntu搭建局域网dns服务器

局域网dns服务器搭建
服务器系统:虚拟机中的ubuntu,nat模式网络,ubuntu系统内ip是dhcp模式
安装bind9
apt-get install bind9
如果报错The following packages have unmet dependencies
bind9 : Depends: libbind9-160 (= 1:9.11.3+dfsg-1ubuntu1) but 1:9.11.3+dfsg-1ubuntu1.1 is to be installed
一堆is to be installed
大概是因为版本的问题,一个个卸载本机已有的依赖库
apt-get remove libbind9-160
...

假如想新增一个域名testj.com

1.
进入/etc/bind目录
编辑named.conf.default-zones,添加如下文本

zone "testj.com" {
    type master;
    file "/etc/bind/db.testj.com";
};

2.
然后新增file对应的文件,即在/etc/bind目录下新增db.testj.com文件
里面文本如下

;
; BIND data file for local loopback interface
;
$TTL	604800
@	IN	SOA	testj. root.testj. (
			      2		; Serial
			 604800		; Refresh
			  86400		; Retry
			2419200		; Expire
			 604800 )	; Negative Cache TTL
;
@	IN	NS	testj.
testj.com	IN	NS	192.168.235.129

www IN A 192.168.235.129
aaa IN A 192.168.235.129


其实就是从db.local赋值过来,修改部分配置,www是主机名,安装了www服务的主机。testj.com是主机,www是主机名

3.
编辑named.conf.options,主要添加listen-on

options {
    directory "/var/cache/bind";

    listen-on port 53 {192.168.235.129;0.0.0.0;};
    allow-transfer {none;};

    // If there is a firewall between you and nameservers you want
    // to talk to, you may need to fix the firewall to allow multiple
    // ports to talk.  See http://www.kb.cert.org/vuls/id/800113

    // If your ISP provided one or more IP addresses for stable 
    // nameservers, you probably want to use them as forwarders.  
    // Uncomment the following block, and insert the addresses replacing 
    // the all-0's placeholder.

    // forwarders {
    //     0.0.0.0;
    // };

    //========================================================================
    // If BIND logs error messages about the root key being expired,
    // you will need to update your keys.  See https://www.isc.org/bind-keys
    //========================================================================
    dnssec-validation auto;

    auth-nxdomain no;    # conform to RFC1035
    listen-on-v6 { any; };
};

4.重启服务
service bind9 restart

5.指明bind9服务器地址
编辑/etc/resolv.conf
# This file is managed by man:systemd-resolved(8). Do not edit.
#
# This is a dynamic resolv.conf file for connecting local clients to the
# internal DNS stub resolver of systemd-resolved. This file lists all
# configured search domains.
#
# Run "systemd-resolve --status" to see details about the uplink DNS servers
# currently in use.
#
# Third party programs must not access this file directly, but only through the
# symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,
# replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.

nameserver 192.168.235.129
search DHCP HOST

一堆注释,其实就是最后两行有用
nameserver 192.168.235.129
search DHCP HOST
这个文件可能随时被还原,被还原后就不能识别www.testj.com了,或者执行第6步。

6.编辑ip地址配置文件

ubuntu的路径是/etc/network/interfaces

# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback

auto ens33
iface ens33 inet dhcp
address 192.168.235.129
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameserver 192.168.235.129
dns-search testj.com

更多的名称是lo和eth0、eth1,这里是ens33

重要的是dns-nameserver一行,以免/etc/resolv.conf还原,或者失效

第5步、第6步得试,配置过程中轮流换着配置,重启。才能持久生效

end.
ping www.testj.com
浏览器输入www.testj.com就可以了(前提是配置了服务器访问目录,详情自行了解nginx、apache)
本机是可以访问的,但是真实主机访问却失败了,虚拟机中的其他系统访问正常。没有更多的真实设备,先这样吧,以后有空,有需求再研究


ubuntu重启网络服务
/etc/init.d/networking restart
或者service networking restart
ubuntu ip配置文件的路径是/etc/network/interfaces

你可能感兴趣的:(linux)