<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.alpinelinux.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Gresskar</id>
	<title>Alpine Linux - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.alpinelinux.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Gresskar"/>
	<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/wiki/Special:Contributions/Gresskar"/>
	<updated>2026-05-10T02:38:19Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.40.0</generator>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Sysctl.conf&amp;diff=26833</id>
		<title>Sysctl.conf</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Sysctl.conf&amp;diff=26833"/>
		<updated>2024-06-12T21:01:43Z</updated>

		<summary type="html">&lt;p&gt;Gresskar: Added some security options&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{DISPLAYTITLE:sysctl.conf}}sysctl.conf is the configuration file at &amp;lt;code&amp;gt;/etc/sysctl.conf&amp;lt;/code&amp;gt; for [https://linux.die.net/man/8/sysctl sysctl] and is used to configure kernel parameters at boot time.  You can load the configuration file with {{Cmd|sysctl -p}} or simply with a reboot.&lt;br /&gt;
This article is not an exhaustive list but covers some of the main points. You may, of course, wish to change some settings to suite your environment.  The config examples are well commented so should provide all the information you need.  If further information is required on anything, please make a note in this page or in the &#039;discussion&#039; area.&lt;br /&gt;
Some of the options shown in the below examples may already be as default in your release. Check with &amp;lt;pre&amp;gt;sysctl -a|grep &amp;lt;somestring&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Lines beginning with a hash &#039;#&#039; are comments and are thus not read until the # is removed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= IPv6 =&lt;br /&gt;
Although IPv6 is [[Configure Networking|configured]] in  &amp;lt;code&amp;gt;/etc/network/interfaces&amp;lt;/code&amp;gt; more advanced options are configured in &amp;lt;code&amp;gt;/etc/sysctl.conf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
####Turn off IPv6 Routing####&lt;br /&gt;
## if not functioning as a router, there is no need&lt;br /&gt;
## to accept redirects or source routes&lt;br /&gt;
net.ipv6.conf.all.accept_redirects = 0&lt;br /&gt;
net.ipv6.conf.all.accept_source_route = 0&lt;br /&gt;
## Number of Router Solicitations to send until assuming no routers are present.&lt;br /&gt;
## This is a host and not router&lt;br /&gt;
net.ipv6.conf.default.router_solicitations = 2&lt;br /&gt;
&lt;br /&gt;
## Router advertisements can cause the system to assign a global &lt;br /&gt;
## unicast address to an interface&lt;br /&gt;
## Turn on/off below (default is 1, on)&lt;br /&gt;
#net.ipv6.conf.default.autoconf = 0&lt;br /&gt;
## How many global unicast IPv6 addresses can be assigned to each interface?&lt;br /&gt;
#net.ipv6.conf.all.max-addresses = 1&lt;br /&gt;
#net.ipv6.conf.default.max_addresses = 1&lt;br /&gt;
&lt;br /&gt;
##Force IPv6 off&lt;br /&gt;
#net.ipv6.conf.all.disable_ipv6 = 1&lt;br /&gt;
#net.ipv6.conf.default.disable_ipv6 = 1&lt;br /&gt;
#net.ipv6.conf.lo.disable_ipv6 = 1&lt;br /&gt;
#net.ipv6.conf.eth0.disable_ipv6 = 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= General networking and performance =&lt;br /&gt;
Do not enable (uncomment) any of this unless you know what you are doing!!  Be prepared to perform thorough testing and potentially break stuff!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### Disable routing&lt;br /&gt;
## send redirects (not a router, disable it)&lt;br /&gt;
net.ipv4.conf.all.send_redirects = 0&lt;br /&gt;
&lt;br /&gt;
## log martian packets&lt;br /&gt;
#net.ipv4.conf.all.log_martians = 1&lt;br /&gt;
&lt;br /&gt;
### Memory and buffer changes. See https://wwwx.cs.unc.edu/~sparkst/howto/network_tuning.php {{Dead link}} for more information.&lt;br /&gt;
## Increase maximum amount of memory allocated to shm&lt;br /&gt;
#kernel.shmmax = 1073741824 &lt;br /&gt;
## Improve file system performance &lt;br /&gt;
#vm.bdflush = 100 1200 128 512 15 5000 500 1884 2 &lt;br /&gt;
## This will increase the amount of memory available for socket input/output queues &lt;br /&gt;
#net.ipv4.tcp_rmem = 4096 87380 524288  &lt;br /&gt;
#net.core.rmem_max = 1048576 &lt;br /&gt;
#net.core.rmem_default = 524288 &lt;br /&gt;
#net.ipv4.tcp_wmem = 4096 65536 524288&lt;br /&gt;
#net.core.wmem_max = 1048576&lt;br /&gt;
#net.core.wmem_default = 524288 &lt;br /&gt;
#net.core.optmem_max = 25165824&lt;br /&gt;
&lt;br /&gt;
## Increase system file descriptor limit    &lt;br /&gt;
fs.file-max = 65535&lt;br /&gt;
&lt;br /&gt;
## Allow for more PID&#039;s&lt;br /&gt;
kernel.pid_max = 65536&lt;br /&gt;
&lt;br /&gt;
## Swapping too much or not enough? Disks spinning up when you&#039;d&lt;br /&gt;
## rather they didn&#039;t? Tweak these.&lt;br /&gt;
#vm.vfs_cache_pressure = 100&lt;br /&gt;
#vm.laptop_mode = 0&lt;br /&gt;
#vm.swappiness = 60&lt;br /&gt;
&lt;br /&gt;
## Set small dirty bytes values (overcomes random short system freezes)&lt;br /&gt;
## If you uncomment the below, it is set to 4MB&lt;br /&gt;
#vm.dirty_background_bytes = 4194304&lt;br /&gt;
#vm.dirty_bytes = 4194304&lt;br /&gt;
&lt;br /&gt;
## reuse/recycle time-wait sockets (this is often needed on busy servers)&lt;br /&gt;
net.ipv4.tcp_tw_reuse = 1&lt;br /&gt;
net.ipv4.tcp_tw_recycle = 1&lt;br /&gt;
&lt;br /&gt;
## Controls the number of syn retries (default is 6)&lt;br /&gt;
#net.ipv4.tcp_syn_retries = 3&lt;br /&gt;
## Controls the number of tcp syn-ack retries (default is 5)&lt;br /&gt;
#net.ipv4.tcp_synack_retries = 3&lt;br /&gt;
&lt;br /&gt;
## Change the time default value for tcp_fin_timeout connection &lt;br /&gt;
## (i.e. time to hold socket in FIN-WAIT-2 if it was closed by us)&lt;br /&gt;
## Default is 60 seconds&lt;br /&gt;
#net.ipv4.tcp_fin_timeout = 15 &lt;br /&gt;
## Decrease the time default value for tcp_keepalive_time connection&lt;br /&gt;
## (i.e. how often to send TCP keepalive message)&lt;br /&gt;
## Default is 2 hours! &lt;br /&gt;
#net.ipv4.tcp_keepalive_time = 360 &lt;br /&gt;
## Turn on tcp_window_scaling &lt;br /&gt;
#net.ipv4.tcp_window_scaling = 1 &lt;br /&gt;
## Turn on the tcp_sack &lt;br /&gt;
#net.ipv4.tcp_sack = 1 &lt;br /&gt;
## tcp_fack should be on because of sack &lt;br /&gt;
#net.ipv4.tcp_fack = 1 &lt;br /&gt;
&lt;br /&gt;
## Set the port range used for outgoing connections&lt;br /&gt;
#net.ipv4.ip_local_port_range = 1200    65000&lt;br /&gt;
&lt;br /&gt;
## the number of packets to queue on input when they arrive faster&lt;br /&gt;
## than they can be processed by the kernel (the socket queue)&lt;br /&gt;
#net.core.netdev_max_backlog = 3000&lt;br /&gt;
&lt;br /&gt;
## Maximum number of remembered connection requests which have not&lt;br /&gt;
## received an ack from connecting client.  Increases in proportion&lt;br /&gt;
## to available memory.  Set it manually below&lt;br /&gt;
#net.ipv4.tcp_max_syn_backlog = 1000&lt;br /&gt;
&lt;br /&gt;
#Don&#039;t penalize programs for using split locks. Marginally speeds up the steam and Google Chrome flatpaks.&lt;br /&gt;
kernel.split_lock_mitigate = 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Security =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Disable magic-sysrq key&lt;br /&gt;
kernel.sysrq = 0&lt;br /&gt;
&lt;br /&gt;
## Restrict dmesg access to root&lt;br /&gt;
kernel.dmesg_restrict = 1&lt;br /&gt;
&lt;br /&gt;
## optionally, ignore all echo requests&lt;br /&gt;
## this is NOT recommended, as it ignores echo requests on localhost as well&lt;br /&gt;
#net.ipv4.icmp_echo_ignore_all = 1&lt;br /&gt;
&lt;br /&gt;
## Don&#039;t expose kernel memory addresses in procfs&lt;br /&gt;
kernel.kptr_restrict = 2&lt;br /&gt;
&lt;br /&gt;
## Restrict access to kernel performance events&lt;br /&gt;
kernel.perf_event_paranoid = 2&lt;br /&gt;
&lt;br /&gt;
## Restrict unprivileged access to eBPF&lt;br /&gt;
kernel.unprivileged_bpf_disabled = 1&lt;br /&gt;
&lt;br /&gt;
## Enable JIT hardening techniques for eBPF&lt;br /&gt;
net.core.bpf_jit_harden = 2&lt;br /&gt;
&lt;br /&gt;
## Disable core dumps&lt;br /&gt;
kernel.core_pattern=|/bin/false&lt;br /&gt;
&lt;br /&gt;
## Restrict access to the ptrace() syscall&lt;br /&gt;
## a value of 3 disables ptrace() entirely&lt;br /&gt;
kernel.yama.ptrace_scope = 2&lt;br /&gt;
&lt;br /&gt;
## Increase bits of entropy for ASLR&lt;br /&gt;
## these values are compatible with x86, but other archs may differ&lt;br /&gt;
vm.mmap_rnd_bits = 32&lt;br /&gt;
vm.mmap_rnd_compat_bits = 16&lt;br /&gt;
&lt;br /&gt;
# Heavily restrict writing to FIFOs; they must be owned, not in sticky dirs...                                                                                                                                                                       &lt;br /&gt;
fs.protected_fifos = 2&lt;br /&gt;
# don&#039;t allow O_CREAT open on regular files that we don&#039;t own in world/group writable sticky directories,&lt;br /&gt;
# unless they are owned by the owner of the directory.&lt;br /&gt;
fs.protected_regular = 2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Networking]]&lt;/div&gt;</summary>
		<author><name>Gresskar</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=AppArmor&amp;diff=26832</id>
		<title>AppArmor</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=AppArmor&amp;diff=26832"/>
		<updated>2024-06-12T20:47:20Z</updated>

		<summary type="html">&lt;p&gt;Gresskar: Added Audit as a dependency when generating AppArmor profiles with the aa-* commands&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{TOC right}}&lt;br /&gt;
