sysctlを使用したカーネル・パラメータの変更
sysctlコマンドを使用して、ネットワーク設定、セキュリティ機能、リソース制限などのOSの動作を変更するためのカーネル・パラメータを表示および変更します。
詳細は、sysctl(8)のマニュアル・ページを参照してください。
カーネルパラメータと値の一覧表示
sysctlコマンドを使用して、/proc/sys仮想ファイル・システムに定義されているカーネル・システム・パラメータを参照します。
ノート
設定の名前のデリミタ文字は、
設定の名前のデリミタ文字は、
/proc/sysに相対的なパスのスラッシュ(/)ではなく、ピリオドです(.など)。したがって、たとえば、net.ipv4.ip_forwardはnet/ipv4/ip_forwardを表します。 - 実行中のカーネルのすべてのカーネル・パラメータとその値を表示するには、
sysctl -aを実行します。たとえば:sudo sysctl -a... kernel.sched_cfs_bandwidth_slice_us = 5000 kernel.sched_deadline_period_max_us = 4194304 kernel.sched_deadline_period_min_us = 100 kernel.sched_rr_timeslice_ms = 100 kernel.sched_rt_period_us = 1000000 kernel.sched_rt_runtime_us = 950000 kernel.sched_schedstats = 0 ... - 特定のパラメータとその値を表示するには、
sysctlおよびパラメータ名を実行します。たとえば:sudo sysctl kernel.dmesg_restrictkernel.dmesg_restrict = 0 - パラメータ設定のコレクションを表示するには、
sysctlおよびコレクションの名前を実行します。たとえば:sudo sysctl net.ipv4.conf.allnet.ipv4.conf.all.accept_local = 0 net.ipv4.conf.all.accept_redirects = 1 net.ipv4.conf.all.accept_source_route = 0 net.ipv4.conf.all.arp_accept = 0 net.ipv4.conf.all.arp_announce = 0 net.ipv4.conf.all.arp_evict_nocarrier = 1 net.ipv4.conf.all.arp_filter = 0 net.ipv4.conf.all.arp_ignore = 0 net.ipv4.conf.all.arp_notify = 0 net.ipv4.conf.all.bc_forwarding = 0 net.ipv4.conf.all.bootp_relay = 0 net.ipv4.conf.all.disable_policy = 0 net.ipv4.conf.all.disable_xfrm = 0 net.ipv4.conf.all.drop_gratuitous_arp = 0 net.ipv4.conf.all.drop_unicast_in_l2_multicast = 0 net.ipv4.conf.all.force_igmp_version = 0 net.ipv4.conf.all.forwarding = 0 net.ipv4.conf.all.igmpv2_unsolicited_report_interval = 10000 net.ipv4.conf.all.igmpv3_unsolicited_report_interval = 1000 net.ipv4.conf.all.ignore_routes_with_linkdown = 0 net.ipv4.conf.all.log_martians = 0 net.ipv4.conf.all.mc_forwarding = 0 net.ipv4.conf.all.medium_id = 0 net.ipv4.conf.all.promote_secondaries = 0 net.ipv4.conf.all.proxy_arp = 0 net.ipv4.conf.all.proxy_arp_pvlan = 0 net.ipv4.conf.all.route_localnet = 0 net.ipv4.conf.all.rp_filter = 0 net.ipv4.conf.all.secure_redirects = 1 net.ipv4.conf.all.send_redirects = 1 net.ipv4.conf.all.shared_media = 1 net.ipv4.conf.all.src_valid_mark = 0 net.ipv4.conf.all.tag = 0
カーネル・パラメータの更新
sysctlコマンドを使用して、/proc/sys仮想ファイル・システムに定義されているカーネル・パラメータの値を変更します。カーネル・パラメータの変更は、次のインスタンスの再起動まで継続するように一時的なものにできます。または、インスタンスの再起動後も維持されるように、カーネル・パラメータの変更を永続的にできます。
- カーネル・パラメータの一時的な変更
sysctlコマンド、パラメータ名および新しい値を使用します。たとえば、あるネットワーク・インタフェースで受信したIPv4パケットを一時的に別のネットワーク・インタフェースに転送できるようにするには、
net.ipv4.ip_forwardパラメータ値を1に設定します。sudo sysctl -w net.ipv4.ip_forward=1net.ipv4.ip_forward = 1パラメータの変更は、次回のインスタンス再起動時に元に戻されます。
- インスタンスの再起動後に維持されるカーネル・パラメータの変更
- 構成ファイルの変更を
/etc/sysctl.dディレクトリに追加します。このディレクトリのファイルに加えた変更は、インスタンスの再起動時、またはsysctl --systemコマンドを実行した場合に有効となります。たとえば、root権限を持つユーザーのみが
dmesgコマンドを実行できるように、カーネル・リング・バッファ・メッセージへのアクセスを永続的に制限できます。これを行うには、構成ファイルを使用してkernel.dmesg_restrictを有効にして、再起動によって変更が維持されるようにします。/etc/sysctl.dディレクトリに移動します。- 構成ファイルを作成します。次に例を示します。
sudo touch 99-custom-sysctl.conf - 構成ファイルを編集モードで開きます。たとえば、viテキスト・エディタでファイルを編集します。
sudo vi 99-custom-sysctl.conf kernel.dmesg_restrict=1をファイルに追加して保存し、エディタを閉じます。sysctl --systemコマンドを使用して、起動時にロードするように構成された値のみを使用するようにインスタンスをリセットします。/etc/sysctl.dディレクトリ内の既存ファイルに追加された構成ファイルまたは構成変更は、システムによって読み取られて適用されます。重要
カーネル・パラメータ値は、複数の場所で定義される場合があります。sysctl --systemコマンドは、再起動せずにカーネル構成の変更をただちに適用します。これにより、/etc/sysctl.conf、/etc/sysctl.d、および/usr/lib/sysctl.d/*.confや/run/sysctl.d/*.confなどの他のすべての場所からのすべての設定がリロードされます。sudo sysctl --system* Applying /usr/lib/sysctl.d/01-unprivileged-bpf.conf ... * Applying /usr/lib/sysctl.d/10-default-yama-scope.conf ... * Applying /usr/lib/sysctl.d/50-coredump.conf ... * Applying /usr/lib/sysctl.d/50-default.conf ... * Applying /usr/lib/sysctl.d/50-ipv6.conf ... * Applying /usr/lib/sysctl.d/50-libkcapi-optmem_max.conf ... * Applying /usr/lib/sysctl.d/50-pid-max.conf ... * Applying /usr/lib/sysctl.d/50-redhat.conf ... * Applying /usr/lib/sysctl.d/50-scsi-logging.conf ... * Applying /etc/sysctl.d/99-custom-sysctl.conf ... <--New configuration file * Applying /etc/sysctl.d/99-sysctl.conf ... * Applying /etc/sysctl.conf ... kernel.unprivileged_bpf_disabled = 1 kernel.yama.ptrace_scope = 0 kernel.core_pattern = |/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %h %d kernel.core_pipe_limit = 16 fs.suid_dumpable = 2 kernel.sysrq = 16 kernel.core_uses_pid = 1 net.ipv4.conf.default.rp_filter = 2 net.ipv4.conf.ens3.rp_filter = 2 net.ipv4.conf.lo.rp_filter = 2 net.ipv4.conf.default.accept_source_route = 0 net.ipv4.conf.ens3.accept_source_route = 0 net.ipv4.conf.lo.accept_source_route = 0 net.ipv4.conf.default.promote_secondaries = 1 net.ipv4.conf.ens3.promote_secondaries = 1 net.ipv4.conf.lo.promote_secondaries = 1 net.ipv4.ping_group_range = 0 2147483647 net.core.default_qdisc = fq_codel fs.protected_hardlinks = 1 fs.protected_symlinks = 1 fs.protected_regular = 1 fs.protected_fifos = 1 net.ipv6.conf.default.disable_ipv6 = 0 net.ipv6.conf.all.disable_ipv6 = 0 net.core.optmem_max = 81920 kernel.pid_max = 4194304 kernel.kptr_restrict = 1 net.ipv4.conf.default.rp_filter = 1 net.ipv4.conf.ens3.rp_filter = 1 net.ipv4.conf.lo.rp_filter = 1 dev.scsi.logging_level = 68 kernel.dmesg_restrict = 1 <--Parameter change read from new configuration file. kernel.unknown_nmi_panic = 1
カーネル・パラメータの詳細は、次を参照してください。