Inspecter la configuration des sockets avec sysctl
Dans cette étape, nous allons explorer comment inspecter les configurations des sockets en utilisant la commande sysctl
. sysctl
est un utilitaire en ligne de commande qui vous permet de visualiser et de modifier les paramètres du noyau à l'exécution. C'est un outil puissant pour affiner le comportement de votre système, y compris les paramètres réseau.
sysctl
lit et écrit des valeurs à partir du système de fichiers virtuel /proc/sys
. Dans l'étape précédente, nous avons utilisé cat
pour lire directement les valeurs à partir des fichiers dans /proc/sys/net
. sysctl
offre un moyen plus pratique et structuré d'accéder et de modifier ces paramètres.
Pour commencer, ouvrez votre terminal.
Commençons par lister tous les paramètres sysctl
liés au réseau disponibles. Pour ce faire, nous pouvons utiliser la commande sysctl -a
et filtrer la sortie à l'aide de grep
pour nous concentrer sur les paramètres réseau.
Tapez la commande suivante dans votre terminal et appuyez sur Entrée :
sysctl -a | grep net.
Cette commande effectue les actions suivantes :
sysctl -a
: Liste tous les paramètres du noyau.
grep net.
: Filtre la sortie pour afficher uniquement les paramètres commençant par net.
.
Vous devriez voir une longue liste de paramètres liés au réseau et leurs valeurs actuelles. La sortie sera similaire à celle-ci :
net.bridge.bridge-nf-call-arptables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-ip6tables = 0
net.core.bpf_jit_enable = 0
net.core.busy_poll = 50
net.core.busy_read = 50
net.core.default_qdisc = fq_codel
net.core.dev_weight = 64
net.core.message_burst = 10
net.core.message_cost = 5
net.core.netdev_max_backlog = 1000
net.core.optmem_max = 20480
net.core.rmem_default = 212992
net.core.rmem_max = 1703936
net.core.somaxconn = 128
net.core.warnings = 1
net.core.wmem_default = 212992
net.core.wmem_max = 1703936
net.ipv4.conf.all.accept_redirects = 1
net.ipv4.conf.all.accept_source_route = 0
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.bootp_relay = 0
net.ipv4.conf.all.forwarding = 0
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 = 1
net.ipv4.conf.all.proxy_arp = 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.default.accept_redirects = 1
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.default.arp_filter = 0
net.ipv4.conf.default.arp_ignore = 0
net.ipv4.conf.default.arp_notify = 0
net.ipv4.conf.default.bootp_relay = 0
net.ipv4.conf.default.forwarding = 0
net.ipv4.conf.default.ignore_routes_with_linkdown = 0
net.ipv4.conf.default.log_martians = 0
net.ipv4.conf.default.mc_forwarding = 0
net.ipv4.conf.default.medium_id = 0
net.ipv4.conf.default.promote_secondaries = 1
net.ipv4.conf.default.proxy_arp = 0
net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.default.secure_redirects = 1
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.lo.accept_redirects = 1
net.ipv4.conf.lo.accept_source_route = 0
net.ipv4.conf.lo.arp_filter = 0
net.ipv4.conf.lo.arp_ignore = 0
net.ipv4.conf.lo.arp_notify = 0
net.ipv4.conf.lo.bootp_relay = 0
net.ipv4.conf.lo.forwarding = 0
net.ipv4.conf.lo.ignore_routes_with_linkdown = 0
net.ipv4.conf.lo.log_martians = 0
net.ipv4.conf.lo.mc_forwarding = 0
net.ipv4.conf.lo.medium_id = 0
net.ipv4.conf.lo.promote_secondaries = 1
net.ipv4.conf.lo.proxy_arp = 0
net.ipv4.conf.lo.rp_filter = 0
net.ipv4.conf.lo.secure_redirects = 1
net.ipv4.conf.lo.send_redirects = 1
net.ipv4.icmp_echo_ignore_all = 0
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.icmp_ignore_bogus_error_responses = 1
net.ipv4.icmp_timestamp_ignore_replies = 0
net.ipv4.ip_default_ttl = 64
net.ipv4.ip_forward = 0
net.ipv4.ip_local_port_range = 32768 60999
net.ipv4.neigh.default.anycast_delay = 1
net.ipv4.neigh.default.app_solicit = 0
net.ipv4.neigh.default.base_reachable_time_ms = 30000
net.ipv4.neigh.default.gc_interval = 30
net.ipv4.neigh.default.gc_stale_time = 60
net.ipv4.neigh.default.locktime = 0
net.ipv4.neigh.default.mcast_solicit = 3
net.ipv4.neigh.default.proxy_qlen = 64
net.ipv4.neigh.default.retrans_time_ms = 1000
net.ipv4.neigh.default.ucast_solicit = 3
net.ipv4.route.flush = 0
net.ipv4.route.gc_elasticity = 9
net.ipv4.route.gc_interval = 30
net.ipv4.route.gc_min_interval = 0
net.ipv4.route.gc_timeout = 210
net.ipv4.route.max_size = 4096
net.ipv4.route.min_adv_mss = 536
net.ipv4.route.mtu_expires = 600
net.ipv4.tcp_abc = 0
net.ipv4.tcp_adv_win_scale = 1
net.ipv4.tcp_allowed_congestion_control = reno
net.ipv4.tcp_congestion_control = reno
net.ipv4.tcp_dsack = 1
net.ipv4.tcp_ecn = 2
net.ipv4.tcp_fack = 1
net.ipv4.tcp_fastopen = 3
net.ipv4.tcp_fin_timeout = 60
net.ipv4.tcp_frto = 2
net.ipv4.tcp_keepalive_intvl = 75
net.ipv4.tcp_keepalive_probes = 9
net.ipv4.tcp_keepalive_time = 7200
net.ipv4.tcp_low_latency = 0
net.ipv4.tcp_max_syn_backlog = 256
net.ipv4.tcp_max_tw_buckets = 180000
net.ipv4.tcp_moderate_rcvbuf = 1
net.ipv4.tcp_mtu_probing = 0
net.ipv4.tcp_no_metrics_save = 0
net.ipv4.tcp_orphan_retries = 8
net.ipv4.tcp_reordering = 3
net.ipv4.tcp_retries1 = 8
net.ipv4.tcp_retries2 = 15
net.ipv4.tcp_rfc1337 = 0
net.ipv4.tcp_rmem = 4096 212992 6291456
net.ipv4.tcp_sack = 1
net.ipv4.tcp_slow_start_after_idle = 1
net.ipv4.tcp_syn_retries = 6
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_timestamps = 1
net.ipv4.tcp_tw_recycle = 0
net.ipv4.tcp_tw_reuse = 0
net.ipv4.tcp_wmem = 4096 16384 4194304
net.ipv6.conf.all.accept_dad = 1
net.ipv6.conf.all.accept_ra = 1
net.ipv6.conf.all.accept_redirects = 1
net.ipv6.conf.all.autoconf = 1
net.ipv6.conf.all.disable_ipv6 = 0
net.ipv6.conf.all.force_mld_version = 0
net.ipv6.conf.all.hop_limit = 64
net.ipv6.conf.all.ignore_routes_with_linkdown = 0
net.ipv6.conf.all.max_addresses = 16
net.ipv6.conf.all.mldv1_unsolicited_report_interval = 1000
net.ipv6.conf.all.mldv2_unsolicited_report_interval = 100
net.ipv6.conf.all.mtu = 0
net.ipv6.conf.all.proxy_ndp = 0
net.ipv6.conf.all.regen_max_random_factor = 600
net.ipv6.conf.all.router_solicitation_delay = 1
net.ipv6.conf.all.router_solicitation_interval = 4
net.ipv6.conf.all.router_solicitations = -1
net.ipv6.conf.all.seg6_enabled = 1
net.ipv6.conf.all.seg6_require_hmac = 0
net.ipv6.conf.all.use_optimistic_dad = 0
net.ipv6.conf.all.use_tempaddr = 0
net.ipv6.conf.default.accept_dad = 1
net.ipv6.conf.default.accept_ra = 1
net.ipv6.conf.default.accept_redirects = 1
net.ipv6.conf.default.autoconf = 1
net.ipv6.conf.default.disable_ipv6 = 0
net.ipv6.conf.default.force_mld_version = 0
net.ipv6.conf.default.hop_limit = 64
net.ipv6.conf.default.ignore_routes_with_linkdown = 0
net.ipv6.conf.default.max_addresses = 16
net.ipv6.conf.default.mldv1_unsolicited_report_interval = 1000
net.ipv6.conf.default.mldv2_unsolicited_report_interval = 100
net.ipv6.conf.default.mtu = 0
net.ipv6.conf.default.proxy_ndp = 0
net.ipv6.conf.default.regen_max_random_factor = 600
net.ipv6.conf.default.router_solicitation_delay = 1
net.ipv6.conf.default.router_solicitation_interval = 4
net.ipv6.conf.default.router_solicitations = -1
net.ipv6.conf.default.seg6_enabled = 1
net.ipv6.conf.default.seg6_require_hmac = 0
net.ipv6.conf.default.use_optimistic_dad = 0
net.ipv6.conf.default.use_tempaddr = 0
net.ipv6.conf.eth0.accept_dad = 1
net.ipv6.conf.eth0.accept_ra = 1
net.ipv6.conf.eth0.accept_redirects = 1
net.ipv6.conf.eth0.autoconf = 1
net.ipv6.conf.eth0.disable_ipv6 = 0
net.ipv6.conf.eth0.force_mld_version = 0
net.ipv6.conf.eth0.hop_limit = 64
net.ipv6.conf.eth0.ignore_routes_with_linkdown = 0
net.ipv6.conf.eth0.max_addresses = 16
net.ipv6.conf.eth0.mldv1_unsolicited_report_interval = 1000
net.ipv6.conf.eth0.mldv2_unsolicited_report_interval = 100
net.ipv6.conf.eth0.mtu = 1500
net.ipv6.conf.eth0.proxy_ndp = 0
net.ipv6.conf.eth0.regen_max_random_factor = 600
net.ipv6.conf.eth0.router_solicitation_delay = 1
net.ipv6.conf.eth0.router_solicitation_interval = 4
net.ipv6.conf.eth0.router_solicitations = -1
net.ipv6.conf.eth0.seg6_enabled = 1
net.ipv6.conf.eth0.seg6_require_hmac = 0
net.ipv6.conf.eth0.use_optimistic_dad = 0
net.ipv6.conf.eth0.use_tempaddr = 0
net.ipv6.conf.lo.accept_dad = 1
net.ipv6.conf.lo.accept_ra = 1
net.ipv6.conf.lo.accept_redirects = 1
net.ipv6.conf.lo.autoconf = 1
net.ipv6.conf.lo.disable_ipv6 = 0
net.ipv6.conf.lo.force_mld_version = 0
net.ipv6.conf.lo.hop_limit = 64
net.ipv6.conf.lo.ignore_routes_with_linkdown = 0
net.ipv6.conf.lo.max_addresses = 16
net.ipv6.conf.lo.mldv1_unsolicited_report_interval = 1000
net.ipv6.conf.lo.mldv2_unsolicited_report_interval = 100
net.ipv6.conf.lo.mtu = 65536
net.ipv6.conf.lo.proxy_ndp = 0
net.ipv6.conf.lo.regen_max_random_factor = 600
net.ipv6.conf.lo.router_solicitation_delay = 1
net.ipv6.conf.lo.router_solicitation_interval = 4
net.ipv6.conf.lo.router_solicitations = -1
net.ipv6.conf.lo.seg6_enabled = 1
net.ipv6.conf.lo.seg6_require_hmac = 0
net.ipv6.conf.lo.use_optimistic_dad = 0
net.ipv6.conf.lo.use_tempaddr = 0
net.netfilter.nf_conntrack_acct = 0
net.netfilter.nf_conntrack_buckets = 65536
net.netfilter.nf_conntrack_checksum = 0
net.netfilter.nf_conntrack_count = 256
net.netfilter.nf_conntrack_expect_max = 128
net.netfilter.nf_conntrack_frag6_high_thresh = 1048576
net.netfilter.nf_conntrack_frag6_low_thresh = 524288
net.netfilter.nf_conntrack_frag6_timeout = 60
net.netfilter.nf_conntrack_frag_high_thresh = 1048576
net.netfilter.nf_conntrack_frag_low_thresh = 524288
net.netfilter.nf_conntrack_frag_timeout = 60
net.netfilter.nf_conntrack_generic_timeout = 3600
net.netfilter.nf_conntrack_helper = 1
net.netfilter.nf_conntrack_icmpv6_timeout = 10
net.netfilter.nf_conntrack_icmp_timeout = 30
net.netfilter.nf_conntrack_log_invalid = 0
net.netfilter.nf_conntrack_max = 262144
net.netfilter.nf_conntrack_sctp_timeout_closed = 0
net.netfilter.nf_conntrack_sctp_timeout_cookie_echoed = 120
net.netfilter.nf_conntrack_sctp_timeout_cookie_wait = 120
net.netfilter.nf_conntrack_sctp_timeout_heartbeat_ack = 0
net.netfilter.nf_conntrack_sctp_timeout_heartbeat_sent = 30
net.netfilter.nf_conntrack_sctp_timeout_shutdown_ack_sent = 0
net.netfilter.nf_conntrack_sctp_timeout_shutdown_recd = 0
net.netfilter.nf_conntrack_sctp_timeout_shutdown_sent = 0
net.netfilter.nf_conntrack_tcp_loose = 1
net.netfilter.nf_conntrack_tcp_max_retrans = 3
net.netfilter.nf_conntrack_tcp_timeout_close = 10
net.netfilter.nf_conntrack_tcp_timeout_close_wait = 60
net.netfilter.nf_conntrack_tcp_timeout_established = 86400
net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 120
net.netfilter.nf_conntrack_tcp_timeout_last_ack = 30
net.netfilter.nf_conntrack_tcp_timeout_max_retrans = 300
net.netfilter.nf_conntrack_tcp_timeout_syn_recv = 60
net.netfilter.nf_conntrack_tcp_timeout_syn_sent = 120
net.netfilter.nf_conntrack_tcp_timeout_time_wait = 120
net.unix.max_dgram_qlen = 512
Pour afficher la valeur d'un paramètre spécifique, utilisez la commande sysctl
suivie du nom du paramètre. Par exemple, pour afficher la valeur de net.ipv4.ip_forward
, tapez la commande suivante et appuyez sur Entrée :
sysctl net.ipv4.ip_forward
Cette commande affichera la valeur actuelle du paramètre net.ipv4.ip_forward
.
net.ipv4.ip_forward = 0
Pour modifier un paramètre sysctl
, vous pouvez utiliser l'option -w
suivie du nom du paramètre et de la nouvelle valeur. Cependant, gardez à l'esprit que les modifications apportées avec l'option -w
sont temporaires et seront perdues après un redémarrage.
Par exemple, pour activer temporairement le transfert IP (définir net.ipv4.ip_forward
sur 1), tapez la commande suivante et appuyez sur Entrée :
sudo sysctl -w net.ipv4.ip_forward=1
Vous pouvez vérifier que la valeur a été modifiée en exécutant à nouveau la commande sysctl
:
sysctl net.ipv4.ip_forward
La sortie devrait maintenant afficher :
net.ipv4.ip_forward = 1
Pour rendre la modification permanente, vous devez éditer le fichier /etc/sysctl.conf
ou créer un nouveau fichier de configuration dans le répertoire /etc/sysctl.d/
.
Par exemple, créons un nouveau fichier nommé 99-labex.conf
dans le répertoire /etc/sysctl.d/
et ajoutons-y le paramètre net.ipv4.ip_forward=1
.
Tout d'abord, créez le fichier à l'aide de nano
:
sudo nano /etc/sysctl.d/99-labex.conf
Ensuite, ajoutez la ligne suivante au fichier :
net.ipv4.ip_forward=1
Appuyez sur Ctrl+X
, puis sur Y
, puis sur Entrée pour enregistrer le fichier.
Enfin, appliquez les modifications en exécutant la commande suivante :
sudo sysctl -p /etc/sysctl.d/99-labex.conf
Cette commande lira le fichier de configuration et appliquera les paramètres.
En utilisant la commande sysctl
et en modifiant le fichier /etc/sysctl.conf
, vous pouvez affiner les paramètres réseau de votre système pour optimiser les performances et la sécurité.