&lt;br /&gt;
AppArmor is a kernel security module that restricts individual programs&#039; capabilities. This can allow administrators to prevent programs accessing system resources in malicious ways according to per-applications specifications. AppArmor works by following profiles, which dictate what each application is and is not allowed to do. &lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
{{Cmd|# apk add {{Pkg|apparmor}}}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should also install &amp;lt;code&amp;gt;apparmor-utils&amp;lt;/code&amp;gt; if you want to use the &amp;lt;code&amp;gt;aa&amp;lt;/code&amp;gt; command to interact with AppArmor.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|# apk add {{Pkg|apparmor-utils}}}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Setup==&lt;br /&gt;
&lt;br /&gt;
Run the command {{Cmd|# cat /sys/kernel/security/lsm}} to see what linux security modules are currently setup. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
=== With SYSLINUX ===&lt;br /&gt;
&lt;br /&gt;
Use a text editor of your choice (preferably a TUI based one since some GUI setups don&#039;t work with privilege escalation, unless you use sudo -e) to edit &amp;lt;pre&amp;gt;/boot/extlinux.conf&amp;lt;/pre&amp;gt; such that the &amp;lt;code&amp;gt;&#039;&#039;&#039;APPEND&#039;&#039;&#039;&amp;lt;/code&amp;gt; line ends with the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lsm=landlock,yama,apparmor&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that because you&#039;re including lsm in this .conf file you are overriding the default lsm. Thus, you should include any lsm that you saw previously running in the above cat command. Additionally, lsm initializes these modules in order, so their position is important in regards to major/minor modules. Ensure that apparmor is placed first among major modules. Note for convenience that yama, capability, and landlock, which come with Alpine Linux, are not major modules, and apparmor can be placed after them. The module called capability is automatically included and does not need to be written in. &lt;br /&gt;
&lt;br /&gt;
=== With GRUB ===&lt;br /&gt;
&lt;br /&gt;
Add the following at the end of the value for key &amp;lt;code&amp;gt;&#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT&#039;&#039;&#039;&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;/etc/default/grub&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apparmor=1 security=apparmor&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then apply with:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|# grub-mkconfig -o /boot/grub/grub.cfg}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Running ==&lt;br /&gt;
&lt;br /&gt;
Next, start AppArmor and tell [[OpenRC]] to start it on boot.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Cmd|# rc-service apparmor start}}&lt;br /&gt;
&lt;br /&gt;
{{Cmd|# rc-update add apparmor boot}}&lt;br /&gt;
&lt;br /&gt;
You can check if AppArmor is running with the command &amp;lt;code&amp;gt;aa-enabled&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Cmd|# aa-enabled}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Configuration ==&lt;br /&gt;
&lt;br /&gt;
AppArmor works using rules established in profiles. A set of pre-made profiles is available for ease of use:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|# apk add {{Pkg|apparmor-profiles}}}}&lt;br /&gt;
&lt;br /&gt;
Reboot following installation&lt;br /&gt;
&lt;br /&gt;
=== Enabling Extra Profiles ===&lt;br /&gt;
&lt;br /&gt;
Extra profiles reside in {{Path|/usr/share/apparmor/extra-profiles/}}. In order to enable to profile, it needs to be copied to {{Path|/etc/apparmor.d/}}:&lt;br /&gt;
&lt;br /&gt;
If you want to enable the profile for &amp;lt;code&amp;gt;usr.bin.chromium-browser&amp;lt;/code&amp;gt;, for example:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|# cp /usr/share/apparmor/extra-profiles/usr.bin.chromium-browser /etc/apparmor.d/}}&lt;br /&gt;
&lt;br /&gt;
This will &#039;&#039;install&#039;&#039; the profile, it then needs to be set to &#039;&#039;&#039;complain&#039;&#039;&#039; or &#039;&#039;&#039;enforce&#039;&#039;&#039; mode:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|# aa-complain /etc/apparmor.d/usr.bin.chromium-browser}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Note|Use &amp;lt;code&amp;gt;aa-enforce&amp;lt;/code&amp;gt; to set it to enforce mode, &#039;&#039;&#039;but beware that this could break functionality&#039;&#039;&#039;.}}&lt;br /&gt;
&lt;br /&gt;
=== Creating additional profiles ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The profiles provided by the apparmor-profiles package are just a starter. You can create your own profiles, but first you must install and start &amp;lt;code&amp;gt;audit&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Cmd|# apk add {{Pkg|audit}}}}&lt;br /&gt;
&lt;br /&gt;
{{Cmd|# rc-service auditd start}}&lt;br /&gt;
&lt;br /&gt;
{{Cmd|# rc-update add auditd}} &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now you can generate your own profiles with&lt;br /&gt;
&lt;br /&gt;
{{Cmd|# aa-easyprof /path/to/binary}}&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
{{Cmd|# aa-genprof /path/to/binary}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that for this to work you&#039;ll probably need to set a more verbose [https://linuxconfig.org/introduction-to-the-linux-kernel-log-levels kernel log level]. For improved security, set it back to a higher level afterwards.&lt;br /&gt;
&lt;br /&gt;
== Use ==&lt;br /&gt;
&lt;br /&gt;
View AppArmor&#039;s report:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|# aa-status}}&lt;br /&gt;
&lt;br /&gt;
This details how many and what profiles are in use as well as relevant findings, such as how many profiles are in complain mode or in kill mode.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
If you notice a bunch of AppArmor errors on boot, try running &amp;lt;code&amp;gt;aa-status&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;aa-enabled&amp;lt;/code&amp;gt; in the terminal. If the output mentions AppArmor being disabled at boot, re-open your &amp;lt;code&amp;gt;/boot/extlinux.conf&amp;lt;/code&amp;gt; file and make sure the &#039;&#039;&#039;APPEND&#039;&#039;&#039; line still ends with &amp;lt;code&amp;gt;lsm=landlock,yama,apparmor&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* [https://wiki.apparmor.net/ AppArmor Wiki]&lt;br /&gt;
* [https://wiki.debian.org/AppArmor/HowToUse Debian Wiki: How to use AppArmor]&lt;br /&gt;
* [https://wiki.archlinux.org/title/AppArmor AppArmor entry on ArchWiki]&lt;br /&gt;
&lt;br /&gt;
[[Category:Security]]&lt;br /&gt;
[[Category:Kernel]]&lt;/div&gt;</summary>
		<author><name>Gresskar</name></author>
	</entry>
</feed>