SysctlによるCentOS 7カーネルの保護と強化

前書き

Sysctlカーネルを再構築することなく、ユーザーがカーネルを微調整できます。また、変更をすぐに適用するため、変更を有効にするためにサーバーを再起動する必要はありません。このチュートリアルではsysctl、Linuxカーネルの特定の部分を調整するための簡単な紹介と使用方法を示します。

コマンド

sysctlの使用を開始するには、以下にリストされているパラメーターと例を確認してください。

パラメーター

-a:これにより、sysctl構成で現在使用可能なすべての値が表示されます。

-A:これにより、sysctl構成で現在使用可能なすべての値が表形式で表示されます。

-e:このオプションは、不明なキーに関するエラーを無視します。

-p:これは、特定のsysctl構成をロードするために使用され、デフォルトで使用します/etc/sysctl.conf

-n:このオプションは、値を出力するときにキー名の表示を無効にします。

-w:このオプションは、オンデマンドでsysctlの値を変更(または追加)するためのものです。

$ sysctl -a
$ sysctl -n fs.file-max
$ sysctl -w fs.file-max=2097152
$ sysctl -p

したがって、最初にデフォルト値をチェックしています。/etc/sysctl.conf空の場合は、すべてのデフォルトのキーと値が表示されます。次に、の値を確認しfs.file-max、新しい値をに設定し2097152ます。最後に、新しい/etc/sysctl.conf構成ファイルをロードしています。

さらにヘルプが必要な場合は、を使用できますman sysctl

カーネルの保護と強化

変更を永続的にするには、これらの値を構成ファイルに追加する必要があります。CentOSがデフォルトで提供する構成ファイルを使用します/etc/sysctl.conf

お気に入りのエディターでファイルを開きます。

デフォルトでは、これに似たものが表示されます。

# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).

最初にシステムのメモリ管理を改善しましょう。

実行する必要のあるスワッピングの量を最小限に抑え、ファイルハンドルとiノードキャッシュのサイズを増やし、コアダンプを制限します。

# Minimizing the amount of swapping
vm.swappiness = 20
vm.dirty_ratio = 80
vm.dirty_background_ratio = 5

# Increases the size of file handles and inode cache & restricts core dumps
fs.file-max = 2097152
fs.suid_dumpable = 0

次に、ネットワーク最適化パフォーマンスを調整します。

着信接続と着信接続のバックログの量を変更し、メモリバッファーの最大量を増やし、デフォルトと最大の送受信バッファーを増やします。

# Change the amount of incoming connections and incoming connections backlog
net.core.somaxconn = 65535
net.core.netdev_max_backlog = 262144

# Increase the maximum amount of memory buffers
net.core.optmem_max = 25165824

# Increase the default and maximum send/receive buffers
net.core.rmem_default = 31457280
net.core.rmem_max = 67108864
net.core.wmem_default = 31457280
net.core.wmem_max = 67108864

最後に、一般的なネットワークセキュリティを改善します。

TCP SYN Cookie保護、IPスプーフィング保護、ICMP要求の無視、ブロードキャスト要求の無視、スプーフィングされたパケット、ソースルーティングされたパケット、リダイレクトパケットへのロギングを有効にします。それに加えて、IPソースルーティングとICMPリダイレクトの受け入れを無効にします。

# Enable TCP SYN cookie protection
net.ipv4.tcp_syncookies = 1

# Enable IP spoofing protection
net.ipv4.conf.all.rp_filter = 1

# Enable ignoring to ICMP requests and broadcasts request
net.ipv4.icmp_echo_ignore_all = 1
net.ipv4.icmp_echo_ignore_broadcasts = 1

# Enable logging of spoofed packets, source routed packets and redirect packets
net.ipv4.conf.all.log_martians = 1

# Disable IP source routing
net.ipv4.conf.all.accept_source_route = 0

# Disable ICMP redirect acceptance
net.ipv4.conf.all.accept_redirects = 0

ファイルを保存して閉じ、sysctl -pコマンドを使用してファイルをロードします。

結論

