Can't Write Sysctl Settings? Topic is solved

Have some feedback, questions, suggestions, or just fancy a chat? Pop it in here.
Post Reply
Parkour_Lama
Posts: 34
Joined: Sat Sep 12, 2020 2:02 pm

Can't Write Sysctl Settings?

Post by Parkour_Lama »

Hello,
I added some commands to the /etc/sysctl.d/dietpi.conf as given below:

Code: Select all

# Reduce swap file usage to a minimum
vm.swappiness=10

# Allow all users to "ping" without further capabilities: https://fedoraproject.org/wiki/Changes/EnableSysctlPingGroupRange
net.ipv4.ping_group_range = 0 2147483647

#For netfilter
net.netfilter.nf_conntrack_generic_timeout=120
net.netfilter.nf_conntrack_sctp_timeout_established=54000
net.netfilter.nf_conntrack_tcp_timeout_fin_wait=60
net.netfilter.nf_conntrack_tcp_timeout_time_wait=60
net.netfilter.nf_conntrack_max=100000
Unfortunatly while reading through the journalctl boot logs, I see this:

Code: Select all

Mar 21 14:35:44 Retracted systemd-sysctl[127]: Couldn't write '120' to 'net/netfilter/nf_conntrack_generic_timeout', ignoring: No such file or directory
Mar 21 14:35:44 Retracted systemd-sysctl[127]: Couldn't write '54000' to 'net/netfilter/nf_conntrack_sctp_timeout_established', ignoring: No such file or directory
Mar 21 14:35:44 Retracted systemd-sysctl[127]: Couldn't write '60' to 'net/netfilter/nf_conntrack_tcp_timeout_fin_wait', ignoring: No such file or directory
Mar 21 14:35:44 Retracted systemd-sysctl[127]: Couldn't write '60' to 'net/netfilter/nf_conntrack_tcp_timeout_time_wait', ignoring: No such file or directory
Mar 21 14:35:44 Retracted systemd-sysctl[127]: Couldn't write '100000' to 'net/netfilter/nf_conntrack_max', ignoring: No such file or directory
So what's going wrong?
If I add sysctl -w before each statement and run them manually, it works just fine.
I've tried pasting the same in /etc/sysctl.conf, and that still produces the same error.

Also, what's the difference between the sysctl.conf and the dietpi.conf files?
User avatar
Joulinar
Posts: 5115
Joined: Sat Nov 16, 2019 12:49 am

Re: Can't Write Sysctl Settings?

Post by Joulinar »

Hi,

did you activate nf_conntrack module? It can be checked as follow

Code: Select all

lsmod | grep nf_conntrack
If it doesn't give anything, you can activate it as follow

Code: Select all

modprobe nf_conntrack
Afterwards you should see related files inside /proc/sys/net/netfilter/
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
User avatar
MichaIng
Site Admin
Posts: 3097
Joined: Sat Nov 18, 2017 6:21 pm

Re: Can't Write Sysctl Settings?

Post by MichaIng »

The init systemd loads all *.conf files inside /etc/sysctl.d/ at boot.

/etc/sysctl.conf is actually not loaded, but only via a trick as there is a symlink /etc/sysctl.d/99-sysctl.conf pointing to /etc/sysctl.conf. So the latter one is a legacy file, kept effective for backwards-compatibility only, but you should not use it anymore.

/etc/sysctl.d/dietpi.conf is our default config. You should not change it either, as it will be overwritten on DietPi updates. With these kind of *.d directories you should create your own additional files to add or overwrite settings, so system defaults are not purged but only overridden and things can be reverted easily + your changes won't be overwritten on any system update.

Sidenote: The files are loaded in alphabetic order, so you can override settings in a file by creating a new one with higher first letter/number.

The issue in your cases might indeed be that the required kernel module has not yet been loaded when those sysctl settings are. Adding a new file like echo nf_conntrack > /etc/modules-load.d/nf_conntrack.conf to have it loaded at boot should work.
Parkour_Lama
Posts: 34
Joined: Sat Sep 12, 2020 2:02 pm

Re: Can't Write Sysctl Settings?

Post by Parkour_Lama »

Yep that worked.
The nf_conntrack was loaded when I was using it, but not at startup when the commands were executed.

As for switching the files, reading through the README and added a new file local.conf and wrote all my personal settings into it. I suppose that's enough?
User avatar
MichaIng
Site Admin
Posts: 3097
Joined: Sat Nov 18, 2017 6:21 pm

Re: Can't Write Sysctl Settings?

Post by MichaIng »

Yes the local.conf will do.

Kernel modules can be loaded on demand, but obviously sysctl doesn't do it when attending to set settings that are part of a kernel module. Good that /etc/modules-load.d is loaded before /etc/sysctl.d is to solve this :).
Post Reply