第6章 ネットワークアプリケーション

目次

6.1. ウェッブブラウザー
6.1.1. Spoofing the User-Agent string
6.1.2. Browser extension
6.2. メールシステム
6.2.1. Eメールの基本
6.2.2. 現代的メールサービスの限界
6.2.3. Historic mail service expectation
6.2.4. メール転送エージェント (MTA)
6.2.4.1. exim4 設定
6.2.4.2. SASL を使う postfix の設定
6.2.4.3. メールアドレス設定
6.2.4.4. 基本的な MTA の操作
6.3. リーモートアクセスサーバーとユーティリティー (SSH)
6.3.1. SSH の基本
6.3.2. リモートホストでのユーザ名
6.3.3. リモートパスワード無しでの接続
6.3.4. 外部 SSH クライアントへの対処法
6.3.5. ssh-agent の設定
6.3.6. リモートホストからメールを送信する
6.3.7. SMTP/POP3 トンネルをするためのポートフォワーディング
6.3.8. SSH 上のリモートシステムをシャットダウンする方法
6.3.9. SSH のトラブルシュート
6.4. プリントサーバーとユーティリティー
6.5. 他のネットワークアプリケーションサーバー
6.6. 他のネットワークアプリケーションクライアント
6.7. システムデーモンの診断

ネットワーク接続を確立した (5章ネットワークの設定参照下さい) あとで、各種のネットワークアプリケーションを実行できます。

[ヒント] ヒント

最近の Debian に特化したネットワークインターフェースのガイドは、 The Debian Administrator's Handbook — Network Infrastructure を参照ください。

[ヒント] ヒント

もしどこかの ISP で "2段階認証" を有効にした場合、あなたのプログラムから POP や SMTP サービスにアクセスするアプリケーションパスワードを入手する必要があります。事前にあなたのホスト IP を許可する必要があるかもしれません。

多くのウェッブブラウザーパッケージがハイパーテキストトランスファープロトコル (HTTP) を使って遠隔コンテントにアクセスするために存在します。


This section focuses on typical mobile workstations on consumer grade Internet connections.

[注意] 注意

もしインターネットと直接メール交換するメールサーバーを設定するなら、このような初歩的文書が不要なぐらいシステムを熟知しているべきです。

email メッセージは、メッセージのエンベロープ(封筒)と、メッセージのヘッダーと、メッセージの本体との、 3 構成要素から成り立っています。

  • メッセージエンベロープ中の "To" (宛先)と "From" (差出人) 情報は SMTP が電子メールを配達するのに用いられます。(メッセージエンベロープの "From" 情報は バウンスアドレス、 From_、 等とも呼ばれます。)

  • メッセージヘッダー中の "To" (宛先)と "From" (差出人) 情報は email クライアント が email を表示するのに用いられます。(通常これらはメッセージエンベロープの情報と共通ですが、必ずしもそうとは限りません。)

  • The email message format covering header and body data is extended by Multipurpose Internet Mail Extensions (MIME) from the plain ASCII text to other character encodings, as well as attachments of audio, video, images, and application programs.

Full featured GUI based email clients offer all the following functions using the GUI based intuitive configuration.

  • It creates and interprets the message header and body data using Multipurpose Internet Mail Extensions (MIME) to deal the content data type and encoding.

  • It authenticates itself to the ISP's SMTP and IMAP servers using the legacy basic access authentication or modern OAuth 2.0. (For OAuth 2.0, set it via Desktop environment settings. E.g., "Settings" -> "Online Accounts".)

  • It sends the message to the ISP's smarthost SMTP server listening to the message submission port (587).

  • It receives the stored message on the ISP's server from the TLS/IMAP4 port (993).

  • 属性によってメールのフィルタリングができます。

  • 連絡先、カレンダー、タスク、メモといった追加の機能を提供することがあります。


スパム(迷惑メール)問題にさらされるのを最小化するために、現代的なメールサービスには様々な制限があります。

  • 確実にメールをリモートホストに直接送るために消費者用インターネット接続上で SMTP サーバーを実行するのは現実的ではありません。

  • A mail may be rejected by any host en route to the destination quietly unless it appears as authentic as possible.

  • 無関係の複数の送信元メールアドレスのメールを、単一のスマートホストを使って確実にリモートホストに送ることを期待するのは現実的ではありません。

