Translated message

A translation of this page exists in English.

TCP セッションを長期間アクティブのままにする

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Linux 5
  • Red Hat Enterprise Linux 6
  • Red Hat Enterprise Linux 7

Issue

  • SSH、vsftpd、およびシェルの auto-session ログアウトの時間を延ばしたいです。

  • ssh、ftp、シェル、およびネットワークセッションのタイムアウトを設定するのにどのようなオプションを使用できますか?

  • ssh ftp またはシェルセッションが期待した時間にタイムアウトにならないのはなぜですか?

  • 複数の設定を行っても、サーバーの SSH セッションが 15分 以上になりません。

Resolution

アプリケーション層、tcp 層、およびリンク層など、リモートネットワークセッションに影響する層が複数あります。
以下は、通常検討が必要な一般的な場所になります。

Bash のタイムアウト設定

  • bash のタイムアウト変数を設定すると、アイドルセッションのタイムアウトになります。
  • bash シェルでこの変数を確認して変更するか、無効にします。
# export | grep TMOUT              # Check if bash shell timeout is set or not
# echo "TMOUT=9999" >> ~/.bashrc   # Change the value

openssh-servers および openssh-clients

openssh タイムアウト設定の詳細は Which options can be use to configure ssh's timeout? を参照してください。

vsftpd

  • アイドルタイムアウトは、以下のディレクティブで変更できます。
# vi /etc/vsftpd/vsftpd.conf
      idle_session_timeout=0

man ページでは以下のように説明されています。

Specifies the maximum amount of time between commands from a remote client.
Once triggered, the connection to the remote client is closed.
The default value is 300. 

ネットワークが停止しているため切断されている

  • カーネルパラメーターのキープアライブ、デーモンサイドの設定、またはクライアント設定に関するオプションが有効な場合は、そのオプションに従って tcp セッションが終了します。
  • たとえば、以下のカーネルパラメーターオプションを例にあげると、600 秒後に最初のキープアライブパケットが送られ、その後は、パケットが 60 秒ごとに 20 回送られます。
  • この間にクライアントまたはサーバーが応答しないと、tcp セッションがなくなったと見なされ終了します。
# echo 600 > /proc/sys/net/ipv4/tcp_keepalive_time
# echo 60 > /proc/sys/net/ipv4/tcp_keepalive_intvl
# echo 20 > /proc/sys/net/ipv4/tcp_keepalive_probes

リンク層

  • ファイアウォールは、各接続のアイドルタイマーを保持します。
  • アイドルタイマーが切れる前にパケットが接続から送られないと、ファイアウォールが接続をすぐに終了し、接続テーブルから削除します。
  • アイドルタイムアウトは通常 60 分に設定されています。
  • ネットワーク管理者に確認してください。
  • たとえば ASA 5500 の場合は以下のようになります。
hostname(config-pmap-c)# set connection timeout tcp hh:mm:ss [reset] 

The tcp hh:mm:ss keyword
sets the idle timeout between 0:5:0 and 1193:00:00.
The default is 1:0:0.
You can also set this value to 0, which means the connection never times out.
The reset keyword sends a reset to TCP endpoints when the connection times out.
The adaptive security appliance sends the reset packet only in response to a host sending another packet for the timed-out flow (on the same source and destination port).
The host then removes the connection from its connection table after receiving the reset packet.
The host application can then attempt to establish a new connection using a SYN packet.

注意: このネットワーク機器の設定には、tcp_keepalive が使用されます。
機器のアイドルタイムアウト値でサーバーまたはクライアントにキープアライブパケットを送るように keepalive 変数を設定すると、機器はセッションをアイドル接続として認識しません。

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments