Ubuntu18:パーティション操作

Gpartedをインストール

Gpartedをインストールします。

root@www:~~# apt -y install gparted

Windows スタートメニューから「アクセサリ」→「リモートデスクトップ接続」 を選択して接続画面を起動します。

スタートメニュー

サーバーIPアドレスを入力し「接続」をクリックします。

サーバーIPアドレスを入力し「接続」をクリック

「root」(ユーザー名)、「password」(パスワード)を入力し「OK」をクリックします。

ディスクトップが表示されます。

パーテーション操作は「アプリケーション」→「システム」→「Gparted」をクリックします。

Ubuntu18:Webmin設定

Webminインストール

必要なモジュールをインストールします。

root@www:~# apt -y install python apt-show-versions libapt-pkg-perl libauthen-pam-perl libio-pty-perl libnet-ssleay-perl

Webmin をインストールします。

root@www:~# curl -L -O http://www.webmin.com/download/deb/webmin-current.deb
root@www:~# dpkg -i webmin-current.deb

miniserv.confを設定します。

root@www:~# vi /etc/webmin/miniserv.conf

最終行にアクセス許可するIPを追記します。

allow=127.0.0.1 192.168.1.1/24
keyfile=/etc/letsencrypt/live/ubuntuserver.jp/privkey.pem
certfile=/etc/letsencrypt/live/ubuntuserver.jp/fullchain.pem

再起動します。

root@www:~# systemctl restart webmin

起動確認

Webブラウザを起動し、「https://ubuntuserver.jp:10000/」へアクセスし, root ユーザーでログインします。

「Change Language and Theme」をクリックします。

「Personal choice ..」、Japanese(JA_JP.UTF-8)を選択して、「Make Changes」をクリックします。

「F5」キー押下して、「日本語表示」を確認します。

Ubuntu18:Usermin設定

Userminインストール

必要なモジュールをインストールします。

root@www:~# apt -y install python apt-show-versions libapt-pkg-perl libauthen-pam-perl libio-pty-perl libnet-ssleay-perl

Userminモジュールをインストールします。

root@www:~# curl -L -O http://www.webmin.com/download/deb/usermin-current.deb
root@www:~# dpkg -i usermin-current.deb

miniserv.confを設定します。

root@www:~# vi /etc/usermin/miniserv.conf

最終行についきします。

allow=127.0.0.1 192.168.1.1/24
denyusers=root
keyfile=/etc/letsencrypt/live/ubuntuserver.jp/privkey.pem
certfile=/etc/letsencrypt/live/ubuntuserver.jp/fullchain.pem

起動します。

root@www:~# systemctl restart usermin

起動確認

Webブラウザを起動し、「https://ubuntuserver.jp:20000/」へアクセスし、ユーザーでログインします。

「Sign in」でログイン

クリックします。

「Sign in」でログイン

クリックします。

「Sign in」でログイン

「Usermin」→「Change Language」を選択して、日本語化します。

Usermin

「Display in language:」→「Japanese(JA_JP,UTF-8)」を選択して、「Change」をクリックします。

「Change」をクリック

「F5」キー押下して、「日本語表示」を確認します。

日本語表示

Ubuntu18:システム監視設定

Nagiosのインストール

nagiosユーザーを作成します。

root@www:~# useradd -d /usr/local/nagios/ -M nagios

Nagiosをダウンロードします。

root@www:~# wget https://downloads.sourceforge.net/project/nagios/nagios-4.x/nagios-4.2.4/nagios-4.2.4.tar.gz

Nagiosを展開します。

root@www:~# tar zxvf nagios-4.2.4.tar.gz

Nagios展開先ディレクトリへ移動します。

root@www:~# cd nagios-4.2.4

Nagios日本語化パッチをダウンロードします。

root@www:nagios-4.2.4# wget http://ftp.momo-i.org/pub/security/nagios/patches/nagios-jp-4.2.4.patch.gz

Nagios日本語化パッチを施行します。

root@www:nagios-4.2.4# gzip -dc nagios-jp-4.2.4.patch.gz |patch -p1

Nagiosをインストールします。

root@www:nagios-4.2.4# ./configure && make all && make fullinstall && make install-config

ディレクトリを抜けます。

root@www:nagios-4.2.4# cd

Nagios展開先ディレクトリを削除します。

root@www:~# rm -rf nagios-4.2.4

ダウンロードしたファイルを削除します。

root@www:~# rm -f nagios-4.2.4.tar.gz

Nagiosプラグインインストール

mysql-clientをインストールします。

root@www:~# apt -y install mysql-client

libmysqlclient-devをインストールします。

root@www:~# apt -y install libmysqlclient-dev

Nagiosプラグインをダウンロードします。

root@www:~# wget https://nagios-plugins.org/download/nagios-plugins-2.1.4.tar.gz

Nagiosプラグインを展開します。

root@www:~# tar zxvf nagios-plugins-2.1.4.tar.gz

Nagiosプラグイン展開先ディレクトリへ移動します。

root@www:~# cd nagios-plugins-2.1.4

Nagiosプラグインをインストールします。

root@www:nagios-plugins-2.1.4# ./configure && make && make install

ディレクトリを抜けます。

root@www:nagios-plugins-2.1.4# cd

Nagiosプラグイン展開先ディレクトリを削除します。

root@www:~# rm -rf nagios-plugins-2.1.4

ダウンロードしたファイルを削除します。

root@www:~# rm -f nagios-plugins-2.1.4.tar.gz

Nagios設定

nagios.cfgを設定します。

root@www:~# vi /usr/local/nagios/etc/nagios.cfg

51行目:行頭の「#」を削除してコメント解除し、サーバー監視設定有効化の設定します。

cfg_dir=/usr/local/nagios/etc/servers

1094行目:日付書式をYYYY-MM-DD HH:MM:SSにするを設定します。

date_format=iso8601

サーバー監視設定ファイル格納ディレクトリを作成します。

root@www:~# mkdir /usr/local/nagios/etc/servers

contacts.cfgを設定します。

root@www:~# vi /usr/local/nagios/etc/objects/contacts.cfg

34行目:管理者メールアドレスを指定を設定します。

define contact{
        contact_name                    nagiosadmin             ; Short name of user
        use                             generic-contact         ; Inherit default values from generic-contact template (defined above)
        alias                           Nagios Admin            ; Full name of user

        email                           root@localhost
        }

localhost.cfgを設定します。

root@www:~# vi /usr/local/nagios/etc/objects/localhost.cfg

141行目:SSH状態変化時に通知するを設定します。

define service{
        use                             local-service         ; Name of service template to use
        host_name                       localhost
        service_description             SSH
        check_command                   check_ssh
        notifications_enabled           1
        }

154行目:SSH状態変化時に通知するを設定します。

define service{
        use                             local-service         ; Name of service template to use
        host_name                       localhost
        service_description             HTTP
        check_command                   check_http
        notifications_enabled           1
        }