なぜなら:

Debian mobile workstations can be configured just with full featured GUI based email clients without mail transfer agent (MTA) program after Debian 12 Bookworm.

Debian traditionally installed some MTA program to support programs expecting the /usr/sbin/sendmail command. Such MTA on mobile workstations must cope with 「現代的メールサービスの限界」 and 「Historic mail service expectation」.

For mobile workstations, the typical choice of MTA is either exim4-daemon-light or postfix with its installation option such as "Mail sent by smarthost; received via SMTP or fetchmail" selected. These are light weight MTAs that respect "/etc/aliases".

[ヒント] ヒント

Configuring exim4 to send the Internet mail via multiple corresponding smarthosts for multiple source email addresses is non-trivial. If you need such capability for some programs, set them up to use msmtp which is easy to set up for multiple source email addresses. Then leave main MTA only for a single email address.


スマートホスト経由のインターネットメールに関しては、exim4-* パッケージを次のように (再)設定します。

$ sudo systemctl stop exim4
$ sudo dpkg-reconfigure exim4-config

"General type of mail configuration" に関して、"スマートホストでメール送信; SMTP または fetchmail で受信する" を選択します。

"System mail name:" をそのデフォルトである FQDN (「ホスト名の解決」参照下さい) に設定します。

"IP-addresses to listen on for incoming SMTP connections:" をそのデフォルトである "127.0.0.1 ; ::1" と設定します。

"Other destinations for which mail is accepted:" の内容を消去します。

"Machines to relay mail for:" の内容を消去します。

"送出スマートホストの IP アドレスまたはホスト名:" を"smtp.hostname.dom:587" と設定します。

"Hide local mail name in outgoing mail?" に対して "No" を選択します。(この代わりに、「メールアドレス設定」にある "/etc/email-addresses" を使用します。)

"DNS クエリの数を最小限に留めますか (ダイヤルオンデマンド)?" に次の内のひとつの返答をします。

  • 起動時にインターネットに接続されている場合は、"No" とします。

  • 起動時にインターネットに接続されていない場合は、"Yes" とします。

"Delivery method for local mail:" を"mbox format in /var/mail/" と設定します。

"Split configuration into small files?:" に対して "Yes" を選択します。

"/etc/exim4/passwd.client" を編集しスマートホストのためのパスワードエントリーを作成します。

$ sudo vim /etc/exim4/passwd.client
 ...
$ cat /etc/exim4/passwd.client
^smtp.*\.hostname\.dom:username@hostname.dom:password

Configure exim4(8) with "QUEUERUNNER='queueonly'", "QUEUERUNNER='nodaemon'", etc. in "/etc/default/exim4" to minimize system resource usages. (optional)

次のようにして exim4 を起動します。

$ sudo systemctl start exim4

"/etc/exim4/passwd.client" 中のホスト名はエイリアスであってはいけません。真のホスト名は次の様にして確認できます。

$ host smtp.hostname.dom
smtp.hostname.dom is an alias for smtp99.hostname.dom.
smtp99.hostname.dom has address 123.234.123.89

エイリアス問題を回避するために "/etc/exim4/passwd.client" の中に正規表現を用いています。もし ISP がエイリアスで示されるホストを移動させても SMTP AUTH はおそらく動きます。

次のようにすれば exim4 の設定を手動で更新できます。

  • "/etc/exim4/" 中の exim4 設定ファイルの更新。

    • MACRO を設定するために "/etc/exim4/exim4.conf.localmacros" を作成し 、"/etc/exim4/exim4.conf.template" を編集します。(非分割設定)

    • "/etc/exim4/exim4.conf.d" サブディレクトリー中で、新規ファイルを作成したり既存ファイルを編集したりします。(分割設定)

  • "systemctl reload exim4" を実行します。

[注意] 注意

"DNS クエリの数を最小限に留めますか (ダイヤルオンデマンド)?" という debconf の質問に "No" (デフォールト値) が選ばれシステムがブート時にインターネットに繋がっていない場合、exim4 の起動は長い時間がかかります。

次に示す正式のガイドを読んで下さい: "/usr/share/doc/exim4-base/README.Debian.gz" と update-exim4.conf(8)。

