ubuntu局域网服务器搭建网站,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

...nginx

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

1.

进入/etc/bind目录

编辑named.conf.default-zones,添加以下文本ubuntu

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

;

$TTL604800

@INSOAtestj. root.testj. (

2; Serial

604800; Refresh

86400; Retry

2419200; Expire

604800 ); Negative Cache TTL

;

@INNStestj.

testj.comINNS192.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 restartdom

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.ide

nameserver 192.168.235.129

search DHCP HOSToop

一堆注释,其实就是最后两行有用

nameserver 192.168.235.129

search DHCP HOST

这个文件可能随时被还原,被还原后就不能识别www.testj.com了,或者执行第6步。this

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