[TOC]
DNS 域名系統(tǒng)
定義
域名系統(tǒng)是域名和IP地址相互映射的一個(gè)分布式數(shù)據(jù)庫(kù)梅尤,能夠是用戶更方便的訪問(wèn)互聯(lián)網(wǎng)柱衔。不用去記住能夠被機(jī)器直接讀取的IP麻掸。
域名分類(lèi)
域是分層管理的
# 根域: [.]
# 頂級(jí)域:
按性質(zhì): [.org\.net\.com\.edu\.gov]
按國(guó)家: [.cn\.tw\.hk]
# 普通域
比如: [.baidu]
解析流程
本地DNS緩存
-> 本地hosts文件
-> 指定的DNS服務(wù)器
如果指定的DNS服務(wù)器沒(méi)有找到對(duì)應(yīng)的域名胰锌,會(huì)返回到客戶端,客戶端會(huì)向上一級(jí)DNS服務(wù)器繼續(xù)發(fā)送請(qǐng)求筹煮。直至查詢到或者頂級(jí)服務(wù)器也沒(méi)查詢到。
DNS分類(lèi)
1. 主DNS服務(wù)器:存儲(chǔ)原始資料
2. 從DNS服務(wù)器:自動(dòng)更新注DNS服務(wù)器的數(shù)據(jù)
3. 緩存服務(wù)器:轉(zhuǎn)發(fā)來(lái)自客戶端的請(qǐng)求居夹,但是會(huì)緩存查詢回來(lái)的結(jié)果
4. 轉(zhuǎn)發(fā)器:不向根域發(fā)送請(qǐng)求败潦,而是直接發(fā)給其他的服務(wù)器,并不緩存結(jié)果
資源記錄
格式
域名 生存期 類(lèi)別 類(lèi)型 值
1. 域名:指定這條記錄適用于哪個(gè)域
2. 生存期:指定該條記錄的穩(wěn)定程度單位秒
3. 類(lèi)別:互聯(lián)網(wǎng)信息都是 IN
4. 類(lèi)型:每個(gè)資源記錄類(lèi)型
5. 值:對(duì)應(yīng)的值
資源記錄類(lèi)型
1. SOA Star of authority 起始授權(quán) 必須是第一行 只能有一個(gè)
2. A IPV4 address
3. AAAA IPV6 address
4. MX Mail exchange
5. NS Name Server
6. CNAME Canonical name 可以將域名轉(zhuǎn)換准脂,別名
7. PTR 方向解析
...還有很多
用bind
搭建一臺(tái)DNS
服務(wù)器
我們?cè)?code>RHEL1上搭建DNS服務(wù)器
安裝bind
yum install bind bind-utils
創(chuàng)建自己的zone
文件
# 可以使用如下命令查看 包 bind 影響的文件夾以及文件夾
[root@rhel1 Desktop]# rpm -ql bind
# 在 /var/named 文件下創(chuàng)建 node.com.zone
[root@rhel1 named]# cat node.com.zone
$TTL 1D # $TTL指令表示一個(gè)資源記錄在其他DNS服務(wù)器
# $ORIGIN指令表示該zone文件用來(lái)描述的域(domain)名稱(chēng)
@ IN SOA @ admin.qq.com. (
20191128;serial版本號(hào)
1D;refresh 刷新時(shí)間,每隔多久去查看版本號(hào)
1H;retry 重新刷新時(shí)間
1W;expire 過(guò)期時(shí)間
3H;否定答案緩存時(shí)間) # 配置SOA劫扒。它定義了一個(gè)域的全局特性,必須是出現(xiàn)在zone文件中的第一個(gè)資源記錄意狠,而且一個(gè)zone文件中必須只有一個(gè)SOA資源記錄粟关。
@ IN NS server # 配置NS
server IN A 192.168.143.10 #配置server地址
control1 A 192.168.143.10 #配置控制接口的域名
control2 A 192.168.143.11 #配置控制接口的域名
control3 A 192.168.143.12 #配置控制接口的域名
net121 A 192.168.140.10 #配置12服務(wù)器連接接口的域名
net122 A 192.168.140.11 #配置12服務(wù)器連接接口的域名
net231 A 192.168.245.10 #配置23服務(wù)器連接接口的域名
net232 A 192.168.245.11 #配置23服務(wù)器連接接口的域名
在主配置文件中,增加自己的zone
# 編輯配置文件 /etc/named.rfc1912.zones 添加如下內(nèi)容
[root@rhel1 named]# tail -4 /etc/named.rfc1912.zones
zone "node.com." IN {
type master;
file "node.com.zone"
};
### 這個(gè)位置正常些文件名字就可以环戈,如果named啟動(dòng)不了改成絕對(duì)路徑/etc/named/node.com.zone
# 也可以在 /etc/named.conf 文件中增加
檢測(cè)是否配置成功
# 檢測(cè)是否配置成功
[root@rhel1 named]# named-checkzone node.com. node.com.zone
zone node.com/IN: loaded serial 20191128
OK
# 啟動(dòng)named
[root@rhel1 named]# systemctl start named
[root@rhel1 named]# systemctl enable named
測(cè)試配置的結(jié)果
# dig命令檢測(cè) dns 解析闷板,
### 沒(méi)有dig命令 請(qǐng)安裝 `bind-utils`
[root@rhel1 named]# dig -t A control1.node.com
; <<>> DiG 9.9.4-RedHat-9.9.4-14.el7 <<>> -t A control1.node.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 61583
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;control1.node.com. IN A
;; ANSWER SECTION:
control1.node.com. 86400 IN A 192.168.143.10
;; AUTHORITY SECTION:
node.com. 86400 IN NS server.node.com.
;; ADDITIONAL SECTION:
server.node.com. 86400 IN A 192.168.143.10
;; Query time: 1 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Thu Nov 28 13:31:41 CST 2019
;; MSG SIZE rcvd: 99
# 直接ping也可以
[root@rhel1 named]# ping control1.node.com
PING control1.node.com (192.168.143.10) 56(84) bytes of data.
64 bytes from 192.168.143.10: icmp_seq=1 ttl=64 time=0.027 ms
# nslookup 測(cè)試
[root@rhel1 named]# nslookup
> control1.node.com
Server: 127.0.0.1
Address: 127.0.0.1#53
Name: control1.node.com
Address: 192.168.143.10
防火墻放行
firewall-cmd --add-service=dns --permanent
firewall-cmd --add-service=dns
在RHEL2
上配置并測(cè)試
# 增加DNS配置
[root@rhel2 html]# tail -1 /etc/resolv.conf
nameserver 192.168.143.10
# 重啟網(wǎng)絡(luò)
[root@rhel2 html]# systemctl restart network
# 確認(rèn)配置還在
[root@rhel2 html]# tail -1 /etc/resolv.conf
nameserver 192.168.143.10
### 有時(shí)候重啟后配置就不在了。是因?yàn)?etc/sysconfig/network-script下的鏈接配置里已經(jīng)配置了DNS院塞,可以在鏈接配置了增加
[root@rhel2 html]# ping control1.node.com
PING control1.node.com (192.168.143.10) 56(84) bytes of data.
用 unbound搭建一個(gè)緩存服務(wù)器
安裝
[root@rhel2 html]# yum install -y unbound
[root@rhel2 html]# systemctl start unbound
[root@rhel2 html]# systemctl enable unbound
更改配置
[root@rhel2 html]# vim /etc/unbound/unbound.conf
# 下面的配置在文件中都能找到遮晚,只是需要打開(kāi)注釋
server:
# whitespace is not necessary, but looks cleaner.
interface: 0.0.0.0
acces-control: 0.0.0.0/0 allow
domain-insecure: "node.com"
# verbosity number, 0 is least verbose. 1 is default.
verbosity: 1
forward-zone:
name: "."
forward-host: 192.168.143.10
# 檢測(cè)配置
[root@rhel2 html]# unbound-checkconf
unbound-checkconf: warning: . forward-host: "192.168.143.10" is an IP4 address, and when looked up as a host name during use may not resolve.
unbound-checkconf: no errors in /etc/unbound/unbound.conf
# 重啟
[root@rhel2 html]# systemctl restart unbound
防火墻放行
[root@rhel2 html]# firewall-cmd --add-service=dns --permanent
[root@rhel2 html]# firewall-cmd --add-service=dns
在RHEL3
上將DNS服務(wù)器配置成緩存服務(wù)器
[root@rhel3 ~]# tail -1 /etc/resolv.conf
nameserver 192.168.143.11
[root@rhel3 ~]# systemctl restart network
[root@rhel3 ~]# ping control1.node.com
PING control1.node.com (192.168.143.10) 56(84) bytes of data.
注: Unbound
與 bind
都能夠搭建主DNS服務(wù)器
郵件服務(wù)器
電子郵件架構(gòu)
Linux服務(wù)器也會(huì)發(fā)送電子郵件,一般是出于自動(dòng)用途拦止,或者向管理員報(bào)告錯(cuò)誤县遣。
# 查看當(dāng)前郵箱列表,可以看到有一封信
[root@rhel1 Desktop]# mail
Heirloom Mail version 12.5 7/5/10. Type ? for help.
"/var/mail/root": 3 messages 1 new 2 unread
1 user@localhost.local Fri Aug 16 19:06 830/62447 "[abrt] full crash report"
# 我們自己給自己發(fā)一封
[root@rhel1 Desktop]# mail root
Subject: test
This is test mail!!!
EOT # 按CTRL+D發(fā)送
# 查看
[root@rhel1 mail]# mail
Heirloom Mail version 12.5 7/5/10. Type ? for help.
"/var/mail/root": 2 messages 1 new
1 user@localhost.local Fri Aug 16 19:06 848/63026 "[abrt] full crash report"
>N 2 root Thu Nov 28 18:10 18/570 "test"
& 2
Message 2:
From root@rhel1.node.com Thu Nov 28 18:10:16 2019
Return-Path: <root@rhel1.node.com>
X-Original-To: root
Delivered-To: root@rhel1.node.com
Date: Thu, 28 Nov 2019 18:10:05 +0800
To: root@rhel1.node.com
Subject: test
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: root@rhel1.node.com (root)
Status: R
This is test mail!!!
郵件協(xié)議
簡(jiǎn)單郵件傳輸協(xié)議(SMTP)
用來(lái)發(fā)送或中轉(zhuǎn)發(fā)出的電子郵件汹族,占用25/tcp
端口
第三版郵局協(xié)議(POP3)
用于將服務(wù)器上把郵件存儲(chǔ)到本地主機(jī)萧求,占用110/tcp
端口
第四版互聯(lián)網(wǎng)信息訪問(wèn)協(xié)議(IMAP4)·
用于在本地追加上訪問(wèn)郵件,占用143/tcp
端口
電子郵件系統(tǒng)
單獨(dú)使用Postfix
服務(wù)程序不能完成收發(fā)郵件的操作顶瞒。我們需要下面的軟件:
-
Postfix
提供的郵件發(fā)送服務(wù)SMTP
-
Dovercot
提供的郵件收取服務(wù)夸政,即POP3
-
OutlookExpress
客戶端收發(fā)郵件工具
搭建郵件系統(tǒng)
創(chuàng)建空的Postfix
服務(wù)器
在RHEL1
上創(chuàng)建空Postfix
,在Redhat
系統(tǒng)中已經(jīng)默認(rèn)安裝了這個(gè)服務(wù)程序榴徐。
- 查看配置文件
# 我們只需要配置下面的配置項(xiàng)即可
myhostname 郵局系統(tǒng)的主機(jī)名
mydomain 郵局系統(tǒng)的域名
myorigin 從本機(jī)寄出郵件的域名名稱(chēng)
inet_interfaces 監(jiān)聽(tīng)的網(wǎng)卡接口
mydestination 可接受郵件的主機(jī)名或域名
mynetworkds 設(shè)置可轉(zhuǎn)發(fā)哪些主機(jī)的郵件
relay_domains 設(shè)置可轉(zhuǎn)發(fā)那些域名得郵件
- 配置
etc/postfix/main.cf
為空的postfix
# 不建議直接編輯守问,使用`postconf`配置
### 配置本機(jī)郵件寄出的域名匀归,會(huì)將從本機(jī)發(fā)出去的發(fā)件人域重寫(xiě)成配置項(xiàng)
[root@rhel1 ~]# postconf -e "myorigin=node.com"
### 設(shè)置成僅偵聽(tīng)用于發(fā)送電子郵件的回環(huán)接口
[root@rhel1 ~]# postconf -e "inet_interfaces=loopback-only"
### 設(shè)置指向的郵件服務(wù)器
### 此處的control2是上面 dns配置的服務(wù)器2的域名
[root@rhel1 ~]# postconf -e "relayhost=[control2.node.com]"
### 關(guān)閉本地電子郵件發(fā)送
[root@rhel1 ~]# postconf -e "local_transport=error:local delivery disabled"
### 本地發(fā)送不會(huì)接受收件人為本地電子郵件賬戶的郵件
[root@rhel1 ~]# postconf -e "mydestination="
### 源自127.0.0.0/8和[::1]/128網(wǎng)絡(luò)的郵件能夠由本地空客戶端發(fā)送到主機(jī)
[root@rhel1 ~]# postconf -e "mynetworks=127.0.0.0/8 [::1]/128"
[root@rhel1 ~]# systemctl restart postfix
配置接收端
在RHEL2
上配置
[root@rhel2 ~]# postconf -e "inet_interfaces = all"
[root@rhel2 ~]# postconf -e "mydestination = node.com"
[root@rhel2 ~]# systemctl restart postfix.service
[root@rhel2 ~]# firewall-cmd --add-service=smtp --permanent
success
[root@rhel2 ~]# firewall-cmd --add-service=smtp
在RHEL1
上發(fā)送RHEL2
查看
[root@rhel1 ~]# mail root
Subject: From control1.node.com
I am control1
EOT
[root@rhel2 ~]# mail
>N 5 root Thu Nov 28 06:26 21/740 "From control1.node.co"
& 5
Message 5:
From root@node.com Thu Nov 28 06:26:41 2019
Return-Path: <root@node.com>
X-Original-To: root@node.com
Delivered-To: root@node.com
Date: Thu, 28 Nov 2019 22:26:41 +0800
To: root@node.com
Subject: From control1.node.com
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: root@node.com (root)
Status: R
I am control1
配置客戶端下載郵件
更改RHEL2
上的 Postfix
配置
[root@rhel2 ~]# postconf -e "inet_interfaces=all"
[root@rhel2 ~]# postconf -e "myhostname=control2.node.com"
[root@rhel2 ~]# postconf -e "mydomain=node.com"
[root@rhel2 ~]# postconf -e "myorigin=node.com"
[root@rhel2 ~]# postconf -e "mydestination=node.com"
[root@rhel2 ~]# systemctl restart postfix
創(chuàng)建一個(gè)賬號(hào)
[root@rhel2 ~]# useradd test_mail_user
[root@rhel2 ~]# echo "test_mail_user" |passwd --stdin test_mail_user
Changing password for user test_mail_user.
passwd: all authentication tokens updated successfully.
配置POP3
服務(wù)器
# 安裝 dovecot
[root@rhel2 ~]# yum install -y dovecot
# 修改配置文件
[root@rhel2 ~]# grep "^[^#]" /etc/dovecot/dovecot.conf
protocols = imap pop3 lmtp
disable_plaintext_auth = no
login_trusted_networks = 0.0.0.0/0
# 配置郵件格式與存儲(chǔ)位置
[root@rhel2 ~]# grep "^mail_location" /etc/dovecot/conf.d/10-mail.conf
mail_location = mbox:~/mail:INBOX=/var/mail/%u
# 創(chuàng)建郵件的存儲(chǔ)目錄
[root@rhel2 ~]# su - test_mail_user
[test_mail_user@rhel2 ~]$ mkdir -p mail/.imap/INBOX
[test_mail_user@rhel2 ~]$ exit
logout
# 重啟dovecot服務(wù)
[root@rhel2 ~]# systemctl restart dovecot
[root@rhel2 ~]# systemctl enable dovecot
ln -s '/usr/lib/systemd/system/dovecot.service' '/etc/systemd/system/multi-user.target.wants/dovecot.service'
# 防火墻放行
[root@rhel2 ~]# firewall-cmd --add-service=smtp --permanent
success
[root@rhel2 ~]# firewall-cmd --add-port=110/tcp --permanent
success
[root@rhel2 ~]# firewall-cmd --reload
success
在物理機(jī)上打開(kāi)Foxmail
進(jìn)行配置
1. 輸入 用戶名密碼:test_mail_user@node.com test_mail_user
2. 輸入服務(wù)器IP兩個(gè)都是`RHEL2`: 192.168.143.11
- 在物理機(jī)發(fā)送一封郵件給
root@node.com
cctest_mail_user@node.com
[root@rhel2 ~]# mail
Heirloom Mail version 12.5 7/5/10. Type ? for help.
"/var/spool/mail/root": 8 messages 4 new 7 unread
1 kane@localhost.local Mon Oct 28 19:18 17/723 "*** SECURITY informat"
U 2 kane@localhost.local Mon Oct 28 19:19 17/722 "*** SECURITY informat"
U 3 root Thu Nov 28 06:24 22/742 "from rhel1 teset"
U 4 root Thu Nov 28 06:25 22/721 "11"
>N 5 root Thu Nov 28 06:26 21/740 "From control1.node.co"
N 6 root Thu Nov 28 06:34 21/711 "ttt"
N 7 root Thu Nov 28 06:34 22/711 "12"
N 8 test_mail_user@node. Thu Nov 28 19:46 49/1965 "Test Mail From Window"
& 8
Message 8:
From test_mail_user@node.com Thu Nov 28 19:46:47 2019
Return-Path: <test_mail_user@node.com>
X-Original-To: root@node.com
Delivered-To: root@node.com
Date: Fri, 29 Nov 2019 11:46:47 +0800
From: "test_mail_user@node.com" <test_mail_user@node.com>
To: root <root@node.com>
Cc: test_mail_user <test_mail_user@node.com>
Subject: Test Mail From Windows
X-Priority: 3
X-Has-Attach: no
X-Mailer: Foxmail 7.2.14.409[cn]
Content-Type: multipart/alternative;
boundary="----=_001_NextPart204586814442_=----"
Status: R
Content-Type: text/plain;
charset="us-ascii"
Hi root
This is a test mail from Foxmail.
test_mail_user@node.com
- 在物理機(jī)上同樣也可以收到這封郵件。