[警告] 警告

For all practical consideration, use SMTP with STARTTLS on port 587 or SMTPS SSL (SMTPS) on port 465, instead of plain SMTP on port 25.

スマートホスト経由のインターネットメールに関しては postfix 文書と重要マニュアルページを読むことから始めるべきです。


postfixsasl2-bin パッケージを次のように (再)設定します。

$ sudo systemctl stop postfix
$ sudo dpkg-reconfigure postfix

"スマートホストを使ってインターネット" を選択します。

"SMTP リレーホスト (なければ空):" を "[smtp.hostname.dom]:587" と設定します。

$ sudo postconf -e 'smtp_sender_dependent_authentication = yes'
$ sudo postconf -e 'smtp_sasl_auth_enable = yes'
$ sudo postconf -e 'smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd'
$ sudo postconf -e 'smtp_sasl_type = cyrus'
$ sudo vim /etc/postfix/sasl_passwd

スマートホストのパスワードエントリーを作成します。

$ cat /etc/postfix/sasl_passwd
[smtp.hostname.dom]:587     username:password
$ sudo postmap hush:/etc/postfix/sasl_passwd

次に記すように postfix を起動します。

$ sudo systemctl start postfix

dpkg-reconfigure ダイアログと "/etc/postfix/sasl_passwd" の中で "[" と "]" を使うことで MX レコードを確認せずに指定された hostname その物を直接使うように確実にします。"/usr/share/doc/postfix/html/SASL_README.html" の中の "Enabling SASL authentication in the Postfix SMTP client" を参照下さい。

メールのトランスポートとデリバリーとユーザーのエージェントが使うメールアドレス設定ファイルが少々存在します。


通常 "/etc/mailname" ファイル中の mailname はホストの IP の一つとして解決できる完全修飾ドメイン名 (FQDN) です。解決できる IP アドレスのあるホスト名を持たない可動ワークステーションの場合には、この mailname を "hostname -f" に設定します。(これは exim4-*postfix の両方に有効な安全な選択肢です。)

[ヒント] ヒント

"/etc/mailname" の内容は多くの MTA 以外のプログラムによってそのデフォールト挙動のために使われます。mutt の場合、~/muttrc ファイル中の "hostname" と "from" 変数を設定して mailname の値をオーバーライドします。bts(1) や dch(1) 等の devscripts パッケージ中のプログラムの場合、環境変数の "$DEBFULLNAME" や "$DEBEMAIL" をエキスポートしてその値をオーバーライドします。

[ヒント] ヒント

通常 popularity-contest パッケージは root アカウントからメールを FQDN 付きで送信します。/usr/share/popularity-contest/default.conf に記載された様に /etc/popularity-contest.conf 中に MAILFROM を設定する必要があります。こうしないと、smarthost の SMTP サーバーによってあなたのメールは拒否されます。少々面倒ですが、root からの全メールの発信元を書き替えるより、この方法は安全ですし、他のデーモンや cron スクリプトに関してもこの方法を適用するべきです。

mailname を"hostname -f" と設定した時には、次によって MTA で発信元メールアドレスを偽装することが実現できます。

  • exim4(8) の場合、exim4-config_files(5) に説明されているように "/etc/email-addresses"

  • postfix(1) の場合、generic(5) に説明されているように "/etc/postfix/generic"

postfix の場合、次に記す追加ステップが必要です。

# postmap hash:/etc/postfix/generic
# postconf -e 'smtp_generic_maps = hash:/etc/postfix/generic'
# postfix reload

あなたのメール設定は次のようにするとテストできます。

  • exim(8) の場合、-brw, -bf, -bF, -bV, … オプションを使用

  • postmap(1) の場合、-q オプションを使用

[ヒント] ヒント

Exim はexiqgrep(8) や exipick(8) のようないくつかのユーティリティープログラムとともに供給されます。利用可能なコマンドは "dpkg -L exim4-base|grep man8/" を参照下さい。

セキュアーシェル (SSH) はインターネット経由で接続するセキュアーな方法です。Debian では、OpenSSH と呼ばれる フリーバージョンのSSH が openssh-clientopenssh-server パッケージとして利用可能です。