commands.cfgを設定します。

root@www:~# vi /usr/local/nagios/etc/objects/commands.cfg

29行目:nkfコマンドのメール本文文字化け対策の設定します。

# 'notify-host-by-email' command definition
define command{
        command_name    notify-host-by-email
        command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/nkf -j | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
        }

35行目:nkfコマンドのメール本文文字化け対策の設定します。

# 'notify-service-by-email' command definition
define command{
        command_name    notify-service-by-email
        command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /usr/bin/nkf -j | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
        }

Apache2設定

Nagios用Apache2設定ファイルを設定します。

root@www:~# vi /etc/apache2/sites-available/nagios.conf

16行目:追記します。

      <RequireAny>

17行目:行頭に「#」を追記してコメント化し、内部からのみアクセス可能にする設定をします。

#         Require all granted

19行目:内部ネットワーク(192.168.1.1/24)からのみアクセス可能にする設定をします。

         Require ip 192.168.1.1/24

20行目:追記します。

      </RequireAny>

49行目:追記します。

      <RequireAny>

50行目:行頭に「#」を追記してコメント化し、内部からのみアクセス可能にする設定をします。

#         Require all granted

52行目:内部ネットワーク(192.168.1.1/24)からのみアクセス可能にする設定をします。

         Require ip 192.168.1.1/24

53行目:追記します。

      </RequireAny>

Webサーバー設定反映を設定します。

root@www:~# systemctl restart apache2

Nagios管理ユーザー(nagiosadmin)を作成します。

root@www:~# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

パスワードを設定します。

New password:
Re-type new password:
Adding password for user nagiosadmin

Nagios起動

起動します。

root@www:~# systemctl restart nagios

Webブラウザを起動し、「http://ubuntuserver.jp/nagios/」にアクセスし、管理ユーザー:nagiosadmin、登録済パスワードでログインして動作確認をします。

nagios

Ubuntu18:ログ解析設定

Webアクセスログ解析(AWStats)のインストール

AWStatsをインストールします。

root@www:~# apt -y install awstats

ファイルを設定します。

root@www:~# vi /etc/awstats/awstats.ubuntuserver.jp.conf 

125行目:変更します。

LogFormat=1

156行目:ホスト名を設定します。

SiteDomain="ubuntuserver.jp"

171行目:除外したドメイン名やIPアドレスを追記します。

HostAliases="localhost 127.0.0.1 REGEX[^.*ubuntuserver\.jp$] REGEX[^192\.168\.1\.]"

ファイルを作成します。

root@www:~# cp /usr/share/doc/awstats/examples/apache.conf /etc/apache2/conf-available/awstats.conf

ファイルを設定します。

root@www:~# vi /etc/apache2/conf-available/awstats.conf 

12行目、21行目、30行目:アクセス許可IPを追記します。

        Allow from 192.168.1.1/24

45行目:行頭に「#」を追記してコメント化します。

#ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

設定有効にします。

root@www:~# a2enconf awstats serve-cgi-bin

再起動します。

root@www:~# systemctl restart apache2
root@www:~# sed -i -e "s/www-data/root/g" /etc/cron.d/awstats

10分毎に自動更新する設定をします。

root@www:~# /usr/share/awstats/tools/update.sh

Web ブラウザを起動し、「http://ubuntuserver.jp/cgi-bin/awstats.pl」にアクセスして、作動確認します。

awstats

メールログ解析(Pfiogsumm)のインストール

pflogsumm をインストールします。

root@www:~# apt -y install pflogsumm

メールログのサマリーを出力します。

root@www:~# perl /usr/sbin/pflogsumm -d yesterday /var/log/maillog
Postfix log summaries for Jul 29

Grand Totals
------------
messages

      8   received
      8   delivered
      2   forwarded
      1   deferred  (1  deferrals)
      0   bounced
      0   rejected (0%)
      0   reject warnings
      0   held
      0   discarded (0%)

   2428k  bytes received
   2429k  bytes delivered
      3   senders
      2   sending hosts/domains
      2   recipients
      2   recipient hosts/domains


Per-Hour Traffic Summary
------------------------
    time          received  delivered   deferred    bounced     rejected
    --------------------------------------------------------------------
    0000-0100           0          0          0          0          0
    0100-0200           0          0          0          0          0
    0200-0300           0          0          0          0          0
…

root宛てにメール送信する設定をします。

root@www:~# crontab -e

最終行に毎日午前1時にメール送信する設定を追記します。

00 01 * * * perl /usr/sbin/pflogsumm -e -d yesterday /var/log/mail.log | mail -s 'Logwatch for Postfix' root

Ubuntu18:MAILサーバー設定

Postfixの設定

外部からWebアクセスできるようにします。

root@www:~# vi /etc/apache2/sites-available/virtualhost-00-ubuntuserver.jp.conf
<VirtualHost *:80>
    ServerName ubuntuserver.jp
    DocumentRoot /var/www/html
    ServerAlias mail.ubuntuserver.jp
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^ubuntuserver\.jp
    RewriteRule ^(.*)$ http://ubuntuserver.jp/$1 [R=301,L]
</VirtualHost>

Postfixをインストールします。

root@www:~# apt -y install postfix

Postfixを設定します。

root@www:~# cp /usr/share/postfix/main.cf.dist /etc/postfix/main.cf
root@www:~# vi /etc/postfix/main.cf

78行目:行頭の「#」を削除してコメント解除します。

mail_owner = postfix

94行目:行頭の「#」を削除してコメント解除し、メールサーバードメイン名を指定します。

myhostname = mail.ubuntuserver.jp

102行目:行頭の「#」を削除してコメント解除し、ドメイン名を指定します。

mydomain =  ubuntuserver.jp

123日行目:行頭の「#」を削除してコメント解除し、送信元メールアドレスにドメイン名を指定します。

myorigin = $mydomain

137行目:行頭の「#」を削除してコメント解除します。

inet_interfaces = all

185行目:行頭の「#」を削除してコメント解除し、ドメインメールを受信する設定に変更します。

mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

228行目:行頭の「#」を削除してコメント解除します。

local_recipient_maps = unix:passwd.byname $alias_maps

270行目:行頭の「#」を削除してコメント解除します。

mynetworks_style = subnet

287行目:ネットワーク設定を追記します。

mynetworks = 127.0.0.0/8, 192.168.1.1/24

407行目:行頭の「#」を削除してコメント解除します。

alias_maps = hash:/etc/aliases

418行目:行頭の「#」を削除してコメント解除します。

alias_database = hash:/etc/aliases

440行目:行頭の「#」を削除してコメント解除し、メール格納形式をMaildir形式にする設定をします。

home_mailbox = Maildir/

576行目:行頭に「#」を追記してコメント化します。

#smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)

577行目:メールサーバーソフト名の隠蔽化の設定を追記します。

