一·搭建dns伺服器
試驗要求:完成dns的正反向解析
試驗前準備:
伺服器 192.168.203.201 server1.example.com
客戶機 192.168.203.202 server2.example.com
192.168.203.203 database.example.com
修改dns
nmcli c modify eno16777736 ipv4.dns 8.8.8.8
systemctl restat network
1.1 安裝相關程式
yum install bind-chroot bind-utils -y #安裝bind
主配置檔案 /etc/named.conf
區域配置檔案 /etc/named.rfc1912.zones
1.2 修改配置檔案
1.2.1 修改主配置檔案
vim /etc/named.conf
11行 listen-on port 53 { any; }; #允許任意接口監聽
17行 allow-query { any; }; #允許所有用戶端查詢
1.2.2 修改區域配置檔案
vim /etc/named.rfc1912.zones
正向解析:
zone "example.com" in {
type master; #服務類型:主伺服器
file "example.com.zone"; #解析規則檔案
allow-update { none; }; #允許動态更新解析資訊的用戶端,none是全部禁止
};
反向解析:
zone "203.168.192.in-addr.arpa" in { #反向解析的域
type master;
file "192.168.203.arpa";
1.2.3 配置解析資料檔案
cd /var/named
cp -a named.localhost example.com.zone #複制正向解析模闆檔案
vim example.com.zone #修改配置檔案
$ttl 1d
@ in soa example.com. root.example.com. (
0 ; serial
1d ; refresh
1h ; retry
1w ; expire
3h ) ; minimum
ns ns.example.com. #ns優先于a記錄
ns in a 192.168.203.201 #指定域名由哪個dns伺服器來解析
workstation in a 192.168.203.100 #a記錄用來指定主機名或域名對應的ip位址
server1 in a 192.168.203.201
server2 in a 192.168.203.202
database in a 192.168.203.203
cp -a named.loopback 192.168.203.arpa #複制反向解析模闆檔案
vim 192.168.203.arpa
ns ns.example.com.
ns a 192.168.203.201
201 ptr ns.example.com.
201 ptr server1.example.com.
202 ptr server2.example.com.
203 ptr database.example.com.
100 ptr sorkstation.example.com.
重新開機服務
systemctl restart named
systemctl enable nemad
1.2.4 在用戶端驗證
nmcli c modify eno16777736 ipv4.dns 192.168.203.201 #修改域名解析伺服器位址
nslookup
>(域名或者ip,可正反向解析)
1.2.5 另:修改主伺服器配置檔案後,主伺服器dns改變,無法上網
在allow-query下面添加:
forward first;
forwarders {
8.8.8.8;
}; #先從本地解析,解析不到轉發給8.8.8.8
二、搭建郵件伺服器
實驗要求:完成郵件伺服器架設,可以發送接收郵件;ssl加密傳輸郵件;使用squirrenail配置一個基于web的郵件傳輸系統
實驗準備:
伺服器:server1.example.com 192.168.203.201
安裝foxmail郵件用戶端軟體
2.1 安裝postfix來配置smtp伺服器
yum install postfix -y
vim /etc/postfix/main.cf
75行 myhostname = server1.example.com #主機名
83行 mydomain = example.com #定義域名
99行 myorigin = $mydomain #起源:調用域名
116行 inet_interfaces = all
164行 mydestination = 最後面添加$mydomain #目的地
264行 mynetworks = 192.168.203.0/24, 127.0.0.0/8 #網段
419行 home_mailbox =maildir/ #郵件存放位置
574行 smtpd_banner = $myhostname esmtp #協定
最後添加:
message_size_limit = 10485760 #郵件大小限制10m
mailbox_size_limit = 1073741824 #郵箱大小限制1g
smtpd_sasl_type = docecot #指定認證類型
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes #啟用認證
smtpd_sasl_secutity_options = noanonymous #匿名使用者
smtpd_sasl_local_domain = $mydomain #本地域名
smtpd_recipient_restricrions = permit_mynetworks,permit_auth_destination,permit_sasl_suthenticated,reject
systemctl restart postfix
systemctl enable postfix
2.2 安裝dovecot來配置pop/imap協定伺服器
yum install dovecot -y
vim /etc/dovecot/dovecot.conf #修改dovecot配置檔案
24行 protocols = imap pop3 lmtp #傳輸協定
30行 listen = * #監聽所有
cd /etc/dovecot/conf.d
vim 10-auth.conf
10行 disable_plaintext_auth = no #關閉明文認證
100行 auth_mechanisms = plain login
vim 10-mail.conf
30行 mail_location = maildir:~/maildir
vim 10-master.conf
96行 去注釋在 mode = 0666 下添加
user = postfix
group = postfix
vim 10-ssl.conf
8行 ssl = no #不使用ssl
systemctl restart dovecot
systemctl enable dovecot
yum -y install php php-mbstring php-pear
vim /etc/php.ini
878 ;date.timezone = "asia/shanghai" //配置時區
2.3 驗證
建立兩個使用者,在foxmail郵件用戶端添加使用者,完成郵件發送與接受
2.4配置ssl加密郵件傳輸
2.4.1 建立證書
cd /etc/pki/tls/certs
make server.key
openssl rsa -in server.key -out server.key #拿掉證書中的密碼
make server.csr #證書申請模闆檔案
openssl x509 -in server.csr -out server.crt -req -signkey server.key -days 365 #生成證書
2.4.2 修改配置檔案
最後添加 :smtpd_use_tls = yes
smtpd_tls_cert_file = /etc/pki/tls/certs/server.crt
smtpd_tls_key_file = /etc/pki/tls/certs/server.key
smtpd_tls_session_cache_database = btree:/etc/postfix/smtpd_scache
vim /etc/postfix/master.cf
26、27、28行 取消注釋
vim /etc/dovecot//conf.d/10-ssl.conf
8行 ssl = yes #使用ssl
14、15行 指定生成的證書檔案
ssl_cert = </etc/pki/tls/certs/server.crt
ssl_key = </etc/pki/tls/certs/server.key
配置ssl
yum -y install mod_ssl
vim /etc/httpd/conf.d/ssl.conf
59 documentroot "/var/www/html"
60 servername workstation.example.com:443//修改為自己的主機名
100 sslcertificatefile /etc/pki/tls/certs/server.crt//修改為自己第一步建立的證書
107 sslcertificatekeyfile /etc/pki/tls/certs/server.key//修改為第一步建立的密鑰
systemctl restart httpd
2.4.3 驗證
在foxmail郵件用戶端選擇使用ssl,用兩個使用者完成郵件的發送與接受
2.5 配置基于web的郵件傳輸系統
2.5.1 安裝squirrelmail
yum -y install squirrelmail
curl -o http://www.squirrelmail.org/plugins/compatibility-2.0.16-1.0.tar.gz
curl -o http://www.squirrelmail.org/plugins/empty_trash-2.0-1.2.2.tar.gz
curl -o http://www.squirrelmail.org/plugins/secure_login-1.4-1.2.8.tar.gz
tar xzvf compatibility-2.0.16-1.0.tar.gz -c /usr/share/squirrelmail/plugins #-c指定解壓目錄
tar xzvf empty_trash-2.0-1.2.2.tar.gz -c /usr/share/squirrelmail/plugins
tar xzvf secure_login-1.4-1.2.8.tar.gz -c /usr/share/squirrelmail/plugins
2.5.2 運作配置腳本
/usr/share/squirrelmail/config/conf.pl
1-->5-->/webmail-->r #修改登出頁面
2-->1-->example.com(修改域名)-->3-->2(smtp)-->a-->4-->mail.example.com(定義imap伺服器)-->8-->dovecot-->9-->detect-->b-->4-->mail.example.com-->7-->y-->login-->n-->r
4-->7-->y-->r
8-->7-->8-->15-->q-->y
cp /usr/share/squirrelmail/plugins/secure_login/config.sample.php /usr/share/squirrelmail/plugins/secure_login/config.php
vim /usr/share/squirrelmail/plugins/secure_login/config.php
24行 $change_back_to_http_after_login = 0;
2.5.3 驗證
登陸http://192.168.203.201//webmail ,使用使用者賬戶登陸,發送郵件。