Inspeccionar la configuración de sockets con sysctl
En este paso, exploraremos cómo inspeccionar la configuración de sockets utilizando el comando sysctl
. sysctl
es una utilidad de línea de comandos que te permite ver y modificar parámetros del kernel en tiempo de ejecución. Es una herramienta poderosa para ajustar el comportamiento de tu sistema, incluyendo la configuración de red.
sysctl
lee y escribe valores desde el sistema de archivos virtual /proc/sys
. En el paso anterior, usamos cat
para leer valores directamente de archivos en /proc/sys/net
. sysctl
proporciona una forma más conveniente y estructurada de acceder y modificar estos parámetros.
Para comenzar, abre tu terminal.
Empecemos listando todos los parámetros sysctl
relacionados con la red disponibles. Para hacer esto, podemos usar el comando sysctl -a
y filtrar la salida usando grep
para centrarnos en la configuración de red.
Escribe el siguiente comando en tu terminal y presiona Enter:
sysctl -a | grep net.
Este comando hace lo siguiente:
sysctl -a
: Lista todos los parámetros del kernel.
grep net.
: Filtra la salida para mostrar solo los parámetros que empiecen por net.
.
Deberías ver una larga lista de parámetros relacionados con la red y sus valores actuales. La salida será similar a esta:
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
Para ver el valor de un parámetro específico, usa el comando sysctl
seguido del nombre del parámetro. Por ejemplo, para ver el valor de net.ipv4.ip_forward
, escribe el siguiente comando y presiona Enter:
sysctl net.ipv4.ip_forward
Este comando mostrará el valor actual del parámetro net.ipv4.ip_forward
.
net.ipv4.ip_forward = 0
Para modificar un parámetro sysctl
, puedes usar la opción -w
seguida del nombre del parámetro y el nuevo valor. Sin embargo, ten en cuenta que los cambios realizados con la opción -w
son temporales y se perderán después de un reinicio.
Por ejemplo, para habilitar temporalmente el reenvío de IP (establecer net.ipv4.ip_forward
en 1), escribe el siguiente comando y presiona Enter:
sudo sysctl -w net.ipv4.ip_forward=1
Puedes verificar que el valor se haya cambiado ejecutando el comando sysctl
de nuevo:
sysctl net.ipv4.ip_forward
La salida ahora debería mostrar:
net.ipv4.ip_forward = 1
Para hacer el cambio permanente, necesitas editar el archivo /etc/sysctl.conf
o crear un nuevo archivo de configuración en el directorio /etc/sysctl.d/
.
Por ejemplo, creemos un nuevo archivo llamado 99-labex.conf
en el directorio /etc/sysctl.d/
y agreguemos la configuración net.ipv4.ip_forward=1
a él.
Primero, crea el archivo usando nano
:
sudo nano /etc/sysctl.d/99-labex.conf
Luego, agrega la siguiente línea al archivo:
net.ipv4.ip_forward=1
Presiona Ctrl+X
, luego Y
, luego Enter
para guardar el archivo.
Finalmente, aplica los cambios ejecutando el siguiente comando:
sudo sysctl -p /etc/sysctl.d/99-labex.conf
Este comando leerá el archivo de configuración y aplicará las configuraciones.
Al usar el comando sysctl
y modificar el archivo /etc/sysctl.conf
, puedes ajustar la configuración de red de tu sistema para optimizar el rendimiento y la seguridad.