smtpd_banner = $myhostname ESMTP unknown

650行目:sendmailパスの設定を追記します。

sendmail_path = /usr/sbin/postfix

655行目:メールの転送の設定を追記します。

newaliases_path = /usr/bin/newaliases

660行目:メールキューの設定を追記します。

mailq_path = /usr/bin/mailq

666行目:送信メッセージの一時格納場所のグループの設定を追記します。

setgid_group = postdrop

670行目:行頭に「#」を追記してコメント化します。

#html_directory =

674行目:行頭に「#」を追記してコメント化します。

#manpage_directory =

679行目:行頭に「#」を追記してコメント化します。

#sample_directory =

683行目:行頭に「#」を追記してコメント化します。

#readme_directory =

SMTP認証の設定を最終行へ追加します。

smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
smtpd_recipient_restrictions = permit_mynetworks, permit_auth_destination, permit_sasl_authenticated, reject

受信メールサイズを10MB=10*1024*1024に制限する設定を最終行へ追記します。

message_size_limit = 10485760

master.cfを設定します。

root@www:~# vi /etc/postfix/master.cf

17行目:行頭の「#」を削除してコメント解除します。

submission inet n    -    n    -    -    smtpd

20行目:行頭の「#」を削除してコメント解除します。

 -o smtpd_sasl_auth_enable=yes

設定を有効にします。

root@www:~# newaliases

再起動します。

root@www:~# systemctl restart postfix

Dovecotのインストール

root@www:~# apt -y install dovecot-core dovecot-pop3d dovecot-imapd

dovecot.confを設定します。

root@www:~# vi /etc/dovecot/dovecot.conf

30行目:行頭「#」を削除してコメント解除し、IPv6を無効にする設定に変更します。

listen = *

10-mail.confを設定します。

root@www:~# vi /etc/dovecot/conf.d/10-mail.conf

30行目:メール格納形式をMaildir形式にする設定に変更します。

mail_location = maildir:~/Maildir

10-auth.confを設定します。

root@www:~# vi /etc/dovecot/conf.d/10-auth.conf

10行目:行頭「#」を削除してコメント解除し、プレインテキスト認証を許可する設定を追記します。

disable_plaintext_auth = no

100行目:追記します。

auth_mechanisms = plain login

10-master.confを設定します。

root@www:~# vi /etc/dovecot/conf.d/10-master.conf

96~98行目:行頭「#」を削除してコメント解除し追記します。

# Postfix smtp-auth
unix_listener /var/spool/postfix/private/auth {
    mode = 0666
    user = postfix
    group = postfix
}

10-ssl.confを設定します。

root@www:~# vi /etc/dovecot/conf.d/10-ssl.conf

6行目:SSL接続を無効にする設定に変更します。

ssl = no

起動します。

root@www:~# systemctl restart dovecot

SMTP認証設定

cyrus-saslをインストールします。

root@www:~# apt -y install sasl2-bin cyrus-sasl-plain

起動します。

root@www:~# systemctl start saslauthd

Maildir形式メールボックスの作成

新規ユーザー追加時に自動でMaildir形式メールボックス作成する設定をします。

root@www:~# mkdir -p /etc/skel/Maildir/{new,cur,tmp}

メールボックスパーミッションを設定します。

root@www:~# chmod -R 700 /etc/skel/Maildir/

起動します。

root@www:~# systemctl restart postfix

現在のユーザーのMaildir形式メールボックス作成する設定をします。

[root@www ~]# wget https://rcg.jp/perfect_maildir/perfect_maildir.pl -O /usr/local/bin/perfect_maildir.pl
[root@www ~]# chmod +x /usr/local/bin/perfect_maildir.pl

Maildir変換に必要なPerlのTimeDateモジュールをインストールします。

[root@www ~]# apt -y install perl-TimeDate

Postfixを停止します。

[root@www ~]# systemctl stop postfix

Maildir一括変換スクリプトを作成します。

[root@www ~]# vi migrate-maildir.sh
#!/bin/bash
#
#Maildir一括変換スクリプト
#
#メールボックス=>Maildir形式変換スクリプト
#http://perfectmaildir.home-dn.net/
FOLDERCONVERT=/usr/local/bin/perfect_maildir.pl
#一般ユーザリスト
USERLIST=`ls /home/`
#ログ
MIGRATELOG=/tmp/migrate-maildir.log
rm -f $MIGRATELOG
#引数(変換元メールボックス形式)チェック
if [ "$1" != "mbox" ] && [ "$1" != "Mailbox" ]; then
echo "Usage: migrate-maildir.sh {mbox|Mailbox}"
exit
fi
#一般ユーザメールボックス移行
for user in $USERLIST;
do
if [ "$1" = "mbox" ]; then
inbox="/var/spool/mail/${user}"
else
inbox="/home/${user}/Mailbox"
fi
if [ -f "${inbox}" ]; then
newdir="/home/${user}/Maildir/"
mkdir -p "$newdir"
mkdir -p "$newdir"/cur
mkdir -p "$newdir"/new
mkdir -p "$newdir"/tmp
chmod -R 700 "${newdir}"
$FOLDERCONVERT "$newdir" < "${inbox}" >> $MIGRATELOG 2>&1
chown -R ${user}. "$newdir"
find "$newdir" -type f -exec chmod 600 {} \;
fi
done
#rootユーザメールボックス移行
user="root"
if [ "$1" = "mbox" ]; then
inbox="/var/spool/mail/${user}"
else
inbox="/${user}/Mailbox"
fi
if [ -f "${inbox}" ]; then
newdir="/${user}/Maildir/"
mkdir -p "$newdir"
mkdir -p "$newdir"/cur
mkdir -p "$newdir"/new
mkdir -p "$newdir"/tmp
chmod -R 700 "${newdir}"
$FOLDERCONVERT "$newdir" < "${inbox}" >> $MIGRATELOG 2>&1
chown -R ${user}. "$newdir"
find "$newdir" -type f -exec chmod 600 {} \;
fi
[ -a $MIGRATELOG ] && cat $MIGRATELOG;rm -f $MIGRATELOG

一括変換スクリプトを実行します。

[root@www ~]# sh migrate-maildir.sh mbox

Maildir一括変換スクリプトを削除します。

[root@www ~]# rm -f migrate-maildir.sh

Maildir変換ツールを削除します。

[root@www ~]# rm -f /usr/local/bin/perfect_maildir.pl

起動します。

[root@www ~]# systemctl restart postfix dovecot

webmasterユーザーをメール使用する場合は「/etc/aliases」を変更します。

[root@www ~]# vi /etc/aliases

行頭に#を追加して転送を無効にします。

#webmaster: root

転送設定を反映します。

[root@www ~]# newaliases

TCP25番、TCP587番ポート開放