最終的に、ファイルは次のようになります。

# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).

# Minimizing the amount of swapping
vm.swappiness = 20
vm.dirty_ratio = 80
vm.dirty_background_ratio = 5

# Increases the size of file handles and inode cache & restricts core dumps
fs.file-max = 2097152
fs.suid_dumpable = 0

# Change the amount of incoming connections and incoming connections backlog
net.core.somaxconn = 65535
net.core.netdev_max_backlog = 262144

# Increase the maximum amount of memory buffers
net.core.optmem_max = 25165824

# Increase the default and maximum send/receive buffers
net.core.rmem_default = 31457280
net.core.rmem_max = 67108864
net.core.wmem_default = 31457280
net.core.wmem_max = 67108864

# Enable TCP SYN cookie protection
net.ipv4.tcp_syncookies = 1

# Enable IP spoofing protection
net.ipv4.conf.all.rp_filter = 1

# Enable ignoring to ICMP requests and broadcasts request
net.ipv4.icmp_echo_ignore_all = 1
net.ipv4.icmp_echo_ignore_broadcasts = 1

# Enable logging of spoofed packets, source routed packets and redirect packets
net.ipv4.conf.all.log_martians = 1

# Disable IP source routing
net.ipv4.conf.all.accept_source_route = 0

# Disable ICMP redirect acceptance
net.ipv4.conf.all.accept_redirects = 0


Leave a Comment

CentOS 7にApacheをインストールする方法

CentOS 7にApacheをインストールする方法

CentOS 7サーバーにApache 2.4をインストールする方法を説明します。安定したウェブサーバーを構築するための前提条件と手順を解説します。

FreeBSD 11.1にBlacklistdをインストールする方法

FreeBSD 11.1にBlacklistdをインストールする方法

FreeBSD 11.1におけるBlacklistdのインストール方法について詳しく解説します。この方法を通じて、強力なセキュリティ対策を実装できます。

Windows Serverのサーバーマネージャーを使用した複数サーバーの管理

Windows Serverのサーバーマネージャーを使用した複数サーバーの管理

サーバーマネージャーを使用して、Windows Serverの管理が向上します。セキュリティリスクを軽減し、効率的な管理を実現します。

CentOS 7にSeafileサーバーをインストールする方法

CentOS 7にSeafileサーバーをインストールする方法

CentOS 7にSeafileサーバーをインストールする方法。Seafile(コミュニティバージョン)は、ownCloudに似た無料のオープンソースファイル同期および共有ソリューションです。

DebianでSnortを設定する方法

DebianでSnortを設定する方法

Snortは無料のネットワーク侵入検知システムです。最新の方法で、SnortをDebianにインストールし、設定する手順を紹介します。ネットワークのセキュリティを強化しましょう。

CentOS 7にGraylogサーバーをインストールする方法

CentOS 7にGraylogサーバーをインストールする方法

CentOS 7にGraylogサーバーをインストールし、ログ管理を行う方法を学びます。

WindowsでhMailServerを使用してメールサーバーを構築する

WindowsでhMailServerを使用してメールサーバーを構築する

WindowsサーバーでWebサイトを実行している場合、電子メールも受信できるようにするためにhMailServerを使用する方法を解説します。

Ubuntu 19.04にFiveMサーバーをインストールする方法

Ubuntu 19.04にFiveMサーバーをインストールする方法

FiveMサーバーをUbuntu 19.04にインストールするための詳細なガイド。必要条件からインストール、起動、トラブルシューティングまで、すべてのステップを含みます。

WsgiDAVを使用してDebian 10にWebDAVをデプロイする

WsgiDAVを使用してDebian 10にWebDAVをデプロイする

Debian 10にWebDAVをデプロイする方法を学び、WsgiDAVとSSL証明書で安全な接続を実現しましょう。

ヘルスケア2021における人工知能の影響

ヘルスケア2021における人工知能の影響

ヘルスケアにおけるAIは、過去数十年から大きな飛躍を遂げました。したがって、ヘルスケアにおけるAIの未来は、日々成長を続けています。