Garden of KnowledgeApplied Sciences › Computer Science › Software › Security › Certifications › LFCS

q25-sysctl-kernel-parameters

Énoncé§

Solve this question on: terminal

  1. Enable IPv4 packet forwarding persistently.
  2. Disable IPv6 on all interfaces persistently.
  3. Set vm.swappiness to 10 for the current session only.
  4. Write the value of kernel.hostname into /opt/course/25/hostname.

Solution§

Read current values§

sysctl kernel.hostname
sysctl -a                                   # dump everything
sysctl -a 2>/dev/null | grep forward
cat /proc/sys/net/ipv4/ip_forward           # equivalent direct read

Each kernel parameter maps to a file under /proc/sys/ — dots become slashes (net.ipv4.ip_forward/proc/sys/net/ipv4/ip_forward).

Step 1 — Persistent IP forwarding§

Create a drop-in file (preferred over editing /etc/sysctl.conf):

sudo tee /etc/sysctl.d/99-forwarding.conf <<'EOF'
net.ipv4.ip_forward = 1
EOF
sudo sysctl --system            # reload all .conf files
# or apply that file only:
sudo sysctl -p /etc/sysctl.d/99-forwarding.conf

Step 2 — Disable IPv6 persistently§

sudo tee /etc/sysctl.d/99-no-ipv6.conf <<'EOF'
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
EOF
sudo sysctl --system

Step 3 — Set a value only for this session§

sudo sysctl -w vm.swappiness=10
# equivalent:
echo 10 | sudo tee /proc/sys/vm/swappiness

Non-persistent changes are lost at reboot.

Step 4 — Write a single value§

sysctl -n kernel.hostname > /opt/course/25/hostname

Order of evaluation§

sysctl --system reads, in order:

  1. /etc/sysctl.d/*.conf
  2. /run/sysctl.d/*.conf
  3. /usr/local/lib/sysctl.d/*.conf
  4. /usr/lib/sysctl.d/*.conf
  5. /lib/sysctl.d/*.conf
  6. /etc/sysctl.conf

Within a directory, files are sorted by name — use 99- prefix to override vendor defaults.

Common tunables to recognise§

KeyEffect
net.ipv4.ip_forwardenable IP routing
net.ipv4.conf.all.rp_filterreverse-path filtering (anti-spoof)
net.ipv4.tcp_syncookiesSYN-flood protection
vm.swappinessswap aggressiveness (0–100)
vm.overcommit_memorymemory overcommit policy
kernel.pid_maxmax PID
fs.file-maxsystem-wide open file limit
kernel.panicseconds before reboot on panic
—The Gardener