ルーターの設定で、TCP25番、TCP587番ポートを開放します。(設定方法はご自身の環境に合わせて調べてください。

ポート開放テスト

こちらのサイトで「ホスト名(ubuntuserver.jp)」、「ポート番号(25,587)」の開放確認をします。

メールサーバーのOP25B対策

メールサーバーのOP25B対策として送信メールをGmailを経由して送信するように設定します。

Postfixを設定します。

root@www:~# vi /etc/postfix/main.cf

以下を最終行へ追加します。

relayhost = [smtp.gmail.com]:587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_tls_security_options = noanonymous
smtp_sasl_mechanism_filter = plain

SMTP認証情報を設定します。

root@www:~# echo [smtp.gmail.com]:587 Gmailアドレス:Gmailパスワード > /etc/postfix/sasl_passwd

root以外参照できないようにパーミッション変更します。

root@www:~# chmod 640 /etc/postfix/sasl_passwd

SMTP認証情報をデータベース化します。

root@www:~# postmap /etc/postfix/sasl_passwd

Postfixを再起動します。

root@www:~# systemctl reload postfix

Gmailのメール転送設定

先にThunderbirdへGmail(送信用メール)を設定します。

Thunderbirdを起動し、送信用メールアドレスで「ブロックされたログインについてご確認ください」を開き、「安全性の低いアプリへのアクセスを許可」をクリックします。

Gmailのメール転送設定

ブラウザでGmailにログインします。

Gmailにログイン

右上のユーザーアイコンを右クリック→「Googleアカウントの管理」→「セキュリティ」→「安全性の低いアプリのアクセス」でアクセスを有効にします。

安全性の低いアプリの許可を有効

TCP110番またはTCP143番ポート開放

ルーターの設定で、TCP110番またはTCP143番ポートを開放します。(設定方法はご自身の環境に合わせて調べてください。

ポート開放テスト

こちらのサイトで「ホスト名(ubuntuserver.jp)」、「ポート番号(110または143)」の開放確認をします。

メールユーザーの追加

ユーザーを追加します。(ユーザー例:ubuntu)

root@www:~# useradd ubuntu

パスワードを設定します。

root@www:~# passwd ubuntu
Changing password for user ubuntu.
New UNIX password:
Retype new UNIX password:

「/etc/ssh/sshd_config」を編集して、秘密鍵での認証接続を無効にする

sshd_configを編集します。

root@www:~# vi /etc/ssh/sshd_config

56行目:「no」→「yes」に変更します。

PasswordAuthentication yes

SSHを再起動します。

root@www:~# systemctl restart sshd

TeraTermにubuntuで新しい接続をします。

SSHサーバー公開鍵認証方式接続の設定をします。

メールソフトの登録

Thunderbirdを起動し、メールをクリックします。

Thunderbird

あなたのお名前、メールアドレス(ubuntu@ubuntuserver.jp)、パスワードを入力し、「続ける」をクリックします。

メールアドレス

「手動設定」をクリックします。

手動設定

サーバーのホスト名 ポート番号 SSL 認証方式
受信サーバー POP3 mail.ubuntuserver.jp 110 接続の保護なし 通常のパスワード認証
送信サーバー SMTP mail.ubuntuserver.jp 587 接続の保護なし 通常のパスワード認証

上の表を参考にして設定し、「完了」をクリックします。

完了

「接続する上での危険性を理解しました」を選択して「完了」をクリックします。

接続する上での危険性を理解しました

サーバー証明書の取得

Certbotをインストールします。

root@www:~# apt -y install certbot

証明書を取得します。

ドキュメントルート:/var/www/html/

メールアドレス:webmasterubuntuerver.jp

メールサーバー名:mail.ubuntuserver.jp

root@www:~# certbot certonly --webroot -w /var/www/html/ -m webmaster@ubuntuserver.jp  -d mail.ubuntuserver.jp --agree-tos

証明書自動更新を設定します。

root@www:~# vi /etc/cron.d/letsencrypt

下記を追記します。

00 16 * * 2 root /usrobin/certbot renew --post-hook "service httpd restart"

SSLの設定

main.cfを設定します。

root@www:~# vi /etc/postfix/main.cf

下記を最終行に追記します。

smtp_tls_security_level = may
smtpd_tls_security_level = may
smtpd_tls_cert_file = /etc/letsencrypt/live/mail.ubuntuserver.jp/fullchain.pem
smtpd_tls_key_file = /etc/letsencrypt/live/mail.ubuntuserver.jp/privkey.pem
smtpd_tls_session_cache_database = btree:/var/lib/postfix/smtpd_scache

tls_high_cipherlist = kEECDH:+kEECDH+SHA:kEDH:+kEDH+SHA:+kEDH+CAMELLIA:kECDH:+kECDH+SHA:kRSA:+kRSA+SHA:+kRSA+CAMELLIA:!aNULL:!eNULL:!SSLv2:!RC4:!MD5:!DES:!EXP:!SEED:!IDEA:!3DES
smtp_tls_ciphers = high
smtpd_tls_ciphers = high
smtpd_tls_mandatory_ciphers = high

smtpd_tls_mandatory_protocols=!SSLv2,!SSLv3
smtp_tls_mandatory_protocols=!SSLv2,!SSLv3
smtpd_tls_protocols=!SSLv2,!SSLv3
smtp_tls_protocols=!SSLv2,!SSLv3

master.cfを設定します。

root@www:~# vi /etc/postfix/master.cf

17行目:行頭に「#」を追加してコメント化し、SUBMISSIONポートを無効化します。

#submission inet n    -    n    -    -    smtpd

20行目:行頭に「#」を追加してコメント化し、SUBMISSIONポートのSMTP認証を無効化します。

#  -o smtpd_sasl_auth_enable=yes

29行目:行頭の「#」を削除してコメント解除し、SMTPSを有効化します。

smtps    inet n    -    n    -    -    smtpd

31行目:行頭の「#」を削除してコメント解除し、SMTPSを有効化します。

 -o smtpd_tls_wrappermode=yes

32行目:行頭の「#」を削除してコメント解除し、SMTPSを有効化します。

 -o smtpd_sasl_auth_enable=yes

45行目:行頭の「#」を削除してコメント解除し、SMTPSを有効化します。

tlsmgr    unix    -    -    n    300    1    tlsmgr

再起動します。

root@www:~# systemctl restart postfix

TCP465番ポート開放

ルーターの設定で、TCP465番ポートを開放します。(設定方法はご自身の環境に合わせて調べてください。

ポート開放テスト

こちらのサイトで「ホスト名(mail.ubuntuserver.jp)」、「ポート番号(465)」の開放確認をします。

TCP587番ポート閉鎖

ルーターの設定で、TCP587番ポートを閉鎖します。(設定方法はご自身の環境に合わせて調べてください。

ポート開放テスト

こちらのサイトで「ホスト名(mail.ubuntuserver.jp)」、「ポート番号(587)」の開放されていないことを確認をします。

Dovecot設定

10-auth.confを設定します。

root@www:~# vi /etc/dovecot/conf.d/10-ssl.conf

6行目:SSL接続を有効にする設定に変更します。

ssl = yes

12行目:行頭の「#」を削除してコメント解除し、サーバー証明書+中間証明書を指定します。

ssl_cert = </etc/letsencrypt/live/mail.ubuntuserver.jp/fullchain.pem

13行目:行頭の「#」を削除してコメント解除し、秘密鍵を指定します。

ssl_key = </etc/letsencrypt/live/mail.ubuntuserver.jp/privkey.pem

49行目:行頭の「#」を削除してコメント解除し、脆弱性のある暗号化方式(SSLv2,SSLv3)を無効化します。

ssl_protocols = !SSLv2 !SSLv3

52行目:行頭の「#」を削除してコメント解除し、使用する暗号化方法を指定します。

ssl_cipher_list = EECDH+AESGCM+AES128:EECDH+AESGCM+AES256:EDH+AESGCM+AES128:EDH+AESGCM+AES256:EECDH+SHA256+AES128:EECDH+SHA384+AES256:EDH+SHA256+AES128:EDH+SHA256+AES256:EECDH+SHA1+AES128:EECDH+SHA1+AES256:EDH+SHA1+AES128:EDH+SHA1+AES256:EECDH+HIGH:EDH+HIGH:AESGCM+AES128:AESGCM+AES256:SHA256+AES128:SHA256+AES256:SHA1+AES128:SHA1+AES256:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!KRB5:!aECDH:!3DES

再起動します。

root@www:~# systemctl restart dovecot

TCP995番またはTCP993番ポート開放

ルーターの設定で、TCP995番またはTCP993番ポートを開放します。(設定方法はご自身の環境に合わせて調べてください。

ポート開放テスト

こちらのサイトで「ホスト名(mail.ubuntuserver.jp)」、「ポート番号(995または993)」の開放確認をします。

メールソフトの設定変更

Thunderbirdを起動し、メールアドレスを選択し、「このアカウントの設定を表示する」をクリックします。

このアカウントの設定を表示する

「サーバー設定」をクリックし、「接続の保護」で「SSL/TLS」を選択します。

サーバー設定

「送信(SMTP)サーバー」をクリックし、SMTPサーバーを選択して「編集」をクリックします。

送信(SMTP)サーバー

「ポート番号」に「465」を入力し、「接続の保護」で「SSL/TLS」を選択して、「OK」をクリックします。

ポート番号

「OK」をクリックします。

「OK」をクリック

アンチウィルスソフトの連携(Clamav)

Clamav をインストールします。

root@www:~# apt -y install clamav-daemon clamsmtp

clamsmtpd.confを設定します。

root@www:~# vi /etc/clamsmtpd.conf

27行目:行頭の「#」を削除してコメント解除します。

Header: X-AV-Checked: ClamAV using ClamSMTP

45行目:変更します。

User: clamav

設定を有効にします。

root@www:~# chown -R clamav. /var/spool/clamsmtp
root@www:~# chown -R clamav. /var/run/clamsmtp

main.cfを設定します。

root@www:~# vi /etc/postfix/main.cf

最終行へ追記します。

content_filter = scan:127.0.0.1:10026

master.cfを設定します。

root@www:~# vi /etc/postfix/master.cf

最終行へ追記します。

scan unix - - n - 16 smtp
-o smtp_data_done_timeout=1200
-o smtp_send_xforward_command=yes
-o disable_dns_lookups=yes
127.0.0.1:10025 inet n - n - 16 smtpd
-o content_filter=
-o local_recipient_maps=
-o relay_recipient_maps=
-o smtpd_restriction_classes=
-o smtpd_client_restrictions=
-o smtpd_helo_restrictions=
-o smtpd_sender_restrictions=
-o smtpd_recipient_restrictions=permit_mynetworks,reject
-o mynetworks_style=host
-o smtpd_authorized_xforward_hosts=127.0.0.0/8

再起動します。

root@www:~# systemctl restart clamav-daemon clamsmtp postfix

Ubuntu18:FTPサーバー設定

Vsftpd のインストール

Vsftpd をインストールします。

root@www:~# apt -y install vsftpd

Vsftpd を設定します。

root@www:~# vi /etc/vsftpd.conf

31行目:行頭の「#」を削除してコメント解除します。

write_enable=YES

99,100行目:行頭の「#」を削除してコメント解除し、アスキーモードでの転送を許可します。

ascii_upload_enable=YES
ascii_download_enable=YES

122,123行目:行頭の「#」を削除しコメント解除し、chrootを有効にします。

chroot_local_user=YES
chroot_list_enable=YES

125行目:行頭の「#」を削除しコメント解除し、リストファイルを指定します。

chroot_list_file=/etc/vsftpd/chroot_list

131行目:行頭の「#」を削除しコメント解除し、ディレクトリ転送を有効にします。

ls_recurse_enable=YES

ローカルタイム指定を最終行に追記します。

seccomp_sandbox=NO

上層への移動を許可するユーザーを追加します。

root@www:~# vi /etc/vsftpd.chroot_list

ユーザー名を追記します。

webmaster

「/var/www/html」の書き込みを許可します。

root@www:~# chmod 0777 /var/www/html

起動します。

root@www:~# systemctl restart vsftpd

FTPクライアントの設定

ドキュメントルート所有者を確認します。

「FFFTP」をダウンロード・インストールし、起動します。

FFFTP

FFFTP

「接続」をクリックします。

接続

「接続」をクリックします。

接続

「新規ホスト」をクリックします。

新規ホスト

「ホストの設定名」に分かりやすい名前を決めて入力します。

ホストの設定名

「ホスト名(192.168.1.3)」を入力します。

ホスト名

「ユーザー名(webmaster)」を入力します。

ユーザー名

「パスワード」を入力します。

パスワード

「OK」をクリックします。

「OK」をクリック

Ubuntu18:データベース設定

MariaDB の インストール

MariaDB をインストールします。

root@www:~# apt -y install mariadb-server mariadb-client

初期設定します。

root@www:~# mysql_secure_installation

下記の表示後、「Enter」を押下します。

Enter current password for root (enter for none):

root パスワードを設定します。

Set root password? [Y/n] y
New password:
Re-enter new password:

「y」で応答します。

Remove anonymous users? [Y/n] y

「y」で応答します。

Disallow root login remotely? [Y/n] y

「y」で応答します。

Remove test database and access to it? [Y/n] y

「y」で応答します。

Reload privilege tables now? [Y/n] y

MariaDBにrootユーザーで接続します。

root@www:~# mysql -u root -p
Enter password:

ユーザー情報一覧を表示します。

MariaDB [(none)]> select user,host,password from mysql.user;
+------+-----------+-------------------------------------------+
| user | host      | password                                  |
+------+-----------+-------------------------------------------+
| root | localhost | ***************************************** |
| root | 127.0.0.1 | ***************************************** |
| root | ::1       | ***************************************** |
+------+-----------+-------------------------------------------+
3 rows in set (0.00 sec)

データベース一覧を表示します。

MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

終了します。

MariaDB [(none)]> exit

phpMyAdmin のインストール

apache2をインストールしておきます。

PHP をインストールしておきます。

phpMyAdminをインストールします。

root@www:~# apt -y install phpmyadmin php-gettext

↑ ↓キーで「apache2」に移動しスペースキーで選択し、Tabキーで「了解」を選択し「Enter」キーを押下します。

← →キーで「はい」を選択し、「Enter」キーを押下します。

パスワードを設定し、Tabキーで「了解」を選択し「Enter」キーを押下します。

パスワードを再入力し、Tabキーで「了解」を選択し「Enter」キーを押下します。

phpMyAdminを設定します。

root@www:~# vi /etc/phpmyadmin/apache.conf

8行目:アクセス許可IPを追記します。

    Require ip 127.0.0.1 192.168.1.1/24

MariaDB にログインします。

root@www:~# ysql -u root -p mysql 
Enter password:

root でログインするための設定に変更します。

MariaDB [mysql]> update mysql.user set plugin='' where user='root';

設定を有効化します。

MariaDB [mysql]> flush privileges;

ログアウトします。

MariaDB [mysql]> exit

再起動します。

root@www:~# systemctl restart apache2

Webブラウザを起動し、「http://ubuntuserver.jp/phpmyadmin/」にアクセスし、登録したユーザーで認証してログインします。(管理画面から MariaDB を操作することができます。)

phpmyadmin

Ubuntu18:Webサーバー設定

Apache2のインストール

Apache2 をインストールします。

root@www:~# apt -y install apache2

ウェルカムページを削除します。

root@www:~# rm -f /var/www/html/index.html

security.confの設定します。

root@www:~# vi /etc/apache2/conf-enabled/security.conf

25行目:変更します。

ServerTokens Prod

dir.confの設定します。

root@www:~# vi /etc/apache2/mods-enabled/dir.conf

2行目:ディレクトリ名のみでアクセスできるファイル名を追記します。

DirectoryIndex index.html index.cgi index.pl index.php index.rb index.py index.xhtml index.htm

apache2.confの設定します。

root@www:~# vi /etc/apache2/apache2.conf

70行目:サーバー名追記します。

ServerName ubuntuserver.jp

000-default.confの設定します。

root@www:~# vi /etc/apache2/sites-enabled/000-default.conf

11行目:管理者アドレス変更します。

ServerAdmin webmaster@ubuntuserver.jp

ドキュメントルート所有者を編集ユーザー(webmaster)に変更します。

root@www:~# chown webmaster. /var/www/html/

ドキュメントルート所有者を確認します。

root@www:~# ll /var/www/
合計 0
drwxr-xr-x 2 root root 6 4月 24 22:46 cgi-bin
drwxr-xr-x 2 webmaster webmaster 6 4月 24 22:46 html

URLのwwwを設定します。

root@www:~# vi /etc/apache2/sites-available/virtualhost-00-ubuntuserver.jp.conf

wwwなしに統一します。

<VirtualHost *:80>
    ServerName ubuntuserver.jp
    DocumentRoot /var/www/html
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www\.ubuntuserver\.jp
    RewriteRule ^(.*)$ http://ubntuserver.jp/$1 [R=301,L]
</VirtualHost>

再起動します。

root@www:~# systemctl restart apache2

HTMLテストページを作成します。

root@www:~# vi /var/www/html/index.html
<html>
<body>
<div style="width: 100%; font-size: 20px; font-weight: bold; text-align: center;">
Test Page
</div>
</body>
</html>

Webブラウザを起動し、「http://ubuntuserver.jp」にアクセスし、動作確認をします。

Webブラウザを起動

TCP80番ポート開放

ルーターの設定で、TCP80番ポートを開放します。(設定方法はご自身の環境に合わせて調べてください。

ポート開放テスト

開放確認サイトで「ホスト名(linuxserver.jp)」、「ポート番号(80)」の開放確認をします。

Perlのインストール

Perl をインストールします。

root@www:~# apt -y install perl

CGI モジュールを有効にします。

root@www:~# a2enmod cgi

apache2を再起動します。

root@www:~# systemctl restart apache2

「html」ディレクトリで CGI の実行を許可する設定します。

root@www:~# vi /etc/apache2/conf-available/html.conf

拡張子 cgi、pl、rb、py を CGI として設定します。

<Directory "/var/www/html">
    Options +ExecCGI
    AddHandler cgi-script .cgi .pl .rb .py
</Directory>

拡張子の設定を有効にします。

root@www:~# a2enconf html

「/usr/local/bin/perl」で、Perlコマンドへアクセスできるようにします。

root@www:~# ln -s /usr/bin/perl /usr/local/bin/perl

Perlのパスを確認します。

root@www:~# whereis perl
perl: /usr/bin/perl /usr/local/bin/perl /usr/share/man/man1/perl.1.gz

再起動します。

root@www:~# systemctl restart apache2

CGIテストページを作成します。

root@www:~# vi /var/www/html/index.cgi
#!/usr/bin/perl

print "Content-type: text/html\n\n";
print "<html>\n<body>\n";
print "<div style=\"width: 100%; font-size: 20px; font-weight: bold; text-align: center;\">\n";
print "CGI Test Page";
print "\n</div>\n";
print "</body>\n</html>\n";

パーミッションを設定します。

root@www:~# chmod 705 /var/www/html/index.cgi

Webブラウザを起動し、「http://ubuntuserver.jp/index.cgi」にアクセスし、動作確認をします。

Webブラウザを起動

PHPのインストール

PHP をインストールします。

root@www:~# apt -y install php php-cgi libapache2-mod-php php-common php-pear php-mbstring php-mysql

PHP を設定します。

root@www:~# a2enconf php7.2-cgi

apache2を再起動します。

root@www:~# systemctl restart apache2

php.iniを設定します。

root@www:~# vi /etc/php/7.2/apache2/php.ini

936行目:行頭の「;」を削除してコメント解除し、自身のタイムゾーンを追記します。

date.timezone = "Asia/Tokyo"

再起動します。

root@www:~# systemctl restart apache2

PHPテストページを作成します。

root@www:~# vi /var/www/html/index.php
<html>
<body>
<div style="width: 100%; font-size: 20px; font-weight: bold; text-align: center;">
<?php
print "PHP Test Page";
?>
</div>
</body>
</html>

Webブラウザを起動し、「http://ubuntuserver.jp/index.php」にアクセスし、動作確認をします。

Webブラウザを起動

Rubyのインストール

Ruby をインストールします。

root@www:~# apt -y install ruby

CGI モジュールを有効にします。

root@www:~# a2enmod cgi

再起動します。

root@www:~# systemctl restart apache2

Rubyテストページを作成します。

root@www:~# vi /var/www/html/index.rb
#!/usr/bin/ruby

print "Content-type: text/html\n\n";
print "<html>\n<body>\n";
print "<div style=\"width: 100%; font-size: 20px; font-weight: bold; text-align: center;\">\n";
print "Ruby Test Page";
print "\n</div>\n";
print "</body>\n</html>\n";

パーミッションを設定します。

root@www:~# chmod 705 /var/www/html/index.rb

Webブラウザを起動し、「http://ubuntuserver.jp/index.rb」にアクセスし、動作確認をします。

Webブラウザを起動

Pythonのインストール

Python をインストールします。

root@www:~# apt -y install python

CGI モジュールを有効にします。

root@www:~# a2enmod cgi

再起動します。

root@www:~# systemctl restart apache2

Python テストページを作成します。

root@www:~# vi /var/www/html/index.py
#!/usr/bin/env python

print "Content-type: text/html\n\n";
print "<html>\n<body>\n";
print "<div style=\"width: 100%; font-size: 20px; font-weight: bold; text-align: center;\">\n";
print "Python Test Page";
print "\n</div>\n";
print "</body>\n</html>\n";

パーミッションを設定します。

root@www:~# chmod 705 /var/www/html/index.py

Webブラウザを起動し、「http://ubuntuserver.jp/index.py」にアクセスし、動作確認をします。

Webブラウザを起動

Perlモジュールのインストール

ビルドツールをインストールします。

root@www:~# apt -y install build-essential

CPANを起動します。

root@www:~# perl -MCPAN -e shell

「y」を入力して「Enter」キー押下します。

Would you like to configure as much as possible automatically? [yes] y

チェックを入れて「OK」をクリックするとインストールログが表示されます。

モジュール名 説明
全て
Jcode 日本語文字コードの変換
Getopt::Long コマンドライン引数のオプションを処理する
Archive::Tar tarファイルの展開と作成(v5.10以降)
Cwd カレントディレクトリのパスを取得する
File::Basename ファイルのベース名とディレクトリ名の取得
File::Copy ファイルの移動とコピー
File::Path 複数階層のディレクトリの作成と削除
File::Spec ファイル名に対する移植性のある処理
File::Temp 一時ファイルの作成
File::Find ファイルの検索
FindBin スクリプトが存在するディレクトリのパスの取得
Encode 日本語などのマルチバイト文字列を適切に処理する
utf8 ソースコード内の文字列を内部文字列に変換
Carp モジュールの呼び出し元の観点で例外を発生させる
lib モジュールの検索パスの追加
Time::Piece 日付・時刻を扱うための標準モジュール(v5.10からコアモジュール)
Time::Local localtime,gmtimeの逆返還
base クラスの継承
Data::Dumper 変数の内容を出力する
Benchmark ベンチマーク(性能比較)を行う
JSON JSONデータの解析
MIME::Base64 Base64形式へのエンコード
MIME::QuotedPrint quoted-printable形式へのエンコード
Digest::MD5 MD5値を求める
Digest::SHA 各種SHA値を求める (v5.10以降)
Storable データのシリアライズ化
Scalar::Util スカラ値に関するユーティリティ
List::Util 配列に対するさまざまな操作
Hash::Uti ハッシュのキーの制限
Sys::Hostname ホスト名の取得
Net::FTP FTPクライアント
Net::Ping リモートホストの生存確認
Exporter 関数のエクスポート
CPAN CPANからモジュールをインストールする
Pod::Usage PODドキュメントの出力
Errno システムのエラー番号をあらわす定数
POSIX POSIXで定義された関数
Math::BigInt 大きな数の計算
Math::BigFloat 大きな数の計算
Mojolicious Webフレームワーク
Mojolicious::Plugin::AutoRoute ルートを自動的に生成
MIME::Lite メールを簡単に送信
Class::Accessor::Fast アクセサの作成
Object::Simple デフォルト値つきのアクセサの作成
DDP データをく出力する
DBIx::Custom データベース簡単操作
MySQL::Diff MySQLの差分を表示
DateTime 日付の汎用的な処理
PDL 統計解析
Imager 画像編集
Text::CSV::Encoded 日本語を含んだCSVファイルを取り扱う
Text::Diff テキストの差分確認
XML::Simple シンプルなXMLパーサ
Validator::Custom HTMLフォームの検証
Data::Page ページング処理の支援
Data::Page::Navigation ページのナビゲーションの作成
Module::Starter モジュールの雛形を作成する
Devel::NYTProf 使いやすいプロファイラ
perltidy ソースコードの整形
Net::Ping::External pingコマンドの実行
IO::ScalarArray 標準入力の自動試験
IO::Capture 標準出力、標準エラー出力の自動試験
FFI::Raw ダイナミックライブラリ内の関数を呼び出す
Math::Trig さまざまな三角関数
FFI::Platypus 機能豊富なFFIモジュール
Time::Moment 日付・時刻の高速な処理
CGI CGIモジュール
CGI::Carp HTTPD(またはその他)にエラーログを書込む
DBI 各種データベースをアクセスする
strict 文法チェックを厳しくする
LWP::UserAgent Web 上のデータに アクセスする
LWP::Protocol::https LWP::UserAgentでSSLに アクセスする
Net::SSLeay LWP::UserAgentでSSLに アクセスする
Net::SSL LWP::UserAgentでSSLに アクセスする
Crypt::SSLeay LWP::UserAgentでSSLに アクセスする
Encode::Guess 文字コードを判別
Image::ExifTool Exifの情報を取得する
Archive::Tar tar 展開、作成、ファイルの追加
Image::Magick ImageMagick のコマンドラインツール
Archive::Zip zip 展開、作成、ファイルの追加

モジュールをインストールします。

Terminal does not support AddHistory.

cpan shell -- CPAN exploration and modules installation (v2.11)
Enter 'h' for help.

cpan[1]>

ImageMagikのインストール

ImageMagickをインストールします。

root@www:~# apt -y install imagemagick

perl ImageMagickをインストールします。

root@www:~# apt -y install libimage-magick-perl

関連のライブラリをインストールします。

root@www:~# apt -y install libmagickwand-dev libmagickcore libmagickcore-dev libmagickwand-dev
root@www:~# apt -y install pkg-config
root@www:~# apt -y install php-dev

サーバー証明書の取得

Certbotをインストールします。

root@www:~# apt -y install certbot

証明書を取得します。

ドキュメントルート:/var/www/html/

メールアドレス:webmasterubuntuserver.jp

Webサーバー名:ubuntuserver.jp

root@www:~# certbot certonly --webroot -w /var/www/html/ -m webmaster@ubuntuserver.jp  -d centserver.jp --agree-tos

証明書自動更新を設定します。

root@www:~# vi /etc/cron.d/letsencrypt

下記を追記します。

00 16 * * 2 root /usr/bin/certbot renew --post-hook "service httpd restart"

SSLの設定

SSLを設定します。

root@www:~# vi /etc/apache2/sites-available/default-ssl.conf

3行目:管理者アドレス変更します。

ServerAdmin webmaster@ubuntuserver.jp

32行目:取得した証明書を指定します。

SSLCertificateFile /etc/letsencrypt/live/ubuntuserver.jp/cert.pem

33行目:取得した鍵ファイルを指定します。

SSLCertificateKeyFile /etc/letsencrypt/live/ubuntuserver.jp/privkey.pem

SSLを有効にします。

root@www:~# a2ensite default-ssl
root@www:~# a2enmod ssl

再起動します。

root@www:~# systemctl restart apache2

Free Monitoring Test Toolsで「https://ubuntuserver.jp」の作動確認をします。

Ubuntu18:DNSサーバー設定

インターフェース名を確認

インターフェース名を確認します。

root@www:~# nmcli device
デバイス タイプ 状態 接続
enp2s0 ethernet 管理無し --

BINDのインストール

BIND をインストールします。

root@www:~# apt -y install bind9 bind9utils bind9-doc bind9-host

BIND を設定します。

root@www:~# vi /etc/bind/named.conf

11行目:行頭に「#」を追記してコメント化します。

# include "/etc/bind/named.conf.default-zones";

最終行に追記します。

include "/etc/bind/named.conf.internal-zones";

内部向けの定義ファイルを作成します。

root@www:~# vi /etc/bind/named.conf.internal-zones

view "internal" {
        match-clients {
                localhost;
                192.168.1.1/24;
        };
        zone "ubuntuserver.jp" IN {
                type master;
                file "/etc/bind/ubuntuserver.jp.lan";
                allow-update { none; };
        };
        zone "1.168.192.in-addr.arpa" IN {
                type master;
                file "/etc/bind/1.168.192.db";
                allow-update { none; };
        };
        include "/etc/bind/named.conf.default-zones";
};

IPv4 のみの使用に設定します。

root@www:~# vi /etc/default/named

6行目:行頭に追記します。

OPTIONS="-u bind -4"

ゾーン情報の設定

内部向け正引き情報ファイルを作成します。

root@www:~# vi /etc/bind/ubuntuserver.jp.lan

$TTL 86400
@   IN  SOA     ubuntuserver.jp. root.ubuntuserver.jp. (
        2014071001  ;Serial
        3600        ;Refresh
        1800        ;Retry
        604800      ;Expire
        86400       ;Minimum TTL
)
        IN  NS      ubuntuserver.jp.
        IN  MX 10   ubuntuserver.jp.
@       IN  A       192.168.1.3
*       IN  A       192.168.1.3

内部向け逆引き情報ファイルを作成します。

root@www:~# vi /etc/bind/1.168.192.db

$TTL 86400
@   IN  SOA     ubuntuserver.jp. root.ubuntuserver.jp. (
        2014071001  ;Serial
        3600        ;Refresh
        1800        ;Retry
        604800      ;Expire
        86400       ;Minimum TTL
)
        IN  NS      ubuntuserver.jp.
        IN  A       255.255.255.0
3       IN  PTR     ubuntuserver.jp.

名前解決の問い合わせ等を設定します。

root@www:~# vi /etc/bind/named.conf.options

16行目:追記します。

allow-query { localhost; 192.168.1.1/24; };
allow-transfer { localhost; 192.168.1.1/24; };
allow-recursion { localhost; 192.168.1.1/24; };

26行目:変更します。

     listen-on-v6 { none; }

TCP/UDP53番ポート開放

ルーターの設定で、TCP/UDP53番ポートを開放します。(設定方法はご自身の環境に合わせて調べてください。

ポート開放テスト

こちらのサイトで「ホスト名(ubuntuserver.jp)」、「ポート番号(53)」の開放確認をします。

BINDの起動と作動確認

名前解決の参照先を変更します。

root@www:~# vi /etc/netplan/01-netcfg.yaml

8~10行目:「nameservers」を変更します。

        nameservers:
            addresses: [192.168.1.3,192.168.1.1]

変更を有効化します。

root@www:~# sudo netplan --debug generate
root@www:~# sudo netplan apply

自動起動を設定して再起動します。

[root@www ~]# systemctl enable --now named

エラーを確認します。

[root@www ~]# systemctl status named

エラーがある場合は構文の検証を行い、エラーを修正します。

192.168.1.1/24」にエラーがある場合は「localhost;」に変更してください。

[root@www ~]# sudo named-checkconf

作動を確認します。

root@www:~# dig ubuntuserver.jp

; <<>> DiG 9.9.4-RedHat-9.9.4-73.el7_6 <<>> ubuntuserver.jp
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 15234
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;ubuntuserver.jp.                                IN      A

;; ANSWER SECTION:
ubuntuserver.jp.                 86400   IN      A       192.168.1.3

;; AUTHORITY SECTION:
ubuntuserver.jp.                 86400   IN      NS      ubuntuserver.jp.

;; Query time: 18 msec
;; SERVER: 192.168.1.3#53(192.168.1.3)
;; WHEN: 水  7月 03 15:23:54 JST 2019
;; MSG SIZE  rcvd: 65


[root@www:~]# dig -x 192.168.1.3

; <<>> DiG 9.9.4-RedHat-9.9.4-73.el7_6 <<>> -x 192.168.1.3
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 54270
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;3.1.168.192.in-addr.arpa.      IN      PTR

;; ANSWER SECTION:
3.1.168.192.in-addr.arpa. 86400 IN      PTR     ubuntuserver.jp.

;; AUTHORITY SECTION:
1.168.192.in-addr.arpa. 86400   IN      NS      ubuntuserver.jp.

;; ADDITIONAL SECTION:
ubuntuserver.jp.                 86400   IN      A       192.168.1.3

;; Query time: 87 msec
;; SERVER: 192.168.1.3#53(192.168.1.3)
;; WHEN: 水  7月 03 16:13:36 JST 2019
;; MSG SIZE  rcvd: 103

ホームネットワーク内PCのDNSを設定変更

Windows10 スタートメニューを右クリックして「ネットワーク接続」をクリックします。

ネットワーク接続

「ネットワークと共有センター」をクリックします。

ネットワークと共有センター

「ローカルエリア接続」をクリックします。

ローカルエリア接続

「プロパティ」をクリックします。

プロパティ

「インターネットプロトコルバージョン4(TCP/IPv4)」を選択して「プロパティ」をクリックします。

インターネットプロトコルバージョン4

「次のDNSサーバーのアドレスを使う」を選択して「優先DNSサーバー」を「192.168.1.3」、「代替DNSサーバー」を「192.168.1.1」に設定し「OK」をクリックします。