服务器
[root@test1 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=eddf2609-55a9-469e-a884-88d05191a1f5
DEVICE=ens33
ONBOOT=yes
IPV6_PRIVACY=no
IPADDR=192.168.10.1
NETMASK=255.255.255.0
GATEWAY=192.168.10.254
DNS1=192.168.10.1
DNS2=192.168.10.2
[root@test1 ~]# systemctl restart network
[root@test1 ~]# ip add
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:d1:20:a2 brd ff:ff:ff:ff:ff:ff
inet 192.168.10.1/24 brd 192.168.10.255 scope global noprefixroute ens33
valid_lft forever preferred_lft forever
inet6 fe80::9c24:1afb:3d4:da7a/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 52:54:00:fb:ac:4d brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000
link/ether 52:54:00:fb:ac:4d brd ff:ff:ff:ff:ff:ff
[root@test1 ~]# mkdir /opt/centos
[root@test1 ~]# mount /dev/cdrom /opt/centos/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@test1 ~]# mv /etc/yum.repos.d/* /home/
[root@test1 ~]# vim /etc/yum.repos.d/local.repo
[centos]
name=centos
baseurl=file:///opt/centos
gpgcheck=0
enabled=1
[root@test1 ~]# yum clean all
已加载插件:fastestmirror, langpacks
正在清理软件源: centos
Cleaning up list of fastest mirrors
Other repos take up 219 M of disk space (use --verbose for details)
[root@test1 ~]# yum repolist
已加载插件:fastestmirror, langpacks
Determining fastest mirrors
centos | 3.6 kB 00:00:00
(1/2): centos/group_gz | 166 kB 00:00:00
(2/2): centos/primary_db | 3.1 MB 00:00:00
源标识 源名称 状态
centos centos 4,021
[root@test1 ~]# yum install bind bind-chroot -y
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 bind.x86_64.32.9.9.4-72.el7 将被 安装
---> 软件包 bind-chroot.x86_64.32.9.9.4-72.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
=======================================================================================
Package 架构 版本 源 大小
=======================================================================================
正在安装:
bind x86_64 32:9.9.4-72.el7 centos 1.8 M
bind-chroot x86_64 32:9.9.4-72.el7 centos 88 k
事务概要
=======================================================================================
安装 2 软件包
总下载量:1.9 M
安装大小:4.5 M
Downloading packages:
---------------------------------------------------------------------------------------
总计 6.5 MB/s | 1.9 MB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : 32:bind-9.9.4-72.el7.x86_64 1/2
正在安装 : 32:bind-chroot-9.9.4-72.el7.x86_64 2/2
验证中 : 32:bind-9.9.4-72.el7.x86_64 1/2
验证中 : 32:bind-chroot-9.9.4-72.el7.x86_64 2/2
已安装:
bind.x86_64 32:9.9.4-72.el7 bind-chroot.x86_64 32:9.9.4-72.el7
完毕!
[root@test1 ~]# rpm -qa |grep bind
bind-license-9.9.4-72.el7.noarch
bind-9.9.4-72.el7.x86_64
keybinder3-0.3.0-1.el7.x86_64
bind-libs-lite-9.9.4-72.el7.x86_64
bind-libs-9.9.4-72.el7.x86_64
bind-utils-9.9.4-72.el7.x86_64
rpcbind-0.2.0-47.el7.x86_64
bind-chroot-9.9.4-72.el7.x86_64
[root@test1 ~]# vim /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";
recursing-file "/var/named/data/named.recursing";
secroots-file "/var/named/data/named.secroots";
allow-query { any; };
recursion yes;
dnssec-enable no;
dnssec-validation no;
/* Path to ISC DLV key */
bindkeys-file "/etc/named.iscdlv.key";
managed-keys-directory "/var/named/dynamic";
pid-file "/run/named/named.pid";
session-keyfile "/run/named/session.key";
};
logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};
zone "." IN {
type hint;
file "";
};
include "/etc/named.zones";
include "/etc/named.root.key";
[root@test1 ~]# cp -p /etc/named.rfc1912.zones /etc/named.zones
[root@test1 ~] vim /etc/named.zones
zone "localhost.localdomain" IN {
type master;
file "named.localhost";
allow-update { none; };
};
zone "localhost" IN {
type master;
file "named.localhost";
allow-update { none; };
};
zone "1.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.loopback";
allow-update { none; };
};
zone "1.0.0.127.in-addr.arpa" IN {
type master;
file "named.loopback";
allow-update { none; };
};
zone "0.in-addr.arpa" IN {
type master;
file "named.empty";
allow-update { none; };
};
zone "" IN {
type master;
file ".hosts";
};
zone "10.168.192.in-addr.arpa" IN {
type master;
file ".back";
};
[root@test1 ~]# named-checkconf
[root@test1 ~]# cp -p /var/named/named.localhost /var/named..hosts
[root@test1 named]# cp -p /var/named/named.localhost /var/named/.hosts
[root@test1 named]# ll
总用量 20
drwxr-x---. 7 root named 61 12月 7 19:59 chroot
drwxrwx---. 2 named named 6 10月 31 2018 data
-rw-r-----. 1 root named 152 6月 21 2007 .hosts
drwxrwx---. 2 named named 6 10月 31 2018 dynamic
-rw-r-----. 1 root named 2281 5月 22 2017
-rw-r-----. 1 root named 152 12月 15 2009 named.empty
-rw-r-----. 1 root named 152 6月 21 2007 named.localhost
-rw-r-----. 1 root named 168 12月 15 2009 named.loopback
drwxrwx---. 2 named named 6 10月 31 2018 slaves
[root@test1 named]# vim /var/named/.hosts
$TTL 1D
@ IN SOA @ root. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
@ IN NS dns..
@ IN MX 10 mail..
dns IN A 192.168.10.1
mail IN A 192.168.10.2
slave IN A 192.168.10.3
www IN A 192.168.10.4
ftp IN A 192.168.10.20
web IN CNAME www..
[root@test1 named]# named-checkzone /var/named/.hosts
zone /IN: loaded serial 0
OK
[root@test1 named]# cp -p /var/named/named.loopback /var/named/.back
[root@test1 named]# ll
总用量 24
drwxr-x---. 7 root named 61 12月 7 19:59 chroot
drwxrwx---. 2 named named 6 10月 31 2018 data
-rw-r-----. 1 root named 168 12月 15 2009 .back
-rw-r-----. 1 root named 235 12月 7 20:29 .hosts
drwxrwx---. 2 named named 6 10月 31 2018 dynamic
-rw-r-----. 1 root named 2281 5月 22 2017
-rw-r-----. 1 root named 152 12月 15 2009 named.empty
-rw-r-----. 1 root named 152 6月 21 2007 named.localhost
-rw-r-----. 1 root named 168 12月 15 2009 named.loopback
drwxrwx---. 2 named named 6 10月 31 2018 slaves
[root@test1 named]# vim /var/named/.back
$TTL 1D
@ IN SOA @ root.. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
@ IN NS dns..
@ IN MX 10 mail..
1 IN PTR dns..
2 IN PTR mail..
3 IN PTR slave..
4 IN PTR www..
20 IN PTR ftp..
[root@test1 named]# named-checkzone 10.168.192.in-addr.arpa /var/named/.back
zone 10.168.192.in-addr.arpa/IN: loaded serial 0
OK
[root@test1 named]# firewall-cmd --permanent --add-service=dns
success
[root@test1 named]# firewall-cmd --reload
success
[root@test1 named]# systemctl restart named
[root@test1 named]# systemctl enable named
Created symlink from /etc/systemd/system/multi-user.target.wants/named.service to /usr/lib/systemd/system/named.service.
[root@test1 ~]# nslookup www.
Server: 192.168.10.1
Address: 192.168.10.1#53
Name: www.
Address: 192.168.10.4
[root@test1 ~]# nslookup 192.168.10.4
Server: 192.168.10.1
Address: 192.168.10.1#53
4.10.168.192.in-addr.arpa name = www..
客户端
[root@test2 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=eddf2609-55a9-469e-a884-88d05191a1f5
DEVICE=ens33
ONBOOT=yes
IPV6_PRIVACY=no
IPADDR=192.168.10.10
NETMASK=255.255.255.0
GATEWAY=192.168.10.254
DNS1=192.168.10.1
DNS2=192.168.10.2
[root@test2 ~]# systemctl restart network
[root@test2 ~]# ip add
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:5c:fa:3d brd ff:ff:ff:ff:ff:ff
inet 192.168.10.10/24 brd 192.168.10.255 scope global noprefixroute ens33
valid_lft forever preferred_lft forever
inet6 fe80::9c24:1afb:3d4:da7a/64 scope link tentative noprefixroute dadfailed
valid_lft forever preferred_lft forever
inet6 fe80::c76e:4a9c:6409:3844/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 52:54:00:fb:ac:4d brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000
link/ether 52:54:00:fb:ac:4d brd ff:ff:ff:ff:ff:ff
[root@test2 ~]# vim /etc/resolv.conf
nameserver 192.168.10.1
nameserver 192.168.10.2
search
[root@test2 ~]# nslookup
> server
Default server: 192.168.10.1
Address: 192.168.10.1#53
Default server: 192.168.10.2
Address: 192.168.10.2#53
> www.
Server: 192.168.10.2
Address: 192.168.10.2#53
Non-authoritative answer:
www. canonical name = .
Name:
Address: 3.33.152.147
Name:
Address: 15.197.142.173
> 192.168.10.4
Server: 192.168.10.2
Address: 192.168.10.2#53