ssh(1) はユーザーにとってより賢明でよりセキュアーな telnet(1) として機能します。telnet コマンドと異なり、ssh コマンドは telnet エスケープ文字 (初期デフォールト CTRL-]) に出会うことで中断される事がありません。


Although shellinabox is not a SSH program, it is listed here as an interesting alternative for the remote terminal access.

See also 「Xサーバ接続」 for connecting to remote X client programs.

[注意] 注意

あなたの SSH がインターネットからアクセスできる場合には、「インターネットのためのセキュリティー強化策」を参照下さい。

[ヒント] ヒント

リモートのシェルプロセスが回線接続の中断の際にも継続するようにするために screen(1) プログラムを使いましょう (「screen プログラム」参照下さい)。

OpenSSH SSH デーモンは SSH プロトコル2のみをサポートします。

Please read "/usr/share/doc/openssh-client/README.Debian.gz", ssh(1), sshd(8), ssh-agent(1), and ssh-keygen(1), ssh-add(1) and ssh-agent(1).

[警告] 警告

OpenSSH サーバーを実行したい場合には、"/etc/ssh/sshd_not_to_be_run" が存在してはいけません。

Don't enable rhost based authentication (HostbasedAuthentication in /etc/ssh/sshd_config).


クライアントから ssh(1) 接続を開始するには以下のようにします。


"shutdown -h now" (「システムをシャットダウンする方法」参照下さい) を実行しているプロセスを at(1) コマンド (「タスク1回実行のスケジュール」参照下さい) を使って次のようにして SSH が終了することから守る必要があります。

# echo "shutdown -h now" | at now

"shutdown -h now" をscreen(1) (「screen プログラム」参照下さい) セッション中で実行しても同様のことができます。

In the old Unix-like system, the BSD Line printer daemon (lpd) was the standard and the standard print out format of the classic free software was PostScript (PS). Some filter system was used along with Ghostscript to enable printing to the non-PostScript printer. See 「Ghostscript」.

In the modern Debian system, the Common UNIX Printing System (CUPS) is the de facto standard and the standard print out format of the modern free software is Portable Document Format (PDF).

The CUPS uses Internet Printing Protocol (IPP). The IPP is now supported by other OSs such as Windows XP and Mac OS X and has became new cross-platform de facto standard for remote printing with bi-directional communication capability.

CUPS システムのファイルフォーマット依存の自動変換機能のおかげで、どんなデーターでも lpr コマンドに供給すると期待される印刷出力が生成されます。(CUPS では、lprcups-bsd パッケージをインストールすると有効となります。)

Debian システムには、プリントサーバーやユーティリティーで留意すべきパッケージがいくつかあります。


[ヒント] ヒント

CUPS システムはウェッブブラウザーを "http://localhost:631/" に向けることで設定できます。

他のネットワークアプリケーションサーバーを次に示します。


コモンインターネットファイルシステムプロトコル (CIFS) はサーバーメッセージブロック (SMB) と同じプロトコルで Microsoft Windows で広く使われています。

[ヒント] ヒント

サーバーシステムの統合には、「最新の集中システム管理」 を参照下さい。

[ヒント] ヒント

ホスト名の解決は通常 DNS サーバーによって提供されます。ホストの IP アドレスが DHCP によって動的にアサインされる場合には Debian wiki 上のDDNS ページ に書かれているようにして bind9isc-dhcp-server を使いホスト名解決のための ダイナミック DNS が設定できます。

[ヒント] ヒント

Debian アーカイブの全内容のローカルのミラーサーバーを使うより、squid 等のプロキシサーバーを使う方がはるかにバンド幅を節約上ではるかに効率的です。

他のネットワークアプリケーションクライアントを次に示します。


telnet プログラムを使うとシステムデーモンへの手動接続とその診断ができます。

プレーンな POP3 サービスをテストするには、次のようにします。

$ telnet mail.ispname.net pop3

一部の ISP が提供する TLS/SSL を有効にした POP3 サービスをテストするには、telnet-sslopenssl パッケージによる、TLS/SSL を有効にした telnet クライアントが必要です。

$ telnet -z ssl pop.gmail.com 995
$ openssl s_client -connect pop.gmail.com:995

次の RFC は各システムデーモンに関する必要な知見を提供します。


"/etc/services" の中にポートの使用され方が記載されています。