<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.brammerloo.nl/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Patrick</id>
	<title>Cheatsheet - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.brammerloo.nl/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Patrick"/>
	<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Special:Contributions/Patrick"/>
	<updated>2026-05-06T15:29:07Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.40.0</generator>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Tools&amp;diff=882</id>
		<title>Linux:Tools</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Tools&amp;diff=882"/>
		<updated>2026-03-11T18:17:14Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* Curl */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet]]&lt;br /&gt;
&lt;br /&gt;
== Commands ==&lt;br /&gt;
=== Quick access ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Scroll through a file with less&lt;br /&gt;
less -s myfile.txt&lt;br /&gt;
&lt;br /&gt;
# Select line 5 from the output&lt;br /&gt;
cat example.txt | sel -e &#039;5&#039;&lt;br /&gt;
&lt;br /&gt;
# Select lines from the output, starting from the top&lt;br /&gt;
cat example.txt | head -5&lt;br /&gt;
&lt;br /&gt;
# Select lines from the output, starting from the bottom&lt;br /&gt;
cat example.txt | tail -5&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Commands ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Display the full path of a file(assuming the syslog file is available in the current folder)&lt;br /&gt;
readlink -f syslog&lt;br /&gt;
&lt;br /&gt;
# Unzip a file&lt;br /&gt;
gunzip /var/log/messages.2.gz&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Uncommon commands ===&lt;br /&gt;
* https://ngelinux.com/what-is-proc-sysrq-trigger-in-linux-and-how-to-use-sysrq-kernel-feature/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CrASHing THIs SERVer, WiTH no SurVIvORS!&lt;br /&gt;
echo c &amp;gt; /proc/sysrq-trigger&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Network ==&lt;br /&gt;
=== ping ===&lt;br /&gt;
Troubleshooting MTU: https://access.redhat.com/solutions/2440411&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Ping with an interval of 5 seconds&lt;br /&gt;
ping -i 5 192.168.0.1&lt;br /&gt;
&lt;br /&gt;
# Ping 192.168.10.5 using a specific interface&lt;br /&gt;
ping -I bond0 192.168.10.5&lt;br /&gt;
&lt;br /&gt;
# Ping 8.8.8.8 for 20 times&lt;br /&gt;
ping -c 20 8.8.8.8&lt;br /&gt;
&lt;br /&gt;
# Ping google.com using IPv4&lt;br /&gt;
ping -4 google.com&lt;br /&gt;
&lt;br /&gt;
# Ping google.com using IPv6&lt;br /&gt;
ping -6 google.com&lt;br /&gt;
&lt;br /&gt;
# Ping using packets of size 264&lt;br /&gt;
ping -s 264 1.1.1.1&lt;br /&gt;
&lt;br /&gt;
# Test an MTU-size of 9000 by sending non-fragmented packages of size 8972 (28 bytes left for the headers)&lt;br /&gt;
ping -M do -s 8972 192.168.77.88&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== traceroute ===&lt;br /&gt;
Package &#039;&#039;&#039;mtr&#039;&#039;&#039; (My traceroute) is also very good&lt;br /&gt;
&lt;br /&gt;
* https://web.archive.org/web/20110101100046/https://www.exit109.com/~jeremy/news/providers/traceroute.html&lt;br /&gt;
* [https://en.wikipedia.org/wiki/Traceroute UDP ports 33434 to 33534 are used by traceroute by default.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show the traversed hops towards google.com using IPv4&lt;br /&gt;
traceroute -4 google.com&lt;br /&gt;
&lt;br /&gt;
# Show the traversed hops towards google.com using IPv6&lt;br /&gt;
traceroute -6 google.com&lt;br /&gt;
&lt;br /&gt;
# Does the same as &amp;quot;traceroute -6 google.com&amp;quot;&lt;br /&gt;
traceroute6 google.com&lt;br /&gt;
&lt;br /&gt;
# Use ICMP for checking hops&lt;br /&gt;
traceroute -4 -I brammerloo.nl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== route ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List configured routes&lt;br /&gt;
route&lt;br /&gt;
&lt;br /&gt;
# List routes but display IPs instead of hostnames&lt;br /&gt;
route -n&lt;br /&gt;
&lt;br /&gt;
# Delete default route &lt;br /&gt;
ip route del 0.0.0.0/0 via 192.168.10.1 dev ens3&lt;br /&gt;
&lt;br /&gt;
# Delete default route (explicit)&lt;br /&gt;
ip route del default via 192.168.0.1 dev eth0 proto static metric 100&lt;br /&gt;
&lt;br /&gt;
# Add a default route via a specific IP and interface&lt;br /&gt;
ip route add default via 192.168.0.1 dev eth0 proto static metric 90&lt;br /&gt;
&lt;br /&gt;
# Add route for a network via gateway on an interface&lt;br /&gt;
ip route add 10.0.100.0/24 via 10.0.100.254 dev ens5&lt;br /&gt;
&lt;br /&gt;
# Add default route met een specifieke metric&lt;br /&gt;
ip route add default via 10.0.180.1 dev ens7 proto static metric 90&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== netstat ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Display network connections and current states&lt;br /&gt;
netstat&lt;br /&gt;
&lt;br /&gt;
# Check listening ports, connected remote IPs, processes, states and more&lt;br /&gt;
netstat -taupen&lt;br /&gt;
&lt;br /&gt;
# Check listening ports and IPs of the local server&lt;br /&gt;
netstat -tulpn&lt;br /&gt;
&lt;br /&gt;
# List the routing table&lt;br /&gt;
netstat -r&lt;br /&gt;
&lt;br /&gt;
# List verbose common TCP and ICMP information&lt;br /&gt;
netstat -s&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ss ===&lt;br /&gt;
Replacement for netstat&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Check open ports, connected IPs, processes, states and more&lt;br /&gt;
ss -taupen&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== tcpdump ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Listen on interface eth0 for traffic coming from host  172.16.0.11&lt;br /&gt;
tcpdump -i eth0 host 172.16.0.11&lt;br /&gt;
&lt;br /&gt;
# Listen on interface eno2 for traffic coming from host  172.16.1.20, going to port 443&lt;br /&gt;
tcpdump -i en02 host 172.16.1.20 port 443&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== uuidgen ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate a unique UUID (for an interface)&lt;br /&gt;
uuidgen eth0&lt;br /&gt;
7bb91614-6ffe-4bdc-9b37-c6e9d37f6987&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ip ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show network information &lt;br /&gt;
ip address&lt;br /&gt;
ip a&lt;br /&gt;
&lt;br /&gt;
# Show all configured routes&lt;br /&gt;
ip r show&lt;br /&gt;
&lt;br /&gt;
# Display statistics for all interfaces&lt;br /&gt;
ip -s link&lt;br /&gt;
&lt;br /&gt;
# Display detailed statistics for all interfaces&lt;br /&gt;
ip -s -s link&lt;br /&gt;
&lt;br /&gt;
# Execute the ifconfig command within a specific router&lt;br /&gt;
ip netns exec qrouter-asdwe49-as8d7-asd2-ert0-cvb7klj2 &amp;quot;ifconfig&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== DNS | dig &amp;amp; nslookup ===&lt;br /&gt;
* https://intodns.com/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Lookup reverse DNS host information&lt;br /&gt;
dig -x 10.0.2.15&lt;br /&gt;
&lt;br /&gt;
# Lookup the nameservers of google.com, by asking nameserver 1.1.1.1&lt;br /&gt;
dig google.com  @1.1.1.1 NS&lt;br /&gt;
&lt;br /&gt;
# Lookup reverse DNS host information&lt;br /&gt;
host 10.0.2.15&lt;br /&gt;
&lt;br /&gt;
# Lookup DNS host information&lt;br /&gt;
nslookup 10.0.2.15&lt;br /&gt;
&lt;br /&gt;
# Lookup host information for google.com while using DNS-server 8.8.8.8&lt;br /&gt;
nslookup google.com 8.8.8.8&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Package managers ==&lt;br /&gt;
=== apt ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check for updates&lt;br /&gt;
apt update&lt;br /&gt;
&lt;br /&gt;
# List packages that can be upgraded&lt;br /&gt;
apt list --upgradable&lt;br /&gt;
&lt;br /&gt;
# Installed available updates&lt;br /&gt;
apt upgrade&lt;br /&gt;
&lt;br /&gt;
# List installed packages&lt;br /&gt;
apt list --installed&lt;br /&gt;
&lt;br /&gt;
# List package details and description&lt;br /&gt;
apt show net-tools&lt;br /&gt;
&lt;br /&gt;
# Search inside all package descriptions for your keyword&lt;br /&gt;
apt-cache search ssh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rpm ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all local RPM packages&lt;br /&gt;
rpm -qa&lt;br /&gt;
&lt;br /&gt;
# Query for a specific installed rpm package&lt;br /&gt;
rpm -qi nginx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== yum ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  Search for all available packages that include string &amp;quot;nginx&amp;quot;&lt;br /&gt;
yum search nginx&lt;br /&gt;
&lt;br /&gt;
# Install the package named Nginx&lt;br /&gt;
yum install nginx&lt;br /&gt;
&lt;br /&gt;
# List installed packages&lt;br /&gt;
yum list installed&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== dnf ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  Upgrade and install updates&lt;br /&gt;
dnf upgrade&lt;br /&gt;
&lt;br /&gt;
# Remove the podman package&lt;br /&gt;
dnf remove podman&lt;br /&gt;
&lt;br /&gt;
# Show information about the zlib package&lt;br /&gt;
dnf info zlib&lt;br /&gt;
&lt;br /&gt;
# Show mandatory/optional/default packages within the Networking Tools group&lt;br /&gt;
dnf group info &amp;quot;Networking Tools&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Filesystem ==&lt;br /&gt;
=== fdisk ===&lt;br /&gt;
&#039;&#039;&#039;cfdisk&#039;&#039;&#039; is also nice&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check your disks and partitions&lt;br /&gt;
fdisk -l&lt;br /&gt;
&lt;br /&gt;
# Enter fdisk interactive mode&lt;br /&gt;
fdisk /dev/nvme0n2p1&lt;br /&gt;
&lt;br /&gt;
# List available partition types&lt;br /&gt;
l&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Format /dev/vdb as BTRFS&lt;br /&gt;
echo -e &amp;quot;n\np\n1\n\n\nt\n8E\np\nw&amp;quot; | fdisk /dev/vdb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Other ==&lt;br /&gt;
=== man + mandb ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Open the manual for the man tool&lt;br /&gt;
man man&lt;br /&gt;
&lt;br /&gt;
# Open the manual for the ls tool&lt;br /&gt;
man ls&lt;br /&gt;
&lt;br /&gt;
# &#039;Update&#039; mandb by purging and or processing manuals&lt;br /&gt;
mandb&lt;br /&gt;
&lt;br /&gt;
# Purge everything and regenerate manuals&lt;br /&gt;
mandb --create&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ls ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List folders sorted by modified date&lt;br /&gt;
ls -trol&lt;br /&gt;
&lt;br /&gt;
# List folder contents recursively&lt;br /&gt;
ls -alsR myfolder/&lt;br /&gt;
&lt;br /&gt;
# List folder contents sorted by time, newest first and reverse order&lt;br /&gt;
ls -latr myfolder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== grep ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Search for any occurences of &amp;quot;inet_interface&amp;quot; in a file&lt;br /&gt;
grep inet_interface /etc/postfix/main.cf&lt;br /&gt;
&lt;br /&gt;
# Search for pattern &amp;quot;audit&amp;quot; in file /var/log/syslog&lt;br /&gt;
grep -e &amp;quot;audit&amp;quot; /var/log/syslog&lt;br /&gt;
&lt;br /&gt;
# Search for text &amp;quot;started&amp;quot; in everything in /var/log/, and list the filename for each occurence&lt;br /&gt;
grep -H &amp;quot;started&amp;quot; /var/log/*&lt;br /&gt;
&lt;br /&gt;
# Search for any mention of &amp;quot;md&amp;quot; within a file, by piping to grep&lt;br /&gt;
cat /var/log/messages | grep md&lt;br /&gt;
&lt;br /&gt;
# Search for any of text &amp;quot;test&amp;quot; within the /etc folder recursively, also shows filename by default&lt;br /&gt;
grep -r &amp;quot;test&amp;quot; /etc&lt;br /&gt;
&lt;br /&gt;
# Recursively search for any mention of &amp;quot;audit&amp;quot; in each file within the specified directory, display linenumber and ignore low/upper case&lt;br /&gt;
grep -rni audit /var/log/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== lsof ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List what has files opened on the directory/mount&lt;br /&gt;
lsof /data/mount/lustre-01&lt;br /&gt;
&lt;br /&gt;
# List processes listening on port 443&lt;br /&gt;
lsof -i :443&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== awk ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List the first column of the output generated by docker ps&lt;br /&gt;
docker ps | awk &#039;{print $1}&#039;&lt;br /&gt;
&lt;br /&gt;
# Print 9th column of folder contents&lt;br /&gt;
ll /mnt/btrfs/share1/ | awk &#039;{print $9}&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== tar ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Compress the destination directory and keep the source path within the zipped file&lt;br /&gt;
tar -czvf name-of-archive.tar.gz /path/to/directory-or-file&lt;br /&gt;
&lt;br /&gt;
# Compress the destination directory, but put the folder contents into the . within the zipped file&lt;br /&gt;
tar -czvf name-of-archive.tar.gz -C /path/to/directory-or-file .&lt;br /&gt;
&lt;br /&gt;
# Extract a tar.gz file to the current folder&lt;br /&gt;
tar -xzvf name-of-archive.tar.gz&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== find ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Basic find command&lt;br /&gt;
find / -name name-to-search-for&lt;br /&gt;
&lt;br /&gt;
# Search the current folder for all files&lt;br /&gt;
find . -name \* &lt;br /&gt;
&lt;br /&gt;
# Search the current folder for all files and count them&lt;br /&gt;
find . -name \* | wc -l&lt;br /&gt;
&lt;br /&gt;
# Find all files with the SUID bit set&lt;br /&gt;
find / -name &amp;quot;*&amp;quot; -perm /u+s&lt;br /&gt;
&lt;br /&gt;
# Find the current folder for files that were modified in the last 15 minutes&lt;br /&gt;
find . -mmin -15 -type f -name &amp;quot;*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Search for all modified files between 2023-01-01 and 2023-12-30&lt;br /&gt;
find /var/log/ -type f -name &amp;quot;*&amp;quot; -newermt 2023-01-01 ! -newermt 2023-12-30&lt;br /&gt;
&lt;br /&gt;
# Search for all modified folders between 2022-01-01 and 2022-02-10, limited to a single folders&#039; depth&lt;br /&gt;
find /data/research001/ -maxdepth 1 -type d -newermt 2022-01-01 ! -newermt 2022-02-10&lt;br /&gt;
&lt;br /&gt;
# Search the current folder for all .log files and search &amp;amp; output any line containing string &amp;quot;error&amp;quot;&lt;br /&gt;
find . -name \*.log -exec grep -H error {} \;&lt;br /&gt;
&lt;br /&gt;
# Screwing around&lt;br /&gt;
for i in $(find URL* -name &amp;quot;*.report&amp;quot; | sort); do echo &amp;quot;$i&amp;quot; &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE ; done&lt;br /&gt;
for i in $(find URL* -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; | sort &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE ; done&lt;br /&gt;
for i in $(find URL* -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; | sort &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE | awk &#039;{print $2}&#039;; done&lt;br /&gt;
for i in $(find URL* -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE | awk &#039;{print $2}&#039;; done&lt;br /&gt;
for i in $(find * -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE | awk &#039;{print $2}&#039;; done&lt;br /&gt;
ll URL* | awk &#039;{print $9}&#039; | grep &amp;quot;*.report&amp;quot; | sort | for i in $(find * -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE | awk &#039;{print $2}&#039;; done&lt;br /&gt;
ll URL* | awk &#039;{print $9}&#039; | grep .report | sort | for i in $(find * -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE&lt;br /&gt;
&lt;br /&gt;
find URL1 -name \*.report -exec grep -H TOTAL_SIZE {} \; | LC_ALL=C awk -M &#039;BEGIN{FS=OFS=&amp;quot;\t&amp;quot;} {printf(&amp;quot;%s\t%.02f\n&amp;quot;, $1, $2/(1024*1024*1024))}&#039; | sed -e &#039;s~^.*/~~&#039; -e &#039;s~\..*SIZE~~&#039; | sort&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== less ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
25     = Go to line 25&lt;br /&gt;
g      = Go to top of file&lt;br /&gt;
G      = Go to bottom of file&lt;br /&gt;
/      = Activate search mode&lt;br /&gt;
/Error = Search for &amp;quot;Error&amp;quot;&lt;br /&gt;
n      = Move to next search result&lt;br /&gt;
N      = Move to previous search result&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Don&#039;t wrap long lines to the current screen (move left or right to see non-truncated line)&lt;br /&gt;
less -S /var/log/syslog&lt;br /&gt;
&lt;br /&gt;
# Output a file&#039;s contents and read it with less&lt;br /&gt;
cat /etc/snmpd/snmp.conf | less -S&lt;br /&gt;
&lt;br /&gt;
# Number the lines when viewing&lt;br /&gt;
less -N /var/log/messages&lt;br /&gt;
&lt;br /&gt;
# Open less at the first search result for &amp;quot;error&amp;quot;. (Do not use space between the -p parameter and your search query)&lt;br /&gt;
less -p&amp;quot;Error&amp;quot; /var/log/messages&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ssh ===&lt;br /&gt;
* https://man.openbsd.org/ssh.1&lt;br /&gt;
* https://www.openssh.com/legacy.html&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Stolen from https://www.openssh.com/legacy.html&lt;br /&gt;
ssh -Q cipher       # List supported ciphers&lt;br /&gt;
ssh -Q mac          # List supported MACs&lt;br /&gt;
ssh -Q key          # List supported public key types&lt;br /&gt;
ssh -Q kex          # List supported key exchange algorithms&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Connect to a server using a specific user&lt;br /&gt;
ssh mirelurk@192.168.0.1&lt;br /&gt;
&lt;br /&gt;
# Connect to a server using a specific RSA private key&lt;br /&gt;
ssh 192.168.0.1 -i /home/john/.ssh/id_rsa_key-5&lt;br /&gt;
&lt;br /&gt;
# Connect to a server using a specific SSH port&lt;br /&gt;
ssh 192.168.0.1 -p 1111&lt;br /&gt;
&lt;br /&gt;
# Show verbose information when connecting to a server&lt;br /&gt;
ssh -v 192.168.0.1&lt;br /&gt;
&lt;br /&gt;
# Connect using an ancient algorithm and keytype&lt;br /&gt;
ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 -c aes128-cbc  admin@10.50.10.50&lt;br /&gt;
&lt;br /&gt;
# Execute &#039;ls&#039; on a remote server and output the result to your shell session&lt;br /&gt;
echo &#039;ls&#039; | ssh -T user@10.0.20.75&lt;br /&gt;
&lt;br /&gt;
# Execute a command on a remote server and output the result to a local file&lt;br /&gt;
echo &#039;ls&#039; | ssh -T user@10.0.20.75 &amp;gt; &amp;lt;filename&amp;gt;.log&lt;br /&gt;
&lt;br /&gt;
# Log in by providing a password in the CLI&lt;br /&gt;
sshpass &#039;MyPassword&#039; ssh -XY root@10.100.25.1&lt;br /&gt;
&lt;br /&gt;
# Copy a local file to another server&lt;br /&gt;
scp /home/root/myfiletocopy ubuntu@192.168.0.10:/home/ubuntu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== vim ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Esc   Switches between input/command mode&lt;br /&gt;
&lt;br /&gt;
o     Create a new line below the current cursor position and switch to input mode&lt;br /&gt;
:wq   Save (write) and quit the file&lt;br /&gt;
:q!   Quit immediately without applying any changes&lt;br /&gt;
&lt;br /&gt;
j     Move the cursor one line downwards&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enter the Vim tutorial&lt;br /&gt;
vimtutor&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rsync ===&lt;br /&gt;
Also see rclone for enterprise storage enviroments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Copy contents of source /mnt/science/data/ to target /home/garyon/backup/science/ recursively&lt;br /&gt;
rsync -a /mnt/science/data/ /home/garyon/backup/science/&lt;br /&gt;
&lt;br /&gt;
# Copy  everything: symlinks, hardlinks, extended attributes, modified times, files, folders, etc&lt;br /&gt;
rsync -avHXS --progress /mnt/science/data/ /home/mayra/backup/science/&lt;br /&gt;
&lt;br /&gt;
# Show progress during a transfer&lt;br /&gt;
rsync -avHXS --progress /mnt/science/data/ /home/stefanie/backup/science/&lt;br /&gt;
&lt;br /&gt;
# rsync is additive by default&lt;br /&gt;
# After an initial rsync, delete files in the target that were deleted in the source&lt;br /&gt;
rsync --delete -avHXS /mnt/science/data/ /home/bob/backup/science/&lt;br /&gt;
&lt;br /&gt;
# Sync using SSH&lt;br /&gt;
rsync -avrS --delete /data/cardio/ 192.168.0.15:/backup/cardio/&lt;br /&gt;
&lt;br /&gt;
# Sync using a specific SSH port&lt;br /&gt;
rsync -avrS --rsh=&#039;ssh -p2020&#039; --delete /data/science/ 192.168.0.20:/backup/science/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Curl ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Fetch the https://brammerloo.nl webpage&lt;br /&gt;
curl https://brammerloo.nl&lt;br /&gt;
&lt;br /&gt;
# Set a max-timeout for fetching the webpage&lt;br /&gt;
curl --connect-timeout 5 https://brammerloo.nl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Basic CURL call to an API fetch information:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
mytoken=&amp;quot;supersecrettoken&amp;quot;&lt;br /&gt;
&lt;br /&gt;
curl -X &amp;quot;GET&amp;quot; &#039;https://mywebsite.brammerloo.nl/cluster/health&#039; \&lt;br /&gt;
     -H &#039;X-Requested-By: peach&#039; \&lt;br /&gt;
     -H &#039;Content-Type: application/json&#039; \&lt;br /&gt;
     -H &#039;Accept: application/json&#039; \&lt;br /&gt;
     --silent \&lt;br /&gt;
     -u &amp;quot;${mytoken}&amp;quot;:token&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of executing a CURL call with a graylog-structured JSON-payload&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
mytoken=&amp;quot;supersecrettoken&amp;quot;&lt;br /&gt;
&lt;br /&gt;
payload=&#039;{&lt;br /&gt;
    &amp;quot;queries&amp;quot;: [{&lt;br /&gt;
            &amp;quot;id&amp;quot;: &amp;quot;?&amp;quot;,&lt;br /&gt;
            &amp;quot;timerange&amp;quot;: {&lt;br /&gt;
                &amp;quot;type&amp;quot;: &amp;quot;keyword&amp;quot;,&lt;br /&gt;
                &amp;quot;keyword&amp;quot;: &amp;quot;one day ago&amp;quot;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    ]&lt;br /&gt;
}&#039;&lt;br /&gt;
&lt;br /&gt;
curl -X &amp;quot;POST&amp;quot; &amp;quot;https://mywebsite.brammerloo.nl/api/search&amp;quot; \&lt;br /&gt;
     -H &#039;X-Requested-By: roshani&#039; \&lt;br /&gt;
     -H &#039;Content-Type: application/json&#039; \&lt;br /&gt;
     -H &#039;Accept: application/json&#039; \&lt;br /&gt;
     --silent \&lt;br /&gt;
     -u &amp;quot;${mytoken}&amp;quot;:token \&lt;br /&gt;
     -d &amp;quot;$payload&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== cron ===&lt;br /&gt;
Run tasks at specific intervals.&lt;br /&gt;
&lt;br /&gt;
* https://crontab.guru/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List cron jobs for the current user&lt;br /&gt;
crontab -l&lt;br /&gt;
&lt;br /&gt;
# Modify cron jobs for the current user&lt;br /&gt;
crontab -eq&lt;br /&gt;
&lt;br /&gt;
# Run  the &amp;quot;ls&amp;quot; command every 5 minutes&lt;br /&gt;
*/5 * * * * ps aux&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== screen ===&lt;br /&gt;
Create virtual sessions on the server you&#039;re connected to.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all current sessions&lt;br /&gt;
screen -list&lt;br /&gt;
&lt;br /&gt;
# Create new session &amp;quot;mynewsession&amp;quot;&lt;br /&gt;
screen -S mynewsession&lt;br /&gt;
&lt;br /&gt;
# Detach current session&lt;br /&gt;
CTRL + A + D&lt;br /&gt;
&lt;br /&gt;
# Attach session &amp;quot;mynewssion&amp;quot;&lt;br /&gt;
screen -r mynewsession&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ldapsearch ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DC = Domain Component&lt;br /&gt;
The values that identify the domain in which the object is located, may contain subdomains too i.e. &amp;quot;DC=customer,DC=amazon,DC=com&amp;quot;&lt;br /&gt;
&lt;br /&gt;
OU =  Organization Unit&lt;br /&gt;
A container/folder in which objects or users are stored. Actively used in Microsoft Active Directory&#039;s i.e. &amp;quot;OU=janitors,DC=customer,DC=amazon,DC=com&amp;quot;&lt;br /&gt;
&lt;br /&gt;
CN = Canonical Name&lt;br /&gt;
The name of the group you&#039;re searching for or in i.e. &amp;quot;CN=fullprivilege,OU=janitors,DC=customer,DC=amazon,DC=com&amp;quot;&lt;br /&gt;
&lt;br /&gt;
UID = User Identifier&lt;br /&gt;
The unique identifier to find a user with, usually the username i.e. &amp;quot;uid=magicmike,CN=fullprivilege,OU=janitors,DC=customer,DC=amazon,DC=com&amp;quot;&lt;br /&gt;
&lt;br /&gt;
DN = Distinguished Name&lt;br /&gt;
The entire path to an object, consisting of a combination of above values, at least the DCs and a CN or UID, i.e. &amp;quot;uid=magicmike,CN=fullprivilege,OU=janitors,DC=customer,DC=amazon,DC=com&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following assumes domain &amp;quot;brammerloo.nl&amp;quot;, based on usage for FreeIPA&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Search and show attributes for user tonberry in group users in group accounts in domain brammerloo.nl, using the admin user to authenticatie&lt;br /&gt;
ldapsearch -W -b &amp;quot;uid=tonberry,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;  -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Do the same as above, but specify LDAP-server ipa01.brammerloo.nl to send the query to&lt;br /&gt;
ldapsearch -W -H ldap://ipa01.brammerloo.nl -b &amp;quot;uid=tonberry,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;  -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Do the same as above, but specify a specific port&lt;br /&gt;
ldapsearch -W -H ldap://ipa01.brammerloo.nl:389 -b &amp;quot;uid=tonberry,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;  -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Use the &amp;quot;elastic&amp;quot; user to query for attributes of the &amp;quot;elastic-users&amp;quot; group which itself is a member of the &amp;quot;groups&amp;quot; group&lt;br /&gt;
ldapsearch -W -b &amp;quot;cn=elastic-users,cn=groups,cn=accounts,dc=brammerloo,dc=nl&amp;quot;  -D &amp;quot;uid=elastic,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Do the same as above, but specify you only want the member attribute&lt;br /&gt;
ldapsearch -W -b &amp;quot;cn=elastic-users,cn=groups,cn=accounts,dc=brammerloo,dc=nl&amp;quot; -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot; member&lt;br /&gt;
&lt;br /&gt;
# Show all groups of which tonberry is a member of by searching for the memberOf attribute&lt;br /&gt;
ldapsearch -W -b &amp;quot;uid=tonberry,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;  -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot; memberOf&lt;br /&gt;
&lt;br /&gt;
# List attributes for all groups in the group &amp;quot;groups&amp;quot;&lt;br /&gt;
ldapsearch -W -b &amp;quot;cn=groups,cn=accounts,dc=brammerloo,dc=nl&amp;quot; -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== git ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List your current branch and situation&lt;br /&gt;
git status&lt;br /&gt;
&lt;br /&gt;
# List all branches and your current one&lt;br /&gt;
git branch --all&lt;br /&gt;
&lt;br /&gt;
# List all available tags&lt;br /&gt;
git tag&lt;br /&gt;
&lt;br /&gt;
# List the current selected tag&lt;br /&gt;
git describe&lt;br /&gt;
git describe --tags&lt;br /&gt;
&lt;br /&gt;
# Compare changes in the current working directory to the committed tree, and list what files have been changed&lt;br /&gt;
git diff-files&lt;br /&gt;
&lt;br /&gt;
# Compare changes in the current working directory to the committed tree, and list what has changed&lt;br /&gt;
git diff-files -p&lt;br /&gt;
&lt;br /&gt;
# Compare the committed tree to the current working directory, and list what has changed&lt;br /&gt;
git diff HEAD&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Common ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a folder and initialize it for use by git&lt;br /&gt;
mkdir gitrepo1; cd gitrepo1; git init&lt;br /&gt;
&lt;br /&gt;
# Switch to another branch&lt;br /&gt;
git checkout stable/zed&lt;br /&gt;
&lt;br /&gt;
# Switch to a specific tag&lt;br /&gt;
git checkout tags/14.11.0&lt;br /&gt;
&lt;br /&gt;
# Fetch data from the current upstream branch&lt;br /&gt;
git pull&lt;br /&gt;
&lt;br /&gt;
# Pull data from a specific branch&lt;br /&gt;
git pull origin unmaintained/yoga&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rclone ===&lt;br /&gt;
* https://rclone.org/&lt;br /&gt;
&lt;br /&gt;
==== Installation ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Install the latest version from the website&lt;br /&gt;
curl https://rclone.org/install.sh | sudo bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Example configuration based on OpenStack swift. Config should be in the homefolder of your user .config/rclone/rclone.conf:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
[swift-ssd]&lt;br /&gt;
type = swift&lt;br /&gt;
user = patrick&lt;br /&gt;
key = &amp;lt;PASSWORD&amp;gt;&lt;br /&gt;
auth = https://openstack.brammerloo.nl:5000/v3&lt;br /&gt;
region = Rotterdam&lt;br /&gt;
domain = Default&lt;br /&gt;
tenant = patrickproject&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# List all containers, buckets and or folders of container &amp;quot;swift-ssd&amp;quot;&lt;br /&gt;
rclone lsd &amp;quot;swift-ssd:&amp;quot;&lt;br /&gt;
          20 2025-02-10 09:46:00         2 ssd-container&lt;br /&gt;
           0 2025-02-10 09:46:00         1 swift-ssd&lt;br /&gt;
           0 2025-02-10 09:46:00         1 swift-ssd2&lt;br /&gt;
&lt;br /&gt;
rclone lsd &amp;quot;swift-ssd:ssd-container&amp;quot;&lt;br /&gt;
           0 2025-02-10 09:48:02        -1 mystorage&lt;br /&gt;
&lt;br /&gt;
# List contents, files, folders of bucket &amp;quot;ssd-container&amp;quot;, within container &amp;quot;swift-ssd&amp;quot;&lt;br /&gt;
rclone ls &amp;quot;swift-ssd:ssd-container&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# List the contents of file &amp;quot;asd&amp;quot;&lt;br /&gt;
rclone cat &amp;quot;swift-ssd:ssd-container/asd&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Mount an object storage to local folder /mnt/object-ssd/&lt;br /&gt;
rclone mount swift-ssd:ssd-container /mnt/object-ssd&lt;br /&gt;
&lt;br /&gt;
# Synchronize a local folder to a destination folder inside a bucket, in interactive mode&lt;br /&gt;
rclone sync -i /etc/rsyslog.d swift-ssd:ssd-container/mystorage/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== mdtest ===&lt;br /&gt;
This chapter was mostly written and contributed by Ivo Palli.&lt;br /&gt;
&lt;br /&gt;
==== General ====&lt;br /&gt;
mdtest is part of the ior performance test package.&lt;br /&gt;
&lt;br /&gt;
==== RHEL Installation ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
wget https://github.com/hpc/ior/releases/download/3.3.0/ior-3.3.0.tar.bz2&lt;br /&gt;
tar xjf ior-*.tar.bz2&lt;br /&gt;
cd ior-*/&lt;br /&gt;
&lt;br /&gt;
yum install openmpi-devel environment-modules&lt;br /&gt;
# Relog your shell so &#039;module&#039; is available&lt;br /&gt;
module load mpi&lt;br /&gt;
module list&lt;br /&gt;
./configure&lt;br /&gt;
make -j4&lt;br /&gt;
make install&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ubuntu Installation ====&lt;br /&gt;
* https://gist.github.com/hokiegeek2/3057f8bb3beb519ae9b556e41824be30&lt;br /&gt;
* https://ior.readthedocs.io/en/latest/userDoc/install.html&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
VERSION=4.0.0&lt;br /&gt;
wget https://github.com/hpc/ior/releases/download/$VERSION/ior-$VERSION.tar.gz&lt;br /&gt;
tar -xzvf ior-$VERSION.tar.gz&lt;br /&gt;
cd ior-$VERSION/&lt;br /&gt;
&lt;br /&gt;
apt install libopenmpi-dev environment-modules openmpi-bin openmpi-common libgtk2.0-dev -y&lt;br /&gt;
./configure&lt;br /&gt;
&lt;br /&gt;
make -j4&lt;br /&gt;
make install&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Usage =====&lt;br /&gt;
Note: Number of items should be a multiple of depth x branching factor&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
module load mpi&lt;br /&gt;
&lt;br /&gt;
# Run command &amp;quot;mdtest -n 2000 -z 5 -b 2 -d /mnt/ssd/&amp;quot; 10 times in a row&lt;br /&gt;
mpirun --oversubscribe --allow-run-as-root -n 10 mdtest -n 2000 -z 5 -b 2 -d /mnt/nfs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Links =====&lt;br /&gt;
* https://github.com/hpc/ior&lt;br /&gt;
* https://www.glennklockwood.com/benchmarks/mdtest.html Guide&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Tools&amp;diff=881</id>
		<title>Linux:Tools</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Tools&amp;diff=881"/>
		<updated>2026-02-23T19:11:08Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* Curl */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet]]&lt;br /&gt;
&lt;br /&gt;
== Commands ==&lt;br /&gt;
=== Quick access ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Scroll through a file with less&lt;br /&gt;
less -s myfile.txt&lt;br /&gt;
&lt;br /&gt;
# Select line 5 from the output&lt;br /&gt;
cat example.txt | sel -e &#039;5&#039;&lt;br /&gt;
&lt;br /&gt;
# Select lines from the output, starting from the top&lt;br /&gt;
cat example.txt | head -5&lt;br /&gt;
&lt;br /&gt;
# Select lines from the output, starting from the bottom&lt;br /&gt;
cat example.txt | tail -5&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Commands ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Display the full path of a file(assuming the syslog file is available in the current folder)&lt;br /&gt;
readlink -f syslog&lt;br /&gt;
&lt;br /&gt;
# Unzip a file&lt;br /&gt;
gunzip /var/log/messages.2.gz&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Uncommon commands ===&lt;br /&gt;
* https://ngelinux.com/what-is-proc-sysrq-trigger-in-linux-and-how-to-use-sysrq-kernel-feature/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CrASHing THIs SERVer, WiTH no SurVIvORS!&lt;br /&gt;
echo c &amp;gt; /proc/sysrq-trigger&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Network ==&lt;br /&gt;
=== ping ===&lt;br /&gt;
Troubleshooting MTU: https://access.redhat.com/solutions/2440411&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Ping with an interval of 5 seconds&lt;br /&gt;
ping -i 5 192.168.0.1&lt;br /&gt;
&lt;br /&gt;
# Ping 192.168.10.5 using a specific interface&lt;br /&gt;
ping -I bond0 192.168.10.5&lt;br /&gt;
&lt;br /&gt;
# Ping 8.8.8.8 for 20 times&lt;br /&gt;
ping -c 20 8.8.8.8&lt;br /&gt;
&lt;br /&gt;
# Ping google.com using IPv4&lt;br /&gt;
ping -4 google.com&lt;br /&gt;
&lt;br /&gt;
# Ping google.com using IPv6&lt;br /&gt;
ping -6 google.com&lt;br /&gt;
&lt;br /&gt;
# Ping using packets of size 264&lt;br /&gt;
ping -s 264 1.1.1.1&lt;br /&gt;
&lt;br /&gt;
# Test an MTU-size of 9000 by sending non-fragmented packages of size 8972 (28 bytes left for the headers)&lt;br /&gt;
ping -M do -s 8972 192.168.77.88&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== traceroute ===&lt;br /&gt;
Package &#039;&#039;&#039;mtr&#039;&#039;&#039; (My traceroute) is also very good&lt;br /&gt;
&lt;br /&gt;
* https://web.archive.org/web/20110101100046/https://www.exit109.com/~jeremy/news/providers/traceroute.html&lt;br /&gt;
* [https://en.wikipedia.org/wiki/Traceroute UDP ports 33434 to 33534 are used by traceroute by default.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show the traversed hops towards google.com using IPv4&lt;br /&gt;
traceroute -4 google.com&lt;br /&gt;
&lt;br /&gt;
# Show the traversed hops towards google.com using IPv6&lt;br /&gt;
traceroute -6 google.com&lt;br /&gt;
&lt;br /&gt;
# Does the same as &amp;quot;traceroute -6 google.com&amp;quot;&lt;br /&gt;
traceroute6 google.com&lt;br /&gt;
&lt;br /&gt;
# Use ICMP for checking hops&lt;br /&gt;
traceroute -4 -I brammerloo.nl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== route ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List configured routes&lt;br /&gt;
route&lt;br /&gt;
&lt;br /&gt;
# List routes but display IPs instead of hostnames&lt;br /&gt;
route -n&lt;br /&gt;
&lt;br /&gt;
# Delete default route &lt;br /&gt;
ip route del 0.0.0.0/0 via 192.168.10.1 dev ens3&lt;br /&gt;
&lt;br /&gt;
# Delete default route (explicit)&lt;br /&gt;
ip route del default via 192.168.0.1 dev eth0 proto static metric 100&lt;br /&gt;
&lt;br /&gt;
# Add a default route via a specific IP and interface&lt;br /&gt;
ip route add default via 192.168.0.1 dev eth0 proto static metric 90&lt;br /&gt;
&lt;br /&gt;
# Add route for a network via gateway on an interface&lt;br /&gt;
ip route add 10.0.100.0/24 via 10.0.100.254 dev ens5&lt;br /&gt;
&lt;br /&gt;
# Add default route met een specifieke metric&lt;br /&gt;
ip route add default via 10.0.180.1 dev ens7 proto static metric 90&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== netstat ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Display network connections and current states&lt;br /&gt;
netstat&lt;br /&gt;
&lt;br /&gt;
# Check listening ports, connected remote IPs, processes, states and more&lt;br /&gt;
netstat -taupen&lt;br /&gt;
&lt;br /&gt;
# Check listening ports and IPs of the local server&lt;br /&gt;
netstat -tulpn&lt;br /&gt;
&lt;br /&gt;
# List the routing table&lt;br /&gt;
netstat -r&lt;br /&gt;
&lt;br /&gt;
# List verbose common TCP and ICMP information&lt;br /&gt;
netstat -s&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ss ===&lt;br /&gt;
Replacement for netstat&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Check open ports, connected IPs, processes, states and more&lt;br /&gt;
ss -taupen&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== tcpdump ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Listen on interface eth0 for traffic coming from host  172.16.0.11&lt;br /&gt;
tcpdump -i eth0 host 172.16.0.11&lt;br /&gt;
&lt;br /&gt;
# Listen on interface eno2 for traffic coming from host  172.16.1.20, going to port 443&lt;br /&gt;
tcpdump -i en02 host 172.16.1.20 port 443&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== uuidgen ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate a unique UUID (for an interface)&lt;br /&gt;
uuidgen eth0&lt;br /&gt;
7bb91614-6ffe-4bdc-9b37-c6e9d37f6987&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ip ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show network information &lt;br /&gt;
ip address&lt;br /&gt;
ip a&lt;br /&gt;
&lt;br /&gt;
# Show all configured routes&lt;br /&gt;
ip r show&lt;br /&gt;
&lt;br /&gt;
# Display statistics for all interfaces&lt;br /&gt;
ip -s link&lt;br /&gt;
&lt;br /&gt;
# Display detailed statistics for all interfaces&lt;br /&gt;
ip -s -s link&lt;br /&gt;
&lt;br /&gt;
# Execute the ifconfig command within a specific router&lt;br /&gt;
ip netns exec qrouter-asdwe49-as8d7-asd2-ert0-cvb7klj2 &amp;quot;ifconfig&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== DNS | dig &amp;amp; nslookup ===&lt;br /&gt;
* https://intodns.com/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Lookup reverse DNS host information&lt;br /&gt;
dig -x 10.0.2.15&lt;br /&gt;
&lt;br /&gt;
# Lookup the nameservers of google.com, by asking nameserver 1.1.1.1&lt;br /&gt;
dig google.com  @1.1.1.1 NS&lt;br /&gt;
&lt;br /&gt;
# Lookup reverse DNS host information&lt;br /&gt;
host 10.0.2.15&lt;br /&gt;
&lt;br /&gt;
# Lookup DNS host information&lt;br /&gt;
nslookup 10.0.2.15&lt;br /&gt;
&lt;br /&gt;
# Lookup host information for google.com while using DNS-server 8.8.8.8&lt;br /&gt;
nslookup google.com 8.8.8.8&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Package managers ==&lt;br /&gt;
=== apt ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check for updates&lt;br /&gt;
apt update&lt;br /&gt;
&lt;br /&gt;
# List packages that can be upgraded&lt;br /&gt;
apt list --upgradable&lt;br /&gt;
&lt;br /&gt;
# Installed available updates&lt;br /&gt;
apt upgrade&lt;br /&gt;
&lt;br /&gt;
# List installed packages&lt;br /&gt;
apt list --installed&lt;br /&gt;
&lt;br /&gt;
# List package details and description&lt;br /&gt;
apt show net-tools&lt;br /&gt;
&lt;br /&gt;
# Search inside all package descriptions for your keyword&lt;br /&gt;
apt-cache search ssh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rpm ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all local RPM packages&lt;br /&gt;
rpm -qa&lt;br /&gt;
&lt;br /&gt;
# Query for a specific installed rpm package&lt;br /&gt;
rpm -qi nginx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== yum ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  Search for all available packages that include string &amp;quot;nginx&amp;quot;&lt;br /&gt;
yum search nginx&lt;br /&gt;
&lt;br /&gt;
# Install the package named Nginx&lt;br /&gt;
yum install nginx&lt;br /&gt;
&lt;br /&gt;
# List installed packages&lt;br /&gt;
yum list installed&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== dnf ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  Upgrade and install updates&lt;br /&gt;
dnf upgrade&lt;br /&gt;
&lt;br /&gt;
# Remove the podman package&lt;br /&gt;
dnf remove podman&lt;br /&gt;
&lt;br /&gt;
# Show information about the zlib package&lt;br /&gt;
dnf info zlib&lt;br /&gt;
&lt;br /&gt;
# Show mandatory/optional/default packages within the Networking Tools group&lt;br /&gt;
dnf group info &amp;quot;Networking Tools&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Filesystem ==&lt;br /&gt;
=== fdisk ===&lt;br /&gt;
&#039;&#039;&#039;cfdisk&#039;&#039;&#039; is also nice&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check your disks and partitions&lt;br /&gt;
fdisk -l&lt;br /&gt;
&lt;br /&gt;
# Enter fdisk interactive mode&lt;br /&gt;
fdisk /dev/nvme0n2p1&lt;br /&gt;
&lt;br /&gt;
# List available partition types&lt;br /&gt;
l&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Format /dev/vdb as BTRFS&lt;br /&gt;
echo -e &amp;quot;n\np\n1\n\n\nt\n8E\np\nw&amp;quot; | fdisk /dev/vdb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Other ==&lt;br /&gt;
=== man + mandb ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Open the manual for the man tool&lt;br /&gt;
man man&lt;br /&gt;
&lt;br /&gt;
# Open the manual for the ls tool&lt;br /&gt;
man ls&lt;br /&gt;
&lt;br /&gt;
# &#039;Update&#039; mandb by purging and or processing manuals&lt;br /&gt;
mandb&lt;br /&gt;
&lt;br /&gt;
# Purge everything and regenerate manuals&lt;br /&gt;
mandb --create&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ls ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List folders sorted by modified date&lt;br /&gt;
ls -trol&lt;br /&gt;
&lt;br /&gt;
# List folder contents recursively&lt;br /&gt;
ls -alsR myfolder/&lt;br /&gt;
&lt;br /&gt;
# List folder contents sorted by time, newest first and reverse order&lt;br /&gt;
ls -latr myfolder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== grep ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Search for any occurences of &amp;quot;inet_interface&amp;quot; in a file&lt;br /&gt;
grep inet_interface /etc/postfix/main.cf&lt;br /&gt;
&lt;br /&gt;
# Search for pattern &amp;quot;audit&amp;quot; in file /var/log/syslog&lt;br /&gt;
grep -e &amp;quot;audit&amp;quot; /var/log/syslog&lt;br /&gt;
&lt;br /&gt;
# Search for text &amp;quot;started&amp;quot; in everything in /var/log/, and list the filename for each occurence&lt;br /&gt;
grep -H &amp;quot;started&amp;quot; /var/log/*&lt;br /&gt;
&lt;br /&gt;
# Search for any mention of &amp;quot;md&amp;quot; within a file, by piping to grep&lt;br /&gt;
cat /var/log/messages | grep md&lt;br /&gt;
&lt;br /&gt;
# Search for any of text &amp;quot;test&amp;quot; within the /etc folder recursively, also shows filename by default&lt;br /&gt;
grep -r &amp;quot;test&amp;quot; /etc&lt;br /&gt;
&lt;br /&gt;
# Recursively search for any mention of &amp;quot;audit&amp;quot; in each file within the specified directory, display linenumber and ignore low/upper case&lt;br /&gt;
grep -rni audit /var/log/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== lsof ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List what has files opened on the directory/mount&lt;br /&gt;
lsof /data/mount/lustre-01&lt;br /&gt;
&lt;br /&gt;
# List processes listening on port 443&lt;br /&gt;
lsof -i :443&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== awk ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List the first column of the output generated by docker ps&lt;br /&gt;
docker ps | awk &#039;{print $1}&#039;&lt;br /&gt;
&lt;br /&gt;
# Print 9th column of folder contents&lt;br /&gt;
ll /mnt/btrfs/share1/ | awk &#039;{print $9}&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== tar ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Compress the destination directory and keep the source path within the zipped file&lt;br /&gt;
tar -czvf name-of-archive.tar.gz /path/to/directory-or-file&lt;br /&gt;
&lt;br /&gt;
# Compress the destination directory, but put the folder contents into the . within the zipped file&lt;br /&gt;
tar -czvf name-of-archive.tar.gz -C /path/to/directory-or-file .&lt;br /&gt;
&lt;br /&gt;
# Extract a tar.gz file to the current folder&lt;br /&gt;
tar -xzvf name-of-archive.tar.gz&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== find ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Basic find command&lt;br /&gt;
find / -name name-to-search-for&lt;br /&gt;
&lt;br /&gt;
# Search the current folder for all files&lt;br /&gt;
find . -name \* &lt;br /&gt;
&lt;br /&gt;
# Search the current folder for all files and count them&lt;br /&gt;
find . -name \* | wc -l&lt;br /&gt;
&lt;br /&gt;
# Find all files with the SUID bit set&lt;br /&gt;
find / -name &amp;quot;*&amp;quot; -perm /u+s&lt;br /&gt;
&lt;br /&gt;
# Find the current folder for files that were modified in the last 15 minutes&lt;br /&gt;
find . -mmin -15 -type f -name &amp;quot;*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Search for all modified files between 2023-01-01 and 2023-12-30&lt;br /&gt;
find /var/log/ -type f -name &amp;quot;*&amp;quot; -newermt 2023-01-01 ! -newermt 2023-12-30&lt;br /&gt;
&lt;br /&gt;
# Search for all modified folders between 2022-01-01 and 2022-02-10, limited to a single folders&#039; depth&lt;br /&gt;
find /data/research001/ -maxdepth 1 -type d -newermt 2022-01-01 ! -newermt 2022-02-10&lt;br /&gt;
&lt;br /&gt;
# Search the current folder for all .log files and search &amp;amp; output any line containing string &amp;quot;error&amp;quot;&lt;br /&gt;
find . -name \*.log -exec grep -H error {} \;&lt;br /&gt;
&lt;br /&gt;
# Screwing around&lt;br /&gt;
for i in $(find URL* -name &amp;quot;*.report&amp;quot; | sort); do echo &amp;quot;$i&amp;quot; &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE ; done&lt;br /&gt;
for i in $(find URL* -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; | sort &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE ; done&lt;br /&gt;
for i in $(find URL* -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; | sort &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE | awk &#039;{print $2}&#039;; done&lt;br /&gt;
for i in $(find URL* -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE | awk &#039;{print $2}&#039;; done&lt;br /&gt;
for i in $(find * -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE | awk &#039;{print $2}&#039;; done&lt;br /&gt;
ll URL* | awk &#039;{print $9}&#039; | grep &amp;quot;*.report&amp;quot; | sort | for i in $(find * -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE | awk &#039;{print $2}&#039;; done&lt;br /&gt;
ll URL* | awk &#039;{print $9}&#039; | grep .report | sort | for i in $(find * -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE&lt;br /&gt;
&lt;br /&gt;
find URL1 -name \*.report -exec grep -H TOTAL_SIZE {} \; | LC_ALL=C awk -M &#039;BEGIN{FS=OFS=&amp;quot;\t&amp;quot;} {printf(&amp;quot;%s\t%.02f\n&amp;quot;, $1, $2/(1024*1024*1024))}&#039; | sed -e &#039;s~^.*/~~&#039; -e &#039;s~\..*SIZE~~&#039; | sort&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== less ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
25     = Go to line 25&lt;br /&gt;
g      = Go to top of file&lt;br /&gt;
G      = Go to bottom of file&lt;br /&gt;
/      = Activate search mode&lt;br /&gt;
/Error = Search for &amp;quot;Error&amp;quot;&lt;br /&gt;
n      = Move to next search result&lt;br /&gt;
N      = Move to previous search result&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Don&#039;t wrap long lines to the current screen (move left or right to see non-truncated line)&lt;br /&gt;
less -S /var/log/syslog&lt;br /&gt;
&lt;br /&gt;
# Output a file&#039;s contents and read it with less&lt;br /&gt;
cat /etc/snmpd/snmp.conf | less -S&lt;br /&gt;
&lt;br /&gt;
# Number the lines when viewing&lt;br /&gt;
less -N /var/log/messages&lt;br /&gt;
&lt;br /&gt;
# Open less at the first search result for &amp;quot;error&amp;quot;. (Do not use space between the -p parameter and your search query)&lt;br /&gt;
less -p&amp;quot;Error&amp;quot; /var/log/messages&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ssh ===&lt;br /&gt;
* https://man.openbsd.org/ssh.1&lt;br /&gt;
* https://www.openssh.com/legacy.html&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Stolen from https://www.openssh.com/legacy.html&lt;br /&gt;
ssh -Q cipher       # List supported ciphers&lt;br /&gt;
ssh -Q mac          # List supported MACs&lt;br /&gt;
ssh -Q key          # List supported public key types&lt;br /&gt;
ssh -Q kex          # List supported key exchange algorithms&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Connect to a server using a specific user&lt;br /&gt;
ssh mirelurk@192.168.0.1&lt;br /&gt;
&lt;br /&gt;
# Connect to a server using a specific RSA private key&lt;br /&gt;
ssh 192.168.0.1 -i /home/john/.ssh/id_rsa_key-5&lt;br /&gt;
&lt;br /&gt;
# Connect to a server using a specific SSH port&lt;br /&gt;
ssh 192.168.0.1 -p 1111&lt;br /&gt;
&lt;br /&gt;
# Show verbose information when connecting to a server&lt;br /&gt;
ssh -v 192.168.0.1&lt;br /&gt;
&lt;br /&gt;
# Connect using an ancient algorithm and keytype&lt;br /&gt;
ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 -c aes128-cbc  admin@10.50.10.50&lt;br /&gt;
&lt;br /&gt;
# Execute &#039;ls&#039; on a remote server and output the result to your shell session&lt;br /&gt;
echo &#039;ls&#039; | ssh -T user@10.0.20.75&lt;br /&gt;
&lt;br /&gt;
# Execute a command on a remote server and output the result to a local file&lt;br /&gt;
echo &#039;ls&#039; | ssh -T user@10.0.20.75 &amp;gt; &amp;lt;filename&amp;gt;.log&lt;br /&gt;
&lt;br /&gt;
# Log in by providing a password in the CLI&lt;br /&gt;
sshpass &#039;MyPassword&#039; ssh -XY root@10.100.25.1&lt;br /&gt;
&lt;br /&gt;
# Copy a local file to another server&lt;br /&gt;
scp /home/root/myfiletocopy ubuntu@192.168.0.10:/home/ubuntu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== vim ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Esc   Switches between input/command mode&lt;br /&gt;
&lt;br /&gt;
o     Create a new line below the current cursor position and switch to input mode&lt;br /&gt;
:wq   Save (write) and quit the file&lt;br /&gt;
:q!   Quit immediately without applying any changes&lt;br /&gt;
&lt;br /&gt;
j     Move the cursor one line downwards&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enter the Vim tutorial&lt;br /&gt;
vimtutor&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rsync ===&lt;br /&gt;
Also see rclone for enterprise storage enviroments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Copy contents of source /mnt/science/data/ to target /home/garyon/backup/science/ recursively&lt;br /&gt;
rsync -a /mnt/science/data/ /home/garyon/backup/science/&lt;br /&gt;
&lt;br /&gt;
# Copy  everything: symlinks, hardlinks, extended attributes, modified times, files, folders, etc&lt;br /&gt;
rsync -avHXS --progress /mnt/science/data/ /home/mayra/backup/science/&lt;br /&gt;
&lt;br /&gt;
# Show progress during a transfer&lt;br /&gt;
rsync -avHXS --progress /mnt/science/data/ /home/stefanie/backup/science/&lt;br /&gt;
&lt;br /&gt;
# rsync is additive by default&lt;br /&gt;
# After an initial rsync, delete files in the target that were deleted in the source&lt;br /&gt;
rsync --delete -avHXS /mnt/science/data/ /home/bob/backup/science/&lt;br /&gt;
&lt;br /&gt;
# Sync using SSH&lt;br /&gt;
rsync -avrS --delete /data/cardio/ 192.168.0.15:/backup/cardio/&lt;br /&gt;
&lt;br /&gt;
# Sync using a specific SSH port&lt;br /&gt;
rsync -avrS --rsh=&#039;ssh -p2020&#039; --delete /data/science/ 192.168.0.20:/backup/science/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Curl ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Fetch the https://brammerloo.nl webpage&lt;br /&gt;
curl https://brammerloo.nl&lt;br /&gt;
&lt;br /&gt;
# Set a max-timeout for fetching the webpage&lt;br /&gt;
curl --connect-timeout 5 https://brammerloo.nl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Basic CURL call to an API fetch information:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
mytoken=&amp;quot;supersecrettoken&amp;quot;&lt;br /&gt;
&lt;br /&gt;
curl -X &amp;quot;GET&amp;quot; &#039;https://mywebsite.brammerloo.nl/cluster/health&#039; \&lt;br /&gt;
     -H &#039;X-Requested-By: peach&#039; \&lt;br /&gt;
     -H &#039;Content-Type: application/json&#039; \&lt;br /&gt;
     -H &#039;Accept: application/json&#039; \&lt;br /&gt;
     --silent \&lt;br /&gt;
     -u &amp;quot;${mytoken}&amp;quot;:token&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of executing a CURL call with a JSON-payload&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
mytoken=&amp;quot;supersecrettoken&amp;quot;&lt;br /&gt;
&lt;br /&gt;
curl -X &amp;quot;POST&amp;quot; &amp;quot;https://mywebsite.brammerloo.nl/api/search&amp;quot; \&lt;br /&gt;
     -H &#039;X-Requested-By: roshani&#039; \&lt;br /&gt;
     -H &#039;Content-Type: application/json&#039; \&lt;br /&gt;
     -H &#039;Accept: application/json&#039; \&lt;br /&gt;
     --silent \&lt;br /&gt;
     -u &amp;quot;${mytoken}&amp;quot;:token \&lt;br /&gt;
     -d &amp;quot;$curly&amp;quot;&lt;br /&gt;
&lt;br /&gt;
curly=&#039;{&lt;br /&gt;
    &amp;quot;queries&amp;quot;: [{&lt;br /&gt;
            &amp;quot;id&amp;quot;: &amp;quot;?&amp;quot;,&lt;br /&gt;
            &amp;quot;timerange&amp;quot;: {&lt;br /&gt;
                &amp;quot;type&amp;quot;: &amp;quot;keyword&amp;quot;,&lt;br /&gt;
                &amp;quot;keyword&amp;quot;: &amp;quot;one day ago&amp;quot;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    ]&lt;br /&gt;
}&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== cron ===&lt;br /&gt;
Run tasks at specific intervals.&lt;br /&gt;
&lt;br /&gt;
* https://crontab.guru/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List cron jobs for the current user&lt;br /&gt;
crontab -l&lt;br /&gt;
&lt;br /&gt;
# Modify cron jobs for the current user&lt;br /&gt;
crontab -eq&lt;br /&gt;
&lt;br /&gt;
# Run  the &amp;quot;ls&amp;quot; command every 5 minutes&lt;br /&gt;
*/5 * * * * ps aux&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== screen ===&lt;br /&gt;
Create virtual sessions on the server you&#039;re connected to.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all current sessions&lt;br /&gt;
screen -list&lt;br /&gt;
&lt;br /&gt;
# Create new session &amp;quot;mynewsession&amp;quot;&lt;br /&gt;
screen -S mynewsession&lt;br /&gt;
&lt;br /&gt;
# Detach current session&lt;br /&gt;
CTRL + A + D&lt;br /&gt;
&lt;br /&gt;
# Attach session &amp;quot;mynewssion&amp;quot;&lt;br /&gt;
screen -r mynewsession&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ldapsearch ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DC = Domain Component&lt;br /&gt;
The values that identify the domain in which the object is located, may contain subdomains too i.e. &amp;quot;DC=customer,DC=amazon,DC=com&amp;quot;&lt;br /&gt;
&lt;br /&gt;
OU =  Organization Unit&lt;br /&gt;
A container/folder in which objects or users are stored. Actively used in Microsoft Active Directory&#039;s i.e. &amp;quot;OU=janitors,DC=customer,DC=amazon,DC=com&amp;quot;&lt;br /&gt;
&lt;br /&gt;
CN = Canonical Name&lt;br /&gt;
The name of the group you&#039;re searching for or in i.e. &amp;quot;CN=fullprivilege,OU=janitors,DC=customer,DC=amazon,DC=com&amp;quot;&lt;br /&gt;
&lt;br /&gt;
UID = User Identifier&lt;br /&gt;
The unique identifier to find a user with, usually the username i.e. &amp;quot;uid=magicmike,CN=fullprivilege,OU=janitors,DC=customer,DC=amazon,DC=com&amp;quot;&lt;br /&gt;
&lt;br /&gt;
DN = Distinguished Name&lt;br /&gt;
The entire path to an object, consisting of a combination of above values, at least the DCs and a CN or UID, i.e. &amp;quot;uid=magicmike,CN=fullprivilege,OU=janitors,DC=customer,DC=amazon,DC=com&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following assumes domain &amp;quot;brammerloo.nl&amp;quot;, based on usage for FreeIPA&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Search and show attributes for user tonberry in group users in group accounts in domain brammerloo.nl, using the admin user to authenticatie&lt;br /&gt;
ldapsearch -W -b &amp;quot;uid=tonberry,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;  -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Do the same as above, but specify LDAP-server ipa01.brammerloo.nl to send the query to&lt;br /&gt;
ldapsearch -W -H ldap://ipa01.brammerloo.nl -b &amp;quot;uid=tonberry,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;  -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Do the same as above, but specify a specific port&lt;br /&gt;
ldapsearch -W -H ldap://ipa01.brammerloo.nl:389 -b &amp;quot;uid=tonberry,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;  -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Use the &amp;quot;elastic&amp;quot; user to query for attributes of the &amp;quot;elastic-users&amp;quot; group which itself is a member of the &amp;quot;groups&amp;quot; group&lt;br /&gt;
ldapsearch -W -b &amp;quot;cn=elastic-users,cn=groups,cn=accounts,dc=brammerloo,dc=nl&amp;quot;  -D &amp;quot;uid=elastic,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Do the same as above, but specify you only want the member attribute&lt;br /&gt;
ldapsearch -W -b &amp;quot;cn=elastic-users,cn=groups,cn=accounts,dc=brammerloo,dc=nl&amp;quot; -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot; member&lt;br /&gt;
&lt;br /&gt;
# Show all groups of which tonberry is a member of by searching for the memberOf attribute&lt;br /&gt;
ldapsearch -W -b &amp;quot;uid=tonberry,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;  -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot; memberOf&lt;br /&gt;
&lt;br /&gt;
# List attributes for all groups in the group &amp;quot;groups&amp;quot;&lt;br /&gt;
ldapsearch -W -b &amp;quot;cn=groups,cn=accounts,dc=brammerloo,dc=nl&amp;quot; -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== git ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List your current branch and situation&lt;br /&gt;
git status&lt;br /&gt;
&lt;br /&gt;
# List all branches and your current one&lt;br /&gt;
git branch --all&lt;br /&gt;
&lt;br /&gt;
# List all available tags&lt;br /&gt;
git tag&lt;br /&gt;
&lt;br /&gt;
# List the current selected tag&lt;br /&gt;
git describe&lt;br /&gt;
git describe --tags&lt;br /&gt;
&lt;br /&gt;
# Compare changes in the current working directory to the committed tree, and list what files have been changed&lt;br /&gt;
git diff-files&lt;br /&gt;
&lt;br /&gt;
# Compare changes in the current working directory to the committed tree, and list what has changed&lt;br /&gt;
git diff-files -p&lt;br /&gt;
&lt;br /&gt;
# Compare the committed tree to the current working directory, and list what has changed&lt;br /&gt;
git diff HEAD&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Common ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a folder and initialize it for use by git&lt;br /&gt;
mkdir gitrepo1; cd gitrepo1; git init&lt;br /&gt;
&lt;br /&gt;
# Switch to another branch&lt;br /&gt;
git checkout stable/zed&lt;br /&gt;
&lt;br /&gt;
# Switch to a specific tag&lt;br /&gt;
git checkout tags/14.11.0&lt;br /&gt;
&lt;br /&gt;
# Fetch data from the current upstream branch&lt;br /&gt;
git pull&lt;br /&gt;
&lt;br /&gt;
# Pull data from a specific branch&lt;br /&gt;
git pull origin unmaintained/yoga&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rclone ===&lt;br /&gt;
* https://rclone.org/&lt;br /&gt;
&lt;br /&gt;
==== Installation ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Install the latest version from the website&lt;br /&gt;
curl https://rclone.org/install.sh | sudo bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Example configuration based on OpenStack swift. Config should be in the homefolder of your user .config/rclone/rclone.conf:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
[swift-ssd]&lt;br /&gt;
type = swift&lt;br /&gt;
user = patrick&lt;br /&gt;
key = &amp;lt;PASSWORD&amp;gt;&lt;br /&gt;
auth = https://openstack.brammerloo.nl:5000/v3&lt;br /&gt;
region = Rotterdam&lt;br /&gt;
domain = Default&lt;br /&gt;
tenant = patrickproject&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# List all containers, buckets and or folders of container &amp;quot;swift-ssd&amp;quot;&lt;br /&gt;
rclone lsd &amp;quot;swift-ssd:&amp;quot;&lt;br /&gt;
          20 2025-02-10 09:46:00         2 ssd-container&lt;br /&gt;
           0 2025-02-10 09:46:00         1 swift-ssd&lt;br /&gt;
           0 2025-02-10 09:46:00         1 swift-ssd2&lt;br /&gt;
&lt;br /&gt;
rclone lsd &amp;quot;swift-ssd:ssd-container&amp;quot;&lt;br /&gt;
           0 2025-02-10 09:48:02        -1 mystorage&lt;br /&gt;
&lt;br /&gt;
# List contents, files, folders of bucket &amp;quot;ssd-container&amp;quot;, within container &amp;quot;swift-ssd&amp;quot;&lt;br /&gt;
rclone ls &amp;quot;swift-ssd:ssd-container&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# List the contents of file &amp;quot;asd&amp;quot;&lt;br /&gt;
rclone cat &amp;quot;swift-ssd:ssd-container/asd&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Mount an object storage to local folder /mnt/object-ssd/&lt;br /&gt;
rclone mount swift-ssd:ssd-container /mnt/object-ssd&lt;br /&gt;
&lt;br /&gt;
# Synchronize a local folder to a destination folder inside a bucket, in interactive mode&lt;br /&gt;
rclone sync -i /etc/rsyslog.d swift-ssd:ssd-container/mystorage/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== mdtest ===&lt;br /&gt;
This chapter was mostly written and contributed by Ivo Palli.&lt;br /&gt;
&lt;br /&gt;
==== General ====&lt;br /&gt;
mdtest is part of the ior performance test package.&lt;br /&gt;
&lt;br /&gt;
==== RHEL Installation ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
wget https://github.com/hpc/ior/releases/download/3.3.0/ior-3.3.0.tar.bz2&lt;br /&gt;
tar xjf ior-*.tar.bz2&lt;br /&gt;
cd ior-*/&lt;br /&gt;
&lt;br /&gt;
yum install openmpi-devel environment-modules&lt;br /&gt;
# Relog your shell so &#039;module&#039; is available&lt;br /&gt;
module load mpi&lt;br /&gt;
module list&lt;br /&gt;
./configure&lt;br /&gt;
make -j4&lt;br /&gt;
make install&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ubuntu Installation ====&lt;br /&gt;
* https://gist.github.com/hokiegeek2/3057f8bb3beb519ae9b556e41824be30&lt;br /&gt;
* https://ior.readthedocs.io/en/latest/userDoc/install.html&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
VERSION=4.0.0&lt;br /&gt;
wget https://github.com/hpc/ior/releases/download/$VERSION/ior-$VERSION.tar.gz&lt;br /&gt;
tar -xzvf ior-$VERSION.tar.gz&lt;br /&gt;
cd ior-$VERSION/&lt;br /&gt;
&lt;br /&gt;
apt install libopenmpi-dev environment-modules openmpi-bin openmpi-common libgtk2.0-dev -y&lt;br /&gt;
./configure&lt;br /&gt;
&lt;br /&gt;
make -j4&lt;br /&gt;
make install&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Usage =====&lt;br /&gt;
Note: Number of items should be a multiple of depth x branching factor&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
module load mpi&lt;br /&gt;
&lt;br /&gt;
# Run command &amp;quot;mdtest -n 2000 -z 5 -b 2 -d /mnt/ssd/&amp;quot; 10 times in a row&lt;br /&gt;
mpirun --oversubscribe --allow-run-as-root -n 10 mdtest -n 2000 -z 5 -b 2 -d /mnt/nfs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Links =====&lt;br /&gt;
* https://github.com/hpc/ior&lt;br /&gt;
* https://www.glennklockwood.com/benchmarks/mdtest.html Guide&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Windows&amp;diff=880</id>
		<title>Windows</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Windows&amp;diff=880"/>
		<updated>2026-02-18T10:18:27Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* Processes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet]]&lt;br /&gt;
&lt;br /&gt;
== Important applications ==&lt;br /&gt;
=== Desktop ===&lt;br /&gt;
&#039;&#039;&#039;SSH&#039;&#039;&#039;&lt;br /&gt;
* MobaxTerm - https://mobaxterm.mobatek.net/&lt;br /&gt;
* Putty &amp;amp; Puttygen - https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Code / Automation&#039;&#039;&#039;&lt;br /&gt;
* VSCodium&lt;br /&gt;
* Intellij Idea&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Databases&#039;&#039;&#039;&lt;br /&gt;
* DBeaver&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Windows management&#039;&#039;&#039;&lt;br /&gt;
* Windows Remote Desktop&lt;br /&gt;
* Windows Remote Server Administration Tools - https://learn.microsoft.com/en-us/troubleshoot/windows-server/system-management-components/remote-server-administration-tools&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Hypervisors&#039;&#039;&#039;&lt;br /&gt;
* Hyper-V&lt;br /&gt;
* VirtualBox&lt;br /&gt;
* VMWare Worststation&lt;br /&gt;
&lt;br /&gt;
=== Server ===&lt;br /&gt;
* BgInfo - https://learn.microsoft.com/en-us/sysinternals/downloads/bginfo&lt;br /&gt;
* Process Monitor - https://learn.microsoft.com/en-us/sysinternals/downloads/procmon&lt;br /&gt;
&lt;br /&gt;
=== Processes ===&lt;br /&gt;
Open the &amp;quot;Run&amp;quot; program by pressing &#039;&#039;&#039;Windows key + R&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
control             Open the Control Panel&lt;br /&gt;
ncpa.cpl            Network Control Panel&lt;br /&gt;
resmon              Resource Monitor&lt;br /&gt;
sysdm.cpl           System properties&lt;br /&gt;
devmgmt.msc         Device Manager&lt;br /&gt;
services.msc        Services            &lt;br /&gt;
compmgmt.msc        Computer management&lt;br /&gt;
wf.msc              Advanced Windows Firewall&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Powershell ==&lt;br /&gt;
=== Checks ===&lt;br /&gt;
==== Network ====&lt;br /&gt;
* https://azega.org/list-open-ports-using-powershell/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# List open ports and related IP-addresses&lt;br /&gt;
Get-NetTCPConnection&lt;br /&gt;
&lt;br /&gt;
# Test the network-connection to a specific IP and port&lt;br /&gt;
Test-NetConnection -ComputerName 192.168.200.20 -InformationLevel &amp;quot;Detailed&amp;quot; -Port 443&lt;br /&gt;
&lt;br /&gt;
# List basic interface information&lt;br /&gt;
Get-NetAdapter&lt;br /&gt;
&lt;br /&gt;
# List basic interface address information&lt;br /&gt;
Get-NetIPConfiguration&lt;br /&gt;
&lt;br /&gt;
# &amp;quot;To show only the listening ports we need to filter for all items in the Listen state with the remote address of 0.0.0.0&amp;quot;&lt;br /&gt;
get-nettcpconnection | where {($_.State -eq &amp;quot;Listen&amp;quot;) -and ($_.RemoteAddress -eq &amp;quot;0.0.0.0&amp;quot;)}&lt;br /&gt;
&lt;br /&gt;
# &amp;quot;You can add additional fields like the process ID for each port. Changing the fields from the default requires selecting each one you want and then piping to ft (format-table).&amp;quot;&lt;br /&gt;
get-nettcpconnection | where {($_.State -eq &amp;quot;Listen&amp;quot;) -and ($_.RemoteAddress -eq &amp;quot;0.0.0.0&amp;quot;)} | Select LocalAddress,LocalPort,RemoteAddress,RemotePort,State,OwningProcess | ft&lt;br /&gt;
&lt;br /&gt;
# &amp;quot;This example will get the name of the process associated with each item.&amp;quot;&lt;br /&gt;
get-nettcpconnection | where {($_.State -eq &amp;quot;Listen&amp;quot;) -and ($_.RemoteAddress -eq &amp;quot;0.0.0.0&amp;quot;)} | select LocalAddress,LocalPort,RemoteAddress,RemotePort,State,@{Name=&amp;quot;Process&amp;quot;;Expression={(Get-Process -Id $_.OwningProcess).ProcessName}} | ft&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Active Directory ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# List available dcdiag commands&lt;br /&gt;
dcdiag /h&lt;br /&gt;
&lt;br /&gt;
# Test all servers in this site&lt;br /&gt;
dcdiag /a&lt;br /&gt;
&lt;br /&gt;
# Test all servers in the enterprise&lt;br /&gt;
dcdiag /e&lt;br /&gt;
&lt;br /&gt;
# Test specific Active Directory components&lt;br /&gt;
dcdiag /test:connectivity&lt;br /&gt;
dcdiag /test:kccevent&lt;br /&gt;
dcdiag /test:topology&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Group Policy =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Show currently applied Group Policy objects&lt;br /&gt;
gpresult /R&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Commands ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Import users from file my-users.csv&lt;br /&gt;
csvde -i -f .\my-users.csv -v&lt;br /&gt;
&lt;br /&gt;
# Import data from another AD using company-1.ldf&lt;br /&gt;
ldifde -v -i -f .\company-1.ldf&lt;br /&gt;
&lt;br /&gt;
# Check for users that have been inactive for longer than 2 weeks&lt;br /&gt;
dsquery user -inactive 2&lt;br /&gt;
&lt;br /&gt;
# Add user Kenpachi to the OU Captain, in the Seireitei.local domain, and add the description &#039;Strongest sword&#039; to his account&lt;br /&gt;
dsadd user &amp;quot;CN=Kenpachi,ou=Captain,dc=Seireitei,dc=local&amp;quot; -desc &amp;quot;Strongest sword&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Find all users that haven&#039;t changed their password in the last 10 days&lt;br /&gt;
dsquery user -stalepwd 10&lt;br /&gt;
&lt;br /&gt;
## patienten5.csv&lt;br /&gt;
 # GivenNAme,Surname,Name,SamAccountNAme,Description,Department,EmployeeID,Path,Enabled,Password,PasswordNeverExpires&lt;br /&gt;
 # User,local1,Userlocal1,Userlocal1,Userlocal1,IT,189478,&amp;quot;OU=test,DC=BMC,DC=local&amp;quot;,$True,a$$w0rd,$True&lt;br /&gt;
 # User,local2,Userlocal2,Userlocal2,Userlocal2,IT,187516,&amp;quot;OU=test,DC=BMC,DC=local&amp;quot;,$True,a$$w0rd,$True&lt;br /&gt;
&lt;br /&gt;
# Import and create users Userlocal1 and Userlocal2 from the given .csv file, and populate certain fields with the given values&lt;br /&gt;
Import-Csv -Path .\patienten5.csv | New-ADUser&lt;br /&gt;
&lt;br /&gt;
# Add various metadata values to the Kirby user, located in the Protagonists OU, existing in the Dreamland.local domain&lt;br /&gt;
dsmod user &amp;quot;CN=Kirby,ou=Protagonists,dc=Dreamland,dc=local&amp;quot; -office Skyborn -Title Hungry -dept Mental -webpg www.dreamland.local/Kirby -company Dreamland.local&lt;br /&gt;
&lt;br /&gt;
# Find all users with the description &#039;Wrestler&#039;, and modify their manager to be &#039;Hulk Hogan&#039; located in the Legendary OU in the WWE domain&lt;br /&gt;
dsquery user -desc Wrestler | dsmod user -mgr &amp;quot;cn=Hulk Hogan,OU=Legendary,DC=WWE,dc=local&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Turn all disabled users within the WuTang folder into enabled users&lt;br /&gt;
dsquery user ou=WuTang,dc=Clan,dc=local -disabled -limit 0 | dsmod user -disabled no&lt;br /&gt;
&lt;br /&gt;
# Create folder 2019 in the Students OU&lt;br /&gt;
New-ADOrganizationalUnit -Name &amp;quot;2019&amp;quot; -Description &amp;quot;The year 2019&amp;quot; -Path &amp;quot;OU=Students,DC=Rotterdam,DC=.nl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Active Directory ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Check what has yet to be replicated&lt;br /&gt;
repadmin /queue&lt;br /&gt;
&lt;br /&gt;
# Perform a Consistency Check for the local server&lt;br /&gt;
repadmin /kcc&lt;br /&gt;
&lt;br /&gt;
# Show basic replication information, neighbours, last attempts and their statuses&lt;br /&gt;
repadmin /showrepl&lt;br /&gt;
&lt;br /&gt;
# Show statistical data concerning replication&lt;br /&gt;
repadmin /replsummary&lt;br /&gt;
&lt;br /&gt;
# Replicate Active Directory changes/settings/configuration&lt;br /&gt;
repadmin /syncall&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Group Policy =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Force a Group Policy update on the device you execute this on&lt;br /&gt;
gpupdate /force&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Firewall ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Turn off your Firewall entirely&lt;br /&gt;
Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled false&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Command Prompt ==&lt;br /&gt;
=== Checks ===&lt;br /&gt;
==== Common ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Open the System information window&lt;br /&gt;
msinfo32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Network ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# List all available routes&lt;br /&gt;
route print&lt;br /&gt;
&lt;br /&gt;
# List detailed Network information&lt;br /&gt;
ipconfig /all&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Commands ===&lt;br /&gt;
==== Common ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Open Server Configuration menu for common configuration&lt;br /&gt;
sconfig&lt;br /&gt;
&lt;br /&gt;
# Logout the current user&lt;br /&gt;
logoff&lt;br /&gt;
&lt;br /&gt;
# Open User Management&lt;br /&gt;
lusrmgr.msc&lt;br /&gt;
&lt;br /&gt;
# Add this machine (SRV01) to domain clinic.local, ask for a password prompt for the Administrator user password&lt;br /&gt;
NETDOM JOIN SRV01 /Domain:clinic.local /UserO:Administrator /PasswordO:* /SecurePasswordPrompt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Shutdown or restart =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Shutdown the computer&lt;br /&gt;
shutdown /s&lt;br /&gt;
&lt;br /&gt;
# Restart the computer (60 seconds time-out)&lt;br /&gt;
shutdown /r&lt;br /&gt;
&lt;br /&gt;
# Shutdown the computer in 200 seconds&lt;br /&gt;
shutdown /t 200&lt;br /&gt;
&lt;br /&gt;
# Restart the computer right now&lt;br /&gt;
shutdown /r /t 0&lt;br /&gt;
&lt;br /&gt;
# Abort a timed shutdown&lt;br /&gt;
shutdown /a&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Windows Update =====&lt;br /&gt;
https://learn.microsoft.com/en-us/windows-server/administration/server-core/server-core-servicing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# For Windows Server Core, use the sconfig menu for easy Windows Update configuration&lt;br /&gt;
sconfig&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Check current configured settings&lt;br /&gt;
%systemroot%\system32\Cscript %systemroot%\system32\scregedit.wsf /AU /v&lt;br /&gt;
&lt;br /&gt;
# Disable automatic updates&lt;br /&gt;
Net stop wuauserv&lt;br /&gt;
%systemroot%\system32\Cscript %systemroot%\system32\scregedit.wsf /AU 1&lt;br /&gt;
Net start wuauserv&lt;br /&gt;
&lt;br /&gt;
# Enable automatic updates&lt;br /&gt;
Net stop wuauserv&lt;br /&gt;
%systemroot%\system32\Cscript %systemroot%\system32\scregedit.wsf /AU 4&lt;br /&gt;
Net start wuauserv&lt;br /&gt;
&lt;br /&gt;
# Update and install updates&lt;br /&gt;
Wuauclt /detectnow&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== License =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# For Windows Server Core, use the sconfig menu for easy license installation and activation&lt;br /&gt;
sconfig&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Install a license key&lt;br /&gt;
slmgr.vbs /ipk ASDI1-POQW2-QOWE5-ASDP0-QWEI3&lt;br /&gt;
&lt;br /&gt;
# Activate installed license key&lt;br /&gt;
slmgr.vbs /dli&lt;br /&gt;
&lt;br /&gt;
# Verify active license&lt;br /&gt;
slmgr.vbs /dli&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Network ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Add a route for a specific network&lt;br /&gt;
route add 192.168.15.0 mask 255.255.255.0 192.168.15.1&lt;br /&gt;
&lt;br /&gt;
# Delete a route for a specific network&lt;br /&gt;
route delete 192.168.15.0 mask 255.255.255.0 192.168.15.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Firewall ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Allow ICMPv4 communication inwards&lt;br /&gt;
netsh advfirewall firewall add rule name=&amp;quot;ICMPv4 Allow&amp;quot; protocol=&amp;quot;icmpv4:8,any&amp;quot; dir=in action=allow&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Shares ====&lt;br /&gt;
* https://www.windows-commandline.com/list-create-delete-network-shares/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
net share sharename=folderpath /grant:username,permissions&lt;br /&gt;
permission: Read, Change or Full&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Create the folder and share it with a user&lt;br /&gt;
mkdir C:\Shares\Users\Mike&lt;br /&gt;
net share MyShareName=&amp;quot;C:\Shares\Users\Mike&amp;quot; /grant:&amp;quot;big.mike,FULL&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Delete the share&lt;br /&gt;
net share MyShareName /DELETE&lt;br /&gt;
&lt;br /&gt;
# Create a share but with multi-user access&lt;br /&gt;
net share Karel=&amp;quot;C:\Shares\Users\Mike&amp;quot; /grant:&amp;quot;Big.Mike,FULL&amp;quot; /grant:&amp;quot;Big.John,READ&amp;quot; /grant:&amp;quot;Administrator,FULL&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Sysprep ====&lt;br /&gt;
# Download and install updates;&lt;br /&gt;
# Restart;&lt;br /&gt;
# Repeat step 1 and 2 until no more updates are available;&lt;br /&gt;
# Optionally disable automatic updates;&lt;br /&gt;
# Set the proper timezone;&lt;br /&gt;
# Set proper keyboard/region format;&lt;br /&gt;
# Optionally activate your license;&lt;br /&gt;
# Optionally enable Remote Desktop - &amp;quot;Allow remote connections to this computer&amp;quot;&lt;br /&gt;
# Optionally take a snapshot before the sysprep;&lt;br /&gt;
# Perform a Sysprep (see commands below).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Sysprep&lt;br /&gt;
C:\Windows\System32\Sysprep\sysprep.exe /generalize /shutdown&lt;br /&gt;
&lt;br /&gt;
# Sysprep using an unattend.xml&lt;br /&gt;
C:\Windows\System32\Sysprep\sysprep.exe /generalize /shutdown /unattend:C:\Windows\System32\Sysprep\unattended.xml &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Windows&amp;diff=879</id>
		<title>Windows</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Windows&amp;diff=879"/>
		<updated>2026-02-10T09:48:48Z</updated>

		<summary type="html">&lt;p&gt;Patrick: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet]]&lt;br /&gt;
&lt;br /&gt;
== Important applications ==&lt;br /&gt;
=== Desktop ===&lt;br /&gt;
&#039;&#039;&#039;SSH&#039;&#039;&#039;&lt;br /&gt;
* MobaxTerm - https://mobaxterm.mobatek.net/&lt;br /&gt;
* Putty &amp;amp; Puttygen - https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Code / Automation&#039;&#039;&#039;&lt;br /&gt;
* VSCodium&lt;br /&gt;
* Intellij Idea&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Databases&#039;&#039;&#039;&lt;br /&gt;
* DBeaver&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Windows management&#039;&#039;&#039;&lt;br /&gt;
* Windows Remote Desktop&lt;br /&gt;
* Windows Remote Server Administration Tools - https://learn.microsoft.com/en-us/troubleshoot/windows-server/system-management-components/remote-server-administration-tools&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Hypervisors&#039;&#039;&#039;&lt;br /&gt;
* Hyper-V&lt;br /&gt;
* VirtualBox&lt;br /&gt;
* VMWare Worststation&lt;br /&gt;
&lt;br /&gt;
=== Server ===&lt;br /&gt;
* BgInfo - https://learn.microsoft.com/en-us/sysinternals/downloads/bginfo&lt;br /&gt;
* Process Monitor - https://learn.microsoft.com/en-us/sysinternals/downloads/procmon&lt;br /&gt;
&lt;br /&gt;
=== Processes ===&lt;br /&gt;
Open the &amp;quot;Run&amp;quot; program by pressing &#039;&#039;&#039;Windows key + R&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
control             Open the Control Panel&lt;br /&gt;
ncpa.cpl            Network Control Panel&lt;br /&gt;
sysdm.cpl           System properties&lt;br /&gt;
devmgmt.msc         Device Manager&lt;br /&gt;
Services            services.msc&lt;br /&gt;
compmgmt.msc        Computer management&lt;br /&gt;
wf.msc              Advanced Windows Firewall&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Powershell ==&lt;br /&gt;
=== Checks ===&lt;br /&gt;
==== Network ====&lt;br /&gt;
* https://azega.org/list-open-ports-using-powershell/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# List open ports and related IP-addresses&lt;br /&gt;
Get-NetTCPConnection&lt;br /&gt;
&lt;br /&gt;
# Test the network-connection to a specific IP and port&lt;br /&gt;
Test-NetConnection -ComputerName 192.168.200.20 -InformationLevel &amp;quot;Detailed&amp;quot; -Port 443&lt;br /&gt;
&lt;br /&gt;
# List basic interface information&lt;br /&gt;
Get-NetAdapter&lt;br /&gt;
&lt;br /&gt;
# List basic interface address information&lt;br /&gt;
Get-NetIPConfiguration&lt;br /&gt;
&lt;br /&gt;
# &amp;quot;To show only the listening ports we need to filter for all items in the Listen state with the remote address of 0.0.0.0&amp;quot;&lt;br /&gt;
get-nettcpconnection | where {($_.State -eq &amp;quot;Listen&amp;quot;) -and ($_.RemoteAddress -eq &amp;quot;0.0.0.0&amp;quot;)}&lt;br /&gt;
&lt;br /&gt;
# &amp;quot;You can add additional fields like the process ID for each port. Changing the fields from the default requires selecting each one you want and then piping to ft (format-table).&amp;quot;&lt;br /&gt;
get-nettcpconnection | where {($_.State -eq &amp;quot;Listen&amp;quot;) -and ($_.RemoteAddress -eq &amp;quot;0.0.0.0&amp;quot;)} | Select LocalAddress,LocalPort,RemoteAddress,RemotePort,State,OwningProcess | ft&lt;br /&gt;
&lt;br /&gt;
# &amp;quot;This example will get the name of the process associated with each item.&amp;quot;&lt;br /&gt;
get-nettcpconnection | where {($_.State -eq &amp;quot;Listen&amp;quot;) -and ($_.RemoteAddress -eq &amp;quot;0.0.0.0&amp;quot;)} | select LocalAddress,LocalPort,RemoteAddress,RemotePort,State,@{Name=&amp;quot;Process&amp;quot;;Expression={(Get-Process -Id $_.OwningProcess).ProcessName}} | ft&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Active Directory ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# List available dcdiag commands&lt;br /&gt;
dcdiag /h&lt;br /&gt;
&lt;br /&gt;
# Test all servers in this site&lt;br /&gt;
dcdiag /a&lt;br /&gt;
&lt;br /&gt;
# Test all servers in the enterprise&lt;br /&gt;
dcdiag /e&lt;br /&gt;
&lt;br /&gt;
# Test specific Active Directory components&lt;br /&gt;
dcdiag /test:connectivity&lt;br /&gt;
dcdiag /test:kccevent&lt;br /&gt;
dcdiag /test:topology&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Group Policy =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Show currently applied Group Policy objects&lt;br /&gt;
gpresult /R&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Commands ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Import users from file my-users.csv&lt;br /&gt;
csvde -i -f .\my-users.csv -v&lt;br /&gt;
&lt;br /&gt;
# Import data from another AD using company-1.ldf&lt;br /&gt;
ldifde -v -i -f .\company-1.ldf&lt;br /&gt;
&lt;br /&gt;
# Check for users that have been inactive for longer than 2 weeks&lt;br /&gt;
dsquery user -inactive 2&lt;br /&gt;
&lt;br /&gt;
# Add user Kenpachi to the OU Captain, in the Seireitei.local domain, and add the description &#039;Strongest sword&#039; to his account&lt;br /&gt;
dsadd user &amp;quot;CN=Kenpachi,ou=Captain,dc=Seireitei,dc=local&amp;quot; -desc &amp;quot;Strongest sword&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Find all users that haven&#039;t changed their password in the last 10 days&lt;br /&gt;
dsquery user -stalepwd 10&lt;br /&gt;
&lt;br /&gt;
## patienten5.csv&lt;br /&gt;
 # GivenNAme,Surname,Name,SamAccountNAme,Description,Department,EmployeeID,Path,Enabled,Password,PasswordNeverExpires&lt;br /&gt;
 # User,local1,Userlocal1,Userlocal1,Userlocal1,IT,189478,&amp;quot;OU=test,DC=BMC,DC=local&amp;quot;,$True,a$$w0rd,$True&lt;br /&gt;
 # User,local2,Userlocal2,Userlocal2,Userlocal2,IT,187516,&amp;quot;OU=test,DC=BMC,DC=local&amp;quot;,$True,a$$w0rd,$True&lt;br /&gt;
&lt;br /&gt;
# Import and create users Userlocal1 and Userlocal2 from the given .csv file, and populate certain fields with the given values&lt;br /&gt;
Import-Csv -Path .\patienten5.csv | New-ADUser&lt;br /&gt;
&lt;br /&gt;
# Add various metadata values to the Kirby user, located in the Protagonists OU, existing in the Dreamland.local domain&lt;br /&gt;
dsmod user &amp;quot;CN=Kirby,ou=Protagonists,dc=Dreamland,dc=local&amp;quot; -office Skyborn -Title Hungry -dept Mental -webpg www.dreamland.local/Kirby -company Dreamland.local&lt;br /&gt;
&lt;br /&gt;
# Find all users with the description &#039;Wrestler&#039;, and modify their manager to be &#039;Hulk Hogan&#039; located in the Legendary OU in the WWE domain&lt;br /&gt;
dsquery user -desc Wrestler | dsmod user -mgr &amp;quot;cn=Hulk Hogan,OU=Legendary,DC=WWE,dc=local&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Turn all disabled users within the WuTang folder into enabled users&lt;br /&gt;
dsquery user ou=WuTang,dc=Clan,dc=local -disabled -limit 0 | dsmod user -disabled no&lt;br /&gt;
&lt;br /&gt;
# Create folder 2019 in the Students OU&lt;br /&gt;
New-ADOrganizationalUnit -Name &amp;quot;2019&amp;quot; -Description &amp;quot;The year 2019&amp;quot; -Path &amp;quot;OU=Students,DC=Rotterdam,DC=.nl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Active Directory ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Check what has yet to be replicated&lt;br /&gt;
repadmin /queue&lt;br /&gt;
&lt;br /&gt;
# Perform a Consistency Check for the local server&lt;br /&gt;
repadmin /kcc&lt;br /&gt;
&lt;br /&gt;
# Show basic replication information, neighbours, last attempts and their statuses&lt;br /&gt;
repadmin /showrepl&lt;br /&gt;
&lt;br /&gt;
# Show statistical data concerning replication&lt;br /&gt;
repadmin /replsummary&lt;br /&gt;
&lt;br /&gt;
# Replicate Active Directory changes/settings/configuration&lt;br /&gt;
repadmin /syncall&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Group Policy =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Force a Group Policy update on the device you execute this on&lt;br /&gt;
gpupdate /force&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Firewall ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Turn off your Firewall entirely&lt;br /&gt;
Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled false&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Command Prompt ==&lt;br /&gt;
=== Checks ===&lt;br /&gt;
==== Common ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Open the System information window&lt;br /&gt;
msinfo32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Network ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# List all available routes&lt;br /&gt;
route print&lt;br /&gt;
&lt;br /&gt;
# List detailed Network information&lt;br /&gt;
ipconfig /all&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Commands ===&lt;br /&gt;
==== Common ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Open Server Configuration menu for common configuration&lt;br /&gt;
sconfig&lt;br /&gt;
&lt;br /&gt;
# Logout the current user&lt;br /&gt;
logoff&lt;br /&gt;
&lt;br /&gt;
# Open User Management&lt;br /&gt;
lusrmgr.msc&lt;br /&gt;
&lt;br /&gt;
# Add this machine (SRV01) to domain clinic.local, ask for a password prompt for the Administrator user password&lt;br /&gt;
NETDOM JOIN SRV01 /Domain:clinic.local /UserO:Administrator /PasswordO:* /SecurePasswordPrompt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Shutdown or restart =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Shutdown the computer&lt;br /&gt;
shutdown /s&lt;br /&gt;
&lt;br /&gt;
# Restart the computer (60 seconds time-out)&lt;br /&gt;
shutdown /r&lt;br /&gt;
&lt;br /&gt;
# Shutdown the computer in 200 seconds&lt;br /&gt;
shutdown /t 200&lt;br /&gt;
&lt;br /&gt;
# Restart the computer right now&lt;br /&gt;
shutdown /r /t 0&lt;br /&gt;
&lt;br /&gt;
# Abort a timed shutdown&lt;br /&gt;
shutdown /a&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Windows Update =====&lt;br /&gt;
https://learn.microsoft.com/en-us/windows-server/administration/server-core/server-core-servicing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# For Windows Server Core, use the sconfig menu for easy Windows Update configuration&lt;br /&gt;
sconfig&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Check current configured settings&lt;br /&gt;
%systemroot%\system32\Cscript %systemroot%\system32\scregedit.wsf /AU /v&lt;br /&gt;
&lt;br /&gt;
# Disable automatic updates&lt;br /&gt;
Net stop wuauserv&lt;br /&gt;
%systemroot%\system32\Cscript %systemroot%\system32\scregedit.wsf /AU 1&lt;br /&gt;
Net start wuauserv&lt;br /&gt;
&lt;br /&gt;
# Enable automatic updates&lt;br /&gt;
Net stop wuauserv&lt;br /&gt;
%systemroot%\system32\Cscript %systemroot%\system32\scregedit.wsf /AU 4&lt;br /&gt;
Net start wuauserv&lt;br /&gt;
&lt;br /&gt;
# Update and install updates&lt;br /&gt;
Wuauclt /detectnow&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== License =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# For Windows Server Core, use the sconfig menu for easy license installation and activation&lt;br /&gt;
sconfig&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Install a license key&lt;br /&gt;
slmgr.vbs /ipk ASDI1-POQW2-QOWE5-ASDP0-QWEI3&lt;br /&gt;
&lt;br /&gt;
# Activate installed license key&lt;br /&gt;
slmgr.vbs /dli&lt;br /&gt;
&lt;br /&gt;
# Verify active license&lt;br /&gt;
slmgr.vbs /dli&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Network ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Add a route for a specific network&lt;br /&gt;
route add 192.168.15.0 mask 255.255.255.0 192.168.15.1&lt;br /&gt;
&lt;br /&gt;
# Delete a route for a specific network&lt;br /&gt;
route delete 192.168.15.0 mask 255.255.255.0 192.168.15.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Firewall ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Allow ICMPv4 communication inwards&lt;br /&gt;
netsh advfirewall firewall add rule name=&amp;quot;ICMPv4 Allow&amp;quot; protocol=&amp;quot;icmpv4:8,any&amp;quot; dir=in action=allow&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Shares ====&lt;br /&gt;
* https://www.windows-commandline.com/list-create-delete-network-shares/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
net share sharename=folderpath /grant:username,permissions&lt;br /&gt;
permission: Read, Change or Full&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Create the folder and share it with a user&lt;br /&gt;
mkdir C:\Shares\Users\Mike&lt;br /&gt;
net share MyShareName=&amp;quot;C:\Shares\Users\Mike&amp;quot; /grant:&amp;quot;big.mike,FULL&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Delete the share&lt;br /&gt;
net share MyShareName /DELETE&lt;br /&gt;
&lt;br /&gt;
# Create a share but with multi-user access&lt;br /&gt;
net share Karel=&amp;quot;C:\Shares\Users\Mike&amp;quot; /grant:&amp;quot;Big.Mike,FULL&amp;quot; /grant:&amp;quot;Big.John,READ&amp;quot; /grant:&amp;quot;Administrator,FULL&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Sysprep ====&lt;br /&gt;
# Download and install updates;&lt;br /&gt;
# Restart;&lt;br /&gt;
# Repeat step 1 and 2 until no more updates are available;&lt;br /&gt;
# Optionally disable automatic updates;&lt;br /&gt;
# Set the proper timezone;&lt;br /&gt;
# Set proper keyboard/region format;&lt;br /&gt;
# Optionally activate your license;&lt;br /&gt;
# Optionally enable Remote Desktop - &amp;quot;Allow remote connections to this computer&amp;quot;&lt;br /&gt;
# Optionally take a snapshot before the sysprep;&lt;br /&gt;
# Perform a Sysprep (see commands below).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Sysprep&lt;br /&gt;
C:\Windows\System32\Sysprep\sysprep.exe /generalize /shutdown&lt;br /&gt;
&lt;br /&gt;
# Sysprep using an unattend.xml&lt;br /&gt;
C:\Windows\System32\Sysprep\sysprep.exe /generalize /shutdown /unattend:C:\Windows\System32\Sysprep\unattended.xml &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Tools&amp;diff=878</id>
		<title>Linux:Tools</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Tools&amp;diff=878"/>
		<updated>2026-01-24T15:30:49Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* rsync */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet]]&lt;br /&gt;
&lt;br /&gt;
== Commands ==&lt;br /&gt;
=== Quick access ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Scroll through a file with less&lt;br /&gt;
less -s myfile.txt&lt;br /&gt;
&lt;br /&gt;
# Select line 5 from the output&lt;br /&gt;
cat example.txt | sel -e &#039;5&#039;&lt;br /&gt;
&lt;br /&gt;
# Select lines from the output, starting from the top&lt;br /&gt;
cat example.txt | head -5&lt;br /&gt;
&lt;br /&gt;
# Select lines from the output, starting from the bottom&lt;br /&gt;
cat example.txt | tail -5&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Commands ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Display the full path of a file(assuming the syslog file is available in the current folder)&lt;br /&gt;
readlink -f syslog&lt;br /&gt;
&lt;br /&gt;
# Unzip a file&lt;br /&gt;
gunzip /var/log/messages.2.gz&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Uncommon commands ===&lt;br /&gt;
* https://ngelinux.com/what-is-proc-sysrq-trigger-in-linux-and-how-to-use-sysrq-kernel-feature/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CrASHing THIs SERVer, WiTH no SurVIvORS!&lt;br /&gt;
echo c &amp;gt; /proc/sysrq-trigger&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Network ==&lt;br /&gt;
=== ping ===&lt;br /&gt;
Troubleshooting MTU: https://access.redhat.com/solutions/2440411&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Ping with an interval of 5 seconds&lt;br /&gt;
ping -i 5 192.168.0.1&lt;br /&gt;
&lt;br /&gt;
# Ping 192.168.10.5 using a specific interface&lt;br /&gt;
ping -I bond0 192.168.10.5&lt;br /&gt;
&lt;br /&gt;
# Ping 8.8.8.8 for 20 times&lt;br /&gt;
ping -c 20 8.8.8.8&lt;br /&gt;
&lt;br /&gt;
# Ping google.com using IPv4&lt;br /&gt;
ping -4 google.com&lt;br /&gt;
&lt;br /&gt;
# Ping google.com using IPv6&lt;br /&gt;
ping -6 google.com&lt;br /&gt;
&lt;br /&gt;
# Ping using packets of size 264&lt;br /&gt;
ping -s 264 1.1.1.1&lt;br /&gt;
&lt;br /&gt;
# Test an MTU-size of 9000 by sending non-fragmented packages of size 8972 (28 bytes left for the headers)&lt;br /&gt;
ping -M do -s 8972 192.168.77.88&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== traceroute ===&lt;br /&gt;
Package &#039;&#039;&#039;mtr&#039;&#039;&#039; (My traceroute) is also very good&lt;br /&gt;
&lt;br /&gt;
* https://web.archive.org/web/20110101100046/https://www.exit109.com/~jeremy/news/providers/traceroute.html&lt;br /&gt;
* [https://en.wikipedia.org/wiki/Traceroute UDP ports 33434 to 33534 are used by traceroute by default.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show the traversed hops towards google.com using IPv4&lt;br /&gt;
traceroute -4 google.com&lt;br /&gt;
&lt;br /&gt;
# Show the traversed hops towards google.com using IPv6&lt;br /&gt;
traceroute -6 google.com&lt;br /&gt;
&lt;br /&gt;
# Does the same as &amp;quot;traceroute -6 google.com&amp;quot;&lt;br /&gt;
traceroute6 google.com&lt;br /&gt;
&lt;br /&gt;
# Use ICMP for checking hops&lt;br /&gt;
traceroute -4 -I brammerloo.nl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== route ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List configured routes&lt;br /&gt;
route&lt;br /&gt;
&lt;br /&gt;
# List routes but display IPs instead of hostnames&lt;br /&gt;
route -n&lt;br /&gt;
&lt;br /&gt;
# Delete default route &lt;br /&gt;
ip route del 0.0.0.0/0 via 192.168.10.1 dev ens3&lt;br /&gt;
&lt;br /&gt;
# Delete default route (explicit)&lt;br /&gt;
ip route del default via 192.168.0.1 dev eth0 proto static metric 100&lt;br /&gt;
&lt;br /&gt;
# Add a default route via a specific IP and interface&lt;br /&gt;
ip route add default via 192.168.0.1 dev eth0 proto static metric 90&lt;br /&gt;
&lt;br /&gt;
# Add route for a network via gateway on an interface&lt;br /&gt;
ip route add 10.0.100.0/24 via 10.0.100.254 dev ens5&lt;br /&gt;
&lt;br /&gt;
# Add default route met een specifieke metric&lt;br /&gt;
ip route add default via 10.0.180.1 dev ens7 proto static metric 90&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== netstat ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Display network connections and current states&lt;br /&gt;
netstat&lt;br /&gt;
&lt;br /&gt;
# Check listening ports, connected remote IPs, processes, states and more&lt;br /&gt;
netstat -taupen&lt;br /&gt;
&lt;br /&gt;
# Check listening ports and IPs of the local server&lt;br /&gt;
netstat -tulpn&lt;br /&gt;
&lt;br /&gt;
# List the routing table&lt;br /&gt;
netstat -r&lt;br /&gt;
&lt;br /&gt;
# List verbose common TCP and ICMP information&lt;br /&gt;
netstat -s&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ss ===&lt;br /&gt;
Replacement for netstat&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Check open ports, connected IPs, processes, states and more&lt;br /&gt;
ss -taupen&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== tcpdump ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Listen on interface eth0 for traffic coming from host  172.16.0.11&lt;br /&gt;
tcpdump -i eth0 host 172.16.0.11&lt;br /&gt;
&lt;br /&gt;
# Listen on interface eno2 for traffic coming from host  172.16.1.20, going to port 443&lt;br /&gt;
tcpdump -i en02 host 172.16.1.20 port 443&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== uuidgen ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate a unique UUID (for an interface)&lt;br /&gt;
uuidgen eth0&lt;br /&gt;
7bb91614-6ffe-4bdc-9b37-c6e9d37f6987&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ip ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show network information &lt;br /&gt;
ip address&lt;br /&gt;
ip a&lt;br /&gt;
&lt;br /&gt;
# Show all configured routes&lt;br /&gt;
ip r show&lt;br /&gt;
&lt;br /&gt;
# Display statistics for all interfaces&lt;br /&gt;
ip -s link&lt;br /&gt;
&lt;br /&gt;
# Display detailed statistics for all interfaces&lt;br /&gt;
ip -s -s link&lt;br /&gt;
&lt;br /&gt;
# Execute the ifconfig command within a specific router&lt;br /&gt;
ip netns exec qrouter-asdwe49-as8d7-asd2-ert0-cvb7klj2 &amp;quot;ifconfig&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== DNS | dig &amp;amp; nslookup ===&lt;br /&gt;
* https://intodns.com/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Lookup reverse DNS host information&lt;br /&gt;
dig -x 10.0.2.15&lt;br /&gt;
&lt;br /&gt;
# Lookup the nameservers of google.com, by asking nameserver 1.1.1.1&lt;br /&gt;
dig google.com  @1.1.1.1 NS&lt;br /&gt;
&lt;br /&gt;
# Lookup reverse DNS host information&lt;br /&gt;
host 10.0.2.15&lt;br /&gt;
&lt;br /&gt;
# Lookup DNS host information&lt;br /&gt;
nslookup 10.0.2.15&lt;br /&gt;
&lt;br /&gt;
# Lookup host information for google.com while using DNS-server 8.8.8.8&lt;br /&gt;
nslookup google.com 8.8.8.8&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Package managers ==&lt;br /&gt;
=== apt ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check for updates&lt;br /&gt;
apt update&lt;br /&gt;
&lt;br /&gt;
# List packages that can be upgraded&lt;br /&gt;
apt list --upgradable&lt;br /&gt;
&lt;br /&gt;
# Installed available updates&lt;br /&gt;
apt upgrade&lt;br /&gt;
&lt;br /&gt;
# List installed packages&lt;br /&gt;
apt list --installed&lt;br /&gt;
&lt;br /&gt;
# List package details and description&lt;br /&gt;
apt show net-tools&lt;br /&gt;
&lt;br /&gt;
# Search inside all package descriptions for your keyword&lt;br /&gt;
apt-cache search ssh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rpm ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all local RPM packages&lt;br /&gt;
rpm -qa&lt;br /&gt;
&lt;br /&gt;
# Query for a specific installed rpm package&lt;br /&gt;
rpm -qi nginx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== yum ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  Search for all available packages that include string &amp;quot;nginx&amp;quot;&lt;br /&gt;
yum search nginx&lt;br /&gt;
&lt;br /&gt;
# Install the package named Nginx&lt;br /&gt;
yum install nginx&lt;br /&gt;
&lt;br /&gt;
# List installed packages&lt;br /&gt;
yum list installed&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== dnf ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  Upgrade and install updates&lt;br /&gt;
dnf upgrade&lt;br /&gt;
&lt;br /&gt;
# Remove the podman package&lt;br /&gt;
dnf remove podman&lt;br /&gt;
&lt;br /&gt;
# Show information about the zlib package&lt;br /&gt;
dnf info zlib&lt;br /&gt;
&lt;br /&gt;
# Show mandatory/optional/default packages within the Networking Tools group&lt;br /&gt;
dnf group info &amp;quot;Networking Tools&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Filesystem ==&lt;br /&gt;
=== fdisk ===&lt;br /&gt;
&#039;&#039;&#039;cfdisk&#039;&#039;&#039; is also nice&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check your disks and partitions&lt;br /&gt;
fdisk -l&lt;br /&gt;
&lt;br /&gt;
# Enter fdisk interactive mode&lt;br /&gt;
fdisk /dev/nvme0n2p1&lt;br /&gt;
&lt;br /&gt;
# List available partition types&lt;br /&gt;
l&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Format /dev/vdb as BTRFS&lt;br /&gt;
echo -e &amp;quot;n\np\n1\n\n\nt\n8E\np\nw&amp;quot; | fdisk /dev/vdb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Other ==&lt;br /&gt;
=== man + mandb ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Open the manual for the man tool&lt;br /&gt;
man man&lt;br /&gt;
&lt;br /&gt;
# Open the manual for the ls tool&lt;br /&gt;
man ls&lt;br /&gt;
&lt;br /&gt;
# &#039;Update&#039; mandb by purging and or processing manuals&lt;br /&gt;
mandb&lt;br /&gt;
&lt;br /&gt;
# Purge everything and regenerate manuals&lt;br /&gt;
mandb --create&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ls ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List folders sorted by modified date&lt;br /&gt;
ls -trol&lt;br /&gt;
&lt;br /&gt;
# List folder contents recursively&lt;br /&gt;
ls -alsR myfolder/&lt;br /&gt;
&lt;br /&gt;
# List folder contents sorted by time, newest first and reverse order&lt;br /&gt;
ls -latr myfolder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== grep ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Search for any occurences of &amp;quot;inet_interface&amp;quot; in a file&lt;br /&gt;
grep inet_interface /etc/postfix/main.cf&lt;br /&gt;
&lt;br /&gt;
# Search for pattern &amp;quot;audit&amp;quot; in file /var/log/syslog&lt;br /&gt;
grep -e &amp;quot;audit&amp;quot; /var/log/syslog&lt;br /&gt;
&lt;br /&gt;
# Search for text &amp;quot;started&amp;quot; in everything in /var/log/, and list the filename for each occurence&lt;br /&gt;
grep -H &amp;quot;started&amp;quot; /var/log/*&lt;br /&gt;
&lt;br /&gt;
# Search for any mention of &amp;quot;md&amp;quot; within a file, by piping to grep&lt;br /&gt;
cat /var/log/messages | grep md&lt;br /&gt;
&lt;br /&gt;
# Search for any of text &amp;quot;test&amp;quot; within the /etc folder recursively, also shows filename by default&lt;br /&gt;
grep -r &amp;quot;test&amp;quot; /etc&lt;br /&gt;
&lt;br /&gt;
# Recursively search for any mention of &amp;quot;audit&amp;quot; in each file within the specified directory, display linenumber and ignore low/upper case&lt;br /&gt;
grep -rni audit /var/log/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== lsof ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List what has files opened on the directory/mount&lt;br /&gt;
lsof /data/mount/lustre-01&lt;br /&gt;
&lt;br /&gt;
# List processes listening on port 443&lt;br /&gt;
lsof -i :443&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== awk ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List the first column of the output generated by docker ps&lt;br /&gt;
docker ps | awk &#039;{print $1}&#039;&lt;br /&gt;
&lt;br /&gt;
# Print 9th column of folder contents&lt;br /&gt;
ll /mnt/btrfs/share1/ | awk &#039;{print $9}&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== tar ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Compress the destination directory and keep the source path within the zipped file&lt;br /&gt;
tar -czvf name-of-archive.tar.gz /path/to/directory-or-file&lt;br /&gt;
&lt;br /&gt;
# Compress the destination directory, but put the folder contents into the . within the zipped file&lt;br /&gt;
tar -czvf name-of-archive.tar.gz -C /path/to/directory-or-file .&lt;br /&gt;
&lt;br /&gt;
# Extract a tar.gz file to the current folder&lt;br /&gt;
tar -xzvf name-of-archive.tar.gz&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== find ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Basic find command&lt;br /&gt;
find / -name name-to-search-for&lt;br /&gt;
&lt;br /&gt;
# Search the current folder for all files&lt;br /&gt;
find . -name \* &lt;br /&gt;
&lt;br /&gt;
# Search the current folder for all files and count them&lt;br /&gt;
find . -name \* | wc -l&lt;br /&gt;
&lt;br /&gt;
# Find all files with the SUID bit set&lt;br /&gt;
find / -name &amp;quot;*&amp;quot; -perm /u+s&lt;br /&gt;
&lt;br /&gt;
# Find the current folder for files that were modified in the last 15 minutes&lt;br /&gt;
find . -mmin -15 -type f -name &amp;quot;*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Search for all modified files between 2023-01-01 and 2023-12-30&lt;br /&gt;
find /var/log/ -type f -name &amp;quot;*&amp;quot; -newermt 2023-01-01 ! -newermt 2023-12-30&lt;br /&gt;
&lt;br /&gt;
# Search for all modified folders between 2022-01-01 and 2022-02-10, limited to a single folders&#039; depth&lt;br /&gt;
find /data/research001/ -maxdepth 1 -type d -newermt 2022-01-01 ! -newermt 2022-02-10&lt;br /&gt;
&lt;br /&gt;
# Search the current folder for all .log files and search &amp;amp; output any line containing string &amp;quot;error&amp;quot;&lt;br /&gt;
find . -name \*.log -exec grep -H error {} \;&lt;br /&gt;
&lt;br /&gt;
# Screwing around&lt;br /&gt;
for i in $(find URL* -name &amp;quot;*.report&amp;quot; | sort); do echo &amp;quot;$i&amp;quot; &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE ; done&lt;br /&gt;
for i in $(find URL* -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; | sort &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE ; done&lt;br /&gt;
for i in $(find URL* -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; | sort &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE | awk &#039;{print $2}&#039;; done&lt;br /&gt;
for i in $(find URL* -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE | awk &#039;{print $2}&#039;; done&lt;br /&gt;
for i in $(find * -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE | awk &#039;{print $2}&#039;; done&lt;br /&gt;
ll URL* | awk &#039;{print $9}&#039; | grep &amp;quot;*.report&amp;quot; | sort | for i in $(find * -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE | awk &#039;{print $2}&#039;; done&lt;br /&gt;
ll URL* | awk &#039;{print $9}&#039; | grep .report | sort | for i in $(find * -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE&lt;br /&gt;
&lt;br /&gt;
find URL1 -name \*.report -exec grep -H TOTAL_SIZE {} \; | LC_ALL=C awk -M &#039;BEGIN{FS=OFS=&amp;quot;\t&amp;quot;} {printf(&amp;quot;%s\t%.02f\n&amp;quot;, $1, $2/(1024*1024*1024))}&#039; | sed -e &#039;s~^.*/~~&#039; -e &#039;s~\..*SIZE~~&#039; | sort&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== less ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
25     = Go to line 25&lt;br /&gt;
g      = Go to top of file&lt;br /&gt;
G      = Go to bottom of file&lt;br /&gt;
/      = Activate search mode&lt;br /&gt;
/Error = Search for &amp;quot;Error&amp;quot;&lt;br /&gt;
n      = Move to next search result&lt;br /&gt;
N      = Move to previous search result&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Don&#039;t wrap long lines to the current screen (move left or right to see non-truncated line)&lt;br /&gt;
less -S /var/log/syslog&lt;br /&gt;
&lt;br /&gt;
# Output a file&#039;s contents and read it with less&lt;br /&gt;
cat /etc/snmpd/snmp.conf | less -S&lt;br /&gt;
&lt;br /&gt;
# Number the lines when viewing&lt;br /&gt;
less -N /var/log/messages&lt;br /&gt;
&lt;br /&gt;
# Open less at the first search result for &amp;quot;error&amp;quot;. (Do not use space between the -p parameter and your search query)&lt;br /&gt;
less -p&amp;quot;Error&amp;quot; /var/log/messages&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ssh ===&lt;br /&gt;
* https://man.openbsd.org/ssh.1&lt;br /&gt;
* https://www.openssh.com/legacy.html&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Stolen from https://www.openssh.com/legacy.html&lt;br /&gt;
ssh -Q cipher       # List supported ciphers&lt;br /&gt;
ssh -Q mac          # List supported MACs&lt;br /&gt;
ssh -Q key          # List supported public key types&lt;br /&gt;
ssh -Q kex          # List supported key exchange algorithms&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Connect to a server using a specific user&lt;br /&gt;
ssh mirelurk@192.168.0.1&lt;br /&gt;
&lt;br /&gt;
# Connect to a server using a specific RSA private key&lt;br /&gt;
ssh 192.168.0.1 -i /home/john/.ssh/id_rsa_key-5&lt;br /&gt;
&lt;br /&gt;
# Connect to a server using a specific SSH port&lt;br /&gt;
ssh 192.168.0.1 -p 1111&lt;br /&gt;
&lt;br /&gt;
# Show verbose information when connecting to a server&lt;br /&gt;
ssh -v 192.168.0.1&lt;br /&gt;
&lt;br /&gt;
# Connect using an ancient algorithm and keytype&lt;br /&gt;
ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 -c aes128-cbc  admin@10.50.10.50&lt;br /&gt;
&lt;br /&gt;
# Execute &#039;ls&#039; on a remote server and output the result to your shell session&lt;br /&gt;
echo &#039;ls&#039; | ssh -T user@10.0.20.75&lt;br /&gt;
&lt;br /&gt;
# Execute a command on a remote server and output the result to a local file&lt;br /&gt;
echo &#039;ls&#039; | ssh -T user@10.0.20.75 &amp;gt; &amp;lt;filename&amp;gt;.log&lt;br /&gt;
&lt;br /&gt;
# Log in by providing a password in the CLI&lt;br /&gt;
sshpass &#039;MyPassword&#039; ssh -XY root@10.100.25.1&lt;br /&gt;
&lt;br /&gt;
# Copy a local file to another server&lt;br /&gt;
scp /home/root/myfiletocopy ubuntu@192.168.0.10:/home/ubuntu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== vim ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Esc   Switches between input/command mode&lt;br /&gt;
&lt;br /&gt;
o     Create a new line below the current cursor position and switch to input mode&lt;br /&gt;
:wq   Save (write) and quit the file&lt;br /&gt;
:q!   Quit immediately without applying any changes&lt;br /&gt;
&lt;br /&gt;
j     Move the cursor one line downwards&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enter the Vim tutorial&lt;br /&gt;
vimtutor&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rsync ===&lt;br /&gt;
Also see rclone for enterprise storage enviroments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Copy contents of source /mnt/science/data/ to target /home/garyon/backup/science/ recursively&lt;br /&gt;
rsync -a /mnt/science/data/ /home/garyon/backup/science/&lt;br /&gt;
&lt;br /&gt;
# Copy  everything: symlinks, hardlinks, extended attributes, modified times, files, folders, etc&lt;br /&gt;
rsync -avHXS --progress /mnt/science/data/ /home/mayra/backup/science/&lt;br /&gt;
&lt;br /&gt;
# Show progress during a transfer&lt;br /&gt;
rsync -avHXS --progress /mnt/science/data/ /home/stefanie/backup/science/&lt;br /&gt;
&lt;br /&gt;
# rsync is additive by default&lt;br /&gt;
# After an initial rsync, delete files in the target that were deleted in the source&lt;br /&gt;
rsync --delete -avHXS /mnt/science/data/ /home/bob/backup/science/&lt;br /&gt;
&lt;br /&gt;
# Sync using SSH&lt;br /&gt;
rsync -avrS --delete /data/cardio/ 192.168.0.15:/backup/cardio/&lt;br /&gt;
&lt;br /&gt;
# Sync using a specific SSH port&lt;br /&gt;
rsync -avrS --rsh=&#039;ssh -p2020&#039; --delete /data/science/ 192.168.0.20:/backup/science/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Curl ===&lt;br /&gt;
Basic CURL call to fetch information from somewhere.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
mytoken=&amp;quot;supersecrettoken&amp;quot;&lt;br /&gt;
&lt;br /&gt;
curl -X &amp;quot;GET&amp;quot; &#039;https://mywebsite.brammerloo.nl/cluster/health&#039; \&lt;br /&gt;
     -H &#039;X-Requested-By: peach&#039; \&lt;br /&gt;
     -H &#039;Content-Type: application/json&#039; \&lt;br /&gt;
     -H &#039;Accept: application/json&#039; \&lt;br /&gt;
     --silent \&lt;br /&gt;
     -u &amp;quot;${mytoken}&amp;quot;:token&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of executing a CURL call with a JSON-payload&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
mytoken=&amp;quot;supersecrettoken&amp;quot;&lt;br /&gt;
&lt;br /&gt;
curl -X &amp;quot;POST&amp;quot; &amp;quot;https://mywebsite.brammerloo.nl/api/search&amp;quot; \&lt;br /&gt;
     -H &#039;X-Requested-By: roshani&#039; \&lt;br /&gt;
     -H &#039;Content-Type: application/json&#039; \&lt;br /&gt;
     -H &#039;Accept: application/json&#039; \&lt;br /&gt;
     --silent \&lt;br /&gt;
     -u &amp;quot;${mytoken}&amp;quot;:token \&lt;br /&gt;
     -d &amp;quot;$curly&amp;quot;&lt;br /&gt;
&lt;br /&gt;
curly=&#039;{&lt;br /&gt;
    &amp;quot;queries&amp;quot;: [{&lt;br /&gt;
            &amp;quot;id&amp;quot;: &amp;quot;?&amp;quot;,&lt;br /&gt;
            &amp;quot;timerange&amp;quot;: {&lt;br /&gt;
                &amp;quot;type&amp;quot;: &amp;quot;keyword&amp;quot;,&lt;br /&gt;
                &amp;quot;keyword&amp;quot;: &amp;quot;one day ago&amp;quot;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    ]&lt;br /&gt;
}&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== cron ===&lt;br /&gt;
Run tasks at specific intervals.&lt;br /&gt;
&lt;br /&gt;
* https://crontab.guru/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List cron jobs for the current user&lt;br /&gt;
crontab -l&lt;br /&gt;
&lt;br /&gt;
# Modify cron jobs for the current user&lt;br /&gt;
crontab -eq&lt;br /&gt;
&lt;br /&gt;
# Run  the &amp;quot;ls&amp;quot; command every 5 minutes&lt;br /&gt;
*/5 * * * * ps aux&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== screen ===&lt;br /&gt;
Create virtual sessions on the server you&#039;re connected to.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all current sessions&lt;br /&gt;
screen -list&lt;br /&gt;
&lt;br /&gt;
# Create new session &amp;quot;mynewsession&amp;quot;&lt;br /&gt;
screen -S mynewsession&lt;br /&gt;
&lt;br /&gt;
# Detach current session&lt;br /&gt;
CTRL + A + D&lt;br /&gt;
&lt;br /&gt;
# Attach session &amp;quot;mynewssion&amp;quot;&lt;br /&gt;
screen -r mynewsession&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ldapsearch ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DC = Domain Component&lt;br /&gt;
The values that identify the domain in which the object is located, may contain subdomains too i.e. &amp;quot;DC=customer,DC=amazon,DC=com&amp;quot;&lt;br /&gt;
&lt;br /&gt;
OU =  Organization Unit&lt;br /&gt;
A container/folder in which objects or users are stored. Actively used in Microsoft Active Directory&#039;s i.e. &amp;quot;OU=janitors,DC=customer,DC=amazon,DC=com&amp;quot;&lt;br /&gt;
&lt;br /&gt;
CN = Canonical Name&lt;br /&gt;
The name of the group you&#039;re searching for or in i.e. &amp;quot;CN=fullprivilege,OU=janitors,DC=customer,DC=amazon,DC=com&amp;quot;&lt;br /&gt;
&lt;br /&gt;
UID = User Identifier&lt;br /&gt;
The unique identifier to find a user with, usually the username i.e. &amp;quot;uid=magicmike,CN=fullprivilege,OU=janitors,DC=customer,DC=amazon,DC=com&amp;quot;&lt;br /&gt;
&lt;br /&gt;
DN = Distinguished Name&lt;br /&gt;
The entire path to an object, consisting of a combination of above values, at least the DCs and a CN or UID, i.e. &amp;quot;uid=magicmike,CN=fullprivilege,OU=janitors,DC=customer,DC=amazon,DC=com&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following assumes domain &amp;quot;brammerloo.nl&amp;quot;, based on usage for FreeIPA&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Search and show attributes for user tonberry in group users in group accounts in domain brammerloo.nl, using the admin user to authenticatie&lt;br /&gt;
ldapsearch -W -b &amp;quot;uid=tonberry,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;  -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Do the same as above, but specify LDAP-server ipa01.brammerloo.nl to send the query to&lt;br /&gt;
ldapsearch -W -H ldap://ipa01.brammerloo.nl -b &amp;quot;uid=tonberry,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;  -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Do the same as above, but specify a specific port&lt;br /&gt;
ldapsearch -W -H ldap://ipa01.brammerloo.nl:389 -b &amp;quot;uid=tonberry,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;  -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Use the &amp;quot;elastic&amp;quot; user to query for attributes of the &amp;quot;elastic-users&amp;quot; group which itself is a member of the &amp;quot;groups&amp;quot; group&lt;br /&gt;
ldapsearch -W -b &amp;quot;cn=elastic-users,cn=groups,cn=accounts,dc=brammerloo,dc=nl&amp;quot;  -D &amp;quot;uid=elastic,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Do the same as above, but specify you only want the member attribute&lt;br /&gt;
ldapsearch -W -b &amp;quot;cn=elastic-users,cn=groups,cn=accounts,dc=brammerloo,dc=nl&amp;quot; -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot; member&lt;br /&gt;
&lt;br /&gt;
# Show all groups of which tonberry is a member of by searching for the memberOf attribute&lt;br /&gt;
ldapsearch -W -b &amp;quot;uid=tonberry,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;  -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot; memberOf&lt;br /&gt;
&lt;br /&gt;
# List attributes for all groups in the group &amp;quot;groups&amp;quot;&lt;br /&gt;
ldapsearch -W -b &amp;quot;cn=groups,cn=accounts,dc=brammerloo,dc=nl&amp;quot; -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== git ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List your current branch and situation&lt;br /&gt;
git status&lt;br /&gt;
&lt;br /&gt;
# List all branches and your current one&lt;br /&gt;
git branch --all&lt;br /&gt;
&lt;br /&gt;
# List all available tags&lt;br /&gt;
git tag&lt;br /&gt;
&lt;br /&gt;
# List the current selected tag&lt;br /&gt;
git describe&lt;br /&gt;
git describe --tags&lt;br /&gt;
&lt;br /&gt;
# Compare changes in the current working directory to the committed tree, and list what files have been changed&lt;br /&gt;
git diff-files&lt;br /&gt;
&lt;br /&gt;
# Compare changes in the current working directory to the committed tree, and list what has changed&lt;br /&gt;
git diff-files -p&lt;br /&gt;
&lt;br /&gt;
# Compare the committed tree to the current working directory, and list what has changed&lt;br /&gt;
git diff HEAD&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Common ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a folder and initialize it for use by git&lt;br /&gt;
mkdir gitrepo1; cd gitrepo1; git init&lt;br /&gt;
&lt;br /&gt;
# Switch to another branch&lt;br /&gt;
git checkout stable/zed&lt;br /&gt;
&lt;br /&gt;
# Switch to a specific tag&lt;br /&gt;
git checkout tags/14.11.0&lt;br /&gt;
&lt;br /&gt;
# Fetch data from the current upstream branch&lt;br /&gt;
git pull&lt;br /&gt;
&lt;br /&gt;
# Pull data from a specific branch&lt;br /&gt;
git pull origin unmaintained/yoga&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rclone ===&lt;br /&gt;
* https://rclone.org/&lt;br /&gt;
&lt;br /&gt;
==== Installation ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Install the latest version from the website&lt;br /&gt;
curl https://rclone.org/install.sh | sudo bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Example configuration based on OpenStack swift. Config should be in the homefolder of your user .config/rclone/rclone.conf:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
[swift-ssd]&lt;br /&gt;
type = swift&lt;br /&gt;
user = patrick&lt;br /&gt;
key = &amp;lt;PASSWORD&amp;gt;&lt;br /&gt;
auth = https://openstack.brammerloo.nl:5000/v3&lt;br /&gt;
region = Rotterdam&lt;br /&gt;
domain = Default&lt;br /&gt;
tenant = patrickproject&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# List all containers, buckets and or folders of container &amp;quot;swift-ssd&amp;quot;&lt;br /&gt;
rclone lsd &amp;quot;swift-ssd:&amp;quot;&lt;br /&gt;
          20 2025-02-10 09:46:00         2 ssd-container&lt;br /&gt;
           0 2025-02-10 09:46:00         1 swift-ssd&lt;br /&gt;
           0 2025-02-10 09:46:00         1 swift-ssd2&lt;br /&gt;
&lt;br /&gt;
rclone lsd &amp;quot;swift-ssd:ssd-container&amp;quot;&lt;br /&gt;
           0 2025-02-10 09:48:02        -1 mystorage&lt;br /&gt;
&lt;br /&gt;
# List contents, files, folders of bucket &amp;quot;ssd-container&amp;quot;, within container &amp;quot;swift-ssd&amp;quot;&lt;br /&gt;
rclone ls &amp;quot;swift-ssd:ssd-container&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# List the contents of file &amp;quot;asd&amp;quot;&lt;br /&gt;
rclone cat &amp;quot;swift-ssd:ssd-container/asd&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Mount an object storage to local folder /mnt/object-ssd/&lt;br /&gt;
rclone mount swift-ssd:ssd-container /mnt/object-ssd&lt;br /&gt;
&lt;br /&gt;
# Synchronize a local folder to a destination folder inside a bucket, in interactive mode&lt;br /&gt;
rclone sync -i /etc/rsyslog.d swift-ssd:ssd-container/mystorage/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== mdtest ===&lt;br /&gt;
This chapter was mostly written and contributed by Ivo Palli.&lt;br /&gt;
&lt;br /&gt;
==== General ====&lt;br /&gt;
mdtest is part of the ior performance test package.&lt;br /&gt;
&lt;br /&gt;
==== RHEL Installation ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
wget https://github.com/hpc/ior/releases/download/3.3.0/ior-3.3.0.tar.bz2&lt;br /&gt;
tar xjf ior-*.tar.bz2&lt;br /&gt;
cd ior-*/&lt;br /&gt;
&lt;br /&gt;
yum install openmpi-devel environment-modules&lt;br /&gt;
# Relog your shell so &#039;module&#039; is available&lt;br /&gt;
module load mpi&lt;br /&gt;
module list&lt;br /&gt;
./configure&lt;br /&gt;
make -j4&lt;br /&gt;
make install&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ubuntu Installation ====&lt;br /&gt;
* https://gist.github.com/hokiegeek2/3057f8bb3beb519ae9b556e41824be30&lt;br /&gt;
* https://ior.readthedocs.io/en/latest/userDoc/install.html&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
VERSION=4.0.0&lt;br /&gt;
wget https://github.com/hpc/ior/releases/download/$VERSION/ior-$VERSION.tar.gz&lt;br /&gt;
tar -xzvf ior-$VERSION.tar.gz&lt;br /&gt;
cd ior-$VERSION/&lt;br /&gt;
&lt;br /&gt;
apt install libopenmpi-dev environment-modules openmpi-bin openmpi-common libgtk2.0-dev -y&lt;br /&gt;
./configure&lt;br /&gt;
&lt;br /&gt;
make -j4&lt;br /&gt;
make install&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Usage =====&lt;br /&gt;
Note: Number of items should be a multiple of depth x branching factor&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
module load mpi&lt;br /&gt;
&lt;br /&gt;
# Run command &amp;quot;mdtest -n 2000 -z 5 -b 2 -d /mnt/ssd/&amp;quot; 10 times in a row&lt;br /&gt;
mpirun --oversubscribe --allow-run-as-root -n 10 mdtest -n 2000 -z 5 -b 2 -d /mnt/nfs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Links =====&lt;br /&gt;
* https://github.com/hpc/ior&lt;br /&gt;
* https://www.glennklockwood.com/benchmarks/mdtest.html Guide&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Scripts&amp;diff=877</id>
		<title>Linux:Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Scripts&amp;diff=877"/>
		<updated>2026-01-24T15:29:32Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* Curl */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet]]&lt;br /&gt;
&lt;br /&gt;
== Advice ==&lt;br /&gt;
* Lowercase or Camelcase only: all BASH variables are uppercase, so don&#039;t get in their way!&lt;br /&gt;
&lt;br /&gt;
== Templates ==&lt;br /&gt;
=== #1 ===&lt;br /&gt;
Script with a single passed variable, description and common exit-protocols.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
#!/usr/bin/env bash&lt;br /&gt;
&lt;br /&gt;
set -o errexit       # Exit on error, do not continue running the script&lt;br /&gt;
set -o nounset       # Trying to access a variable that has not been set generates an error&lt;br /&gt;
set -o pipefail      # When a pipe fails generate an error&lt;br /&gt;
&lt;br /&gt;
if [[ &amp;quot;${1-}&amp;quot; =~ ^-*h(elp)?$ ]] || [[ &amp;quot;$#&amp;quot; -eq 0 ]] ; then&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
    echo &#039;Usage: myscript.sh value1&lt;br /&gt;
&lt;br /&gt;
This is the description of my script.&lt;br /&gt;
&#039;&lt;br /&gt;
    exit&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== #2 ===&lt;br /&gt;
Inspired by: https://stackoverflow.com/questions/16483119/an-example-of-how-to-use-getopts-in-bash&lt;br /&gt;
&lt;br /&gt;
Dedicated usage/help function to catch faulty script usage. This template catches custom flags and save them as variables.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
#!/usr/bin/env bash&lt;br /&gt;
&lt;br /&gt;
set -o errexit       # Exit on error, do not continue running the script&lt;br /&gt;
# We comment this because we explicitly check for variable existence later&lt;br /&gt;
#set -o nounset       # Trying to access a variable that has not been set generates an error&lt;br /&gt;
set -o pipefail      # When a pipe fails generate an error&lt;br /&gt;
&lt;br /&gt;
# Basic help output&lt;br /&gt;
usage () {&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
    echo &amp;quot;Usage: ${0} -s something -o something-else&lt;br /&gt;
Examples:&lt;br /&gt;
${0} -s herp -o derp&lt;br /&gt;
&lt;br /&gt;
This is the description of my script.&lt;br /&gt;
&amp;quot;&lt;br /&gt;
    exit 0&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Catch insufficent arguments and or help parameter, then run the usage function&lt;br /&gt;
if [[ &amp;quot;${1-}&amp;quot; =~ ^-*h(elp)?$ ]] || [[ &amp;quot;$#&amp;quot; -lt 2 ]] ; then&lt;br /&gt;
    usage&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# Create options &amp;quot;s&amp;quot; and &amp;quot;o&amp;quot; and save them as variables &amp;quot;var1&amp;quot; and &amp;quot;var2&amp;quot; respectively&lt;br /&gt;
# Missing or wrong arguments will run the usage function&lt;br /&gt;
while getopts &amp;quot;:s:o:&amp;quot; arg; do&lt;br /&gt;
    case &amp;quot;${arg}&amp;quot; in&lt;br /&gt;
        s) var1=${OPTARG};;&lt;br /&gt;
        o) var2=${OPTARG};;&lt;br /&gt;
        *) usage ;;&lt;br /&gt;
    esac&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
# Remove parsed parameters done by getopts, so that any remaining options can be interpreted as i.e. $1, $2, $3 etc&lt;br /&gt;
shift $((OPTIND-1))&lt;br /&gt;
&lt;br /&gt;
# Check whether the filled arguments are not empty, set -o nounset was commented to make this work properly&lt;br /&gt;
# If the variables aren&#039;t filled, run the usage function&lt;br /&gt;
if [[ -z &amp;quot;${var1}&amp;quot; ]] || [[ -z &amp;quot;${var2}&amp;quot; ]]; then&lt;br /&gt;
    usage&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Common syntax ==&lt;br /&gt;
=== for ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Execute a command for all objects within this folder and all subdirectories&lt;br /&gt;
for i in *; do du -h &amp;quot;$i&amp;quot; ; done&lt;br /&gt;
&lt;br /&gt;
# Execute a command x amount of times based on $i&lt;br /&gt;
for((i=1;i&amp;lt;=5;++i)); do dd if=/dev/zero of=myshare/file-$i bs=1M count=1; done&lt;br /&gt;
&lt;br /&gt;
# Shell script version - Execute a command x amount of times based on $i&lt;br /&gt;
for((i=1;i&amp;lt;=5;++i)) do&lt;br /&gt;
echo $i&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== if ===&lt;br /&gt;
==== Testing - [[ ]] ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Use the test functionality [[ ]] to compare values and types using expressions&lt;br /&gt;
man test&lt;br /&gt;
&lt;br /&gt;
# Test whether the directory saved in the $MyDirectoryVariable variable exists&lt;br /&gt;
[[ -d &amp;quot;$MyDirectoryVariable&amp;quot; ]]&lt;br /&gt;
&lt;br /&gt;
# Combine testing with an if statement&lt;br /&gt;
if [[ $(echo &amp;quot;world&amp;quot;) == &amp;quot;world&amp;quot; ]]; then&lt;br /&gt;
    echo -e &amp;quot;all is bad in da world&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
    echo -e &amp;quot;all is good&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
https://stackoverflow.com/questions/638975/how-do-i-tell-if-a-file-does-not-exist-in-bash&lt;br /&gt;
&lt;br /&gt;
FILE=/home/javier/wopper.txt&lt;br /&gt;
[ -b &amp;quot;$FILE&amp;quot; ] = Block special file&lt;br /&gt;
[ -c &amp;quot;$FILE&amp;quot; ] = Special character file&lt;br /&gt;
[ -d &amp;quot;$FILE&amp;quot; ] = If directory exists&lt;br /&gt;
[ -e &amp;quot;$FILE&amp;quot; ] = Check for file existence, regardless of type (node, directory, socket, etc.)&lt;br /&gt;
[ -f &amp;quot;$FILE&amp;quot; ] = Check for regular file existence not a directory&lt;br /&gt;
[ -G &amp;quot;$FILE&amp;quot; ] = Check if file exists and is owned by effective group ID&lt;br /&gt;
[ -G &amp;quot;$FILE&amp;quot; ] = set-group-id - True if file exists and is set-group-id&lt;br /&gt;
[ -k &amp;quot;$FILE&amp;quot; ] = Sticky bit&lt;br /&gt;
[ -L &amp;quot;$FILE&amp;quot; ] = Symbolic link&lt;br /&gt;
[ -O &amp;quot;$FILE&amp;quot; ] = True if file exists and is owned by the effective user id&lt;br /&gt;
[ -r &amp;quot;$FILE&amp;quot; ] = Check if file is a readable&lt;br /&gt;
[ -S &amp;quot;$FILE&amp;quot; ] = Check if file is socket&lt;br /&gt;
[ -s &amp;quot;$FILE&amp;quot; ] = Check if file is nonzero size&lt;br /&gt;
[ -u &amp;quot;$FILE&amp;quot; ] = Check if file set-user-id bit is set&lt;br /&gt;
[ -w &amp;quot;$FILE&amp;quot; ] = Check if file is writable&lt;br /&gt;
[ -x &amp;quot;$FILE&amp;quot; ] = Check if file is executable&lt;br /&gt;
&lt;br /&gt;
FOLDER=/home/javier/&lt;br /&gt;
[ -d &amp;quot;$FOLDER&amp;quot; ]  = If directory exists&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Examples ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
FILE=~/todo.txt&lt;br /&gt;
if [ -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 cat &amp;quot;~/todo.txt&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
 echo &amp;quot;You don&#039;t have the file, so you should make it.&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
USER=$(whoami)&lt;br /&gt;
FILE=~/todo.txt&lt;br /&gt;
&lt;br /&gt;
if [ &amp;quot;$USER&amp;quot; != &amp;quot;root&amp;quot; -a -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 echo &amp;quot;You&#039;re a normal user, you do have the file and this is its output:&amp;quot;&lt;br /&gt;
 cat &amp;quot;$FILE&amp;quot;&lt;br /&gt;
elif [ &amp;quot;$USER&amp;quot; != &amp;quot;root&amp;quot; -a ! -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 echo &amp;quot;You&#039;re a normal user, you don&#039;t have the file, so you should make it.&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scripts ==&lt;br /&gt;
=== SSH ===&lt;br /&gt;
==== centos-create-user.sh ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# Execute as root&lt;br /&gt;
# Usage: ./centos-create-user.sh USER&lt;br /&gt;
&lt;br /&gt;
USER=&amp;quot;$1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating user ${USER}&amp;quot;&lt;br /&gt;
useradd -m ${USER} -G wheel&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating authorized keys file and settings rights for ${USER} user&amp;quot;&lt;br /&gt;
mkdir -p /home/${USER}/.ssh&lt;br /&gt;
&lt;br /&gt;
cat &amp;lt;&amp;lt; &#039;EOF&#039; &amp;gt;&amp;gt; /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
# PUT ANY KEYS IN HERE&lt;br /&gt;
# KEY-1&lt;br /&gt;
# KEY-2&lt;br /&gt;
# KEY-3&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
chown -R ${USER}:${USER} /home/${USER}/.ssh&lt;br /&gt;
chmod 700 /home/${USER}/.ssh&lt;br /&gt;
chmod 600 /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
# EOF&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ubuntu-create-user.sh ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# Execute as root&lt;br /&gt;
# Usage: ./ubuntu-create-user.sh USER&lt;br /&gt;
&lt;br /&gt;
USER=&amp;quot;$1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating user ${USER}&amp;quot;&lt;br /&gt;
adduser ${USER} --disabled-password&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Adding ${USER} to the sudo group&amp;quot;&lt;br /&gt;
usermod -aG sudo ${USER}&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating authorized keys file and settings rights for ${USER} user&amp;quot;&lt;br /&gt;
mkdir -p /home/${USER}/.ssh&lt;br /&gt;
&lt;br /&gt;
cat &amp;lt;&amp;lt; &#039;EOF&#039; &amp;gt;&amp;gt; /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
# PUT ANY KEYS IN HERE&lt;br /&gt;
# KEY-1&lt;br /&gt;
# KEY-2&lt;br /&gt;
# KEY-3&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
chown -R ${USER}:${USER} /home/${USER}/.ssh&lt;br /&gt;
chmod 700 /home/${USER}/.ssh&lt;br /&gt;
chmod 600 /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
# EOF&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mail ===&lt;br /&gt;
==== Automatic sendmail ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
#requires: date,sendmail&lt;br /&gt;
function fappend {&lt;br /&gt;
    echo &amp;quot;$2&amp;quot;&amp;gt;&amp;gt;$1;&lt;br /&gt;
}&lt;br /&gt;
YYYYMMDD=`date +%Y%m%d`&lt;br /&gt;
&lt;br /&gt;
# CHANGE THESE&lt;br /&gt;
TOEMAIL=&amp;quot;ADMINISTRATOR@MYDOMAIN.COM&amp;quot;;&lt;br /&gt;
FREMAIL=&amp;quot;FROMNOREPLY@MYDOMAIN.com&amp;quot;;&lt;br /&gt;
SUBJECT=&amp;quot;E-mail Subject&amp;quot;;&lt;br /&gt;
MSGBODY=$(Command);&lt;br /&gt;
&lt;br /&gt;
# DON&#039;T CHANGE ANYTHING BELOW&lt;br /&gt;
TMP=`mktemp`&lt;br /&gt;
&lt;br /&gt;
rm -rf $TMP;&lt;br /&gt;
fappend $TMP &amp;quot;From: $FREMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;To: $TOEMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;Reply-To: $FREMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;Subject: $SUBJECT&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;$MSGBODY&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
cat $TMP|/usr/sbin/sendmail -t;&lt;br /&gt;
rm $TMP;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Scripts&amp;diff=876</id>
		<title>Linux:Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Scripts&amp;diff=876"/>
		<updated>2026-01-24T15:25:28Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* Examples */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet]]&lt;br /&gt;
&lt;br /&gt;
== Advice ==&lt;br /&gt;
* Lowercase or Camelcase only: all BASH variables are uppercase, so don&#039;t get in their way!&lt;br /&gt;
&lt;br /&gt;
== Templates ==&lt;br /&gt;
=== #1 ===&lt;br /&gt;
Script with a single passed variable, description and common exit-protocols.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
#!/usr/bin/env bash&lt;br /&gt;
&lt;br /&gt;
set -o errexit       # Exit on error, do not continue running the script&lt;br /&gt;
set -o nounset       # Trying to access a variable that has not been set generates an error&lt;br /&gt;
set -o pipefail      # When a pipe fails generate an error&lt;br /&gt;
&lt;br /&gt;
if [[ &amp;quot;${1-}&amp;quot; =~ ^-*h(elp)?$ ]] || [[ &amp;quot;$#&amp;quot; -eq 0 ]] ; then&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
    echo &#039;Usage: myscript.sh value1&lt;br /&gt;
&lt;br /&gt;
This is the description of my script.&lt;br /&gt;
&#039;&lt;br /&gt;
    exit&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== #2 ===&lt;br /&gt;
Inspired by: https://stackoverflow.com/questions/16483119/an-example-of-how-to-use-getopts-in-bash&lt;br /&gt;
&lt;br /&gt;
Dedicated usage/help function to catch faulty script usage. This template catches custom flags and save them as variables.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
#!/usr/bin/env bash&lt;br /&gt;
&lt;br /&gt;
set -o errexit       # Exit on error, do not continue running the script&lt;br /&gt;
# We comment this because we explicitly check for variable existence later&lt;br /&gt;
#set -o nounset       # Trying to access a variable that has not been set generates an error&lt;br /&gt;
set -o pipefail      # When a pipe fails generate an error&lt;br /&gt;
&lt;br /&gt;
# Basic help output&lt;br /&gt;
usage () {&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
    echo &amp;quot;Usage: ${0} -s something -o something-else&lt;br /&gt;
Examples:&lt;br /&gt;
${0} -s herp -o derp&lt;br /&gt;
&lt;br /&gt;
This is the description of my script.&lt;br /&gt;
&amp;quot;&lt;br /&gt;
    exit 0&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Catch insufficent arguments and or help parameter, then run the usage function&lt;br /&gt;
if [[ &amp;quot;${1-}&amp;quot; =~ ^-*h(elp)?$ ]] || [[ &amp;quot;$#&amp;quot; -lt 2 ]] ; then&lt;br /&gt;
    usage&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# Create options &amp;quot;s&amp;quot; and &amp;quot;o&amp;quot; and save them as variables &amp;quot;var1&amp;quot; and &amp;quot;var2&amp;quot; respectively&lt;br /&gt;
# Missing or wrong arguments will run the usage function&lt;br /&gt;
while getopts &amp;quot;:s:o:&amp;quot; arg; do&lt;br /&gt;
    case &amp;quot;${arg}&amp;quot; in&lt;br /&gt;
        s) var1=${OPTARG};;&lt;br /&gt;
        o) var2=${OPTARG};;&lt;br /&gt;
        *) usage ;;&lt;br /&gt;
    esac&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
# Remove parsed parameters done by getopts, so that any remaining options can be interpreted as i.e. $1, $2, $3 etc&lt;br /&gt;
shift $((OPTIND-1))&lt;br /&gt;
&lt;br /&gt;
# Check whether the filled arguments are not empty, set -o nounset was commented to make this work properly&lt;br /&gt;
# If the variables aren&#039;t filled, run the usage function&lt;br /&gt;
if [[ -z &amp;quot;${var1}&amp;quot; ]] || [[ -z &amp;quot;${var2}&amp;quot; ]]; then&lt;br /&gt;
    usage&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Common syntax ==&lt;br /&gt;
=== for ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Execute a command for all objects within this folder and all subdirectories&lt;br /&gt;
for i in *; do du -h &amp;quot;$i&amp;quot; ; done&lt;br /&gt;
&lt;br /&gt;
# Execute a command x amount of times based on $i&lt;br /&gt;
for((i=1;i&amp;lt;=5;++i)); do dd if=/dev/zero of=myshare/file-$i bs=1M count=1; done&lt;br /&gt;
&lt;br /&gt;
# Shell script version - Execute a command x amount of times based on $i&lt;br /&gt;
for((i=1;i&amp;lt;=5;++i)) do&lt;br /&gt;
echo $i&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== if ===&lt;br /&gt;
==== Testing - [[ ]] ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Use the test functionality [[ ]] to compare values and types using expressions&lt;br /&gt;
man test&lt;br /&gt;
&lt;br /&gt;
# Test whether the directory saved in the $MyDirectoryVariable variable exists&lt;br /&gt;
[[ -d &amp;quot;$MyDirectoryVariable&amp;quot; ]]&lt;br /&gt;
&lt;br /&gt;
# Combine testing with an if statement&lt;br /&gt;
if [[ $(echo &amp;quot;world&amp;quot;) == &amp;quot;world&amp;quot; ]]; then&lt;br /&gt;
    echo -e &amp;quot;all is bad in da world&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
    echo -e &amp;quot;all is good&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
https://stackoverflow.com/questions/638975/how-do-i-tell-if-a-file-does-not-exist-in-bash&lt;br /&gt;
&lt;br /&gt;
FILE=/home/javier/wopper.txt&lt;br /&gt;
[ -b &amp;quot;$FILE&amp;quot; ] = Block special file&lt;br /&gt;
[ -c &amp;quot;$FILE&amp;quot; ] = Special character file&lt;br /&gt;
[ -d &amp;quot;$FILE&amp;quot; ] = If directory exists&lt;br /&gt;
[ -e &amp;quot;$FILE&amp;quot; ] = Check for file existence, regardless of type (node, directory, socket, etc.)&lt;br /&gt;
[ -f &amp;quot;$FILE&amp;quot; ] = Check for regular file existence not a directory&lt;br /&gt;
[ -G &amp;quot;$FILE&amp;quot; ] = Check if file exists and is owned by effective group ID&lt;br /&gt;
[ -G &amp;quot;$FILE&amp;quot; ] = set-group-id - True if file exists and is set-group-id&lt;br /&gt;
[ -k &amp;quot;$FILE&amp;quot; ] = Sticky bit&lt;br /&gt;
[ -L &amp;quot;$FILE&amp;quot; ] = Symbolic link&lt;br /&gt;
[ -O &amp;quot;$FILE&amp;quot; ] = True if file exists and is owned by the effective user id&lt;br /&gt;
[ -r &amp;quot;$FILE&amp;quot; ] = Check if file is a readable&lt;br /&gt;
[ -S &amp;quot;$FILE&amp;quot; ] = Check if file is socket&lt;br /&gt;
[ -s &amp;quot;$FILE&amp;quot; ] = Check if file is nonzero size&lt;br /&gt;
[ -u &amp;quot;$FILE&amp;quot; ] = Check if file set-user-id bit is set&lt;br /&gt;
[ -w &amp;quot;$FILE&amp;quot; ] = Check if file is writable&lt;br /&gt;
[ -x &amp;quot;$FILE&amp;quot; ] = Check if file is executable&lt;br /&gt;
&lt;br /&gt;
FOLDER=/home/javier/&lt;br /&gt;
[ -d &amp;quot;$FOLDER&amp;quot; ]  = If directory exists&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Examples ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
FILE=~/todo.txt&lt;br /&gt;
if [ -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 cat &amp;quot;~/todo.txt&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
 echo &amp;quot;You don&#039;t have the file, so you should make it.&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
USER=$(whoami)&lt;br /&gt;
FILE=~/todo.txt&lt;br /&gt;
&lt;br /&gt;
if [ &amp;quot;$USER&amp;quot; != &amp;quot;root&amp;quot; -a -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 echo &amp;quot;You&#039;re a normal user, you do have the file and this is its output:&amp;quot;&lt;br /&gt;
 cat &amp;quot;$FILE&amp;quot;&lt;br /&gt;
elif [ &amp;quot;$USER&amp;quot; != &amp;quot;root&amp;quot; -a ! -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 echo &amp;quot;You&#039;re a normal user, you don&#039;t have the file, so you should make it.&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Curl ====&lt;br /&gt;
Example of executing a CURL call with a JSON-payload&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
mytoken=&amp;quot;supersecrettoken&amp;quot;&lt;br /&gt;
&lt;br /&gt;
curl -X &amp;quot;POST&amp;quot; &amp;quot;https://mywebsite.brammerloo.nl&amp;quot; \&lt;br /&gt;
     -H &#039;X-Requested-By: roshani&#039; \&lt;br /&gt;
     -H &#039;Content-Type: application/json&#039; \&lt;br /&gt;
     -H &#039;Accept: application/json&#039; \&lt;br /&gt;
     --silent \&lt;br /&gt;
     -u &amp;quot;${mytoken}&amp;quot;:token \&lt;br /&gt;
     -d &amp;quot;$curly&amp;quot;&lt;br /&gt;
&lt;br /&gt;
curly=&#039;{&lt;br /&gt;
    &amp;quot;queries&amp;quot;: [{&lt;br /&gt;
            &amp;quot;id&amp;quot;: &amp;quot;?&amp;quot;,&lt;br /&gt;
            &amp;quot;timerange&amp;quot;: {&lt;br /&gt;
                &amp;quot;type&amp;quot;: &amp;quot;keyword&amp;quot;,&lt;br /&gt;
                &amp;quot;keyword&amp;quot;: &amp;quot;one day ago&amp;quot;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    ]&lt;br /&gt;
}&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scripts ==&lt;br /&gt;
=== SSH ===&lt;br /&gt;
==== centos-create-user.sh ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# Execute as root&lt;br /&gt;
# Usage: ./centos-create-user.sh USER&lt;br /&gt;
&lt;br /&gt;
USER=&amp;quot;$1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating user ${USER}&amp;quot;&lt;br /&gt;
useradd -m ${USER} -G wheel&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating authorized keys file and settings rights for ${USER} user&amp;quot;&lt;br /&gt;
mkdir -p /home/${USER}/.ssh&lt;br /&gt;
&lt;br /&gt;
cat &amp;lt;&amp;lt; &#039;EOF&#039; &amp;gt;&amp;gt; /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
# PUT ANY KEYS IN HERE&lt;br /&gt;
# KEY-1&lt;br /&gt;
# KEY-2&lt;br /&gt;
# KEY-3&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
chown -R ${USER}:${USER} /home/${USER}/.ssh&lt;br /&gt;
chmod 700 /home/${USER}/.ssh&lt;br /&gt;
chmod 600 /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
# EOF&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ubuntu-create-user.sh ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# Execute as root&lt;br /&gt;
# Usage: ./ubuntu-create-user.sh USER&lt;br /&gt;
&lt;br /&gt;
USER=&amp;quot;$1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating user ${USER}&amp;quot;&lt;br /&gt;
adduser ${USER} --disabled-password&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Adding ${USER} to the sudo group&amp;quot;&lt;br /&gt;
usermod -aG sudo ${USER}&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating authorized keys file and settings rights for ${USER} user&amp;quot;&lt;br /&gt;
mkdir -p /home/${USER}/.ssh&lt;br /&gt;
&lt;br /&gt;
cat &amp;lt;&amp;lt; &#039;EOF&#039; &amp;gt;&amp;gt; /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
# PUT ANY KEYS IN HERE&lt;br /&gt;
# KEY-1&lt;br /&gt;
# KEY-2&lt;br /&gt;
# KEY-3&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
chown -R ${USER}:${USER} /home/${USER}/.ssh&lt;br /&gt;
chmod 700 /home/${USER}/.ssh&lt;br /&gt;
chmod 600 /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
# EOF&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mail ===&lt;br /&gt;
==== Automatic sendmail ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
#requires: date,sendmail&lt;br /&gt;
function fappend {&lt;br /&gt;
    echo &amp;quot;$2&amp;quot;&amp;gt;&amp;gt;$1;&lt;br /&gt;
}&lt;br /&gt;
YYYYMMDD=`date +%Y%m%d`&lt;br /&gt;
&lt;br /&gt;
# CHANGE THESE&lt;br /&gt;
TOEMAIL=&amp;quot;ADMINISTRATOR@MYDOMAIN.COM&amp;quot;;&lt;br /&gt;
FREMAIL=&amp;quot;FROMNOREPLY@MYDOMAIN.com&amp;quot;;&lt;br /&gt;
SUBJECT=&amp;quot;E-mail Subject&amp;quot;;&lt;br /&gt;
MSGBODY=$(Command);&lt;br /&gt;
&lt;br /&gt;
# DON&#039;T CHANGE ANYTHING BELOW&lt;br /&gt;
TMP=`mktemp`&lt;br /&gt;
&lt;br /&gt;
rm -rf $TMP;&lt;br /&gt;
fappend $TMP &amp;quot;From: $FREMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;To: $TOEMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;Reply-To: $FREMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;Subject: $SUBJECT&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;$MSGBODY&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
cat $TMP|/usr/sbin/sendmail -t;&lt;br /&gt;
rm $TMP;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Scripts&amp;diff=875</id>
		<title>Linux:Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Scripts&amp;diff=875"/>
		<updated>2026-01-24T15:20:46Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* Testing - [[]] */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet]]&lt;br /&gt;
&lt;br /&gt;
== Advice ==&lt;br /&gt;
* Lowercase or Camelcase only: all BASH variables are uppercase, so don&#039;t get in their way!&lt;br /&gt;
&lt;br /&gt;
== Templates ==&lt;br /&gt;
=== #1 ===&lt;br /&gt;
Script with a single passed variable, description and common exit-protocols.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
#!/usr/bin/env bash&lt;br /&gt;
&lt;br /&gt;
set -o errexit       # Exit on error, do not continue running the script&lt;br /&gt;
set -o nounset       # Trying to access a variable that has not been set generates an error&lt;br /&gt;
set -o pipefail      # When a pipe fails generate an error&lt;br /&gt;
&lt;br /&gt;
if [[ &amp;quot;${1-}&amp;quot; =~ ^-*h(elp)?$ ]] || [[ &amp;quot;$#&amp;quot; -eq 0 ]] ; then&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
    echo &#039;Usage: myscript.sh value1&lt;br /&gt;
&lt;br /&gt;
This is the description of my script.&lt;br /&gt;
&#039;&lt;br /&gt;
    exit&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== #2 ===&lt;br /&gt;
Inspired by: https://stackoverflow.com/questions/16483119/an-example-of-how-to-use-getopts-in-bash&lt;br /&gt;
&lt;br /&gt;
Dedicated usage/help function to catch faulty script usage. This template catches custom flags and save them as variables.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
#!/usr/bin/env bash&lt;br /&gt;
&lt;br /&gt;
set -o errexit       # Exit on error, do not continue running the script&lt;br /&gt;
# We comment this because we explicitly check for variable existence later&lt;br /&gt;
#set -o nounset       # Trying to access a variable that has not been set generates an error&lt;br /&gt;
set -o pipefail      # When a pipe fails generate an error&lt;br /&gt;
&lt;br /&gt;
# Basic help output&lt;br /&gt;
usage () {&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
    echo &amp;quot;Usage: ${0} -s something -o something-else&lt;br /&gt;
Examples:&lt;br /&gt;
${0} -s herp -o derp&lt;br /&gt;
&lt;br /&gt;
This is the description of my script.&lt;br /&gt;
&amp;quot;&lt;br /&gt;
    exit 0&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Catch insufficent arguments and or help parameter, then run the usage function&lt;br /&gt;
if [[ &amp;quot;${1-}&amp;quot; =~ ^-*h(elp)?$ ]] || [[ &amp;quot;$#&amp;quot; -lt 2 ]] ; then&lt;br /&gt;
    usage&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# Create options &amp;quot;s&amp;quot; and &amp;quot;o&amp;quot; and save them as variables &amp;quot;var1&amp;quot; and &amp;quot;var2&amp;quot; respectively&lt;br /&gt;
# Missing or wrong arguments will run the usage function&lt;br /&gt;
while getopts &amp;quot;:s:o:&amp;quot; arg; do&lt;br /&gt;
    case &amp;quot;${arg}&amp;quot; in&lt;br /&gt;
        s) var1=${OPTARG};;&lt;br /&gt;
        o) var2=${OPTARG};;&lt;br /&gt;
        *) usage ;;&lt;br /&gt;
    esac&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
# Remove parsed parameters done by getopts, so that any remaining options can be interpreted as i.e. $1, $2, $3 etc&lt;br /&gt;
shift $((OPTIND-1))&lt;br /&gt;
&lt;br /&gt;
# Check whether the filled arguments are not empty, set -o nounset was commented to make this work properly&lt;br /&gt;
# If the variables aren&#039;t filled, run the usage function&lt;br /&gt;
if [[ -z &amp;quot;${var1}&amp;quot; ]] || [[ -z &amp;quot;${var2}&amp;quot; ]]; then&lt;br /&gt;
    usage&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Common syntax ==&lt;br /&gt;
=== for ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Execute a command for all objects within this folder and all subdirectories&lt;br /&gt;
for i in *; do du -h &amp;quot;$i&amp;quot; ; done&lt;br /&gt;
&lt;br /&gt;
# Execute a command x amount of times based on $i&lt;br /&gt;
for((i=1;i&amp;lt;=5;++i)); do dd if=/dev/zero of=myshare/file-$i bs=1M count=1; done&lt;br /&gt;
&lt;br /&gt;
# Shell script version - Execute a command x amount of times based on $i&lt;br /&gt;
for((i=1;i&amp;lt;=5;++i)) do&lt;br /&gt;
echo $i&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== if ===&lt;br /&gt;
==== Testing - [[ ]] ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Use the test functionality [[ ]] to compare values and types using expressions&lt;br /&gt;
man test&lt;br /&gt;
&lt;br /&gt;
# Test whether the directory saved in the $MyDirectoryVariable variable exists&lt;br /&gt;
[[ -d &amp;quot;$MyDirectoryVariable&amp;quot; ]]&lt;br /&gt;
&lt;br /&gt;
# Combine testing with an if statement&lt;br /&gt;
if [[ $(echo &amp;quot;world&amp;quot;) == &amp;quot;world&amp;quot; ]]; then&lt;br /&gt;
    echo -e &amp;quot;all is bad in da world&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
    echo -e &amp;quot;all is good&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
https://stackoverflow.com/questions/638975/how-do-i-tell-if-a-file-does-not-exist-in-bash&lt;br /&gt;
&lt;br /&gt;
FILE=/home/javier/wopper.txt&lt;br /&gt;
[ -b &amp;quot;$FILE&amp;quot; ] = Block special file&lt;br /&gt;
[ -c &amp;quot;$FILE&amp;quot; ] = Special character file&lt;br /&gt;
[ -d &amp;quot;$FILE&amp;quot; ] = If directory exists&lt;br /&gt;
[ -e &amp;quot;$FILE&amp;quot; ] = Check for file existence, regardless of type (node, directory, socket, etc.)&lt;br /&gt;
[ -f &amp;quot;$FILE&amp;quot; ] = Check for regular file existence not a directory&lt;br /&gt;
[ -G &amp;quot;$FILE&amp;quot; ] = Check if file exists and is owned by effective group ID&lt;br /&gt;
[ -G &amp;quot;$FILE&amp;quot; ] = set-group-id - True if file exists and is set-group-id&lt;br /&gt;
[ -k &amp;quot;$FILE&amp;quot; ] = Sticky bit&lt;br /&gt;
[ -L &amp;quot;$FILE&amp;quot; ] = Symbolic link&lt;br /&gt;
[ -O &amp;quot;$FILE&amp;quot; ] = True if file exists and is owned by the effective user id&lt;br /&gt;
[ -r &amp;quot;$FILE&amp;quot; ] = Check if file is a readable&lt;br /&gt;
[ -S &amp;quot;$FILE&amp;quot; ] = Check if file is socket&lt;br /&gt;
[ -s &amp;quot;$FILE&amp;quot; ] = Check if file is nonzero size&lt;br /&gt;
[ -u &amp;quot;$FILE&amp;quot; ] = Check if file set-user-id bit is set&lt;br /&gt;
[ -w &amp;quot;$FILE&amp;quot; ] = Check if file is writable&lt;br /&gt;
[ -x &amp;quot;$FILE&amp;quot; ] = Check if file is executable&lt;br /&gt;
&lt;br /&gt;
FOLDER=/home/javier/&lt;br /&gt;
[ -d &amp;quot;$FOLDER&amp;quot; ]  = If directory exists&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Examples ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
FILE=~/todo.txt&lt;br /&gt;
if [ -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 cat &amp;quot;~/todo.txt&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
 echo &amp;quot;You don&#039;t have the file, so you should make it.&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
USER=$(whoami)&lt;br /&gt;
FILE=~/todo.txt&lt;br /&gt;
&lt;br /&gt;
if [ &amp;quot;$USER&amp;quot; != &amp;quot;root&amp;quot; -a -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 echo &amp;quot;You&#039;re a normal user, you do have the file and this is its output:&amp;quot;&lt;br /&gt;
 cat &amp;quot;$FILE&amp;quot;&lt;br /&gt;
elif [ &amp;quot;$USER&amp;quot; != &amp;quot;root&amp;quot; -a ! -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 echo &amp;quot;You&#039;re a normal user, you don&#039;t have the file, so you should make it.&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scripts ==&lt;br /&gt;
=== SSH ===&lt;br /&gt;
==== centos-create-user.sh ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# Execute as root&lt;br /&gt;
# Usage: ./centos-create-user.sh USER&lt;br /&gt;
&lt;br /&gt;
USER=&amp;quot;$1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating user ${USER}&amp;quot;&lt;br /&gt;
useradd -m ${USER} -G wheel&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating authorized keys file and settings rights for ${USER} user&amp;quot;&lt;br /&gt;
mkdir -p /home/${USER}/.ssh&lt;br /&gt;
&lt;br /&gt;
cat &amp;lt;&amp;lt; &#039;EOF&#039; &amp;gt;&amp;gt; /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
# PUT ANY KEYS IN HERE&lt;br /&gt;
# KEY-1&lt;br /&gt;
# KEY-2&lt;br /&gt;
# KEY-3&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
chown -R ${USER}:${USER} /home/${USER}/.ssh&lt;br /&gt;
chmod 700 /home/${USER}/.ssh&lt;br /&gt;
chmod 600 /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
# EOF&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ubuntu-create-user.sh ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# Execute as root&lt;br /&gt;
# Usage: ./ubuntu-create-user.sh USER&lt;br /&gt;
&lt;br /&gt;
USER=&amp;quot;$1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating user ${USER}&amp;quot;&lt;br /&gt;
adduser ${USER} --disabled-password&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Adding ${USER} to the sudo group&amp;quot;&lt;br /&gt;
usermod -aG sudo ${USER}&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating authorized keys file and settings rights for ${USER} user&amp;quot;&lt;br /&gt;
mkdir -p /home/${USER}/.ssh&lt;br /&gt;
&lt;br /&gt;
cat &amp;lt;&amp;lt; &#039;EOF&#039; &amp;gt;&amp;gt; /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
# PUT ANY KEYS IN HERE&lt;br /&gt;
# KEY-1&lt;br /&gt;
# KEY-2&lt;br /&gt;
# KEY-3&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
chown -R ${USER}:${USER} /home/${USER}/.ssh&lt;br /&gt;
chmod 700 /home/${USER}/.ssh&lt;br /&gt;
chmod 600 /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
# EOF&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mail ===&lt;br /&gt;
==== Automatic sendmail ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
#requires: date,sendmail&lt;br /&gt;
function fappend {&lt;br /&gt;
    echo &amp;quot;$2&amp;quot;&amp;gt;&amp;gt;$1;&lt;br /&gt;
}&lt;br /&gt;
YYYYMMDD=`date +%Y%m%d`&lt;br /&gt;
&lt;br /&gt;
# CHANGE THESE&lt;br /&gt;
TOEMAIL=&amp;quot;ADMINISTRATOR@MYDOMAIN.COM&amp;quot;;&lt;br /&gt;
FREMAIL=&amp;quot;FROMNOREPLY@MYDOMAIN.com&amp;quot;;&lt;br /&gt;
SUBJECT=&amp;quot;E-mail Subject&amp;quot;;&lt;br /&gt;
MSGBODY=$(Command);&lt;br /&gt;
&lt;br /&gt;
# DON&#039;T CHANGE ANYTHING BELOW&lt;br /&gt;
TMP=`mktemp`&lt;br /&gt;
&lt;br /&gt;
rm -rf $TMP;&lt;br /&gt;
fappend $TMP &amp;quot;From: $FREMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;To: $TOEMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;Reply-To: $FREMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;Subject: $SUBJECT&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;$MSGBODY&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
cat $TMP|/usr/sbin/sendmail -t;&lt;br /&gt;
rm $TMP;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Scripts&amp;diff=874</id>
		<title>Linux:Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Scripts&amp;diff=874"/>
		<updated>2026-01-24T15:18:56Z</updated>

		<summary type="html">&lt;p&gt;Patrick: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet]]&lt;br /&gt;
&lt;br /&gt;
== Advice ==&lt;br /&gt;
* Lowercase or Camelcase only: all BASH variables are uppercase, so don&#039;t get in their way!&lt;br /&gt;
&lt;br /&gt;
== Templates ==&lt;br /&gt;
=== #1 ===&lt;br /&gt;
Script with a single passed variable, description and common exit-protocols.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
#!/usr/bin/env bash&lt;br /&gt;
&lt;br /&gt;
set -o errexit       # Exit on error, do not continue running the script&lt;br /&gt;
set -o nounset       # Trying to access a variable that has not been set generates an error&lt;br /&gt;
set -o pipefail      # When a pipe fails generate an error&lt;br /&gt;
&lt;br /&gt;
if [[ &amp;quot;${1-}&amp;quot; =~ ^-*h(elp)?$ ]] || [[ &amp;quot;$#&amp;quot; -eq 0 ]] ; then&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
    echo &#039;Usage: myscript.sh value1&lt;br /&gt;
&lt;br /&gt;
This is the description of my script.&lt;br /&gt;
&#039;&lt;br /&gt;
    exit&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== #2 ===&lt;br /&gt;
Inspired by: https://stackoverflow.com/questions/16483119/an-example-of-how-to-use-getopts-in-bash&lt;br /&gt;
&lt;br /&gt;
Dedicated usage/help function to catch faulty script usage. This template catches custom flags and save them as variables.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
#!/usr/bin/env bash&lt;br /&gt;
&lt;br /&gt;
set -o errexit       # Exit on error, do not continue running the script&lt;br /&gt;
# We comment this because we explicitly check for variable existence later&lt;br /&gt;
#set -o nounset       # Trying to access a variable that has not been set generates an error&lt;br /&gt;
set -o pipefail      # When a pipe fails generate an error&lt;br /&gt;
&lt;br /&gt;
# Basic help output&lt;br /&gt;
usage () {&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
    echo &amp;quot;Usage: ${0} -s something -o something-else&lt;br /&gt;
Examples:&lt;br /&gt;
${0} -s herp -o derp&lt;br /&gt;
&lt;br /&gt;
This is the description of my script.&lt;br /&gt;
&amp;quot;&lt;br /&gt;
    exit 0&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Catch insufficent arguments and or help parameter, then run the usage function&lt;br /&gt;
if [[ &amp;quot;${1-}&amp;quot; =~ ^-*h(elp)?$ ]] || [[ &amp;quot;$#&amp;quot; -lt 2 ]] ; then&lt;br /&gt;
    usage&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# Create options &amp;quot;s&amp;quot; and &amp;quot;o&amp;quot; and save them as variables &amp;quot;var1&amp;quot; and &amp;quot;var2&amp;quot; respectively&lt;br /&gt;
# Missing or wrong arguments will run the usage function&lt;br /&gt;
while getopts &amp;quot;:s:o:&amp;quot; arg; do&lt;br /&gt;
    case &amp;quot;${arg}&amp;quot; in&lt;br /&gt;
        s) var1=${OPTARG};;&lt;br /&gt;
        o) var2=${OPTARG};;&lt;br /&gt;
        *) usage ;;&lt;br /&gt;
    esac&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
# Remove parsed parameters done by getopts, so that any remaining options can be interpreted as i.e. $1, $2, $3 etc&lt;br /&gt;
shift $((OPTIND-1))&lt;br /&gt;
&lt;br /&gt;
# Check whether the filled arguments are not empty, set -o nounset was commented to make this work properly&lt;br /&gt;
# If the variables aren&#039;t filled, run the usage function&lt;br /&gt;
if [[ -z &amp;quot;${var1}&amp;quot; ]] || [[ -z &amp;quot;${var2}&amp;quot; ]]; then&lt;br /&gt;
    usage&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Common syntax ==&lt;br /&gt;
=== for ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Execute a command for all objects within this folder and all subdirectories&lt;br /&gt;
for i in *; do du -h &amp;quot;$i&amp;quot; ; done&lt;br /&gt;
&lt;br /&gt;
# Execute a command x amount of times based on $i&lt;br /&gt;
for((i=1;i&amp;lt;=5;++i)); do dd if=/dev/zero of=myshare/file-$i bs=1M count=1; done&lt;br /&gt;
&lt;br /&gt;
# Shell script version - Execute a command x amount of times based on $i&lt;br /&gt;
for((i=1;i&amp;lt;=5;++i)) do&lt;br /&gt;
echo $i&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== if ===&lt;br /&gt;
==== Testing - [[]] ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Use the test functionality [[]] to compare values and types, using expressions&lt;br /&gt;
man test&lt;br /&gt;
[[ -d &amp;quot;$MyDirectoryVariable&amp;quot; ]]&lt;br /&gt;
&lt;br /&gt;
# Combine testing with an if statement&lt;br /&gt;
if [[ $(echo &amp;quot;world&amp;quot;) == &amp;quot;world&amp;quot; ]]; then&lt;br /&gt;
    echo -e &amp;quot;all is bad in da world&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
    echo -e &amp;quot;all is good&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
https://stackoverflow.com/questions/638975/how-do-i-tell-if-a-file-does-not-exist-in-bash&lt;br /&gt;
&lt;br /&gt;
FILE=/home/javier/wopper.txt&lt;br /&gt;
[ -b &amp;quot;$FILE&amp;quot; ] = Block special file&lt;br /&gt;
[ -c &amp;quot;$FILE&amp;quot; ] = Special character file&lt;br /&gt;
[ -d &amp;quot;$FILE&amp;quot; ] = If directory exists&lt;br /&gt;
[ -e &amp;quot;$FILE&amp;quot; ] = Check for file existence, regardless of type (node, directory, socket, etc.)&lt;br /&gt;
[ -f &amp;quot;$FILE&amp;quot; ] = Check for regular file existence not a directory&lt;br /&gt;
[ -G &amp;quot;$FILE&amp;quot; ] = Check if file exists and is owned by effective group ID&lt;br /&gt;
[ -G &amp;quot;$FILE&amp;quot; ] = set-group-id - True if file exists and is set-group-id&lt;br /&gt;
[ -k &amp;quot;$FILE&amp;quot; ] = Sticky bit&lt;br /&gt;
[ -L &amp;quot;$FILE&amp;quot; ] = Symbolic link&lt;br /&gt;
[ -O &amp;quot;$FILE&amp;quot; ] = True if file exists and is owned by the effective user id&lt;br /&gt;
[ -r &amp;quot;$FILE&amp;quot; ] = Check if file is a readable&lt;br /&gt;
[ -S &amp;quot;$FILE&amp;quot; ] = Check if file is socket&lt;br /&gt;
[ -s &amp;quot;$FILE&amp;quot; ] = Check if file is nonzero size&lt;br /&gt;
[ -u &amp;quot;$FILE&amp;quot; ] = Check if file set-user-id bit is set&lt;br /&gt;
[ -w &amp;quot;$FILE&amp;quot; ] = Check if file is writable&lt;br /&gt;
[ -x &amp;quot;$FILE&amp;quot; ] = Check if file is executable&lt;br /&gt;
&lt;br /&gt;
FOLDER=/home/javier/&lt;br /&gt;
[ -d &amp;quot;$FOLDER&amp;quot; ]  = If directory exists&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Examples ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
FILE=~/todo.txt&lt;br /&gt;
if [ -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 cat &amp;quot;~/todo.txt&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
 echo &amp;quot;You don&#039;t have the file, so you should make it.&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
USER=$(whoami)&lt;br /&gt;
FILE=~/todo.txt&lt;br /&gt;
&lt;br /&gt;
if [ &amp;quot;$USER&amp;quot; != &amp;quot;root&amp;quot; -a -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 echo &amp;quot;You&#039;re a normal user, you do have the file and this is its output:&amp;quot;&lt;br /&gt;
 cat &amp;quot;$FILE&amp;quot;&lt;br /&gt;
elif [ &amp;quot;$USER&amp;quot; != &amp;quot;root&amp;quot; -a ! -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 echo &amp;quot;You&#039;re a normal user, you don&#039;t have the file, so you should make it.&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scripts ==&lt;br /&gt;
=== SSH ===&lt;br /&gt;
==== centos-create-user.sh ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# Execute as root&lt;br /&gt;
# Usage: ./centos-create-user.sh USER&lt;br /&gt;
&lt;br /&gt;
USER=&amp;quot;$1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating user ${USER}&amp;quot;&lt;br /&gt;
useradd -m ${USER} -G wheel&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating authorized keys file and settings rights for ${USER} user&amp;quot;&lt;br /&gt;
mkdir -p /home/${USER}/.ssh&lt;br /&gt;
&lt;br /&gt;
cat &amp;lt;&amp;lt; &#039;EOF&#039; &amp;gt;&amp;gt; /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
# PUT ANY KEYS IN HERE&lt;br /&gt;
# KEY-1&lt;br /&gt;
# KEY-2&lt;br /&gt;
# KEY-3&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
chown -R ${USER}:${USER} /home/${USER}/.ssh&lt;br /&gt;
chmod 700 /home/${USER}/.ssh&lt;br /&gt;
chmod 600 /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
# EOF&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ubuntu-create-user.sh ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# Execute as root&lt;br /&gt;
# Usage: ./ubuntu-create-user.sh USER&lt;br /&gt;
&lt;br /&gt;
USER=&amp;quot;$1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating user ${USER}&amp;quot;&lt;br /&gt;
adduser ${USER} --disabled-password&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Adding ${USER} to the sudo group&amp;quot;&lt;br /&gt;
usermod -aG sudo ${USER}&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating authorized keys file and settings rights for ${USER} user&amp;quot;&lt;br /&gt;
mkdir -p /home/${USER}/.ssh&lt;br /&gt;
&lt;br /&gt;
cat &amp;lt;&amp;lt; &#039;EOF&#039; &amp;gt;&amp;gt; /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
# PUT ANY KEYS IN HERE&lt;br /&gt;
# KEY-1&lt;br /&gt;
# KEY-2&lt;br /&gt;
# KEY-3&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
chown -R ${USER}:${USER} /home/${USER}/.ssh&lt;br /&gt;
chmod 700 /home/${USER}/.ssh&lt;br /&gt;
chmod 600 /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
# EOF&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mail ===&lt;br /&gt;
==== Automatic sendmail ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
#requires: date,sendmail&lt;br /&gt;
function fappend {&lt;br /&gt;
    echo &amp;quot;$2&amp;quot;&amp;gt;&amp;gt;$1;&lt;br /&gt;
}&lt;br /&gt;
YYYYMMDD=`date +%Y%m%d`&lt;br /&gt;
&lt;br /&gt;
# CHANGE THESE&lt;br /&gt;
TOEMAIL=&amp;quot;ADMINISTRATOR@MYDOMAIN.COM&amp;quot;;&lt;br /&gt;
FREMAIL=&amp;quot;FROMNOREPLY@MYDOMAIN.com&amp;quot;;&lt;br /&gt;
SUBJECT=&amp;quot;E-mail Subject&amp;quot;;&lt;br /&gt;
MSGBODY=$(Command);&lt;br /&gt;
&lt;br /&gt;
# DON&#039;T CHANGE ANYTHING BELOW&lt;br /&gt;
TMP=`mktemp`&lt;br /&gt;
&lt;br /&gt;
rm -rf $TMP;&lt;br /&gt;
fappend $TMP &amp;quot;From: $FREMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;To: $TOEMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;Reply-To: $FREMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;Subject: $SUBJECT&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;$MSGBODY&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
cat $TMP|/usr/sbin/sendmail -t;&lt;br /&gt;
rm $TMP;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Scripts&amp;diff=873</id>
		<title>Linux:Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Scripts&amp;diff=873"/>
		<updated>2026-01-24T15:17:50Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* Template */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet]]&lt;br /&gt;
&lt;br /&gt;
== Advice ==&lt;br /&gt;
* Lowercase or Camelcase only: all BASH variables are uppercase, so don&#039;t get in their way!&lt;br /&gt;
&lt;br /&gt;
== Templates ==&lt;br /&gt;
=== #1 ===&lt;br /&gt;
Script with a single passed variable, description and common exit-protocols.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
#!/usr/bin/env bash&lt;br /&gt;
&lt;br /&gt;
set -o errexit       # Exit on error, do not continue running the script&lt;br /&gt;
set -o nounset       # Trying to access a variable that has not been set generates an error&lt;br /&gt;
set -o pipefail      # When a pipe fails generate an error&lt;br /&gt;
&lt;br /&gt;
if [[ &amp;quot;${1-}&amp;quot; =~ ^-*h(elp)?$ ]] || [[ &amp;quot;$#&amp;quot; -eq 0 ]] ; then&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
    echo &#039;Usage: myscript.sh value1&lt;br /&gt;
&lt;br /&gt;
This is the description of my script.&lt;br /&gt;
&#039;&lt;br /&gt;
    exit&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== #2 ===&lt;br /&gt;
Inspired by: https://stackoverflow.com/questions/16483119/an-example-of-how-to-use-getopts-in-bash&lt;br /&gt;
&lt;br /&gt;
Dedicated usage/help function to catch faulty script usage. This template catches custom flags and save them as variables.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
#!/usr/bin/env bash&lt;br /&gt;
&lt;br /&gt;
set -o errexit       # Exit on error, do not continue running the script&lt;br /&gt;
# We comment this because we explicitly check for variable existence later&lt;br /&gt;
#set -o nounset       # Trying to access a variable that has not been set generates an error&lt;br /&gt;
set -o pipefail      # When a pipe fails generate an error&lt;br /&gt;
&lt;br /&gt;
# Basic help output&lt;br /&gt;
usage () {&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
    echo &amp;quot;Usage: ${0} -s something -o something-else&lt;br /&gt;
Examples:&lt;br /&gt;
${0} -s herp -o derp&lt;br /&gt;
&lt;br /&gt;
This is the description of my script.&lt;br /&gt;
&amp;quot;&lt;br /&gt;
    exit 0&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Catch insufficent arguments and or help parameter, then run the usage function&lt;br /&gt;
if [[ &amp;quot;${1-}&amp;quot; =~ ^-*h(elp)?$ ]] || [[ &amp;quot;$#&amp;quot; -lt 2 ]] ; then&lt;br /&gt;
    usage&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# Create options &amp;quot;s&amp;quot; and &amp;quot;o&amp;quot; and save them as variables &amp;quot;var1&amp;quot; and &amp;quot;var2&amp;quot; respectively&lt;br /&gt;
# Missing or wrong arguments will run the usage function&lt;br /&gt;
while getopts &amp;quot;:s:o:&amp;quot; arg; do&lt;br /&gt;
    case &amp;quot;${arg}&amp;quot; in&lt;br /&gt;
        s) var1=${OPTARG};;&lt;br /&gt;
        o) var2=${OPTARG};;&lt;br /&gt;
        *) usage ;;&lt;br /&gt;
    esac&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
# Remove parsed parameters done by getopts, so that any remaining options can be interpreted as i.e. $1, $2, $3 etc&lt;br /&gt;
shift $((OPTIND-1))&lt;br /&gt;
&lt;br /&gt;
# Check whether the filled arguments are not empty, set -o nounset was commented to make this work properly&lt;br /&gt;
# If the variables aren&#039;t filled, run the usage function&lt;br /&gt;
if [[ -z &amp;quot;${var1}&amp;quot; ]] || [[ -z &amp;quot;${var2}&amp;quot; ]]; then&lt;br /&gt;
    usage&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing - [[]] ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Use the test functionality [[]] to compare values and types, using expressions&lt;br /&gt;
man test&lt;br /&gt;
[[ -d &amp;quot;$MyDirectoryVariable&amp;quot; ]]&lt;br /&gt;
&lt;br /&gt;
# Combine testing with an if statement&lt;br /&gt;
if [[ $(echo &amp;quot;world&amp;quot;) == &amp;quot;world&amp;quot; ]]; then&lt;br /&gt;
    echo -e &amp;quot;all is bad in da world&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
    echo -e &amp;quot;all is good&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
https://stackoverflow.com/questions/638975/how-do-i-tell-if-a-file-does-not-exist-in-bash&lt;br /&gt;
&lt;br /&gt;
FILE=/home/javier/wopper.txt&lt;br /&gt;
[ -b &amp;quot;$FILE&amp;quot; ] = Block special file&lt;br /&gt;
[ -c &amp;quot;$FILE&amp;quot; ] = Special character file&lt;br /&gt;
[ -d &amp;quot;$FILE&amp;quot; ] = If directory exists&lt;br /&gt;
[ -e &amp;quot;$FILE&amp;quot; ] = Check for file existence, regardless of type (node, directory, socket, etc.)&lt;br /&gt;
[ -f &amp;quot;$FILE&amp;quot; ] = Check for regular file existence not a directory&lt;br /&gt;
[ -G &amp;quot;$FILE&amp;quot; ] = Check if file exists and is owned by effective group ID&lt;br /&gt;
[ -G &amp;quot;$FILE&amp;quot; ] = set-group-id - True if file exists and is set-group-id&lt;br /&gt;
[ -k &amp;quot;$FILE&amp;quot; ] = Sticky bit&lt;br /&gt;
[ -L &amp;quot;$FILE&amp;quot; ] = Symbolic link&lt;br /&gt;
[ -O &amp;quot;$FILE&amp;quot; ] = True if file exists and is owned by the effective user id&lt;br /&gt;
[ -r &amp;quot;$FILE&amp;quot; ] = Check if file is a readable&lt;br /&gt;
[ -S &amp;quot;$FILE&amp;quot; ] = Check if file is socket&lt;br /&gt;
[ -s &amp;quot;$FILE&amp;quot; ] = Check if file is nonzero size&lt;br /&gt;
[ -u &amp;quot;$FILE&amp;quot; ] = Check if file set-user-id bit is set&lt;br /&gt;
[ -w &amp;quot;$FILE&amp;quot; ] = Check if file is writable&lt;br /&gt;
[ -x &amp;quot;$FILE&amp;quot; ] = Check if file is executable&lt;br /&gt;
&lt;br /&gt;
FOLDER=/home/javier/&lt;br /&gt;
[ -d &amp;quot;$FOLDER&amp;quot; ]  = If directory exists&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Common syntax ==&lt;br /&gt;
=== for ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Execute a command for all objects within this folder and all subdirectories&lt;br /&gt;
for i in *; do du -h &amp;quot;$i&amp;quot; ; done&lt;br /&gt;
&lt;br /&gt;
# Execute a command x amount of times based on $i&lt;br /&gt;
for((i=1;i&amp;lt;=5;++i)); do dd if=/dev/zero of=myshare/file-$i bs=1M count=1; done&lt;br /&gt;
&lt;br /&gt;
# Shell script version - Execute a command x amount of times based on $i&lt;br /&gt;
for((i=1;i&amp;lt;=5;++i)) do&lt;br /&gt;
echo $i&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== if ===&lt;br /&gt;
==== Examples ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
FILE=~/todo.txt&lt;br /&gt;
if [ -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 cat &amp;quot;~/todo.txt&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
 echo &amp;quot;You don&#039;t have the file, so you should make it.&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
USER=$(whoami)&lt;br /&gt;
FILE=~/todo.txt&lt;br /&gt;
&lt;br /&gt;
if [ &amp;quot;$USER&amp;quot; != &amp;quot;root&amp;quot; -a -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 echo &amp;quot;You&#039;re a normal user, you do have the file and this is its output:&amp;quot;&lt;br /&gt;
 cat &amp;quot;$FILE&amp;quot;&lt;br /&gt;
elif [ &amp;quot;$USER&amp;quot; != &amp;quot;root&amp;quot; -a ! -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 echo &amp;quot;You&#039;re a normal user, you don&#039;t have the file, so you should make it.&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scripts ==&lt;br /&gt;
=== SSH ===&lt;br /&gt;
==== centos-create-user.sh ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# Execute as root&lt;br /&gt;
# Usage: ./centos-create-user.sh USER&lt;br /&gt;
&lt;br /&gt;
USER=&amp;quot;$1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating user ${USER}&amp;quot;&lt;br /&gt;
useradd -m ${USER} -G wheel&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating authorized keys file and settings rights for ${USER} user&amp;quot;&lt;br /&gt;
mkdir -p /home/${USER}/.ssh&lt;br /&gt;
&lt;br /&gt;
cat &amp;lt;&amp;lt; &#039;EOF&#039; &amp;gt;&amp;gt; /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
# PUT ANY KEYS IN HERE&lt;br /&gt;
# KEY-1&lt;br /&gt;
# KEY-2&lt;br /&gt;
# KEY-3&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
chown -R ${USER}:${USER} /home/${USER}/.ssh&lt;br /&gt;
chmod 700 /home/${USER}/.ssh&lt;br /&gt;
chmod 600 /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
# EOF&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ubuntu-create-user.sh ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# Execute as root&lt;br /&gt;
# Usage: ./ubuntu-create-user.sh USER&lt;br /&gt;
&lt;br /&gt;
USER=&amp;quot;$1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating user ${USER}&amp;quot;&lt;br /&gt;
adduser ${USER} --disabled-password&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Adding ${USER} to the sudo group&amp;quot;&lt;br /&gt;
usermod -aG sudo ${USER}&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating authorized keys file and settings rights for ${USER} user&amp;quot;&lt;br /&gt;
mkdir -p /home/${USER}/.ssh&lt;br /&gt;
&lt;br /&gt;
cat &amp;lt;&amp;lt; &#039;EOF&#039; &amp;gt;&amp;gt; /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
# PUT ANY KEYS IN HERE&lt;br /&gt;
# KEY-1&lt;br /&gt;
# KEY-2&lt;br /&gt;
# KEY-3&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
chown -R ${USER}:${USER} /home/${USER}/.ssh&lt;br /&gt;
chmod 700 /home/${USER}/.ssh&lt;br /&gt;
chmod 600 /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
# EOF&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mail ===&lt;br /&gt;
==== Automatic sendmail ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
#requires: date,sendmail&lt;br /&gt;
function fappend {&lt;br /&gt;
    echo &amp;quot;$2&amp;quot;&amp;gt;&amp;gt;$1;&lt;br /&gt;
}&lt;br /&gt;
YYYYMMDD=`date +%Y%m%d`&lt;br /&gt;
&lt;br /&gt;
# CHANGE THESE&lt;br /&gt;
TOEMAIL=&amp;quot;ADMINISTRATOR@MYDOMAIN.COM&amp;quot;;&lt;br /&gt;
FREMAIL=&amp;quot;FROMNOREPLY@MYDOMAIN.com&amp;quot;;&lt;br /&gt;
SUBJECT=&amp;quot;E-mail Subject&amp;quot;;&lt;br /&gt;
MSGBODY=$(Command);&lt;br /&gt;
&lt;br /&gt;
# DON&#039;T CHANGE ANYTHING BELOW&lt;br /&gt;
TMP=`mktemp`&lt;br /&gt;
&lt;br /&gt;
rm -rf $TMP;&lt;br /&gt;
fappend $TMP &amp;quot;From: $FREMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;To: $TOEMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;Reply-To: $FREMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;Subject: $SUBJECT&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;$MSGBODY&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
cat $TMP|/usr/sbin/sendmail -t;&lt;br /&gt;
rm $TMP;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Scripts&amp;diff=872</id>
		<title>Linux:Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Scripts&amp;diff=872"/>
		<updated>2026-01-24T15:17:30Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* Template */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet]]&lt;br /&gt;
&lt;br /&gt;
== Advice ==&lt;br /&gt;
* Lowercase or Camelcase only: all BASH variables are uppercase, so don&#039;t get in their way!&lt;br /&gt;
&lt;br /&gt;
== Template ==&lt;br /&gt;
=== #1 ===&lt;br /&gt;
Script with a single passed variable, description and common exit-protocols.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
#!/usr/bin/env bash&lt;br /&gt;
&lt;br /&gt;
set -o errexit       # Exit on error, do not continue running the script&lt;br /&gt;
set -o nounset       # Trying to access a variable that has not been set generates an error&lt;br /&gt;
set -o pipefail      # When a pipe fails generate an error&lt;br /&gt;
&lt;br /&gt;
if [[ &amp;quot;${1-}&amp;quot; =~ ^-*h(elp)?$ ]] || [[ &amp;quot;$#&amp;quot; -eq 0 ]] ; then&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
    echo &#039;Usage: myscript.sh value1&lt;br /&gt;
&lt;br /&gt;
This is the description of my script.&lt;br /&gt;
&#039;&lt;br /&gt;
    exit&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== #2 ===&lt;br /&gt;
Inspired by: https://stackoverflow.com/questions/16483119/an-example-of-how-to-use-getopts-in-bash&lt;br /&gt;
&lt;br /&gt;
Dedicated usage/help function to catch faulty script usage. This template catches custom flags and save them as variables.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
#!/usr/bin/env bash&lt;br /&gt;
&lt;br /&gt;
set -o errexit       # Exit on error, do not continue running the script&lt;br /&gt;
# We comment this because we explicitly check for variable existence later&lt;br /&gt;
#set -o nounset       # Trying to access a variable that has not been set generates an error&lt;br /&gt;
set -o pipefail      # When a pipe fails generate an error&lt;br /&gt;
&lt;br /&gt;
# Basic help output&lt;br /&gt;
usage () {&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
    echo &amp;quot;Usage: ${0} -s something -o something-else&lt;br /&gt;
Examples:&lt;br /&gt;
${0} -s herp -o derp&lt;br /&gt;
&lt;br /&gt;
This is the description of my script.&lt;br /&gt;
&amp;quot;&lt;br /&gt;
    exit 0&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Catch insufficent arguments and or help parameter, then run the usage function&lt;br /&gt;
if [[ &amp;quot;${1-}&amp;quot; =~ ^-*h(elp)?$ ]] || [[ &amp;quot;$#&amp;quot; -lt 2 ]] ; then&lt;br /&gt;
    usage&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# Create options &amp;quot;s&amp;quot; and &amp;quot;o&amp;quot; and save them as variables &amp;quot;var1&amp;quot; and &amp;quot;var2&amp;quot; respectively&lt;br /&gt;
# Missing or wrong arguments will run the usage function&lt;br /&gt;
while getopts &amp;quot;:s:o:&amp;quot; arg; do&lt;br /&gt;
    case &amp;quot;${arg}&amp;quot; in&lt;br /&gt;
        s) var1=${OPTARG};;&lt;br /&gt;
        o) var2=${OPTARG};;&lt;br /&gt;
        *) usage ;;&lt;br /&gt;
    esac&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
# Remove parsed parameters done by getopts, so that any remaining options can be interpreted as i.e. $1, $2, $3 etc&lt;br /&gt;
shift $((OPTIND-1))&lt;br /&gt;
&lt;br /&gt;
# Check whether the filled arguments are not empty, set -o nounset was commented to make this work properly&lt;br /&gt;
# If the variables aren&#039;t filled, run the usage function&lt;br /&gt;
if [[ -z &amp;quot;${var1}&amp;quot; ]] || [[ -z &amp;quot;${var2}&amp;quot; ]]; then&lt;br /&gt;
    usage&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing - [[]] ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Use the test functionality [[]] to compare values and types, using expressions&lt;br /&gt;
man test&lt;br /&gt;
[[ -d &amp;quot;$MyDirectoryVariable&amp;quot; ]]&lt;br /&gt;
&lt;br /&gt;
# Combine testing with an if statement&lt;br /&gt;
if [[ $(echo &amp;quot;world&amp;quot;) == &amp;quot;world&amp;quot; ]]; then&lt;br /&gt;
    echo -e &amp;quot;all is bad in da world&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
    echo -e &amp;quot;all is good&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
https://stackoverflow.com/questions/638975/how-do-i-tell-if-a-file-does-not-exist-in-bash&lt;br /&gt;
&lt;br /&gt;
FILE=/home/javier/wopper.txt&lt;br /&gt;
[ -b &amp;quot;$FILE&amp;quot; ] = Block special file&lt;br /&gt;
[ -c &amp;quot;$FILE&amp;quot; ] = Special character file&lt;br /&gt;
[ -d &amp;quot;$FILE&amp;quot; ] = If directory exists&lt;br /&gt;
[ -e &amp;quot;$FILE&amp;quot; ] = Check for file existence, regardless of type (node, directory, socket, etc.)&lt;br /&gt;
[ -f &amp;quot;$FILE&amp;quot; ] = Check for regular file existence not a directory&lt;br /&gt;
[ -G &amp;quot;$FILE&amp;quot; ] = Check if file exists and is owned by effective group ID&lt;br /&gt;
[ -G &amp;quot;$FILE&amp;quot; ] = set-group-id - True if file exists and is set-group-id&lt;br /&gt;
[ -k &amp;quot;$FILE&amp;quot; ] = Sticky bit&lt;br /&gt;
[ -L &amp;quot;$FILE&amp;quot; ] = Symbolic link&lt;br /&gt;
[ -O &amp;quot;$FILE&amp;quot; ] = True if file exists and is owned by the effective user id&lt;br /&gt;
[ -r &amp;quot;$FILE&amp;quot; ] = Check if file is a readable&lt;br /&gt;
[ -S &amp;quot;$FILE&amp;quot; ] = Check if file is socket&lt;br /&gt;
[ -s &amp;quot;$FILE&amp;quot; ] = Check if file is nonzero size&lt;br /&gt;
[ -u &amp;quot;$FILE&amp;quot; ] = Check if file set-user-id bit is set&lt;br /&gt;
[ -w &amp;quot;$FILE&amp;quot; ] = Check if file is writable&lt;br /&gt;
[ -x &amp;quot;$FILE&amp;quot; ] = Check if file is executable&lt;br /&gt;
&lt;br /&gt;
FOLDER=/home/javier/&lt;br /&gt;
[ -d &amp;quot;$FOLDER&amp;quot; ]  = If directory exists&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Common syntax ==&lt;br /&gt;
=== for ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Execute a command for all objects within this folder and all subdirectories&lt;br /&gt;
for i in *; do du -h &amp;quot;$i&amp;quot; ; done&lt;br /&gt;
&lt;br /&gt;
# Execute a command x amount of times based on $i&lt;br /&gt;
for((i=1;i&amp;lt;=5;++i)); do dd if=/dev/zero of=myshare/file-$i bs=1M count=1; done&lt;br /&gt;
&lt;br /&gt;
# Shell script version - Execute a command x amount of times based on $i&lt;br /&gt;
for((i=1;i&amp;lt;=5;++i)) do&lt;br /&gt;
echo $i&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== if ===&lt;br /&gt;
==== Examples ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
FILE=~/todo.txt&lt;br /&gt;
if [ -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 cat &amp;quot;~/todo.txt&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
 echo &amp;quot;You don&#039;t have the file, so you should make it.&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
USER=$(whoami)&lt;br /&gt;
FILE=~/todo.txt&lt;br /&gt;
&lt;br /&gt;
if [ &amp;quot;$USER&amp;quot; != &amp;quot;root&amp;quot; -a -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 echo &amp;quot;You&#039;re a normal user, you do have the file and this is its output:&amp;quot;&lt;br /&gt;
 cat &amp;quot;$FILE&amp;quot;&lt;br /&gt;
elif [ &amp;quot;$USER&amp;quot; != &amp;quot;root&amp;quot; -a ! -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 echo &amp;quot;You&#039;re a normal user, you don&#039;t have the file, so you should make it.&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scripts ==&lt;br /&gt;
=== SSH ===&lt;br /&gt;
==== centos-create-user.sh ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# Execute as root&lt;br /&gt;
# Usage: ./centos-create-user.sh USER&lt;br /&gt;
&lt;br /&gt;
USER=&amp;quot;$1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating user ${USER}&amp;quot;&lt;br /&gt;
useradd -m ${USER} -G wheel&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating authorized keys file and settings rights for ${USER} user&amp;quot;&lt;br /&gt;
mkdir -p /home/${USER}/.ssh&lt;br /&gt;
&lt;br /&gt;
cat &amp;lt;&amp;lt; &#039;EOF&#039; &amp;gt;&amp;gt; /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
# PUT ANY KEYS IN HERE&lt;br /&gt;
# KEY-1&lt;br /&gt;
# KEY-2&lt;br /&gt;
# KEY-3&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
chown -R ${USER}:${USER} /home/${USER}/.ssh&lt;br /&gt;
chmod 700 /home/${USER}/.ssh&lt;br /&gt;
chmod 600 /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
# EOF&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ubuntu-create-user.sh ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# Execute as root&lt;br /&gt;
# Usage: ./ubuntu-create-user.sh USER&lt;br /&gt;
&lt;br /&gt;
USER=&amp;quot;$1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating user ${USER}&amp;quot;&lt;br /&gt;
adduser ${USER} --disabled-password&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Adding ${USER} to the sudo group&amp;quot;&lt;br /&gt;
usermod -aG sudo ${USER}&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating authorized keys file and settings rights for ${USER} user&amp;quot;&lt;br /&gt;
mkdir -p /home/${USER}/.ssh&lt;br /&gt;
&lt;br /&gt;
cat &amp;lt;&amp;lt; &#039;EOF&#039; &amp;gt;&amp;gt; /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
# PUT ANY KEYS IN HERE&lt;br /&gt;
# KEY-1&lt;br /&gt;
# KEY-2&lt;br /&gt;
# KEY-3&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
chown -R ${USER}:${USER} /home/${USER}/.ssh&lt;br /&gt;
chmod 700 /home/${USER}/.ssh&lt;br /&gt;
chmod 600 /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
# EOF&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mail ===&lt;br /&gt;
==== Automatic sendmail ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
#requires: date,sendmail&lt;br /&gt;
function fappend {&lt;br /&gt;
    echo &amp;quot;$2&amp;quot;&amp;gt;&amp;gt;$1;&lt;br /&gt;
}&lt;br /&gt;
YYYYMMDD=`date +%Y%m%d`&lt;br /&gt;
&lt;br /&gt;
# CHANGE THESE&lt;br /&gt;
TOEMAIL=&amp;quot;ADMINISTRATOR@MYDOMAIN.COM&amp;quot;;&lt;br /&gt;
FREMAIL=&amp;quot;FROMNOREPLY@MYDOMAIN.com&amp;quot;;&lt;br /&gt;
SUBJECT=&amp;quot;E-mail Subject&amp;quot;;&lt;br /&gt;
MSGBODY=$(Command);&lt;br /&gt;
&lt;br /&gt;
# DON&#039;T CHANGE ANYTHING BELOW&lt;br /&gt;
TMP=`mktemp`&lt;br /&gt;
&lt;br /&gt;
rm -rf $TMP;&lt;br /&gt;
fappend $TMP &amp;quot;From: $FREMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;To: $TOEMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;Reply-To: $FREMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;Subject: $SUBJECT&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;$MSGBODY&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
cat $TMP|/usr/sbin/sendmail -t;&lt;br /&gt;
rm $TMP;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Scripts&amp;diff=871</id>
		<title>Linux:Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Scripts&amp;diff=871"/>
		<updated>2026-01-24T13:56:29Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* Pointers */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet]]&lt;br /&gt;
&lt;br /&gt;
== Advice ==&lt;br /&gt;
* Lowercase or Camelcase only: all BASH variables are uppercase, so don&#039;t get in their way!&lt;br /&gt;
&lt;br /&gt;
== Template ==&lt;br /&gt;
Script with a single passed variable, description and common exit-protocols.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
#!/usr/bin/env bash&lt;br /&gt;
&lt;br /&gt;
set -o errexit       # Exit on error, do not continue running the script&lt;br /&gt;
set -o nounset       # Trying to access a variable that has not been set generates an error&lt;br /&gt;
set -o pipefail      # When a pipe fails generate an error&lt;br /&gt;
&lt;br /&gt;
if [[ &amp;quot;${1-}&amp;quot; =~ ^-*h(elp)?$ ]] || [[ &amp;quot;$#&amp;quot; -eq 0 ]] ; then&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
    echo &#039;Usage: myscript.sh value1&lt;br /&gt;
&lt;br /&gt;
This is the description of my script.&lt;br /&gt;
&#039;&lt;br /&gt;
    exit&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing - [[]] ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Use the test functionality [[]] to compare values and types, using expressions&lt;br /&gt;
man test&lt;br /&gt;
[[ -d &amp;quot;$MyDirectoryVariable&amp;quot; ]]&lt;br /&gt;
&lt;br /&gt;
# Combine testing with an if statement&lt;br /&gt;
if [[ $(echo &amp;quot;world&amp;quot;) == &amp;quot;world&amp;quot; ]]; then&lt;br /&gt;
    echo -e &amp;quot;all is bad in da world&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
    echo -e &amp;quot;all is good&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
https://stackoverflow.com/questions/638975/how-do-i-tell-if-a-file-does-not-exist-in-bash&lt;br /&gt;
&lt;br /&gt;
FILE=/home/javier/wopper.txt&lt;br /&gt;
[ -b &amp;quot;$FILE&amp;quot; ] = Block special file&lt;br /&gt;
[ -c &amp;quot;$FILE&amp;quot; ] = Special character file&lt;br /&gt;
[ -d &amp;quot;$FILE&amp;quot; ] = If directory exists&lt;br /&gt;
[ -e &amp;quot;$FILE&amp;quot; ] = Check for file existence, regardless of type (node, directory, socket, etc.)&lt;br /&gt;
[ -f &amp;quot;$FILE&amp;quot; ] = Check for regular file existence not a directory&lt;br /&gt;
[ -G &amp;quot;$FILE&amp;quot; ] = Check if file exists and is owned by effective group ID&lt;br /&gt;
[ -G &amp;quot;$FILE&amp;quot; ] = set-group-id - True if file exists and is set-group-id&lt;br /&gt;
[ -k &amp;quot;$FILE&amp;quot; ] = Sticky bit&lt;br /&gt;
[ -L &amp;quot;$FILE&amp;quot; ] = Symbolic link&lt;br /&gt;
[ -O &amp;quot;$FILE&amp;quot; ] = True if file exists and is owned by the effective user id&lt;br /&gt;
[ -r &amp;quot;$FILE&amp;quot; ] = Check if file is a readable&lt;br /&gt;
[ -S &amp;quot;$FILE&amp;quot; ] = Check if file is socket&lt;br /&gt;
[ -s &amp;quot;$FILE&amp;quot; ] = Check if file is nonzero size&lt;br /&gt;
[ -u &amp;quot;$FILE&amp;quot; ] = Check if file set-user-id bit is set&lt;br /&gt;
[ -w &amp;quot;$FILE&amp;quot; ] = Check if file is writable&lt;br /&gt;
[ -x &amp;quot;$FILE&amp;quot; ] = Check if file is executable&lt;br /&gt;
&lt;br /&gt;
FOLDER=/home/javier/&lt;br /&gt;
[ -d &amp;quot;$FOLDER&amp;quot; ]  = If directory exists&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Common syntax ==&lt;br /&gt;
=== for ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Execute a command for all objects within this folder and all subdirectories&lt;br /&gt;
for i in *; do du -h &amp;quot;$i&amp;quot; ; done&lt;br /&gt;
&lt;br /&gt;
# Execute a command x amount of times based on $i&lt;br /&gt;
for((i=1;i&amp;lt;=5;++i)); do dd if=/dev/zero of=myshare/file-$i bs=1M count=1; done&lt;br /&gt;
&lt;br /&gt;
# Shell script version - Execute a command x amount of times based on $i&lt;br /&gt;
for((i=1;i&amp;lt;=5;++i)) do&lt;br /&gt;
echo $i&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== if ===&lt;br /&gt;
==== Examples ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
FILE=~/todo.txt&lt;br /&gt;
if [ -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 cat &amp;quot;~/todo.txt&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
 echo &amp;quot;You don&#039;t have the file, so you should make it.&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
USER=$(whoami)&lt;br /&gt;
FILE=~/todo.txt&lt;br /&gt;
&lt;br /&gt;
if [ &amp;quot;$USER&amp;quot; != &amp;quot;root&amp;quot; -a -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 echo &amp;quot;You&#039;re a normal user, you do have the file and this is its output:&amp;quot;&lt;br /&gt;
 cat &amp;quot;$FILE&amp;quot;&lt;br /&gt;
elif [ &amp;quot;$USER&amp;quot; != &amp;quot;root&amp;quot; -a ! -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 echo &amp;quot;You&#039;re a normal user, you don&#039;t have the file, so you should make it.&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scripts ==&lt;br /&gt;
=== SSH ===&lt;br /&gt;
==== centos-create-user.sh ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# Execute as root&lt;br /&gt;
# Usage: ./centos-create-user.sh USER&lt;br /&gt;
&lt;br /&gt;
USER=&amp;quot;$1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating user ${USER}&amp;quot;&lt;br /&gt;
useradd -m ${USER} -G wheel&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating authorized keys file and settings rights for ${USER} user&amp;quot;&lt;br /&gt;
mkdir -p /home/${USER}/.ssh&lt;br /&gt;
&lt;br /&gt;
cat &amp;lt;&amp;lt; &#039;EOF&#039; &amp;gt;&amp;gt; /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
# PUT ANY KEYS IN HERE&lt;br /&gt;
# KEY-1&lt;br /&gt;
# KEY-2&lt;br /&gt;
# KEY-3&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
chown -R ${USER}:${USER} /home/${USER}/.ssh&lt;br /&gt;
chmod 700 /home/${USER}/.ssh&lt;br /&gt;
chmod 600 /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
# EOF&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ubuntu-create-user.sh ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# Execute as root&lt;br /&gt;
# Usage: ./ubuntu-create-user.sh USER&lt;br /&gt;
&lt;br /&gt;
USER=&amp;quot;$1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating user ${USER}&amp;quot;&lt;br /&gt;
adduser ${USER} --disabled-password&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Adding ${USER} to the sudo group&amp;quot;&lt;br /&gt;
usermod -aG sudo ${USER}&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating authorized keys file and settings rights for ${USER} user&amp;quot;&lt;br /&gt;
mkdir -p /home/${USER}/.ssh&lt;br /&gt;
&lt;br /&gt;
cat &amp;lt;&amp;lt; &#039;EOF&#039; &amp;gt;&amp;gt; /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
# PUT ANY KEYS IN HERE&lt;br /&gt;
# KEY-1&lt;br /&gt;
# KEY-2&lt;br /&gt;
# KEY-3&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
chown -R ${USER}:${USER} /home/${USER}/.ssh&lt;br /&gt;
chmod 700 /home/${USER}/.ssh&lt;br /&gt;
chmod 600 /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
# EOF&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mail ===&lt;br /&gt;
==== Automatic sendmail ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
#requires: date,sendmail&lt;br /&gt;
function fappend {&lt;br /&gt;
    echo &amp;quot;$2&amp;quot;&amp;gt;&amp;gt;$1;&lt;br /&gt;
}&lt;br /&gt;
YYYYMMDD=`date +%Y%m%d`&lt;br /&gt;
&lt;br /&gt;
# CHANGE THESE&lt;br /&gt;
TOEMAIL=&amp;quot;ADMINISTRATOR@MYDOMAIN.COM&amp;quot;;&lt;br /&gt;
FREMAIL=&amp;quot;FROMNOREPLY@MYDOMAIN.com&amp;quot;;&lt;br /&gt;
SUBJECT=&amp;quot;E-mail Subject&amp;quot;;&lt;br /&gt;
MSGBODY=$(Command);&lt;br /&gt;
&lt;br /&gt;
# DON&#039;T CHANGE ANYTHING BELOW&lt;br /&gt;
TMP=`mktemp`&lt;br /&gt;
&lt;br /&gt;
rm -rf $TMP;&lt;br /&gt;
fappend $TMP &amp;quot;From: $FREMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;To: $TOEMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;Reply-To: $FREMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;Subject: $SUBJECT&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;$MSGBODY&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
cat $TMP|/usr/sbin/sendmail -t;&lt;br /&gt;
rm $TMP;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Fortinet&amp;diff=870</id>
		<title>Fortinet</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Fortinet&amp;diff=870"/>
		<updated>2026-01-24T13:55:50Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* Syslog */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet|Cheatsheets]]&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
* https://docs.fortinet.com/product/fortigate/6.4&lt;br /&gt;
* https://docs.fortinet.com/document/fortigate/6.4.7/administration-guide/954635/getting-started&lt;br /&gt;
* https://docs.fortinet.com/document/fortigate/6.0.0/cli-reference/830108/ping-options-ping6-options&lt;br /&gt;
&lt;br /&gt;
== CLI Configuration ==&lt;br /&gt;
&#039;&#039;&#039;Don&#039;t forget to enter the proper vDOM when applicable&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== DHCP server ===&lt;br /&gt;
&#039;&#039;&#039;edit 0&#039;&#039;&#039; will cause the first available ID to be assigned to this range.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
config system dhcp server&lt;br /&gt;
    edit 0&lt;br /&gt;
        set lease-time 86400&lt;br /&gt;
        set default-gateway 192.168.20.1&lt;br /&gt;
        set netmask 255.255.255.0&lt;br /&gt;
        set interface &amp;quot;VDOM-LAN01&amp;quot;&lt;br /&gt;
        config ip-range&lt;br /&gt;
            edit 1&lt;br /&gt;
                set start-ip 192.168.20.10&lt;br /&gt;
                set end-ip 192.168.20.254&lt;br /&gt;
            next&lt;br /&gt;
        end&lt;br /&gt;
        set dns-server1 192.168.20.2&lt;br /&gt;
        set dns-server2 8.8.8.8&lt;br /&gt;
    next&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Checks ==&lt;br /&gt;
=== Common ===&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# Ping IP 8.8.8.8&lt;br /&gt;
execute ping 8.8.8.8&lt;br /&gt;
&lt;br /&gt;
# Ping from a specific interface IP&lt;br /&gt;
execute ping-options source 10.0.25.1&lt;br /&gt;
&lt;br /&gt;
# Ping for a certain amount of times&lt;br /&gt;
execute ping-options repeat-count&lt;br /&gt;
&lt;br /&gt;
# Traceroute to IP 1.1.1.1&lt;br /&gt;
execute traceroute 1.1.1.1&lt;br /&gt;
&lt;br /&gt;
# List all available interfaces&lt;br /&gt;
diagnose netlink interface list&lt;br /&gt;
&lt;br /&gt;
# Show detailed interface statistics&lt;br /&gt;
diagnose netlink interface list name &amp;lt;INTERFACE&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== VPN ===&lt;br /&gt;
* https://docs.fortinet.com/document/fortigate/5.4.0/cookbook/168495/ipsec-vpn-troubleshooting&lt;br /&gt;
* https://www.fortinetguru.com/2017/10/ipsec-phase-2-parameters/&lt;br /&gt;
* https://docs.fortinet.com/document/fortigate/6.2.11/cookbook/031670/ikev2-ipsec-site-to-site-vpn-to-an-aws-vpn-gateway&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# Show phase 1 configuration for a specific interface.&lt;br /&gt;
show vpn ipsec phase1-interface &amp;lt;PHASE1NAME&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Ping for a certain amount&lt;br /&gt;
show vpn ipsec phase2-interface &amp;lt;PHASE2NAME&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Show summary of VPN tunnel when within a vDom&lt;br /&gt;
get vpn ipsec tunnel summary&lt;br /&gt;
&lt;br /&gt;
# Show detailed phase 1 information of a VPN.&lt;br /&gt;
diagnose vpn ike gateway list name &amp;lt;Phase1name&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# Enable VPN phase-1 debug mode and display logs in the console&lt;br /&gt;
diagnose vpn ike log filter name &amp;lt;phase1-name&amp;gt; &lt;br /&gt;
diagnose debug app ike -1&lt;br /&gt;
diagnose debug enable&lt;br /&gt;
&lt;br /&gt;
# Disable debug mode&lt;br /&gt;
diagnose debug disable&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Syslog ===&lt;br /&gt;
&amp;lt;section begin=&amp;quot;fortinetsyslog&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# Test logging capability&lt;br /&gt;
diag log test&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Custom UDP Configuration ====&lt;br /&gt;
Example has Syslog traffic going over a VPN-interface and an IP-address specified that&#039;s allowed to travel over it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
config log syslogd setting&lt;br /&gt;
    set status enable&lt;br /&gt;
    set server &amp;quot;192.168.77.88&amp;quot;&lt;br /&gt;
    set port 1514&lt;br /&gt;
    set source-ip &amp;quot;192.168.77.1&amp;quot;&lt;br /&gt;
    set interface-select-method specify&lt;br /&gt;
    set interface &amp;quot;My_VPN_interface&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== TCP Configuration ====&lt;br /&gt;
The set mode command support multiple RFC-compliant Syslog message structures.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
config log syslogd setting&lt;br /&gt;
    set status enable&lt;br /&gt;
    set server &amp;quot;logger.brammerloo.nl&amp;quot;&lt;br /&gt;
    set mode reliable&lt;br /&gt;
    set port 1515&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section end=&amp;quot;fortinetsyslog&amp;quot;/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Fortinet&amp;diff=869</id>
		<title>Fortinet</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Fortinet&amp;diff=869"/>
		<updated>2026-01-24T13:51:31Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* Syslog */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet|Cheatsheets]]&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
* https://docs.fortinet.com/product/fortigate/6.4&lt;br /&gt;
* https://docs.fortinet.com/document/fortigate/6.4.7/administration-guide/954635/getting-started&lt;br /&gt;
* https://docs.fortinet.com/document/fortigate/6.0.0/cli-reference/830108/ping-options-ping6-options&lt;br /&gt;
&lt;br /&gt;
== CLI Configuration ==&lt;br /&gt;
&#039;&#039;&#039;Don&#039;t forget to enter the proper vDOM when applicable&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== DHCP server ===&lt;br /&gt;
&#039;&#039;&#039;edit 0&#039;&#039;&#039; will cause the first available ID to be assigned to this range.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
config system dhcp server&lt;br /&gt;
    edit 0&lt;br /&gt;
        set lease-time 86400&lt;br /&gt;
        set default-gateway 192.168.20.1&lt;br /&gt;
        set netmask 255.255.255.0&lt;br /&gt;
        set interface &amp;quot;VDOM-LAN01&amp;quot;&lt;br /&gt;
        config ip-range&lt;br /&gt;
            edit 1&lt;br /&gt;
                set start-ip 192.168.20.10&lt;br /&gt;
                set end-ip 192.168.20.254&lt;br /&gt;
            next&lt;br /&gt;
        end&lt;br /&gt;
        set dns-server1 192.168.20.2&lt;br /&gt;
        set dns-server2 8.8.8.8&lt;br /&gt;
    next&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Checks ==&lt;br /&gt;
=== Common ===&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# Ping IP 8.8.8.8&lt;br /&gt;
execute ping 8.8.8.8&lt;br /&gt;
&lt;br /&gt;
# Ping from a specific interface IP&lt;br /&gt;
execute ping-options source 10.0.25.1&lt;br /&gt;
&lt;br /&gt;
# Ping for a certain amount of times&lt;br /&gt;
execute ping-options repeat-count&lt;br /&gt;
&lt;br /&gt;
# Traceroute to IP 1.1.1.1&lt;br /&gt;
execute traceroute 1.1.1.1&lt;br /&gt;
&lt;br /&gt;
# List all available interfaces&lt;br /&gt;
diagnose netlink interface list&lt;br /&gt;
&lt;br /&gt;
# Show detailed interface statistics&lt;br /&gt;
diagnose netlink interface list name &amp;lt;INTERFACE&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== VPN ===&lt;br /&gt;
* https://docs.fortinet.com/document/fortigate/5.4.0/cookbook/168495/ipsec-vpn-troubleshooting&lt;br /&gt;
* https://www.fortinetguru.com/2017/10/ipsec-phase-2-parameters/&lt;br /&gt;
* https://docs.fortinet.com/document/fortigate/6.2.11/cookbook/031670/ikev2-ipsec-site-to-site-vpn-to-an-aws-vpn-gateway&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# Show phase 1 configuration for a specific interface.&lt;br /&gt;
show vpn ipsec phase1-interface &amp;lt;PHASE1NAME&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Ping for a certain amount&lt;br /&gt;
show vpn ipsec phase2-interface &amp;lt;PHASE2NAME&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Show summary of VPN tunnel when within a vDom&lt;br /&gt;
get vpn ipsec tunnel summary&lt;br /&gt;
&lt;br /&gt;
# Show detailed phase 1 information of a VPN.&lt;br /&gt;
diagnose vpn ike gateway list name &amp;lt;Phase1name&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# Enable VPN phase-1 debug mode and display logs in the console&lt;br /&gt;
diagnose vpn ike log filter name &amp;lt;phase1-name&amp;gt; &lt;br /&gt;
diagnose debug app ike -1&lt;br /&gt;
diagnose debug enable&lt;br /&gt;
&lt;br /&gt;
# Disable debug mode&lt;br /&gt;
diagnose debug disable&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Syslog ===&lt;br /&gt;
&amp;lt;section begin=&amp;quot;fortinetsyslog&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# Test logging capability&lt;br /&gt;
diag log test&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Custom UDP Configuration ====&lt;br /&gt;
Example has Syslog traffic going over a VPN-interface and an IP-address specified that&#039;s allowed to travel over it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
config log syslogd setting&lt;br /&gt;
    set status enable&lt;br /&gt;
    set server &amp;quot;192.168.77.88&amp;quot;&lt;br /&gt;
	set port 1514&lt;br /&gt;
    set source-ip &amp;quot;192.168.77.1&amp;quot;&lt;br /&gt;
    set interface-select-method specify&lt;br /&gt;
    set interface &amp;quot;My_VPN_interface&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== TCP Configuration ====&lt;br /&gt;
The set mode command support multiple RFC-compliant Syslog message structures.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
config log syslogd setting&lt;br /&gt;
    set status enable&lt;br /&gt;
    set server &amp;quot;logger.brammerloo.nl&amp;quot;&lt;br /&gt;
    set mode reliable&lt;br /&gt;
    set port 1515&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section end=&amp;quot;fortinetsyslog&amp;quot;/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Network&amp;diff=868</id>
		<title>Linux:Network</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Network&amp;diff=868"/>
		<updated>2026-01-23T16:08:42Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* Routes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet]]&lt;br /&gt;
&lt;br /&gt;
* https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers&lt;br /&gt;
&lt;br /&gt;
== Checks ==&lt;br /&gt;
=== Common ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List route table&lt;br /&gt;
route -n&lt;br /&gt;
&lt;br /&gt;
# Display network connections and current states&lt;br /&gt;
netstat&lt;br /&gt;
&lt;br /&gt;
# Check listening ports, connected remote IPs, processes, states and more&lt;br /&gt;
netstat -taupen&lt;br /&gt;
&lt;br /&gt;
# Check listening ports and IPs of the local server&lt;br /&gt;
netstat -tulpn&lt;br /&gt;
&lt;br /&gt;
# List the routing table&lt;br /&gt;
netstat -r&lt;br /&gt;
&lt;br /&gt;
# List verbose common TCP and ICMP information&lt;br /&gt;
netstat -s&lt;br /&gt;
&lt;br /&gt;
# List iptable rules (Nftables)&lt;br /&gt;
iptables -nvL&lt;br /&gt;
&lt;br /&gt;
# List iptable rules (Legacy iptables)&lt;br /&gt;
iptables-legacy -nvL&lt;br /&gt;
&lt;br /&gt;
# Test specific IP and port combination for connectivity&lt;br /&gt;
telnet 172.16.2.1 22&lt;br /&gt;
&lt;br /&gt;
# Wireshark on a specific interface to a file, listening on a local port and for a remote IP&lt;br /&gt;
tshark -p -i bond0 -w file.pcap -f &amp;quot;port 443 and host 172.16.16.25&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# List available routers&lt;br /&gt;
ip netns&lt;br /&gt;
&lt;br /&gt;
# Show interfaces with an IPv4 address&lt;br /&gt;
ip -4 a&lt;br /&gt;
&lt;br /&gt;
# Show interfaces with an IPv6 address&lt;br /&gt;
ip -6 a&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== nmcli ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Show all active network connections&lt;br /&gt;
nmcli connection show&lt;br /&gt;
&lt;br /&gt;
# Show connection information for interface ens5&lt;br /&gt;
nmcli connection show ens5&lt;br /&gt;
&lt;br /&gt;
# Show active and unactive network connections&lt;br /&gt;
nmcli dev status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Common configuration ==&lt;br /&gt;
=== Routing ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Add a route for 192.168.7.0/24 via a specific IP and interface&lt;br /&gt;
ip route add 192.168.7.0/24 via 192.168.7.199 dev eth0&lt;br /&gt;
&lt;br /&gt;
# Delete the route we added previously&lt;br /&gt;
ip route del 192.168.7.0/24 via 192.168.7.199 dev eth0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== nmcli ===&lt;br /&gt;
&#039;&#039;&#039;nmtui&#039;&#039;&#039; is a GUI-tool for managing NetworkManager connections.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Bring logical interface ens6 up&lt;br /&gt;
nmcli device up ens6&lt;br /&gt;
&lt;br /&gt;
# Turn off DHCP&lt;br /&gt;
nmcli con mod ens6 ipv4.method manual&lt;br /&gt;
nmcli con mod ens6 connection.autoconnect yes&lt;br /&gt;
&lt;br /&gt;
# Add an IP-address to interface ens6&lt;br /&gt;
nmcli connection modify ens6 ipv4.address &amp;quot;192.168.0.10/24&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Add DNS-servers to interface ens6&lt;br /&gt;
nmcli connection modify ens6 ipv4.dns &amp;quot;8.8.8.8,1.1.1.1,196.168.0.1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Add a gateway to interface ens6&lt;br /&gt;
nmcli con mod ens6 ipv4.gateway &amp;quot;192.168.0.1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Add a default route to interface ens160&lt;br /&gt;
nmcli connection modify ens160 +ipv4.routes &amp;quot;0.0.0.0/0 192.168.3.100&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Remove an IP-address from interface ens6&lt;br /&gt;
nmcli con mod ens6 -ipv4.addresses 192.168.0.11/24&lt;br /&gt;
&lt;br /&gt;
# Apply changes to interface ens&lt;br /&gt;
nmcli device reapply ens6&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Network ==&lt;br /&gt;
=== RHEL ===&lt;br /&gt;
==== Generic Interface ====&lt;br /&gt;
&amp;lt;code&amp;gt; BOOTPROTO=static &amp;lt;/code&amp;gt; for static address &amp;lt;/br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; BOOTPROTO=dhcp &amp;lt;/code&amp;gt; for DHCP&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# /etc/sysconfig/network-scripts/ifcfg-ens128&lt;br /&gt;
DEVICE=ens128&lt;br /&gt;
NAME=ens128&lt;br /&gt;
HWADDR=ab:cd:ef:gh:ij:kl&lt;br /&gt;
UUID=0a8d3485-d512-46da-8225-19f4721813c1&lt;br /&gt;
BOOTPROTO=static&lt;br /&gt;
STARTMODE=auto&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
IPADDR=192.168.10.2&lt;br /&gt;
NETMASK=255.255.255.0&lt;br /&gt;
GATEWAY=192.168.10.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Generic VLAN Interface ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# /etc/sysconfig/network-scripts/ifcfg-eno2.100&lt;br /&gt;
VLAN=yes&lt;br /&gt;
TYPE=Vlan&lt;br /&gt;
PHYSDEV=eno2&lt;br /&gt;
VLAN_ID=100&lt;br /&gt;
NAME=eno2.100&lt;br /&gt;
BOOTPROTO=static&lt;br /&gt;
HWADDR=ab:cd:ef:gh:ij:kl&lt;br /&gt;
IPADDR=192.168.100.217&lt;br /&gt;
NETMASK=255.255.255.0&lt;br /&gt;
STARTMODE=auto&lt;br /&gt;
UUID=689cff6f-c750-4db7-936c-234fb80b6018&lt;br /&gt;
GATEWAY=192.168.100.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== VLAN Bond interface configuration ====&lt;br /&gt;
===== Virtual Bond Master =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
BONDING_OPTS=&amp;quot;mode=802.3ad miimon=100&amp;quot;&lt;br /&gt;
TYPE=Bond&lt;br /&gt;
BONDING_MASTER=yes&lt;br /&gt;
PROXY_METHOD=none&lt;br /&gt;
BROWSER_ONLY=no&lt;br /&gt;
IPV6INIT=no&lt;br /&gt;
NAME=bond0&lt;br /&gt;
UUID=7bb91614-6ffe-4bdc-9b37-c6e9d37f6987&lt;br /&gt;
DEVICE=bond0&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
AUTOCONNECT_PRIORITY=9&lt;br /&gt;
AUTOCONNECT_RETRIES=0&lt;br /&gt;
AUTOCONNECT_SLAVES=yes&lt;br /&gt;
MTU=1500&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Physical bond Slaves =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# /etc/sysconfig/network-scripts/ifcfg-ens1&lt;br /&gt;
TYPE=Ethernet&lt;br /&gt;
NAME=ens1&lt;br /&gt;
UUID=c6a4da43-b84a-44f4-b49f-4bdc717d4238&lt;br /&gt;
DEVICE=ens1&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
AUTOCONNECT_PRIORITY=9&lt;br /&gt;
AUTOCONNECT_RETRIES=0&lt;br /&gt;
MASTER_UUID=7bb91614-6ffe-4bdc-9b37-c6e9d37f6987&lt;br /&gt;
MASTER=bond0&lt;br /&gt;
SLAVE=yes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# /etc/sysconfig/network-scripts/ifcfg-ens2&lt;br /&gt;
TYPE=Ethernet&lt;br /&gt;
NAME=ens2&lt;br /&gt;
UUID=ca09a126-a082-4620-a920-be45269e5d8a&lt;br /&gt;
DEVICE=ens2&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
AUTOCONNECT_PRIORITY=9&lt;br /&gt;
AUTOCONNECT_RETRIES=0&lt;br /&gt;
MASTER_UUID=7bb91614-6ffe-4bdc-9b37-c6e9d37f6987&lt;br /&gt;
MASTER=bond0&lt;br /&gt;
SLAVE=yes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== VLAN 100 Interface =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# /etc/sysconfig/network-scripts/ifcfg-vlan-bond0.100&lt;br /&gt;
VLAN=yes&lt;br /&gt;
TYPE=Vlan&lt;br /&gt;
PHYSDEV=bond0&lt;br /&gt;
VLAN_ID=100&lt;br /&gt;
REORDER_HDR=yes&lt;br /&gt;
GVRP=no&lt;br /&gt;
MVRP=no&lt;br /&gt;
HWADDR=&lt;br /&gt;
PROXY_METHOD=none&lt;br /&gt;
BROWSER_ONLY=no&lt;br /&gt;
BOOTPROTO=none&lt;br /&gt;
IPADDR=192.168.100.10&lt;br /&gt;
PREFIX=24&lt;br /&gt;
DEFROUTE=yes&lt;br /&gt;
IPV4_FAILURE_FATAL=no&lt;br /&gt;
NAME=vlan-bond0.100&lt;br /&gt;
UUID=83b0e31c-9a9f-47da-9dc6-645796bc47aa&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
AUTOCONNECT_PRIORITY=9&lt;br /&gt;
AUTOCONNECT_RETRIES=0&lt;br /&gt;
GATEWAY=192.168.100.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Ubuntu/Debian ===&lt;br /&gt;
==== Netplan ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Apply the configuration, but if the dialogue is left unconfirmed, the configuration will be reverted.&lt;br /&gt;
netplan try&lt;br /&gt;
&lt;br /&gt;
# Apply the configuration&lt;br /&gt;
netplan apply&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Generic DCHP interface =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;yaml&#039;&amp;gt;&lt;br /&gt;
network:&lt;br /&gt;
    version: 2&lt;br /&gt;
    ethernets:&lt;br /&gt;
        ens4:&lt;br /&gt;
            # Some info about the Interface/why does it exist&lt;br /&gt;
            dhcp4: true&lt;br /&gt;
            match:&lt;br /&gt;
                macaddress: fa:16:3e:aa:bb:cc&lt;br /&gt;
            set-name: ens4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Generic DHCP Interfaces, but while ignoring the routes for an Interface and disabling DHCP on the other.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;yaml&#039;&amp;gt;&lt;br /&gt;
network:&lt;br /&gt;
    version: 2&lt;br /&gt;
    ethernets:&lt;br /&gt;
        ens4:&lt;br /&gt;
            # Some info about the Interface/why does it exist&lt;br /&gt;
            dhcp4: true&lt;br /&gt;
            dhcp4-overrides:&lt;br /&gt;
              use-routes: false&lt;br /&gt;
            match:&lt;br /&gt;
                macaddress: fa:16:3e:aa:bb:cc&lt;br /&gt;
            set-name: ens4&lt;br /&gt;
        ens5:&lt;br /&gt;
            # Some info about the Interface/why does it exist&lt;br /&gt;
            dhcp4: no&lt;br /&gt;
            match:&lt;br /&gt;
                macaddress: fa:16:cc:dd:ee&lt;br /&gt;
            set-name: ens5&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Generic static interface =====&lt;br /&gt;
You may have to disable automatic network-configuration:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;yaml&#039;&amp;gt;&lt;br /&gt;
sudo bash -c &#039;echo &amp;quot;network: {config: disabled}&amp;quot; &amp;gt; /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;yaml&#039;&amp;gt;&lt;br /&gt;
network:&lt;br /&gt;
    version: 2&lt;br /&gt;
    ethernets:&lt;br /&gt;
        ens7:&lt;br /&gt;
           addresses:&lt;br /&gt;
              - 192.168.0.23/24&lt;br /&gt;
           match:&lt;br /&gt;
               macaddress: ab:cd:ef:gh:ij:kl&lt;br /&gt;
           mtu: 1500&lt;br /&gt;
           set-name: ens7&lt;br /&gt;
           nameservers:&lt;br /&gt;
               addresses: [1.1.1.1, 8.8.8.8]&lt;br /&gt;
           routes:&lt;br /&gt;
              - to: default&lt;br /&gt;
                via: 192.168.0.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== VLAN Interface =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;yaml&#039;&amp;gt;&lt;br /&gt;
network:&lt;br /&gt;
    version: 2&lt;br /&gt;
    ethernets:&lt;br /&gt;
        eno1: {}&lt;br /&gt;
    vlans:&lt;br /&gt;
        eno1.10:&lt;br /&gt;
            id: 10&lt;br /&gt;
            link: eno1&lt;br /&gt;
            addresses: [192.168.1.1/24]&lt;br /&gt;
        eno1.20:&lt;br /&gt;
            id: 20&lt;br /&gt;
            link: eno1&lt;br /&gt;
            addresses: [192.168.2.1/24]&lt;br /&gt;
            nameservers:&lt;br /&gt;
              addresses:&lt;br /&gt;
                - 1.1.1.1&lt;br /&gt;
                - 8.8.8.8&lt;br /&gt;
              search: []&lt;br /&gt;
            routes:&lt;br /&gt;
              - to: default&lt;br /&gt;
                via: 192.168.2.1&lt;br /&gt;
        eno1.30:&lt;br /&gt;
            id: 30&lt;br /&gt;
            link: eno1&lt;br /&gt;
            addresses: [192.168.3.1/24]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Empty Interface =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;yaml&#039;&amp;gt;&lt;br /&gt;
network:&lt;br /&gt;
  version: 2&lt;br /&gt;
  ethernets:&lt;br /&gt;
    eno2:&lt;br /&gt;
      dhcp4: false&lt;br /&gt;
      dhcp6: false&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Interface files ====&lt;br /&gt;
Classic &amp;lt;code&amp;gt;/etc/network/interfaces.d&amp;lt;/code&amp;gt; files i.e. &amp;lt;code&amp;gt; /etc/network/interfaces.d/ens200.conf &amp;lt;/code&amp;gt;&lt;br /&gt;
Otherwise use &amp;lt;code&amp;gt;/etc/network/interfaces &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Generic IPv4 =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# /etc/network/interfaces.d/ens160.conf&lt;br /&gt;
auto ens160&lt;br /&gt;
iface ens160 inet static&lt;br /&gt;
    address 192.168.23.7&lt;br /&gt;
    netmask 255.255.255.0&lt;br /&gt;
    gateway 192.168.23.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Generic IPv6 =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# /etc/network/interfaces.d/ens3.conf&lt;br /&gt;
iface ens3 inet6 static&lt;br /&gt;
    address abcd:defg:0:1234:5123:abcd:abcd:1234&lt;br /&gt;
    netmask 48&lt;br /&gt;
    gateway abcd:defg::1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Bond =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
auto eno1&lt;br /&gt;
iface eno1 inet manual&lt;br /&gt;
&lt;br /&gt;
auto eno2&lt;br /&gt;
iface eno2 inet manual&lt;br /&gt;
&lt;br /&gt;
auto bond0&lt;br /&gt;
iface bond0 inet static&lt;br /&gt;
        address 192.168.39.245&lt;br /&gt;
        gateway 192.168.39.254&lt;br /&gt;
        network 255.255.255.0&lt;br /&gt;
        bond-slaves eno1 eno2&lt;br /&gt;
        bond-miimon 100&lt;br /&gt;
        bond-mode 802.3ad&lt;br /&gt;
        bond-xmit-hash-policy layer2+3&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Network&amp;diff=867</id>
		<title>Linux:Network</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Network&amp;diff=867"/>
		<updated>2026-01-23T16:08:35Z</updated>

		<summary type="html">&lt;p&gt;Patrick: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet]]&lt;br /&gt;
&lt;br /&gt;
* https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers&lt;br /&gt;
&lt;br /&gt;
== Checks ==&lt;br /&gt;
=== Common ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List route table&lt;br /&gt;
route -n&lt;br /&gt;
&lt;br /&gt;
# Display network connections and current states&lt;br /&gt;
netstat&lt;br /&gt;
&lt;br /&gt;
# Check listening ports, connected remote IPs, processes, states and more&lt;br /&gt;
netstat -taupen&lt;br /&gt;
&lt;br /&gt;
# Check listening ports and IPs of the local server&lt;br /&gt;
netstat -tulpn&lt;br /&gt;
&lt;br /&gt;
# List the routing table&lt;br /&gt;
netstat -r&lt;br /&gt;
&lt;br /&gt;
# List verbose common TCP and ICMP information&lt;br /&gt;
netstat -s&lt;br /&gt;
&lt;br /&gt;
# List iptable rules (Nftables)&lt;br /&gt;
iptables -nvL&lt;br /&gt;
&lt;br /&gt;
# List iptable rules (Legacy iptables)&lt;br /&gt;
iptables-legacy -nvL&lt;br /&gt;
&lt;br /&gt;
# Test specific IP and port combination for connectivity&lt;br /&gt;
telnet 172.16.2.1 22&lt;br /&gt;
&lt;br /&gt;
# Wireshark on a specific interface to a file, listening on a local port and for a remote IP&lt;br /&gt;
tshark -p -i bond0 -w file.pcap -f &amp;quot;port 443 and host 172.16.16.25&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# List available routers&lt;br /&gt;
ip netns&lt;br /&gt;
&lt;br /&gt;
# Show interfaces with an IPv4 address&lt;br /&gt;
ip -4 a&lt;br /&gt;
&lt;br /&gt;
# Show interfaces with an IPv6 address&lt;br /&gt;
ip -6 a&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== nmcli ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Show all active network connections&lt;br /&gt;
nmcli connection show&lt;br /&gt;
&lt;br /&gt;
# Show connection information for interface ens5&lt;br /&gt;
nmcli connection show ens5&lt;br /&gt;
&lt;br /&gt;
# Show active and unactive network connections&lt;br /&gt;
nmcli dev status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Common configuration ==&lt;br /&gt;
=== Routes ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Add a route for 192.168.7.0/24 via a specific IP and interface&lt;br /&gt;
ip route add 192.168.7.0/24 via 192.168.7.199 dev eth0&lt;br /&gt;
&lt;br /&gt;
# Delete the route we added previously&lt;br /&gt;
ip route del 192.168.7.0/24 via 192.168.7.199 dev eth0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== nmcli ===&lt;br /&gt;
&#039;&#039;&#039;nmtui&#039;&#039;&#039; is a GUI-tool for managing NetworkManager connections.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Bring logical interface ens6 up&lt;br /&gt;
nmcli device up ens6&lt;br /&gt;
&lt;br /&gt;
# Turn off DHCP&lt;br /&gt;
nmcli con mod ens6 ipv4.method manual&lt;br /&gt;
nmcli con mod ens6 connection.autoconnect yes&lt;br /&gt;
&lt;br /&gt;
# Add an IP-address to interface ens6&lt;br /&gt;
nmcli connection modify ens6 ipv4.address &amp;quot;192.168.0.10/24&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Add DNS-servers to interface ens6&lt;br /&gt;
nmcli connection modify ens6 ipv4.dns &amp;quot;8.8.8.8,1.1.1.1,196.168.0.1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Add a gateway to interface ens6&lt;br /&gt;
nmcli con mod ens6 ipv4.gateway &amp;quot;192.168.0.1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Add a default route to interface ens160&lt;br /&gt;
nmcli connection modify ens160 +ipv4.routes &amp;quot;0.0.0.0/0 192.168.3.100&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Remove an IP-address from interface ens6&lt;br /&gt;
nmcli con mod ens6 -ipv4.addresses 192.168.0.11/24&lt;br /&gt;
&lt;br /&gt;
# Apply changes to interface ens&lt;br /&gt;
nmcli device reapply ens6&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Network ==&lt;br /&gt;
=== RHEL ===&lt;br /&gt;
==== Generic Interface ====&lt;br /&gt;
&amp;lt;code&amp;gt; BOOTPROTO=static &amp;lt;/code&amp;gt; for static address &amp;lt;/br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; BOOTPROTO=dhcp &amp;lt;/code&amp;gt; for DHCP&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# /etc/sysconfig/network-scripts/ifcfg-ens128&lt;br /&gt;
DEVICE=ens128&lt;br /&gt;
NAME=ens128&lt;br /&gt;
HWADDR=ab:cd:ef:gh:ij:kl&lt;br /&gt;
UUID=0a8d3485-d512-46da-8225-19f4721813c1&lt;br /&gt;
BOOTPROTO=static&lt;br /&gt;
STARTMODE=auto&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
IPADDR=192.168.10.2&lt;br /&gt;
NETMASK=255.255.255.0&lt;br /&gt;
GATEWAY=192.168.10.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Generic VLAN Interface ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# /etc/sysconfig/network-scripts/ifcfg-eno2.100&lt;br /&gt;
VLAN=yes&lt;br /&gt;
TYPE=Vlan&lt;br /&gt;
PHYSDEV=eno2&lt;br /&gt;
VLAN_ID=100&lt;br /&gt;
NAME=eno2.100&lt;br /&gt;
BOOTPROTO=static&lt;br /&gt;
HWADDR=ab:cd:ef:gh:ij:kl&lt;br /&gt;
IPADDR=192.168.100.217&lt;br /&gt;
NETMASK=255.255.255.0&lt;br /&gt;
STARTMODE=auto&lt;br /&gt;
UUID=689cff6f-c750-4db7-936c-234fb80b6018&lt;br /&gt;
GATEWAY=192.168.100.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== VLAN Bond interface configuration ====&lt;br /&gt;
===== Virtual Bond Master =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
BONDING_OPTS=&amp;quot;mode=802.3ad miimon=100&amp;quot;&lt;br /&gt;
TYPE=Bond&lt;br /&gt;
BONDING_MASTER=yes&lt;br /&gt;
PROXY_METHOD=none&lt;br /&gt;
BROWSER_ONLY=no&lt;br /&gt;
IPV6INIT=no&lt;br /&gt;
NAME=bond0&lt;br /&gt;
UUID=7bb91614-6ffe-4bdc-9b37-c6e9d37f6987&lt;br /&gt;
DEVICE=bond0&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
AUTOCONNECT_PRIORITY=9&lt;br /&gt;
AUTOCONNECT_RETRIES=0&lt;br /&gt;
AUTOCONNECT_SLAVES=yes&lt;br /&gt;
MTU=1500&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Physical bond Slaves =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# /etc/sysconfig/network-scripts/ifcfg-ens1&lt;br /&gt;
TYPE=Ethernet&lt;br /&gt;
NAME=ens1&lt;br /&gt;
UUID=c6a4da43-b84a-44f4-b49f-4bdc717d4238&lt;br /&gt;
DEVICE=ens1&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
AUTOCONNECT_PRIORITY=9&lt;br /&gt;
AUTOCONNECT_RETRIES=0&lt;br /&gt;
MASTER_UUID=7bb91614-6ffe-4bdc-9b37-c6e9d37f6987&lt;br /&gt;
MASTER=bond0&lt;br /&gt;
SLAVE=yes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# /etc/sysconfig/network-scripts/ifcfg-ens2&lt;br /&gt;
TYPE=Ethernet&lt;br /&gt;
NAME=ens2&lt;br /&gt;
UUID=ca09a126-a082-4620-a920-be45269e5d8a&lt;br /&gt;
DEVICE=ens2&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
AUTOCONNECT_PRIORITY=9&lt;br /&gt;
AUTOCONNECT_RETRIES=0&lt;br /&gt;
MASTER_UUID=7bb91614-6ffe-4bdc-9b37-c6e9d37f6987&lt;br /&gt;
MASTER=bond0&lt;br /&gt;
SLAVE=yes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== VLAN 100 Interface =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# /etc/sysconfig/network-scripts/ifcfg-vlan-bond0.100&lt;br /&gt;
VLAN=yes&lt;br /&gt;
TYPE=Vlan&lt;br /&gt;
PHYSDEV=bond0&lt;br /&gt;
VLAN_ID=100&lt;br /&gt;
REORDER_HDR=yes&lt;br /&gt;
GVRP=no&lt;br /&gt;
MVRP=no&lt;br /&gt;
HWADDR=&lt;br /&gt;
PROXY_METHOD=none&lt;br /&gt;
BROWSER_ONLY=no&lt;br /&gt;
BOOTPROTO=none&lt;br /&gt;
IPADDR=192.168.100.10&lt;br /&gt;
PREFIX=24&lt;br /&gt;
DEFROUTE=yes&lt;br /&gt;
IPV4_FAILURE_FATAL=no&lt;br /&gt;
NAME=vlan-bond0.100&lt;br /&gt;
UUID=83b0e31c-9a9f-47da-9dc6-645796bc47aa&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
AUTOCONNECT_PRIORITY=9&lt;br /&gt;
AUTOCONNECT_RETRIES=0&lt;br /&gt;
GATEWAY=192.168.100.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Ubuntu/Debian ===&lt;br /&gt;
==== Netplan ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Apply the configuration, but if the dialogue is left unconfirmed, the configuration will be reverted.&lt;br /&gt;
netplan try&lt;br /&gt;
&lt;br /&gt;
# Apply the configuration&lt;br /&gt;
netplan apply&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Generic DCHP interface =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;yaml&#039;&amp;gt;&lt;br /&gt;
network:&lt;br /&gt;
    version: 2&lt;br /&gt;
    ethernets:&lt;br /&gt;
        ens4:&lt;br /&gt;
            # Some info about the Interface/why does it exist&lt;br /&gt;
            dhcp4: true&lt;br /&gt;
            match:&lt;br /&gt;
                macaddress: fa:16:3e:aa:bb:cc&lt;br /&gt;
            set-name: ens4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Generic DHCP Interfaces, but while ignoring the routes for an Interface and disabling DHCP on the other.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;yaml&#039;&amp;gt;&lt;br /&gt;
network:&lt;br /&gt;
    version: 2&lt;br /&gt;
    ethernets:&lt;br /&gt;
        ens4:&lt;br /&gt;
            # Some info about the Interface/why does it exist&lt;br /&gt;
            dhcp4: true&lt;br /&gt;
            dhcp4-overrides:&lt;br /&gt;
              use-routes: false&lt;br /&gt;
            match:&lt;br /&gt;
                macaddress: fa:16:3e:aa:bb:cc&lt;br /&gt;
            set-name: ens4&lt;br /&gt;
        ens5:&lt;br /&gt;
            # Some info about the Interface/why does it exist&lt;br /&gt;
            dhcp4: no&lt;br /&gt;
            match:&lt;br /&gt;
                macaddress: fa:16:cc:dd:ee&lt;br /&gt;
            set-name: ens5&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Generic static interface =====&lt;br /&gt;
You may have to disable automatic network-configuration:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;yaml&#039;&amp;gt;&lt;br /&gt;
sudo bash -c &#039;echo &amp;quot;network: {config: disabled}&amp;quot; &amp;gt; /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;yaml&#039;&amp;gt;&lt;br /&gt;
network:&lt;br /&gt;
    version: 2&lt;br /&gt;
    ethernets:&lt;br /&gt;
        ens7:&lt;br /&gt;
           addresses:&lt;br /&gt;
              - 192.168.0.23/24&lt;br /&gt;
           match:&lt;br /&gt;
               macaddress: ab:cd:ef:gh:ij:kl&lt;br /&gt;
           mtu: 1500&lt;br /&gt;
           set-name: ens7&lt;br /&gt;
           nameservers:&lt;br /&gt;
               addresses: [1.1.1.1, 8.8.8.8]&lt;br /&gt;
           routes:&lt;br /&gt;
              - to: default&lt;br /&gt;
                via: 192.168.0.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== VLAN Interface =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;yaml&#039;&amp;gt;&lt;br /&gt;
network:&lt;br /&gt;
    version: 2&lt;br /&gt;
    ethernets:&lt;br /&gt;
        eno1: {}&lt;br /&gt;
    vlans:&lt;br /&gt;
        eno1.10:&lt;br /&gt;
            id: 10&lt;br /&gt;
            link: eno1&lt;br /&gt;
            addresses: [192.168.1.1/24]&lt;br /&gt;
        eno1.20:&lt;br /&gt;
            id: 20&lt;br /&gt;
            link: eno1&lt;br /&gt;
            addresses: [192.168.2.1/24]&lt;br /&gt;
            nameservers:&lt;br /&gt;
              addresses:&lt;br /&gt;
                - 1.1.1.1&lt;br /&gt;
                - 8.8.8.8&lt;br /&gt;
              search: []&lt;br /&gt;
            routes:&lt;br /&gt;
              - to: default&lt;br /&gt;
                via: 192.168.2.1&lt;br /&gt;
        eno1.30:&lt;br /&gt;
            id: 30&lt;br /&gt;
            link: eno1&lt;br /&gt;
            addresses: [192.168.3.1/24]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Empty Interface =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;yaml&#039;&amp;gt;&lt;br /&gt;
network:&lt;br /&gt;
  version: 2&lt;br /&gt;
  ethernets:&lt;br /&gt;
    eno2:&lt;br /&gt;
      dhcp4: false&lt;br /&gt;
      dhcp6: false&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Interface files ====&lt;br /&gt;
Classic &amp;lt;code&amp;gt;/etc/network/interfaces.d&amp;lt;/code&amp;gt; files i.e. &amp;lt;code&amp;gt; /etc/network/interfaces.d/ens200.conf &amp;lt;/code&amp;gt;&lt;br /&gt;
Otherwise use &amp;lt;code&amp;gt;/etc/network/interfaces &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Generic IPv4 =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# /etc/network/interfaces.d/ens160.conf&lt;br /&gt;
auto ens160&lt;br /&gt;
iface ens160 inet static&lt;br /&gt;
    address 192.168.23.7&lt;br /&gt;
    netmask 255.255.255.0&lt;br /&gt;
    gateway 192.168.23.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Generic IPv6 =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# /etc/network/interfaces.d/ens3.conf&lt;br /&gt;
iface ens3 inet6 static&lt;br /&gt;
    address abcd:defg:0:1234:5123:abcd:abcd:1234&lt;br /&gt;
    netmask 48&lt;br /&gt;
    gateway abcd:defg::1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Bond =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
auto eno1&lt;br /&gt;
iface eno1 inet manual&lt;br /&gt;
&lt;br /&gt;
auto eno2&lt;br /&gt;
iface eno2 inet manual&lt;br /&gt;
&lt;br /&gt;
auto bond0&lt;br /&gt;
iface bond0 inet static&lt;br /&gt;
        address 192.168.39.245&lt;br /&gt;
        gateway 192.168.39.254&lt;br /&gt;
        network 255.255.255.0&lt;br /&gt;
        bond-slaves eno1 eno2&lt;br /&gt;
        bond-miimon 100&lt;br /&gt;
        bond-mode 802.3ad&lt;br /&gt;
        bond-xmit-hash-policy layer2+3&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Network&amp;diff=866</id>
		<title>Linux:Network</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Network&amp;diff=866"/>
		<updated>2026-01-23T16:06:48Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* Config changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet]]&lt;br /&gt;
&lt;br /&gt;
* https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers&lt;br /&gt;
&lt;br /&gt;
== Checks ==&lt;br /&gt;
=== Common ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List route table&lt;br /&gt;
route -n&lt;br /&gt;
&lt;br /&gt;
# Display network connections and current states&lt;br /&gt;
netstat&lt;br /&gt;
&lt;br /&gt;
# Check listening ports, connected remote IPs, processes, states and more&lt;br /&gt;
netstat -taupen&lt;br /&gt;
&lt;br /&gt;
# Check listening ports and IPs of the local server&lt;br /&gt;
netstat -tulpn&lt;br /&gt;
&lt;br /&gt;
# List the routing table&lt;br /&gt;
netstat -r&lt;br /&gt;
&lt;br /&gt;
# List verbose common TCP and ICMP information&lt;br /&gt;
netstat -s&lt;br /&gt;
&lt;br /&gt;
# List iptable rules (Nftables)&lt;br /&gt;
iptables -nvL&lt;br /&gt;
&lt;br /&gt;
# List iptable rules (Legacy iptables)&lt;br /&gt;
iptables-legacy -nvL&lt;br /&gt;
&lt;br /&gt;
# Test specific IP and port combination for connectivity&lt;br /&gt;
telnet 172.16.2.1 22&lt;br /&gt;
&lt;br /&gt;
# Wireshark on a specific interface to a file, listening on a local port and for a remote IP&lt;br /&gt;
tshark -p -i bond0 -w file.pcap -f &amp;quot;port 443 and host 172.16.16.25&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# List available routers&lt;br /&gt;
ip netns&lt;br /&gt;
&lt;br /&gt;
# Show interfaces with an IPv4 address&lt;br /&gt;
ip -4 a&lt;br /&gt;
&lt;br /&gt;
# Show interfaces with an IPv6 address&lt;br /&gt;
ip -6 a&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Common configuration ==&lt;br /&gt;
=== Routes ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Add a route for 192.168.7.0/24 via a specific IP and interface&lt;br /&gt;
ip route add 192.168.7.0/24 via 192.168.7.199 dev eth0&lt;br /&gt;
&lt;br /&gt;
# Delete the route we added previously&lt;br /&gt;
ip route del 192.168.7.0/24 via 192.168.7.199 dev eth0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Network ==&lt;br /&gt;
=== NetworkManager ===&lt;br /&gt;
&#039;&#039;&#039;nmtui&#039;&#039;&#039; is a GUI-tool for managing NetworkManager connections.&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Show all active network connections&lt;br /&gt;
nmcli connection show&lt;br /&gt;
&lt;br /&gt;
# Show connection information for interface ens5&lt;br /&gt;
nmcli connection show ens5&lt;br /&gt;
&lt;br /&gt;
# Show active and unactive network connections&lt;br /&gt;
nmcli dev status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== nmcli ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Bring logical interface ens6 up&lt;br /&gt;
nmcli device up ens6&lt;br /&gt;
&lt;br /&gt;
# Turn off DHCP&lt;br /&gt;
nmcli con mod ens6 ipv4.method manual&lt;br /&gt;
nmcli con mod ens6 connection.autoconnect yes&lt;br /&gt;
&lt;br /&gt;
# Add an IP-address to interface ens6&lt;br /&gt;
nmcli connection modify ens6 ipv4.address &amp;quot;192.168.0.10/24&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Add DNS-servers to interface ens6&lt;br /&gt;
nmcli connection modify ens6 ipv4.dns &amp;quot;8.8.8.8,1.1.1.1,196.168.0.1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Add a gateway to interface ens6&lt;br /&gt;
nmcli con mod ens6 ipv4.gateway &amp;quot;192.168.0.1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Add a default route to interface ens160&lt;br /&gt;
nmcli connection modify ens160 +ipv4.routes &amp;quot;0.0.0.0/0 192.168.3.100&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Remove an IP-address from interface ens6&lt;br /&gt;
nmcli con mod ens6 -ipv4.addresses 192.168.0.11/24&lt;br /&gt;
&lt;br /&gt;
# Apply changes to interface ens&lt;br /&gt;
nmcli device reapply ens6&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== RHEL ===&lt;br /&gt;
==== Generic Interface ====&lt;br /&gt;
&amp;lt;code&amp;gt; BOOTPROTO=static &amp;lt;/code&amp;gt; for static address &amp;lt;/br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; BOOTPROTO=dhcp &amp;lt;/code&amp;gt; for DHCP&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# /etc/sysconfig/network-scripts/ifcfg-ens128&lt;br /&gt;
DEVICE=ens128&lt;br /&gt;
NAME=ens128&lt;br /&gt;
HWADDR=ab:cd:ef:gh:ij:kl&lt;br /&gt;
UUID=0a8d3485-d512-46da-8225-19f4721813c1&lt;br /&gt;
BOOTPROTO=static&lt;br /&gt;
STARTMODE=auto&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
IPADDR=192.168.10.2&lt;br /&gt;
NETMASK=255.255.255.0&lt;br /&gt;
GATEWAY=192.168.10.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Generic VLAN Interface ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# /etc/sysconfig/network-scripts/ifcfg-eno2.100&lt;br /&gt;
VLAN=yes&lt;br /&gt;
TYPE=Vlan&lt;br /&gt;
PHYSDEV=eno2&lt;br /&gt;
VLAN_ID=100&lt;br /&gt;
NAME=eno2.100&lt;br /&gt;
BOOTPROTO=static&lt;br /&gt;
HWADDR=ab:cd:ef:gh:ij:kl&lt;br /&gt;
IPADDR=192.168.100.217&lt;br /&gt;
NETMASK=255.255.255.0&lt;br /&gt;
STARTMODE=auto&lt;br /&gt;
UUID=689cff6f-c750-4db7-936c-234fb80b6018&lt;br /&gt;
GATEWAY=192.168.100.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== VLAN Bond interface configuration ====&lt;br /&gt;
===== Virtual Bond Master =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
BONDING_OPTS=&amp;quot;mode=802.3ad miimon=100&amp;quot;&lt;br /&gt;
TYPE=Bond&lt;br /&gt;
BONDING_MASTER=yes&lt;br /&gt;
PROXY_METHOD=none&lt;br /&gt;
BROWSER_ONLY=no&lt;br /&gt;
IPV6INIT=no&lt;br /&gt;
NAME=bond0&lt;br /&gt;
UUID=7bb91614-6ffe-4bdc-9b37-c6e9d37f6987&lt;br /&gt;
DEVICE=bond0&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
AUTOCONNECT_PRIORITY=9&lt;br /&gt;
AUTOCONNECT_RETRIES=0&lt;br /&gt;
AUTOCONNECT_SLAVES=yes&lt;br /&gt;
MTU=1500&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Physical bond Slaves =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# /etc/sysconfig/network-scripts/ifcfg-ens1&lt;br /&gt;
TYPE=Ethernet&lt;br /&gt;
NAME=ens1&lt;br /&gt;
UUID=c6a4da43-b84a-44f4-b49f-4bdc717d4238&lt;br /&gt;
DEVICE=ens1&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
AUTOCONNECT_PRIORITY=9&lt;br /&gt;
AUTOCONNECT_RETRIES=0&lt;br /&gt;
MASTER_UUID=7bb91614-6ffe-4bdc-9b37-c6e9d37f6987&lt;br /&gt;
MASTER=bond0&lt;br /&gt;
SLAVE=yes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# /etc/sysconfig/network-scripts/ifcfg-ens2&lt;br /&gt;
TYPE=Ethernet&lt;br /&gt;
NAME=ens2&lt;br /&gt;
UUID=ca09a126-a082-4620-a920-be45269e5d8a&lt;br /&gt;
DEVICE=ens2&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
AUTOCONNECT_PRIORITY=9&lt;br /&gt;
AUTOCONNECT_RETRIES=0&lt;br /&gt;
MASTER_UUID=7bb91614-6ffe-4bdc-9b37-c6e9d37f6987&lt;br /&gt;
MASTER=bond0&lt;br /&gt;
SLAVE=yes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== VLAN 100 Interface =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# /etc/sysconfig/network-scripts/ifcfg-vlan-bond0.100&lt;br /&gt;
VLAN=yes&lt;br /&gt;
TYPE=Vlan&lt;br /&gt;
PHYSDEV=bond0&lt;br /&gt;
VLAN_ID=100&lt;br /&gt;
REORDER_HDR=yes&lt;br /&gt;
GVRP=no&lt;br /&gt;
MVRP=no&lt;br /&gt;
HWADDR=&lt;br /&gt;
PROXY_METHOD=none&lt;br /&gt;
BROWSER_ONLY=no&lt;br /&gt;
BOOTPROTO=none&lt;br /&gt;
IPADDR=192.168.100.10&lt;br /&gt;
PREFIX=24&lt;br /&gt;
DEFROUTE=yes&lt;br /&gt;
IPV4_FAILURE_FATAL=no&lt;br /&gt;
NAME=vlan-bond0.100&lt;br /&gt;
UUID=83b0e31c-9a9f-47da-9dc6-645796bc47aa&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
AUTOCONNECT_PRIORITY=9&lt;br /&gt;
AUTOCONNECT_RETRIES=0&lt;br /&gt;
GATEWAY=192.168.100.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Ubuntu/Debian ===&lt;br /&gt;
==== Netplan ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Apply the configuration, but if the dialogue is left unconfirmed, the configuration will be reverted.&lt;br /&gt;
netplan try&lt;br /&gt;
&lt;br /&gt;
# Apply the configuration&lt;br /&gt;
netplan apply&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Generic DCHP interface =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;yaml&#039;&amp;gt;&lt;br /&gt;
network:&lt;br /&gt;
    version: 2&lt;br /&gt;
    ethernets:&lt;br /&gt;
        ens4:&lt;br /&gt;
            # Some info about the Interface/why does it exist&lt;br /&gt;
            dhcp4: true&lt;br /&gt;
            match:&lt;br /&gt;
                macaddress: fa:16:3e:aa:bb:cc&lt;br /&gt;
            set-name: ens4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Generic DHCP Interfaces, but while ignoring the routes for an Interface and disabling DHCP on the other.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;yaml&#039;&amp;gt;&lt;br /&gt;
network:&lt;br /&gt;
    version: 2&lt;br /&gt;
    ethernets:&lt;br /&gt;
        ens4:&lt;br /&gt;
            # Some info about the Interface/why does it exist&lt;br /&gt;
            dhcp4: true&lt;br /&gt;
            dhcp4-overrides:&lt;br /&gt;
              use-routes: false&lt;br /&gt;
            match:&lt;br /&gt;
                macaddress: fa:16:3e:aa:bb:cc&lt;br /&gt;
            set-name: ens4&lt;br /&gt;
        ens5:&lt;br /&gt;
            # Some info about the Interface/why does it exist&lt;br /&gt;
            dhcp4: no&lt;br /&gt;
            match:&lt;br /&gt;
                macaddress: fa:16:cc:dd:ee&lt;br /&gt;
            set-name: ens5&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Generic static interface =====&lt;br /&gt;
You may have to disable automatic network-configuration:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;yaml&#039;&amp;gt;&lt;br /&gt;
sudo bash -c &#039;echo &amp;quot;network: {config: disabled}&amp;quot; &amp;gt; /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;yaml&#039;&amp;gt;&lt;br /&gt;
network:&lt;br /&gt;
    version: 2&lt;br /&gt;
    ethernets:&lt;br /&gt;
        ens7:&lt;br /&gt;
           addresses:&lt;br /&gt;
              - 192.168.0.23/24&lt;br /&gt;
           match:&lt;br /&gt;
               macaddress: ab:cd:ef:gh:ij:kl&lt;br /&gt;
           mtu: 1500&lt;br /&gt;
           set-name: ens7&lt;br /&gt;
           nameservers:&lt;br /&gt;
               addresses: [1.1.1.1, 8.8.8.8]&lt;br /&gt;
           routes:&lt;br /&gt;
              - to: default&lt;br /&gt;
                via: 192.168.0.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== VLAN Interface =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;yaml&#039;&amp;gt;&lt;br /&gt;
network:&lt;br /&gt;
    version: 2&lt;br /&gt;
    ethernets:&lt;br /&gt;
        eno1: {}&lt;br /&gt;
    vlans:&lt;br /&gt;
        eno1.10:&lt;br /&gt;
            id: 10&lt;br /&gt;
            link: eno1&lt;br /&gt;
            addresses: [192.168.1.1/24]&lt;br /&gt;
        eno1.20:&lt;br /&gt;
            id: 20&lt;br /&gt;
            link: eno1&lt;br /&gt;
            addresses: [192.168.2.1/24]&lt;br /&gt;
            nameservers:&lt;br /&gt;
              addresses:&lt;br /&gt;
                - 1.1.1.1&lt;br /&gt;
                - 8.8.8.8&lt;br /&gt;
              search: []&lt;br /&gt;
            routes:&lt;br /&gt;
              - to: default&lt;br /&gt;
                via: 192.168.2.1&lt;br /&gt;
        eno1.30:&lt;br /&gt;
            id: 30&lt;br /&gt;
            link: eno1&lt;br /&gt;
            addresses: [192.168.3.1/24]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Empty Interface =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;yaml&#039;&amp;gt;&lt;br /&gt;
network:&lt;br /&gt;
  version: 2&lt;br /&gt;
  ethernets:&lt;br /&gt;
    eno2:&lt;br /&gt;
      dhcp4: false&lt;br /&gt;
      dhcp6: false&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Interface files ====&lt;br /&gt;
Classic &amp;lt;code&amp;gt;/etc/network/interfaces.d&amp;lt;/code&amp;gt; files i.e. &amp;lt;code&amp;gt; /etc/network/interfaces.d/ens200.conf &amp;lt;/code&amp;gt;&lt;br /&gt;
Otherwise use &amp;lt;code&amp;gt;/etc/network/interfaces &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Generic IPv4 =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# /etc/network/interfaces.d/ens160.conf&lt;br /&gt;
auto ens160&lt;br /&gt;
iface ens160 inet static&lt;br /&gt;
    address 192.168.23.7&lt;br /&gt;
    netmask 255.255.255.0&lt;br /&gt;
    gateway 192.168.23.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Generic IPv6 =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# /etc/network/interfaces.d/ens3.conf&lt;br /&gt;
iface ens3 inet6 static&lt;br /&gt;
    address abcd:defg:0:1234:5123:abcd:abcd:1234&lt;br /&gt;
    netmask 48&lt;br /&gt;
    gateway abcd:defg::1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Bond =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
auto eno1&lt;br /&gt;
iface eno1 inet manual&lt;br /&gt;
&lt;br /&gt;
auto eno2&lt;br /&gt;
iface eno2 inet manual&lt;br /&gt;
&lt;br /&gt;
auto bond0&lt;br /&gt;
iface bond0 inet static&lt;br /&gt;
        address 192.168.39.245&lt;br /&gt;
        gateway 192.168.39.254&lt;br /&gt;
        network 255.255.255.0&lt;br /&gt;
        bond-slaves eno1 eno2&lt;br /&gt;
        bond-miimon 100&lt;br /&gt;
        bond-mode 802.3ad&lt;br /&gt;
        bond-xmit-hash-policy layer2+3&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Network&amp;diff=865</id>
		<title>Linux:Network</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Network&amp;diff=865"/>
		<updated>2026-01-23T16:06:16Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* Common */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet]]&lt;br /&gt;
&lt;br /&gt;
* https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers&lt;br /&gt;
&lt;br /&gt;
== Checks ==&lt;br /&gt;
=== Common ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List route table&lt;br /&gt;
route -n&lt;br /&gt;
&lt;br /&gt;
# Display network connections and current states&lt;br /&gt;
netstat&lt;br /&gt;
&lt;br /&gt;
# Check listening ports, connected remote IPs, processes, states and more&lt;br /&gt;
netstat -taupen&lt;br /&gt;
&lt;br /&gt;
# Check listening ports and IPs of the local server&lt;br /&gt;
netstat -tulpn&lt;br /&gt;
&lt;br /&gt;
# List the routing table&lt;br /&gt;
netstat -r&lt;br /&gt;
&lt;br /&gt;
# List verbose common TCP and ICMP information&lt;br /&gt;
netstat -s&lt;br /&gt;
&lt;br /&gt;
# List iptable rules (Nftables)&lt;br /&gt;
iptables -nvL&lt;br /&gt;
&lt;br /&gt;
# List iptable rules (Legacy iptables)&lt;br /&gt;
iptables-legacy -nvL&lt;br /&gt;
&lt;br /&gt;
# Test specific IP and port combination for connectivity&lt;br /&gt;
telnet 172.16.2.1 22&lt;br /&gt;
&lt;br /&gt;
# Wireshark on a specific interface to a file, listening on a local port and for a remote IP&lt;br /&gt;
tshark -p -i bond0 -w file.pcap -f &amp;quot;port 443 and host 172.16.16.25&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# List available routers&lt;br /&gt;
ip netns&lt;br /&gt;
&lt;br /&gt;
# Show interfaces with an IPv4 address&lt;br /&gt;
ip -4 a&lt;br /&gt;
&lt;br /&gt;
# Show interfaces with an IPv6 address&lt;br /&gt;
ip -6 a&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Config changes ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Add a route for 192.168.7.0/24 via a specific IP and interface&lt;br /&gt;
ip route add 192.168.7.0/24 via 192.168.7.199 dev eth0&lt;br /&gt;
&lt;br /&gt;
# Delete the route we added previously&lt;br /&gt;
ip route del 192.168.7.0/24 via 192.168.7.199 dev eth0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Network ==&lt;br /&gt;
=== NetworkManager ===&lt;br /&gt;
&#039;&#039;&#039;nmtui&#039;&#039;&#039; is a GUI-tool for managing NetworkManager connections.&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Show all active network connections&lt;br /&gt;
nmcli connection show&lt;br /&gt;
&lt;br /&gt;
# Show connection information for interface ens5&lt;br /&gt;
nmcli connection show ens5&lt;br /&gt;
&lt;br /&gt;
# Show active and unactive network connections&lt;br /&gt;
nmcli dev status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== nmcli ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Bring logical interface ens6 up&lt;br /&gt;
nmcli device up ens6&lt;br /&gt;
&lt;br /&gt;
# Turn off DHCP&lt;br /&gt;
nmcli con mod ens6 ipv4.method manual&lt;br /&gt;
nmcli con mod ens6 connection.autoconnect yes&lt;br /&gt;
&lt;br /&gt;
# Add an IP-address to interface ens6&lt;br /&gt;
nmcli connection modify ens6 ipv4.address &amp;quot;192.168.0.10/24&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Add DNS-servers to interface ens6&lt;br /&gt;
nmcli connection modify ens6 ipv4.dns &amp;quot;8.8.8.8,1.1.1.1,196.168.0.1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Add a gateway to interface ens6&lt;br /&gt;
nmcli con mod ens6 ipv4.gateway &amp;quot;192.168.0.1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Add a default route to interface ens160&lt;br /&gt;
nmcli connection modify ens160 +ipv4.routes &amp;quot;0.0.0.0/0 192.168.3.100&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Remove an IP-address from interface ens6&lt;br /&gt;
nmcli con mod ens6 -ipv4.addresses 192.168.0.11/24&lt;br /&gt;
&lt;br /&gt;
# Apply changes to interface ens&lt;br /&gt;
nmcli device reapply ens6&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== RHEL ===&lt;br /&gt;
==== Generic Interface ====&lt;br /&gt;
&amp;lt;code&amp;gt; BOOTPROTO=static &amp;lt;/code&amp;gt; for static address &amp;lt;/br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; BOOTPROTO=dhcp &amp;lt;/code&amp;gt; for DHCP&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# /etc/sysconfig/network-scripts/ifcfg-ens128&lt;br /&gt;
DEVICE=ens128&lt;br /&gt;
NAME=ens128&lt;br /&gt;
HWADDR=ab:cd:ef:gh:ij:kl&lt;br /&gt;
UUID=0a8d3485-d512-46da-8225-19f4721813c1&lt;br /&gt;
BOOTPROTO=static&lt;br /&gt;
STARTMODE=auto&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
IPADDR=192.168.10.2&lt;br /&gt;
NETMASK=255.255.255.0&lt;br /&gt;
GATEWAY=192.168.10.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Generic VLAN Interface ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# /etc/sysconfig/network-scripts/ifcfg-eno2.100&lt;br /&gt;
VLAN=yes&lt;br /&gt;
TYPE=Vlan&lt;br /&gt;
PHYSDEV=eno2&lt;br /&gt;
VLAN_ID=100&lt;br /&gt;
NAME=eno2.100&lt;br /&gt;
BOOTPROTO=static&lt;br /&gt;
HWADDR=ab:cd:ef:gh:ij:kl&lt;br /&gt;
IPADDR=192.168.100.217&lt;br /&gt;
NETMASK=255.255.255.0&lt;br /&gt;
STARTMODE=auto&lt;br /&gt;
UUID=689cff6f-c750-4db7-936c-234fb80b6018&lt;br /&gt;
GATEWAY=192.168.100.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== VLAN Bond interface configuration ====&lt;br /&gt;
===== Virtual Bond Master =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
BONDING_OPTS=&amp;quot;mode=802.3ad miimon=100&amp;quot;&lt;br /&gt;
TYPE=Bond&lt;br /&gt;
BONDING_MASTER=yes&lt;br /&gt;
PROXY_METHOD=none&lt;br /&gt;
BROWSER_ONLY=no&lt;br /&gt;
IPV6INIT=no&lt;br /&gt;
NAME=bond0&lt;br /&gt;
UUID=7bb91614-6ffe-4bdc-9b37-c6e9d37f6987&lt;br /&gt;
DEVICE=bond0&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
AUTOCONNECT_PRIORITY=9&lt;br /&gt;
AUTOCONNECT_RETRIES=0&lt;br /&gt;
AUTOCONNECT_SLAVES=yes&lt;br /&gt;
MTU=1500&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Physical bond Slaves =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# /etc/sysconfig/network-scripts/ifcfg-ens1&lt;br /&gt;
TYPE=Ethernet&lt;br /&gt;
NAME=ens1&lt;br /&gt;
UUID=c6a4da43-b84a-44f4-b49f-4bdc717d4238&lt;br /&gt;
DEVICE=ens1&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
AUTOCONNECT_PRIORITY=9&lt;br /&gt;
AUTOCONNECT_RETRIES=0&lt;br /&gt;
MASTER_UUID=7bb91614-6ffe-4bdc-9b37-c6e9d37f6987&lt;br /&gt;
MASTER=bond0&lt;br /&gt;
SLAVE=yes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# /etc/sysconfig/network-scripts/ifcfg-ens2&lt;br /&gt;
TYPE=Ethernet&lt;br /&gt;
NAME=ens2&lt;br /&gt;
UUID=ca09a126-a082-4620-a920-be45269e5d8a&lt;br /&gt;
DEVICE=ens2&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
AUTOCONNECT_PRIORITY=9&lt;br /&gt;
AUTOCONNECT_RETRIES=0&lt;br /&gt;
MASTER_UUID=7bb91614-6ffe-4bdc-9b37-c6e9d37f6987&lt;br /&gt;
MASTER=bond0&lt;br /&gt;
SLAVE=yes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== VLAN 100 Interface =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# /etc/sysconfig/network-scripts/ifcfg-vlan-bond0.100&lt;br /&gt;
VLAN=yes&lt;br /&gt;
TYPE=Vlan&lt;br /&gt;
PHYSDEV=bond0&lt;br /&gt;
VLAN_ID=100&lt;br /&gt;
REORDER_HDR=yes&lt;br /&gt;
GVRP=no&lt;br /&gt;
MVRP=no&lt;br /&gt;
HWADDR=&lt;br /&gt;
PROXY_METHOD=none&lt;br /&gt;
BROWSER_ONLY=no&lt;br /&gt;
BOOTPROTO=none&lt;br /&gt;
IPADDR=192.168.100.10&lt;br /&gt;
PREFIX=24&lt;br /&gt;
DEFROUTE=yes&lt;br /&gt;
IPV4_FAILURE_FATAL=no&lt;br /&gt;
NAME=vlan-bond0.100&lt;br /&gt;
UUID=83b0e31c-9a9f-47da-9dc6-645796bc47aa&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
AUTOCONNECT_PRIORITY=9&lt;br /&gt;
AUTOCONNECT_RETRIES=0&lt;br /&gt;
GATEWAY=192.168.100.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Ubuntu/Debian ===&lt;br /&gt;
==== Netplan ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Apply the configuration, but if the dialogue is left unconfirmed, the configuration will be reverted.&lt;br /&gt;
netplan try&lt;br /&gt;
&lt;br /&gt;
# Apply the configuration&lt;br /&gt;
netplan apply&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Generic DCHP interface =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;yaml&#039;&amp;gt;&lt;br /&gt;
network:&lt;br /&gt;
    version: 2&lt;br /&gt;
    ethernets:&lt;br /&gt;
        ens4:&lt;br /&gt;
            # Some info about the Interface/why does it exist&lt;br /&gt;
            dhcp4: true&lt;br /&gt;
            match:&lt;br /&gt;
                macaddress: fa:16:3e:aa:bb:cc&lt;br /&gt;
            set-name: ens4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Generic DHCP Interfaces, but while ignoring the routes for an Interface and disabling DHCP on the other.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;yaml&#039;&amp;gt;&lt;br /&gt;
network:&lt;br /&gt;
    version: 2&lt;br /&gt;
    ethernets:&lt;br /&gt;
        ens4:&lt;br /&gt;
            # Some info about the Interface/why does it exist&lt;br /&gt;
            dhcp4: true&lt;br /&gt;
            dhcp4-overrides:&lt;br /&gt;
              use-routes: false&lt;br /&gt;
            match:&lt;br /&gt;
                macaddress: fa:16:3e:aa:bb:cc&lt;br /&gt;
            set-name: ens4&lt;br /&gt;
        ens5:&lt;br /&gt;
            # Some info about the Interface/why does it exist&lt;br /&gt;
            dhcp4: no&lt;br /&gt;
            match:&lt;br /&gt;
                macaddress: fa:16:cc:dd:ee&lt;br /&gt;
            set-name: ens5&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Generic static interface =====&lt;br /&gt;
You may have to disable automatic network-configuration:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;yaml&#039;&amp;gt;&lt;br /&gt;
sudo bash -c &#039;echo &amp;quot;network: {config: disabled}&amp;quot; &amp;gt; /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;yaml&#039;&amp;gt;&lt;br /&gt;
network:&lt;br /&gt;
    version: 2&lt;br /&gt;
    ethernets:&lt;br /&gt;
        ens7:&lt;br /&gt;
           addresses:&lt;br /&gt;
              - 192.168.0.23/24&lt;br /&gt;
           match:&lt;br /&gt;
               macaddress: ab:cd:ef:gh:ij:kl&lt;br /&gt;
           mtu: 1500&lt;br /&gt;
           set-name: ens7&lt;br /&gt;
           nameservers:&lt;br /&gt;
               addresses: [1.1.1.1, 8.8.8.8]&lt;br /&gt;
           routes:&lt;br /&gt;
              - to: default&lt;br /&gt;
                via: 192.168.0.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== VLAN Interface =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;yaml&#039;&amp;gt;&lt;br /&gt;
network:&lt;br /&gt;
    version: 2&lt;br /&gt;
    ethernets:&lt;br /&gt;
        eno1: {}&lt;br /&gt;
    vlans:&lt;br /&gt;
        eno1.10:&lt;br /&gt;
            id: 10&lt;br /&gt;
            link: eno1&lt;br /&gt;
            addresses: [192.168.1.1/24]&lt;br /&gt;
        eno1.20:&lt;br /&gt;
            id: 20&lt;br /&gt;
            link: eno1&lt;br /&gt;
            addresses: [192.168.2.1/24]&lt;br /&gt;
            nameservers:&lt;br /&gt;
              addresses:&lt;br /&gt;
                - 1.1.1.1&lt;br /&gt;
                - 8.8.8.8&lt;br /&gt;
              search: []&lt;br /&gt;
            routes:&lt;br /&gt;
              - to: default&lt;br /&gt;
                via: 192.168.2.1&lt;br /&gt;
        eno1.30:&lt;br /&gt;
            id: 30&lt;br /&gt;
            link: eno1&lt;br /&gt;
            addresses: [192.168.3.1/24]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Empty Interface =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;yaml&#039;&amp;gt;&lt;br /&gt;
network:&lt;br /&gt;
  version: 2&lt;br /&gt;
  ethernets:&lt;br /&gt;
    eno2:&lt;br /&gt;
      dhcp4: false&lt;br /&gt;
      dhcp6: false&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Interface files ====&lt;br /&gt;
Classic &amp;lt;code&amp;gt;/etc/network/interfaces.d&amp;lt;/code&amp;gt; files i.e. &amp;lt;code&amp;gt; /etc/network/interfaces.d/ens200.conf &amp;lt;/code&amp;gt;&lt;br /&gt;
Otherwise use &amp;lt;code&amp;gt;/etc/network/interfaces &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Generic IPv4 =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# /etc/network/interfaces.d/ens160.conf&lt;br /&gt;
auto ens160&lt;br /&gt;
iface ens160 inet static&lt;br /&gt;
    address 192.168.23.7&lt;br /&gt;
    netmask 255.255.255.0&lt;br /&gt;
    gateway 192.168.23.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Generic IPv6 =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# /etc/network/interfaces.d/ens3.conf&lt;br /&gt;
iface ens3 inet6 static&lt;br /&gt;
    address abcd:defg:0:1234:5123:abcd:abcd:1234&lt;br /&gt;
    netmask 48&lt;br /&gt;
    gateway abcd:defg::1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Bond =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
auto eno1&lt;br /&gt;
iface eno1 inet manual&lt;br /&gt;
&lt;br /&gt;
auto eno2&lt;br /&gt;
iface eno2 inet manual&lt;br /&gt;
&lt;br /&gt;
auto bond0&lt;br /&gt;
iface bond0 inet static&lt;br /&gt;
        address 192.168.39.245&lt;br /&gt;
        gateway 192.168.39.254&lt;br /&gt;
        network 255.255.255.0&lt;br /&gt;
        bond-slaves eno1 eno2&lt;br /&gt;
        bond-miimon 100&lt;br /&gt;
        bond-mode 802.3ad&lt;br /&gt;
        bond-xmit-hash-policy layer2+3&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Scripts&amp;diff=864</id>
		<title>Linux:Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Scripts&amp;diff=864"/>
		<updated>2026-01-03T08:04:42Z</updated>

		<summary type="html">&lt;p&gt;Patrick: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet]]&lt;br /&gt;
&lt;br /&gt;
== Pointers ==&lt;br /&gt;
* Lowercase or Camelcase only: all BASH variables are uppercase, so don&#039;t get in their way!&lt;br /&gt;
&lt;br /&gt;
== Template ==&lt;br /&gt;
Script with a single passed variable, description and common exit-protocols.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
#!/usr/bin/env bash&lt;br /&gt;
&lt;br /&gt;
set -o errexit       # Exit on error, do not continue running the script&lt;br /&gt;
set -o nounset       # Trying to access a variable that has not been set generates an error&lt;br /&gt;
set -o pipefail      # When a pipe fails generate an error&lt;br /&gt;
&lt;br /&gt;
if [[ &amp;quot;${1-}&amp;quot; =~ ^-*h(elp)?$ ]] || [[ &amp;quot;$#&amp;quot; -eq 0 ]] ; then&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
    echo &#039;Usage: myscript.sh value1&lt;br /&gt;
&lt;br /&gt;
This is the description of my script.&lt;br /&gt;
&#039;&lt;br /&gt;
    exit&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing - [[]] ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Use the test functionality [[]] to compare values and types, using expressions&lt;br /&gt;
man test&lt;br /&gt;
[[ -d &amp;quot;$MyDirectoryVariable&amp;quot; ]]&lt;br /&gt;
&lt;br /&gt;
# Combine testing with an if statement&lt;br /&gt;
if [[ $(echo &amp;quot;world&amp;quot;) == &amp;quot;world&amp;quot; ]]; then&lt;br /&gt;
    echo -e &amp;quot;all is bad in da world&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
    echo -e &amp;quot;all is good&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
https://stackoverflow.com/questions/638975/how-do-i-tell-if-a-file-does-not-exist-in-bash&lt;br /&gt;
&lt;br /&gt;
FILE=/home/javier/wopper.txt&lt;br /&gt;
[ -b &amp;quot;$FILE&amp;quot; ] = Block special file&lt;br /&gt;
[ -c &amp;quot;$FILE&amp;quot; ] = Special character file&lt;br /&gt;
[ -d &amp;quot;$FILE&amp;quot; ] = If directory exists&lt;br /&gt;
[ -e &amp;quot;$FILE&amp;quot; ] = Check for file existence, regardless of type (node, directory, socket, etc.)&lt;br /&gt;
[ -f &amp;quot;$FILE&amp;quot; ] = Check for regular file existence not a directory&lt;br /&gt;
[ -G &amp;quot;$FILE&amp;quot; ] = Check if file exists and is owned by effective group ID&lt;br /&gt;
[ -G &amp;quot;$FILE&amp;quot; ] = set-group-id - True if file exists and is set-group-id&lt;br /&gt;
[ -k &amp;quot;$FILE&amp;quot; ] = Sticky bit&lt;br /&gt;
[ -L &amp;quot;$FILE&amp;quot; ] = Symbolic link&lt;br /&gt;
[ -O &amp;quot;$FILE&amp;quot; ] = True if file exists and is owned by the effective user id&lt;br /&gt;
[ -r &amp;quot;$FILE&amp;quot; ] = Check if file is a readable&lt;br /&gt;
[ -S &amp;quot;$FILE&amp;quot; ] = Check if file is socket&lt;br /&gt;
[ -s &amp;quot;$FILE&amp;quot; ] = Check if file is nonzero size&lt;br /&gt;
[ -u &amp;quot;$FILE&amp;quot; ] = Check if file set-user-id bit is set&lt;br /&gt;
[ -w &amp;quot;$FILE&amp;quot; ] = Check if file is writable&lt;br /&gt;
[ -x &amp;quot;$FILE&amp;quot; ] = Check if file is executable&lt;br /&gt;
&lt;br /&gt;
FOLDER=/home/javier/&lt;br /&gt;
[ -d &amp;quot;$FOLDER&amp;quot; ]  = If directory exists&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Common syntax ==&lt;br /&gt;
=== for ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Execute a command for all objects within this folder and all subdirectories&lt;br /&gt;
for i in *; do du -h &amp;quot;$i&amp;quot; ; done&lt;br /&gt;
&lt;br /&gt;
# Execute a command x amount of times based on $i&lt;br /&gt;
for((i=1;i&amp;lt;=5;++i)); do dd if=/dev/zero of=myshare/file-$i bs=1M count=1; done&lt;br /&gt;
&lt;br /&gt;
# Shell script version - Execute a command x amount of times based on $i&lt;br /&gt;
for((i=1;i&amp;lt;=5;++i)) do&lt;br /&gt;
echo $i&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== if ===&lt;br /&gt;
==== Examples ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
FILE=~/todo.txt&lt;br /&gt;
if [ -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 cat &amp;quot;~/todo.txt&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
 echo &amp;quot;You don&#039;t have the file, so you should make it.&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
USER=$(whoami)&lt;br /&gt;
FILE=~/todo.txt&lt;br /&gt;
&lt;br /&gt;
if [ &amp;quot;$USER&amp;quot; != &amp;quot;root&amp;quot; -a -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 echo &amp;quot;You&#039;re a normal user, you do have the file and this is its output:&amp;quot;&lt;br /&gt;
 cat &amp;quot;$FILE&amp;quot;&lt;br /&gt;
elif [ &amp;quot;$USER&amp;quot; != &amp;quot;root&amp;quot; -a ! -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 echo &amp;quot;You&#039;re a normal user, you don&#039;t have the file, so you should make it.&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scripts ==&lt;br /&gt;
=== SSH ===&lt;br /&gt;
==== centos-create-user.sh ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# Execute as root&lt;br /&gt;
# Usage: ./centos-create-user.sh USER&lt;br /&gt;
&lt;br /&gt;
USER=&amp;quot;$1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating user ${USER}&amp;quot;&lt;br /&gt;
useradd -m ${USER} -G wheel&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating authorized keys file and settings rights for ${USER} user&amp;quot;&lt;br /&gt;
mkdir -p /home/${USER}/.ssh&lt;br /&gt;
&lt;br /&gt;
cat &amp;lt;&amp;lt; &#039;EOF&#039; &amp;gt;&amp;gt; /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
# PUT ANY KEYS IN HERE&lt;br /&gt;
# KEY-1&lt;br /&gt;
# KEY-2&lt;br /&gt;
# KEY-3&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
chown -R ${USER}:${USER} /home/${USER}/.ssh&lt;br /&gt;
chmod 700 /home/${USER}/.ssh&lt;br /&gt;
chmod 600 /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
# EOF&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ubuntu-create-user.sh ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# Execute as root&lt;br /&gt;
# Usage: ./ubuntu-create-user.sh USER&lt;br /&gt;
&lt;br /&gt;
USER=&amp;quot;$1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating user ${USER}&amp;quot;&lt;br /&gt;
adduser ${USER} --disabled-password&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Adding ${USER} to the sudo group&amp;quot;&lt;br /&gt;
usermod -aG sudo ${USER}&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating authorized keys file and settings rights for ${USER} user&amp;quot;&lt;br /&gt;
mkdir -p /home/${USER}/.ssh&lt;br /&gt;
&lt;br /&gt;
cat &amp;lt;&amp;lt; &#039;EOF&#039; &amp;gt;&amp;gt; /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
# PUT ANY KEYS IN HERE&lt;br /&gt;
# KEY-1&lt;br /&gt;
# KEY-2&lt;br /&gt;
# KEY-3&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
chown -R ${USER}:${USER} /home/${USER}/.ssh&lt;br /&gt;
chmod 700 /home/${USER}/.ssh&lt;br /&gt;
chmod 600 /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
# EOF&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mail ===&lt;br /&gt;
==== Automatic sendmail ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
#requires: date,sendmail&lt;br /&gt;
function fappend {&lt;br /&gt;
    echo &amp;quot;$2&amp;quot;&amp;gt;&amp;gt;$1;&lt;br /&gt;
}&lt;br /&gt;
YYYYMMDD=`date +%Y%m%d`&lt;br /&gt;
&lt;br /&gt;
# CHANGE THESE&lt;br /&gt;
TOEMAIL=&amp;quot;ADMINISTRATOR@MYDOMAIN.COM&amp;quot;;&lt;br /&gt;
FREMAIL=&amp;quot;FROMNOREPLY@MYDOMAIN.com&amp;quot;;&lt;br /&gt;
SUBJECT=&amp;quot;E-mail Subject&amp;quot;;&lt;br /&gt;
MSGBODY=$(Command);&lt;br /&gt;
&lt;br /&gt;
# DON&#039;T CHANGE ANYTHING BELOW&lt;br /&gt;
TMP=`mktemp`&lt;br /&gt;
&lt;br /&gt;
rm -rf $TMP;&lt;br /&gt;
fappend $TMP &amp;quot;From: $FREMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;To: $TOEMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;Reply-To: $FREMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;Subject: $SUBJECT&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;$MSGBODY&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
cat $TMP|/usr/sbin/sendmail -t;&lt;br /&gt;
rm $TMP;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Scripts&amp;diff=863</id>
		<title>Linux:Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Scripts&amp;diff=863"/>
		<updated>2026-01-02T16:58:37Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* Testing - [] */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet]]&lt;br /&gt;
&lt;br /&gt;
== Pointers ==&lt;br /&gt;
* Lowercase or and Upper+lowercase variables only - all BASH variables use uppercase, so don&#039;t get in their way!&lt;br /&gt;
&lt;br /&gt;
== Template ==&lt;br /&gt;
Script with a single passed variable, description and common exit-protocols.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
#!/usr/bin/env bash&lt;br /&gt;
&lt;br /&gt;
set -o errexit       # Exit on error, do not continue running the script&lt;br /&gt;
set -o nounset       # Trying to access a variable that has not been set generates an error&lt;br /&gt;
set -o pipefail      # When a pipe fails generate an error&lt;br /&gt;
&lt;br /&gt;
if [[ &amp;quot;${1-}&amp;quot; =~ ^-*h(elp)?$ ]] || [[ &amp;quot;$#&amp;quot; -eq 0 ]] ; then&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
    echo &#039;Usage: myscript.sh value1&lt;br /&gt;
&lt;br /&gt;
This is the description of my script.&lt;br /&gt;
&#039;&lt;br /&gt;
    exit&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing - [[]] ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Use the test functionality [[]] to compare values and types, using expressions&lt;br /&gt;
man test&lt;br /&gt;
[[ -d &amp;quot;$MyDirectoryVariable&amp;quot; ]]&lt;br /&gt;
&lt;br /&gt;
# Combine testing with an if statement&lt;br /&gt;
if [[ $(echo &amp;quot;world&amp;quot;) == &amp;quot;world&amp;quot; ]]; then&lt;br /&gt;
    echo -e &amp;quot;all is bad in da world&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
    echo -e &amp;quot;all is good&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
https://stackoverflow.com/questions/638975/how-do-i-tell-if-a-file-does-not-exist-in-bash&lt;br /&gt;
&lt;br /&gt;
FILE=/home/javier/wopper.txt&lt;br /&gt;
[ -b &amp;quot;$FILE&amp;quot; ] = Block special file&lt;br /&gt;
[ -c &amp;quot;$FILE&amp;quot; ] = Special character file&lt;br /&gt;
[ -d &amp;quot;$FILE&amp;quot; ] = If directory exists&lt;br /&gt;
[ -e &amp;quot;$FILE&amp;quot; ] = Check for file existence, regardless of type (node, directory, socket, etc.)&lt;br /&gt;
[ -f &amp;quot;$FILE&amp;quot; ] = Check for regular file existence not a directory&lt;br /&gt;
[ -G &amp;quot;$FILE&amp;quot; ] = Check if file exists and is owned by effective group ID&lt;br /&gt;
[ -G &amp;quot;$FILE&amp;quot; ] = set-group-id - True if file exists and is set-group-id&lt;br /&gt;
[ -k &amp;quot;$FILE&amp;quot; ] = Sticky bit&lt;br /&gt;
[ -L &amp;quot;$FILE&amp;quot; ] = Symbolic link&lt;br /&gt;
[ -O &amp;quot;$FILE&amp;quot; ] = True if file exists and is owned by the effective user id&lt;br /&gt;
[ -r &amp;quot;$FILE&amp;quot; ] = Check if file is a readable&lt;br /&gt;
[ -S &amp;quot;$FILE&amp;quot; ] = Check if file is socket&lt;br /&gt;
[ -s &amp;quot;$FILE&amp;quot; ] = Check if file is nonzero size&lt;br /&gt;
[ -u &amp;quot;$FILE&amp;quot; ] = Check if file set-user-id bit is set&lt;br /&gt;
[ -w &amp;quot;$FILE&amp;quot; ] = Check if file is writable&lt;br /&gt;
[ -x &amp;quot;$FILE&amp;quot; ] = Check if file is executable&lt;br /&gt;
&lt;br /&gt;
FOLDER=/home/javier/&lt;br /&gt;
[ -d &amp;quot;$FOLDER&amp;quot; ]  = If directory exists&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Common syntax ==&lt;br /&gt;
=== for ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Execute a command for all objects within this folder and all subdirectories&lt;br /&gt;
for i in *; do du -h &amp;quot;$i&amp;quot; ; done&lt;br /&gt;
&lt;br /&gt;
# Execute a command x amount of times based on $i&lt;br /&gt;
for((i=1;i&amp;lt;=5;++i)); do dd if=/dev/zero of=myshare/file-$i bs=1M count=1; done&lt;br /&gt;
&lt;br /&gt;
# Shell script version - Execute a command x amount of times based on $i&lt;br /&gt;
for((i=1;i&amp;lt;=5;++i)) do&lt;br /&gt;
echo $i&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== if ===&lt;br /&gt;
==== Examples ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
FILE=~/todo.txt&lt;br /&gt;
if [ -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 cat &amp;quot;~/todo.txt&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
 echo &amp;quot;You don&#039;t have the file, so you should make it.&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
USER=$(whoami)&lt;br /&gt;
FILE=~/todo.txt&lt;br /&gt;
&lt;br /&gt;
if [ &amp;quot;$USER&amp;quot; != &amp;quot;root&amp;quot; -a -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 echo &amp;quot;You&#039;re a normal user, you do have the file and this is its output:&amp;quot;&lt;br /&gt;
 cat &amp;quot;$FILE&amp;quot;&lt;br /&gt;
elif [ &amp;quot;$USER&amp;quot; != &amp;quot;root&amp;quot; -a ! -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 echo &amp;quot;You&#039;re a normal user, you don&#039;t have the file, so you should make it.&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scripts ==&lt;br /&gt;
=== SSH ===&lt;br /&gt;
==== centos-create-user.sh ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# Execute as root&lt;br /&gt;
# Usage: ./centos-create-user.sh USER&lt;br /&gt;
&lt;br /&gt;
USER=&amp;quot;$1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating user ${USER}&amp;quot;&lt;br /&gt;
useradd -m ${USER} -G wheel&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating authorized keys file and settings rights for ${USER} user&amp;quot;&lt;br /&gt;
mkdir -p /home/${USER}/.ssh&lt;br /&gt;
&lt;br /&gt;
cat &amp;lt;&amp;lt; &#039;EOF&#039; &amp;gt;&amp;gt; /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
# PUT ANY KEYS IN HERE&lt;br /&gt;
# KEY-1&lt;br /&gt;
# KEY-2&lt;br /&gt;
# KEY-3&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
chown -R ${USER}:${USER} /home/${USER}/.ssh&lt;br /&gt;
chmod 700 /home/${USER}/.ssh&lt;br /&gt;
chmod 600 /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
# EOF&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ubuntu-create-user.sh ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# Execute as root&lt;br /&gt;
# Usage: ./ubuntu-create-user.sh USER&lt;br /&gt;
&lt;br /&gt;
USER=&amp;quot;$1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating user ${USER}&amp;quot;&lt;br /&gt;
adduser ${USER} --disabled-password&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Adding ${USER} to the sudo group&amp;quot;&lt;br /&gt;
usermod -aG sudo ${USER}&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating authorized keys file and settings rights for ${USER} user&amp;quot;&lt;br /&gt;
mkdir -p /home/${USER}/.ssh&lt;br /&gt;
&lt;br /&gt;
cat &amp;lt;&amp;lt; &#039;EOF&#039; &amp;gt;&amp;gt; /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
# PUT ANY KEYS IN HERE&lt;br /&gt;
# KEY-1&lt;br /&gt;
# KEY-2&lt;br /&gt;
# KEY-3&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
chown -R ${USER}:${USER} /home/${USER}/.ssh&lt;br /&gt;
chmod 700 /home/${USER}/.ssh&lt;br /&gt;
chmod 600 /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
# EOF&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mail ===&lt;br /&gt;
==== Automatic sendmail ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
#requires: date,sendmail&lt;br /&gt;
function fappend {&lt;br /&gt;
    echo &amp;quot;$2&amp;quot;&amp;gt;&amp;gt;$1;&lt;br /&gt;
}&lt;br /&gt;
YYYYMMDD=`date +%Y%m%d`&lt;br /&gt;
&lt;br /&gt;
# CHANGE THESE&lt;br /&gt;
TOEMAIL=&amp;quot;ADMINISTRATOR@MYDOMAIN.COM&amp;quot;;&lt;br /&gt;
FREMAIL=&amp;quot;FROMNOREPLY@MYDOMAIN.com&amp;quot;;&lt;br /&gt;
SUBJECT=&amp;quot;E-mail Subject&amp;quot;;&lt;br /&gt;
MSGBODY=$(Command);&lt;br /&gt;
&lt;br /&gt;
# DON&#039;T CHANGE ANYTHING BELOW&lt;br /&gt;
TMP=`mktemp`&lt;br /&gt;
&lt;br /&gt;
rm -rf $TMP;&lt;br /&gt;
fappend $TMP &amp;quot;From: $FREMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;To: $TOEMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;Reply-To: $FREMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;Subject: $SUBJECT&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;$MSGBODY&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
cat $TMP|/usr/sbin/sendmail -t;&lt;br /&gt;
rm $TMP;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Scripts&amp;diff=862</id>
		<title>Linux:Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Scripts&amp;diff=862"/>
		<updated>2026-01-02T16:55:54Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* Testing - [] */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet]]&lt;br /&gt;
&lt;br /&gt;
== Pointers ==&lt;br /&gt;
* Lowercase or and Upper+lowercase variables only - all BASH variables use uppercase, so don&#039;t get in their way!&lt;br /&gt;
&lt;br /&gt;
== Template ==&lt;br /&gt;
Script with a single passed variable, description and common exit-protocols.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
#!/usr/bin/env bash&lt;br /&gt;
&lt;br /&gt;
set -o errexit       # Exit on error, do not continue running the script&lt;br /&gt;
set -o nounset       # Trying to access a variable that has not been set generates an error&lt;br /&gt;
set -o pipefail      # When a pipe fails generate an error&lt;br /&gt;
&lt;br /&gt;
if [[ &amp;quot;${1-}&amp;quot; =~ ^-*h(elp)?$ ]] || [[ &amp;quot;$#&amp;quot; -eq 0 ]] ; then&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
    echo &#039;Usage: myscript.sh value1&lt;br /&gt;
&lt;br /&gt;
This is the description of my script.&lt;br /&gt;
&#039;&lt;br /&gt;
    exit&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing - [] ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Use the test functionality [] to compare values and types, using expressions&lt;br /&gt;
man test&lt;br /&gt;
if [ -d &amp;quot;$MyDirectoryVariable&amp;quot; ]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
https://stackoverflow.com/questions/638975/how-do-i-tell-if-a-file-does-not-exist-in-bash&lt;br /&gt;
&lt;br /&gt;
FILE=/home/javier/wopper.txt&lt;br /&gt;
[ -b &amp;quot;$FILE&amp;quot; ] = Block special file&lt;br /&gt;
[ -c &amp;quot;$FILE&amp;quot; ] = Special character file&lt;br /&gt;
[ -d &amp;quot;$FILE&amp;quot; ] = If directory exists&lt;br /&gt;
[ -e &amp;quot;$FILE&amp;quot; ] = Check for file existence, regardless of type (node, directory, socket, etc.)&lt;br /&gt;
[ -f &amp;quot;$FILE&amp;quot; ] = Check for regular file existence not a directory&lt;br /&gt;
[ -G &amp;quot;$FILE&amp;quot; ] = Check if file exists and is owned by effective group ID&lt;br /&gt;
[ -G &amp;quot;$FILE&amp;quot; ] = set-group-id - True if file exists and is set-group-id&lt;br /&gt;
[ -k &amp;quot;$FILE&amp;quot; ] = Sticky bit&lt;br /&gt;
[ -L &amp;quot;$FILE&amp;quot; ] = Symbolic link&lt;br /&gt;
[ -O &amp;quot;$FILE&amp;quot; ] = True if file exists and is owned by the effective user id&lt;br /&gt;
[ -r &amp;quot;$FILE&amp;quot; ] = Check if file is a readable&lt;br /&gt;
[ -S &amp;quot;$FILE&amp;quot; ] = Check if file is socket&lt;br /&gt;
[ -s &amp;quot;$FILE&amp;quot; ] = Check if file is nonzero size&lt;br /&gt;
[ -u &amp;quot;$FILE&amp;quot; ] = Check if file set-user-id bit is set&lt;br /&gt;
[ -w &amp;quot;$FILE&amp;quot; ] = Check if file is writable&lt;br /&gt;
[ -x &amp;quot;$FILE&amp;quot; ] = Check if file is executable&lt;br /&gt;
&lt;br /&gt;
FOLDER=/home/javier/&lt;br /&gt;
[ -d &amp;quot;$FOLDER&amp;quot; ]  = If directory exists&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Common syntax ==&lt;br /&gt;
=== for ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Execute a command for all objects within this folder and all subdirectories&lt;br /&gt;
for i in *; do du -h &amp;quot;$i&amp;quot; ; done&lt;br /&gt;
&lt;br /&gt;
# Execute a command x amount of times based on $i&lt;br /&gt;
for((i=1;i&amp;lt;=5;++i)); do dd if=/dev/zero of=myshare/file-$i bs=1M count=1; done&lt;br /&gt;
&lt;br /&gt;
# Shell script version - Execute a command x amount of times based on $i&lt;br /&gt;
for((i=1;i&amp;lt;=5;++i)) do&lt;br /&gt;
echo $i&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== if ===&lt;br /&gt;
==== Examples ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
FILE=~/todo.txt&lt;br /&gt;
if [ -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 cat &amp;quot;~/todo.txt&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
 echo &amp;quot;You don&#039;t have the file, so you should make it.&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
USER=$(whoami)&lt;br /&gt;
FILE=~/todo.txt&lt;br /&gt;
&lt;br /&gt;
if [ &amp;quot;$USER&amp;quot; != &amp;quot;root&amp;quot; -a -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 echo &amp;quot;You&#039;re a normal user, you do have the file and this is its output:&amp;quot;&lt;br /&gt;
 cat &amp;quot;$FILE&amp;quot;&lt;br /&gt;
elif [ &amp;quot;$USER&amp;quot; != &amp;quot;root&amp;quot; -a ! -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 echo &amp;quot;You&#039;re a normal user, you don&#039;t have the file, so you should make it.&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scripts ==&lt;br /&gt;
=== SSH ===&lt;br /&gt;
==== centos-create-user.sh ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# Execute as root&lt;br /&gt;
# Usage: ./centos-create-user.sh USER&lt;br /&gt;
&lt;br /&gt;
USER=&amp;quot;$1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating user ${USER}&amp;quot;&lt;br /&gt;
useradd -m ${USER} -G wheel&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating authorized keys file and settings rights for ${USER} user&amp;quot;&lt;br /&gt;
mkdir -p /home/${USER}/.ssh&lt;br /&gt;
&lt;br /&gt;
cat &amp;lt;&amp;lt; &#039;EOF&#039; &amp;gt;&amp;gt; /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
# PUT ANY KEYS IN HERE&lt;br /&gt;
# KEY-1&lt;br /&gt;
# KEY-2&lt;br /&gt;
# KEY-3&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
chown -R ${USER}:${USER} /home/${USER}/.ssh&lt;br /&gt;
chmod 700 /home/${USER}/.ssh&lt;br /&gt;
chmod 600 /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
# EOF&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ubuntu-create-user.sh ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# Execute as root&lt;br /&gt;
# Usage: ./ubuntu-create-user.sh USER&lt;br /&gt;
&lt;br /&gt;
USER=&amp;quot;$1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating user ${USER}&amp;quot;&lt;br /&gt;
adduser ${USER} --disabled-password&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Adding ${USER} to the sudo group&amp;quot;&lt;br /&gt;
usermod -aG sudo ${USER}&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating authorized keys file and settings rights for ${USER} user&amp;quot;&lt;br /&gt;
mkdir -p /home/${USER}/.ssh&lt;br /&gt;
&lt;br /&gt;
cat &amp;lt;&amp;lt; &#039;EOF&#039; &amp;gt;&amp;gt; /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
# PUT ANY KEYS IN HERE&lt;br /&gt;
# KEY-1&lt;br /&gt;
# KEY-2&lt;br /&gt;
# KEY-3&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
chown -R ${USER}:${USER} /home/${USER}/.ssh&lt;br /&gt;
chmod 700 /home/${USER}/.ssh&lt;br /&gt;
chmod 600 /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
# EOF&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mail ===&lt;br /&gt;
==== Automatic sendmail ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
#requires: date,sendmail&lt;br /&gt;
function fappend {&lt;br /&gt;
    echo &amp;quot;$2&amp;quot;&amp;gt;&amp;gt;$1;&lt;br /&gt;
}&lt;br /&gt;
YYYYMMDD=`date +%Y%m%d`&lt;br /&gt;
&lt;br /&gt;
# CHANGE THESE&lt;br /&gt;
TOEMAIL=&amp;quot;ADMINISTRATOR@MYDOMAIN.COM&amp;quot;;&lt;br /&gt;
FREMAIL=&amp;quot;FROMNOREPLY@MYDOMAIN.com&amp;quot;;&lt;br /&gt;
SUBJECT=&amp;quot;E-mail Subject&amp;quot;;&lt;br /&gt;
MSGBODY=$(Command);&lt;br /&gt;
&lt;br /&gt;
# DON&#039;T CHANGE ANYTHING BELOW&lt;br /&gt;
TMP=`mktemp`&lt;br /&gt;
&lt;br /&gt;
rm -rf $TMP;&lt;br /&gt;
fappend $TMP &amp;quot;From: $FREMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;To: $TOEMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;Reply-To: $FREMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;Subject: $SUBJECT&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;$MSGBODY&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
cat $TMP|/usr/sbin/sendmail -t;&lt;br /&gt;
rm $TMP;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Scripts&amp;diff=861</id>
		<title>Linux:Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Scripts&amp;diff=861"/>
		<updated>2026-01-02T15:08:59Z</updated>

		<summary type="html">&lt;p&gt;Patrick: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet]]&lt;br /&gt;
&lt;br /&gt;
== Pointers ==&lt;br /&gt;
* Lowercase or and Upper+lowercase variables only - all BASH variables use uppercase, so don&#039;t get in their way!&lt;br /&gt;
&lt;br /&gt;
== Template ==&lt;br /&gt;
Script with a single passed variable, description and common exit-protocols.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
#!/usr/bin/env bash&lt;br /&gt;
&lt;br /&gt;
set -o errexit       # Exit on error, do not continue running the script&lt;br /&gt;
set -o nounset       # Trying to access a variable that has not been set generates an error&lt;br /&gt;
set -o pipefail      # When a pipe fails generate an error&lt;br /&gt;
&lt;br /&gt;
if [[ &amp;quot;${1-}&amp;quot; =~ ^-*h(elp)?$ ]] || [[ &amp;quot;$#&amp;quot; -eq 0 ]] ; then&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
    echo &#039;Usage: myscript.sh value1&lt;br /&gt;
&lt;br /&gt;
This is the description of my script.&lt;br /&gt;
&#039;&lt;br /&gt;
    exit&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing - [] ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Use the test functionality [] to compare values and types, using expressions&lt;br /&gt;
man test&lt;br /&gt;
if [ -d &amp;quot;$MyDirectoryVariable&amp;quot; ]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
https://stackoverflow.com/questions/638975/how-do-i-tell-if-a-file-does-not-exist-in-bash&lt;br /&gt;
&lt;br /&gt;
FILE=/home/javier/wopper.txt&lt;br /&gt;
[ -b &amp;quot;$FILE&amp;quot; ] = Block special file&lt;br /&gt;
[ -c &amp;quot;$FILE&amp;quot; ] = Special character file&lt;br /&gt;
[ -d &amp;quot;$FILE&amp;quot; ] = If file exists&lt;br /&gt;
[ -e &amp;quot;$FILE&amp;quot; ] = Check for file existence, regardless of type (node, directory, socket, etc.)&lt;br /&gt;
[ -f &amp;quot;$FILE&amp;quot; ] = Check for regular file existence not a directory&lt;br /&gt;
[ -G &amp;quot;$FILE&amp;quot; ] = Check if file exists and is owned by effective group ID&lt;br /&gt;
[ -G &amp;quot;$FILE&amp;quot; ] = set-group-id - True if file exists and is set-group-id&lt;br /&gt;
[ -k &amp;quot;$FILE&amp;quot; ] = Sticky bit&lt;br /&gt;
[ -L &amp;quot;$FILE&amp;quot; ] = Symbolic link&lt;br /&gt;
[ -O &amp;quot;$FILE&amp;quot; ] = True if file exists and is owned by the effective user id&lt;br /&gt;
[ -r &amp;quot;$FILE&amp;quot; ] = Check if file is a readable&lt;br /&gt;
[ -S &amp;quot;$FILE&amp;quot; ] = Check if file is socket&lt;br /&gt;
[ -s &amp;quot;$FILE&amp;quot; ] = Check if file is nonzero size&lt;br /&gt;
[ -u &amp;quot;$FILE&amp;quot; ] = Check if file set-user-id bit is set&lt;br /&gt;
[ -w &amp;quot;$FILE&amp;quot; ] = Check if file is writable&lt;br /&gt;
[ -x &amp;quot;$FILE&amp;quot; ] = Check if file is executable&lt;br /&gt;
&lt;br /&gt;
FOLDER=/home/javier/&lt;br /&gt;
[ -f &amp;quot;$FOLDER&amp;quot; ]  = If directory exists&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Common syntax ==&lt;br /&gt;
=== for ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Execute a command for all objects within this folder and all subdirectories&lt;br /&gt;
for i in *; do du -h &amp;quot;$i&amp;quot; ; done&lt;br /&gt;
&lt;br /&gt;
# Execute a command x amount of times based on $i&lt;br /&gt;
for((i=1;i&amp;lt;=5;++i)); do dd if=/dev/zero of=myshare/file-$i bs=1M count=1; done&lt;br /&gt;
&lt;br /&gt;
# Shell script version - Execute a command x amount of times based on $i&lt;br /&gt;
for((i=1;i&amp;lt;=5;++i)) do&lt;br /&gt;
echo $i&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== if ===&lt;br /&gt;
==== Examples ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
FILE=~/todo.txt&lt;br /&gt;
if [ -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 cat &amp;quot;~/todo.txt&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
 echo &amp;quot;You don&#039;t have the file, so you should make it.&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
USER=$(whoami)&lt;br /&gt;
FILE=~/todo.txt&lt;br /&gt;
&lt;br /&gt;
if [ &amp;quot;$USER&amp;quot; != &amp;quot;root&amp;quot; -a -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 echo &amp;quot;You&#039;re a normal user, you do have the file and this is its output:&amp;quot;&lt;br /&gt;
 cat &amp;quot;$FILE&amp;quot;&lt;br /&gt;
elif [ &amp;quot;$USER&amp;quot; != &amp;quot;root&amp;quot; -a ! -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 echo &amp;quot;You&#039;re a normal user, you don&#039;t have the file, so you should make it.&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scripts ==&lt;br /&gt;
=== SSH ===&lt;br /&gt;
==== centos-create-user.sh ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# Execute as root&lt;br /&gt;
# Usage: ./centos-create-user.sh USER&lt;br /&gt;
&lt;br /&gt;
USER=&amp;quot;$1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating user ${USER}&amp;quot;&lt;br /&gt;
useradd -m ${USER} -G wheel&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating authorized keys file and settings rights for ${USER} user&amp;quot;&lt;br /&gt;
mkdir -p /home/${USER}/.ssh&lt;br /&gt;
&lt;br /&gt;
cat &amp;lt;&amp;lt; &#039;EOF&#039; &amp;gt;&amp;gt; /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
# PUT ANY KEYS IN HERE&lt;br /&gt;
# KEY-1&lt;br /&gt;
# KEY-2&lt;br /&gt;
# KEY-3&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
chown -R ${USER}:${USER} /home/${USER}/.ssh&lt;br /&gt;
chmod 700 /home/${USER}/.ssh&lt;br /&gt;
chmod 600 /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
# EOF&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ubuntu-create-user.sh ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# Execute as root&lt;br /&gt;
# Usage: ./ubuntu-create-user.sh USER&lt;br /&gt;
&lt;br /&gt;
USER=&amp;quot;$1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating user ${USER}&amp;quot;&lt;br /&gt;
adduser ${USER} --disabled-password&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Adding ${USER} to the sudo group&amp;quot;&lt;br /&gt;
usermod -aG sudo ${USER}&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating authorized keys file and settings rights for ${USER} user&amp;quot;&lt;br /&gt;
mkdir -p /home/${USER}/.ssh&lt;br /&gt;
&lt;br /&gt;
cat &amp;lt;&amp;lt; &#039;EOF&#039; &amp;gt;&amp;gt; /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
# PUT ANY KEYS IN HERE&lt;br /&gt;
# KEY-1&lt;br /&gt;
# KEY-2&lt;br /&gt;
# KEY-3&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
chown -R ${USER}:${USER} /home/${USER}/.ssh&lt;br /&gt;
chmod 700 /home/${USER}/.ssh&lt;br /&gt;
chmod 600 /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
# EOF&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mail ===&lt;br /&gt;
==== Automatic sendmail ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
#requires: date,sendmail&lt;br /&gt;
function fappend {&lt;br /&gt;
    echo &amp;quot;$2&amp;quot;&amp;gt;&amp;gt;$1;&lt;br /&gt;
}&lt;br /&gt;
YYYYMMDD=`date +%Y%m%d`&lt;br /&gt;
&lt;br /&gt;
# CHANGE THESE&lt;br /&gt;
TOEMAIL=&amp;quot;ADMINISTRATOR@MYDOMAIN.COM&amp;quot;;&lt;br /&gt;
FREMAIL=&amp;quot;FROMNOREPLY@MYDOMAIN.com&amp;quot;;&lt;br /&gt;
SUBJECT=&amp;quot;E-mail Subject&amp;quot;;&lt;br /&gt;
MSGBODY=$(Command);&lt;br /&gt;
&lt;br /&gt;
# DON&#039;T CHANGE ANYTHING BELOW&lt;br /&gt;
TMP=`mktemp`&lt;br /&gt;
&lt;br /&gt;
rm -rf $TMP;&lt;br /&gt;
fappend $TMP &amp;quot;From: $FREMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;To: $TOEMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;Reply-To: $FREMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;Subject: $SUBJECT&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;$MSGBODY&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
cat $TMP|/usr/sbin/sendmail -t;&lt;br /&gt;
rm $TMP;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Scripts&amp;diff=860</id>
		<title>Linux:Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Scripts&amp;diff=860"/>
		<updated>2026-01-02T15:08:50Z</updated>

		<summary type="html">&lt;p&gt;Patrick: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet]]&lt;br /&gt;
&lt;br /&gt;
== Pointers ==&lt;br /&gt;
* Lowercaseor or and Upper+lowercase variables only - all BASH variables use uppercase, so don&#039;t get in their way!&lt;br /&gt;
&lt;br /&gt;
== Template ==&lt;br /&gt;
Script with a single passed variable, description and common exit-protocols.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
#!/usr/bin/env bash&lt;br /&gt;
&lt;br /&gt;
set -o errexit       # Exit on error, do not continue running the script&lt;br /&gt;
set -o nounset       # Trying to access a variable that has not been set generates an error&lt;br /&gt;
set -o pipefail      # When a pipe fails generate an error&lt;br /&gt;
&lt;br /&gt;
if [[ &amp;quot;${1-}&amp;quot; =~ ^-*h(elp)?$ ]] || [[ &amp;quot;$#&amp;quot; -eq 0 ]] ; then&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
    echo &#039;Usage: myscript.sh value1&lt;br /&gt;
&lt;br /&gt;
This is the description of my script.&lt;br /&gt;
&#039;&lt;br /&gt;
    exit&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing - [] ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Use the test functionality [] to compare values and types, using expressions&lt;br /&gt;
man test&lt;br /&gt;
if [ -d &amp;quot;$MyDirectoryVariable&amp;quot; ]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
https://stackoverflow.com/questions/638975/how-do-i-tell-if-a-file-does-not-exist-in-bash&lt;br /&gt;
&lt;br /&gt;
FILE=/home/javier/wopper.txt&lt;br /&gt;
[ -b &amp;quot;$FILE&amp;quot; ] = Block special file&lt;br /&gt;
[ -c &amp;quot;$FILE&amp;quot; ] = Special character file&lt;br /&gt;
[ -d &amp;quot;$FILE&amp;quot; ] = If file exists&lt;br /&gt;
[ -e &amp;quot;$FILE&amp;quot; ] = Check for file existence, regardless of type (node, directory, socket, etc.)&lt;br /&gt;
[ -f &amp;quot;$FILE&amp;quot; ] = Check for regular file existence not a directory&lt;br /&gt;
[ -G &amp;quot;$FILE&amp;quot; ] = Check if file exists and is owned by effective group ID&lt;br /&gt;
[ -G &amp;quot;$FILE&amp;quot; ] = set-group-id - True if file exists and is set-group-id&lt;br /&gt;
[ -k &amp;quot;$FILE&amp;quot; ] = Sticky bit&lt;br /&gt;
[ -L &amp;quot;$FILE&amp;quot; ] = Symbolic link&lt;br /&gt;
[ -O &amp;quot;$FILE&amp;quot; ] = True if file exists and is owned by the effective user id&lt;br /&gt;
[ -r &amp;quot;$FILE&amp;quot; ] = Check if file is a readable&lt;br /&gt;
[ -S &amp;quot;$FILE&amp;quot; ] = Check if file is socket&lt;br /&gt;
[ -s &amp;quot;$FILE&amp;quot; ] = Check if file is nonzero size&lt;br /&gt;
[ -u &amp;quot;$FILE&amp;quot; ] = Check if file set-user-id bit is set&lt;br /&gt;
[ -w &amp;quot;$FILE&amp;quot; ] = Check if file is writable&lt;br /&gt;
[ -x &amp;quot;$FILE&amp;quot; ] = Check if file is executable&lt;br /&gt;
&lt;br /&gt;
FOLDER=/home/javier/&lt;br /&gt;
[ -f &amp;quot;$FOLDER&amp;quot; ]  = If directory exists&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Common syntax ==&lt;br /&gt;
=== for ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Execute a command for all objects within this folder and all subdirectories&lt;br /&gt;
for i in *; do du -h &amp;quot;$i&amp;quot; ; done&lt;br /&gt;
&lt;br /&gt;
# Execute a command x amount of times based on $i&lt;br /&gt;
for((i=1;i&amp;lt;=5;++i)); do dd if=/dev/zero of=myshare/file-$i bs=1M count=1; done&lt;br /&gt;
&lt;br /&gt;
# Shell script version - Execute a command x amount of times based on $i&lt;br /&gt;
for((i=1;i&amp;lt;=5;++i)) do&lt;br /&gt;
echo $i&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== if ===&lt;br /&gt;
==== Examples ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
FILE=~/todo.txt&lt;br /&gt;
if [ -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 cat &amp;quot;~/todo.txt&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
 echo &amp;quot;You don&#039;t have the file, so you should make it.&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
USER=$(whoami)&lt;br /&gt;
FILE=~/todo.txt&lt;br /&gt;
&lt;br /&gt;
if [ &amp;quot;$USER&amp;quot; != &amp;quot;root&amp;quot; -a -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 echo &amp;quot;You&#039;re a normal user, you do have the file and this is its output:&amp;quot;&lt;br /&gt;
 cat &amp;quot;$FILE&amp;quot;&lt;br /&gt;
elif [ &amp;quot;$USER&amp;quot; != &amp;quot;root&amp;quot; -a ! -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 echo &amp;quot;You&#039;re a normal user, you don&#039;t have the file, so you should make it.&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scripts ==&lt;br /&gt;
=== SSH ===&lt;br /&gt;
==== centos-create-user.sh ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# Execute as root&lt;br /&gt;
# Usage: ./centos-create-user.sh USER&lt;br /&gt;
&lt;br /&gt;
USER=&amp;quot;$1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating user ${USER}&amp;quot;&lt;br /&gt;
useradd -m ${USER} -G wheel&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating authorized keys file and settings rights for ${USER} user&amp;quot;&lt;br /&gt;
mkdir -p /home/${USER}/.ssh&lt;br /&gt;
&lt;br /&gt;
cat &amp;lt;&amp;lt; &#039;EOF&#039; &amp;gt;&amp;gt; /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
# PUT ANY KEYS IN HERE&lt;br /&gt;
# KEY-1&lt;br /&gt;
# KEY-2&lt;br /&gt;
# KEY-3&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
chown -R ${USER}:${USER} /home/${USER}/.ssh&lt;br /&gt;
chmod 700 /home/${USER}/.ssh&lt;br /&gt;
chmod 600 /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
# EOF&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ubuntu-create-user.sh ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# Execute as root&lt;br /&gt;
# Usage: ./ubuntu-create-user.sh USER&lt;br /&gt;
&lt;br /&gt;
USER=&amp;quot;$1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating user ${USER}&amp;quot;&lt;br /&gt;
adduser ${USER} --disabled-password&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Adding ${USER} to the sudo group&amp;quot;&lt;br /&gt;
usermod -aG sudo ${USER}&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating authorized keys file and settings rights for ${USER} user&amp;quot;&lt;br /&gt;
mkdir -p /home/${USER}/.ssh&lt;br /&gt;
&lt;br /&gt;
cat &amp;lt;&amp;lt; &#039;EOF&#039; &amp;gt;&amp;gt; /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
# PUT ANY KEYS IN HERE&lt;br /&gt;
# KEY-1&lt;br /&gt;
# KEY-2&lt;br /&gt;
# KEY-3&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
chown -R ${USER}:${USER} /home/${USER}/.ssh&lt;br /&gt;
chmod 700 /home/${USER}/.ssh&lt;br /&gt;
chmod 600 /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
# EOF&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mail ===&lt;br /&gt;
==== Automatic sendmail ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
#requires: date,sendmail&lt;br /&gt;
function fappend {&lt;br /&gt;
    echo &amp;quot;$2&amp;quot;&amp;gt;&amp;gt;$1;&lt;br /&gt;
}&lt;br /&gt;
YYYYMMDD=`date +%Y%m%d`&lt;br /&gt;
&lt;br /&gt;
# CHANGE THESE&lt;br /&gt;
TOEMAIL=&amp;quot;ADMINISTRATOR@MYDOMAIN.COM&amp;quot;;&lt;br /&gt;
FREMAIL=&amp;quot;FROMNOREPLY@MYDOMAIN.com&amp;quot;;&lt;br /&gt;
SUBJECT=&amp;quot;E-mail Subject&amp;quot;;&lt;br /&gt;
MSGBODY=$(Command);&lt;br /&gt;
&lt;br /&gt;
# DON&#039;T CHANGE ANYTHING BELOW&lt;br /&gt;
TMP=`mktemp`&lt;br /&gt;
&lt;br /&gt;
rm -rf $TMP;&lt;br /&gt;
fappend $TMP &amp;quot;From: $FREMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;To: $TOEMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;Reply-To: $FREMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;Subject: $SUBJECT&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;$MSGBODY&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
cat $TMP|/usr/sbin/sendmail -t;&lt;br /&gt;
rm $TMP;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Scripts&amp;diff=859</id>
		<title>Linux:Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Scripts&amp;diff=859"/>
		<updated>2026-01-02T12:59:35Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* Template */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet]]&lt;br /&gt;
&lt;br /&gt;
== Template ==&lt;br /&gt;
Script with a single passed variable, description and common exit-protocols.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
#!/usr/bin/env bash&lt;br /&gt;
&lt;br /&gt;
set -o errexit       # Exit on error, do not continue running the script&lt;br /&gt;
set -o nounset       # Trying to access a variable that has not been set generates an error&lt;br /&gt;
set -o pipefail      # When a pipe fails generate an error&lt;br /&gt;
&lt;br /&gt;
if [[ &amp;quot;${1-}&amp;quot; =~ ^-*h(elp)?$ ]] || [[ &amp;quot;$#&amp;quot; -eq 0 ]] ; then&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
    echo &#039;Usage: myscript.sh value1&lt;br /&gt;
&lt;br /&gt;
This is the description of my script.&lt;br /&gt;
&#039;&lt;br /&gt;
    exit&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing - [] ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Use the test functionality [] to compare values and types, using expressions&lt;br /&gt;
man test&lt;br /&gt;
if [ -d &amp;quot;$MyDirectoryVariable&amp;quot; ]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
https://stackoverflow.com/questions/638975/how-do-i-tell-if-a-file-does-not-exist-in-bash&lt;br /&gt;
&lt;br /&gt;
FILE=/home/javier/wopper.txt&lt;br /&gt;
[ -b &amp;quot;$FILE&amp;quot; ] = Block special file&lt;br /&gt;
[ -c &amp;quot;$FILE&amp;quot; ] = Special character file&lt;br /&gt;
[ -d &amp;quot;$FILE&amp;quot; ] = If file exists&lt;br /&gt;
[ -e &amp;quot;$FILE&amp;quot; ] = Check for file existence, regardless of type (node, directory, socket, etc.)&lt;br /&gt;
[ -f &amp;quot;$FILE&amp;quot; ] = Check for regular file existence not a directory&lt;br /&gt;
[ -G &amp;quot;$FILE&amp;quot; ] = Check if file exists and is owned by effective group ID&lt;br /&gt;
[ -G &amp;quot;$FILE&amp;quot; ] = set-group-id - True if file exists and is set-group-id&lt;br /&gt;
[ -k &amp;quot;$FILE&amp;quot; ] = Sticky bit&lt;br /&gt;
[ -L &amp;quot;$FILE&amp;quot; ] = Symbolic link&lt;br /&gt;
[ -O &amp;quot;$FILE&amp;quot; ] = True if file exists and is owned by the effective user id&lt;br /&gt;
[ -r &amp;quot;$FILE&amp;quot; ] = Check if file is a readable&lt;br /&gt;
[ -S &amp;quot;$FILE&amp;quot; ] = Check if file is socket&lt;br /&gt;
[ -s &amp;quot;$FILE&amp;quot; ] = Check if file is nonzero size&lt;br /&gt;
[ -u &amp;quot;$FILE&amp;quot; ] = Check if file set-user-id bit is set&lt;br /&gt;
[ -w &amp;quot;$FILE&amp;quot; ] = Check if file is writable&lt;br /&gt;
[ -x &amp;quot;$FILE&amp;quot; ] = Check if file is executable&lt;br /&gt;
&lt;br /&gt;
FOLDER=/home/javier/&lt;br /&gt;
[ -f &amp;quot;$FOLDER&amp;quot; ]  = If directory exists&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Common syntax ==&lt;br /&gt;
=== for ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Execute a command for all objects within this folder and all subdirectories&lt;br /&gt;
for i in *; do du -h &amp;quot;$i&amp;quot; ; done&lt;br /&gt;
&lt;br /&gt;
# Execute a command x amount of times based on $i&lt;br /&gt;
for((i=1;i&amp;lt;=5;++i)); do dd if=/dev/zero of=myshare/file-$i bs=1M count=1; done&lt;br /&gt;
&lt;br /&gt;
# Shell script version - Execute a command x amount of times based on $i&lt;br /&gt;
for((i=1;i&amp;lt;=5;++i)) do&lt;br /&gt;
echo $i&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== if ===&lt;br /&gt;
==== Examples ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
FILE=~/todo.txt&lt;br /&gt;
if [ -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 cat &amp;quot;~/todo.txt&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
 echo &amp;quot;You don&#039;t have the file, so you should make it.&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
USER=$(whoami)&lt;br /&gt;
FILE=~/todo.txt&lt;br /&gt;
&lt;br /&gt;
if [ &amp;quot;$USER&amp;quot; != &amp;quot;root&amp;quot; -a -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 echo &amp;quot;You&#039;re a normal user, you do have the file and this is its output:&amp;quot;&lt;br /&gt;
 cat &amp;quot;$FILE&amp;quot;&lt;br /&gt;
elif [ &amp;quot;$USER&amp;quot; != &amp;quot;root&amp;quot; -a ! -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 echo &amp;quot;You&#039;re a normal user, you don&#039;t have the file, so you should make it.&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scripts ==&lt;br /&gt;
=== SSH ===&lt;br /&gt;
==== centos-create-user.sh ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# Execute as root&lt;br /&gt;
# Usage: ./centos-create-user.sh USER&lt;br /&gt;
&lt;br /&gt;
USER=&amp;quot;$1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating user ${USER}&amp;quot;&lt;br /&gt;
useradd -m ${USER} -G wheel&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating authorized keys file and settings rights for ${USER} user&amp;quot;&lt;br /&gt;
mkdir -p /home/${USER}/.ssh&lt;br /&gt;
&lt;br /&gt;
cat &amp;lt;&amp;lt; &#039;EOF&#039; &amp;gt;&amp;gt; /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
# PUT ANY KEYS IN HERE&lt;br /&gt;
# KEY-1&lt;br /&gt;
# KEY-2&lt;br /&gt;
# KEY-3&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
chown -R ${USER}:${USER} /home/${USER}/.ssh&lt;br /&gt;
chmod 700 /home/${USER}/.ssh&lt;br /&gt;
chmod 600 /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
# EOF&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ubuntu-create-user.sh ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# Execute as root&lt;br /&gt;
# Usage: ./ubuntu-create-user.sh USER&lt;br /&gt;
&lt;br /&gt;
USER=&amp;quot;$1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating user ${USER}&amp;quot;&lt;br /&gt;
adduser ${USER} --disabled-password&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Adding ${USER} to the sudo group&amp;quot;&lt;br /&gt;
usermod -aG sudo ${USER}&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating authorized keys file and settings rights for ${USER} user&amp;quot;&lt;br /&gt;
mkdir -p /home/${USER}/.ssh&lt;br /&gt;
&lt;br /&gt;
cat &amp;lt;&amp;lt; &#039;EOF&#039; &amp;gt;&amp;gt; /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
# PUT ANY KEYS IN HERE&lt;br /&gt;
# KEY-1&lt;br /&gt;
# KEY-2&lt;br /&gt;
# KEY-3&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
chown -R ${USER}:${USER} /home/${USER}/.ssh&lt;br /&gt;
chmod 700 /home/${USER}/.ssh&lt;br /&gt;
chmod 600 /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
# EOF&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mail ===&lt;br /&gt;
==== Automatic sendmail ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
#requires: date,sendmail&lt;br /&gt;
function fappend {&lt;br /&gt;
    echo &amp;quot;$2&amp;quot;&amp;gt;&amp;gt;$1;&lt;br /&gt;
}&lt;br /&gt;
YYYYMMDD=`date +%Y%m%d`&lt;br /&gt;
&lt;br /&gt;
# CHANGE THESE&lt;br /&gt;
TOEMAIL=&amp;quot;ADMINISTRATOR@MYDOMAIN.COM&amp;quot;;&lt;br /&gt;
FREMAIL=&amp;quot;FROMNOREPLY@MYDOMAIN.com&amp;quot;;&lt;br /&gt;
SUBJECT=&amp;quot;E-mail Subject&amp;quot;;&lt;br /&gt;
MSGBODY=$(Command);&lt;br /&gt;
&lt;br /&gt;
# DON&#039;T CHANGE ANYTHING BELOW&lt;br /&gt;
TMP=`mktemp`&lt;br /&gt;
&lt;br /&gt;
rm -rf $TMP;&lt;br /&gt;
fappend $TMP &amp;quot;From: $FREMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;To: $TOEMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;Reply-To: $FREMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;Subject: $SUBJECT&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;$MSGBODY&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
cat $TMP|/usr/sbin/sendmail -t;&lt;br /&gt;
rm $TMP;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Scripts&amp;diff=858</id>
		<title>Linux:Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Scripts&amp;diff=858"/>
		<updated>2026-01-02T12:59:15Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* Template */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet]]&lt;br /&gt;
&lt;br /&gt;
== Template ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
#!/usr/bin/env bash&lt;br /&gt;
&lt;br /&gt;
set -o errexit       # Exit on error, do not continue running the script&lt;br /&gt;
set -o nounset       # Trying to access a variable that has not been set generates an error&lt;br /&gt;
set -o pipefail      # When a pipe fails generate an error&lt;br /&gt;
&lt;br /&gt;
if [[ &amp;quot;${1-}&amp;quot; =~ ^-*h(elp)?$ ]] || [[ &amp;quot;$#&amp;quot; -eq 0 ]] ; then&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
    echo &#039;Usage: myscript.sh value1&lt;br /&gt;
&lt;br /&gt;
This is the description of my script.&lt;br /&gt;
&#039;&lt;br /&gt;
    exit&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing - [] ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Use the test functionality [] to compare values and types, using expressions&lt;br /&gt;
man test&lt;br /&gt;
if [ -d &amp;quot;$MyDirectoryVariable&amp;quot; ]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
https://stackoverflow.com/questions/638975/how-do-i-tell-if-a-file-does-not-exist-in-bash&lt;br /&gt;
&lt;br /&gt;
FILE=/home/javier/wopper.txt&lt;br /&gt;
[ -b &amp;quot;$FILE&amp;quot; ] = Block special file&lt;br /&gt;
[ -c &amp;quot;$FILE&amp;quot; ] = Special character file&lt;br /&gt;
[ -d &amp;quot;$FILE&amp;quot; ] = If file exists&lt;br /&gt;
[ -e &amp;quot;$FILE&amp;quot; ] = Check for file existence, regardless of type (node, directory, socket, etc.)&lt;br /&gt;
[ -f &amp;quot;$FILE&amp;quot; ] = Check for regular file existence not a directory&lt;br /&gt;
[ -G &amp;quot;$FILE&amp;quot; ] = Check if file exists and is owned by effective group ID&lt;br /&gt;
[ -G &amp;quot;$FILE&amp;quot; ] = set-group-id - True if file exists and is set-group-id&lt;br /&gt;
[ -k &amp;quot;$FILE&amp;quot; ] = Sticky bit&lt;br /&gt;
[ -L &amp;quot;$FILE&amp;quot; ] = Symbolic link&lt;br /&gt;
[ -O &amp;quot;$FILE&amp;quot; ] = True if file exists and is owned by the effective user id&lt;br /&gt;
[ -r &amp;quot;$FILE&amp;quot; ] = Check if file is a readable&lt;br /&gt;
[ -S &amp;quot;$FILE&amp;quot; ] = Check if file is socket&lt;br /&gt;
[ -s &amp;quot;$FILE&amp;quot; ] = Check if file is nonzero size&lt;br /&gt;
[ -u &amp;quot;$FILE&amp;quot; ] = Check if file set-user-id bit is set&lt;br /&gt;
[ -w &amp;quot;$FILE&amp;quot; ] = Check if file is writable&lt;br /&gt;
[ -x &amp;quot;$FILE&amp;quot; ] = Check if file is executable&lt;br /&gt;
&lt;br /&gt;
FOLDER=/home/javier/&lt;br /&gt;
[ -f &amp;quot;$FOLDER&amp;quot; ]  = If directory exists&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Common syntax ==&lt;br /&gt;
=== for ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Execute a command for all objects within this folder and all subdirectories&lt;br /&gt;
for i in *; do du -h &amp;quot;$i&amp;quot; ; done&lt;br /&gt;
&lt;br /&gt;
# Execute a command x amount of times based on $i&lt;br /&gt;
for((i=1;i&amp;lt;=5;++i)); do dd if=/dev/zero of=myshare/file-$i bs=1M count=1; done&lt;br /&gt;
&lt;br /&gt;
# Shell script version - Execute a command x amount of times based on $i&lt;br /&gt;
for((i=1;i&amp;lt;=5;++i)) do&lt;br /&gt;
echo $i&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== if ===&lt;br /&gt;
==== Examples ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
FILE=~/todo.txt&lt;br /&gt;
if [ -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 cat &amp;quot;~/todo.txt&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
 echo &amp;quot;You don&#039;t have the file, so you should make it.&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
USER=$(whoami)&lt;br /&gt;
FILE=~/todo.txt&lt;br /&gt;
&lt;br /&gt;
if [ &amp;quot;$USER&amp;quot; != &amp;quot;root&amp;quot; -a -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 echo &amp;quot;You&#039;re a normal user, you do have the file and this is its output:&amp;quot;&lt;br /&gt;
 cat &amp;quot;$FILE&amp;quot;&lt;br /&gt;
elif [ &amp;quot;$USER&amp;quot; != &amp;quot;root&amp;quot; -a ! -f &amp;quot;$FILE&amp;quot; ]; then&lt;br /&gt;
 echo &amp;quot;You&#039;re a normal user, you don&#039;t have the file, so you should make it.&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scripts ==&lt;br /&gt;
=== SSH ===&lt;br /&gt;
==== centos-create-user.sh ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# Execute as root&lt;br /&gt;
# Usage: ./centos-create-user.sh USER&lt;br /&gt;
&lt;br /&gt;
USER=&amp;quot;$1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating user ${USER}&amp;quot;&lt;br /&gt;
useradd -m ${USER} -G wheel&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating authorized keys file and settings rights for ${USER} user&amp;quot;&lt;br /&gt;
mkdir -p /home/${USER}/.ssh&lt;br /&gt;
&lt;br /&gt;
cat &amp;lt;&amp;lt; &#039;EOF&#039; &amp;gt;&amp;gt; /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
# PUT ANY KEYS IN HERE&lt;br /&gt;
# KEY-1&lt;br /&gt;
# KEY-2&lt;br /&gt;
# KEY-3&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
chown -R ${USER}:${USER} /home/${USER}/.ssh&lt;br /&gt;
chmod 700 /home/${USER}/.ssh&lt;br /&gt;
chmod 600 /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
# EOF&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ubuntu-create-user.sh ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# Execute as root&lt;br /&gt;
# Usage: ./ubuntu-create-user.sh USER&lt;br /&gt;
&lt;br /&gt;
USER=&amp;quot;$1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating user ${USER}&amp;quot;&lt;br /&gt;
adduser ${USER} --disabled-password&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Adding ${USER} to the sudo group&amp;quot;&lt;br /&gt;
usermod -aG sudo ${USER}&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating authorized keys file and settings rights for ${USER} user&amp;quot;&lt;br /&gt;
mkdir -p /home/${USER}/.ssh&lt;br /&gt;
&lt;br /&gt;
cat &amp;lt;&amp;lt; &#039;EOF&#039; &amp;gt;&amp;gt; /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
# PUT ANY KEYS IN HERE&lt;br /&gt;
# KEY-1&lt;br /&gt;
# KEY-2&lt;br /&gt;
# KEY-3&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
chown -R ${USER}:${USER} /home/${USER}/.ssh&lt;br /&gt;
chmod 700 /home/${USER}/.ssh&lt;br /&gt;
chmod 600 /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
# EOF&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mail ===&lt;br /&gt;
==== Automatic sendmail ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
#requires: date,sendmail&lt;br /&gt;
function fappend {&lt;br /&gt;
    echo &amp;quot;$2&amp;quot;&amp;gt;&amp;gt;$1;&lt;br /&gt;
}&lt;br /&gt;
YYYYMMDD=`date +%Y%m%d`&lt;br /&gt;
&lt;br /&gt;
# CHANGE THESE&lt;br /&gt;
TOEMAIL=&amp;quot;ADMINISTRATOR@MYDOMAIN.COM&amp;quot;;&lt;br /&gt;
FREMAIL=&amp;quot;FROMNOREPLY@MYDOMAIN.com&amp;quot;;&lt;br /&gt;
SUBJECT=&amp;quot;E-mail Subject&amp;quot;;&lt;br /&gt;
MSGBODY=$(Command);&lt;br /&gt;
&lt;br /&gt;
# DON&#039;T CHANGE ANYTHING BELOW&lt;br /&gt;
TMP=`mktemp`&lt;br /&gt;
&lt;br /&gt;
rm -rf $TMP;&lt;br /&gt;
fappend $TMP &amp;quot;From: $FREMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;To: $TOEMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;Reply-To: $FREMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;Subject: $SUBJECT&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;$MSGBODY&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
cat $TMP|/usr/sbin/sendmail -t;&lt;br /&gt;
rm $TMP;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Services&amp;diff=857</id>
		<title>Linux:Services</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Services&amp;diff=857"/>
		<updated>2025-11-20T15:18:02Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* smbd / Samba / CIFS */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet|Cheatsheets]]&lt;br /&gt;
&lt;br /&gt;
== Services ==&lt;br /&gt;
&amp;lt;section begin=&amp;quot;linuxservices&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Common ===&lt;br /&gt;
==== systemctl ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all services that are running or exited&lt;br /&gt;
systemctl&lt;br /&gt;
&lt;br /&gt;
# List all services, running or otherwise&lt;br /&gt;
systemctl --all&lt;br /&gt;
&lt;br /&gt;
# List all failed services&lt;br /&gt;
systemctl --state=failed&lt;br /&gt;
&lt;br /&gt;
# Reset the failed service &amp;quot;nginx&amp;quot;&lt;br /&gt;
systemctl reset-failed nginx&lt;br /&gt;
&lt;br /&gt;
# View the status of the &amp;quot;nfs-server&amp;quot; service&lt;br /&gt;
systemctl status nfs-server&lt;br /&gt;
&lt;br /&gt;
# Output the config file of &amp;quot;rsyslog&amp;quot; to the shell&lt;br /&gt;
systemctl cat rsyslog&lt;br /&gt;
&lt;br /&gt;
# Restart the &amp;quot;sshd&amp;quot; service, terminating established connections and re-parsing the configuration&lt;br /&gt;
systemctl restart sshd&lt;br /&gt;
&lt;br /&gt;
# Reload the &amp;quot;nginx&amp;quot; service so that it only re-parses the configuration&lt;br /&gt;
systemctl reload nginx&lt;br /&gt;
&lt;br /&gt;
# Stop the &amp;quot;nfs-ganesha&amp;quot; service so that it stops being run&lt;br /&gt;
systemctl stop nfs-ganesha&lt;br /&gt;
&lt;br /&gt;
# Start the &amp;quot;nfs-ganesha&amp;quot; service so that it starts being run again&lt;br /&gt;
systemctl start nfs-ganesha&lt;br /&gt;
&lt;br /&gt;
# Disable the &amp;quot;mariadb&amp;quot; service so that it doesn&#039;t start after the next boot&lt;br /&gt;
systemctl disable mariadb&lt;br /&gt;
&lt;br /&gt;
# Enable the &amp;quot;mariadb&amp;quot; service so that it starts after the next boot.&lt;br /&gt;
systemctl enable mariadb&lt;br /&gt;
&lt;br /&gt;
# Check the logs for all failed services&lt;br /&gt;
for i in $(systemctl --state=failed | head -n -4 | tail -n +2 | awk &#039;{print $1}&#039;); do systemctl --no-pager status &amp;quot;$i&amp;quot;; done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== NTP ===&lt;br /&gt;
==== Timedatectl ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show the current status of timedatectl&lt;br /&gt;
timedatectl&lt;br /&gt;
&lt;br /&gt;
# List available timezones&lt;br /&gt;
timedatectl list-timezones&lt;br /&gt;
&lt;br /&gt;
# Set the timezone to Amsterdam&lt;br /&gt;
timedatectl set-timezone Europe/Amsterdam&lt;br /&gt;
&lt;br /&gt;
# Show verbose sync information&lt;br /&gt;
timedatectl timesync-status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SNMP ===&lt;br /&gt;
==== V3 client installation ====&lt;br /&gt;
* https://kifarunix.com/quick-way-to-install-and-configure-snmp-on-ubuntu-20-04/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
apt install snmpd snmp libsnmp-dev&lt;br /&gt;
cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.bak&lt;br /&gt;
systemctl stop snmpd&lt;br /&gt;
net-snmp-create-v3-user -ro -X &amp;lt;CRYPTO-PASSWORD&amp;gt; -a SHA -X &amp;lt;PASSWORD&amp;gt; -x AES &amp;lt;USERNAME&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/snmp/snmpd.conf&lt;br /&gt;
sysLocation    NL;Zuid-Holland;Rotterdam, 78 MyStreet;2nd Floor;Server Room;Rack&lt;br /&gt;
sysContact     Me &amp;lt;me@example.org&amp;gt;&lt;br /&gt;
agentaddress   192.168.0.10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
systemctl start snmpd&lt;br /&gt;
systemctl enable snmpd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Test&lt;br /&gt;
snmpwalk -v3 -a SHA -A &amp;quot;AUTHENTICATION PASSWORD&amp;quot; -x AES -X &amp;quot;CRYPTO PASSWORD&amp;quot; -l authPriv -u &amp;quot;MYUSER&amp;quot; localhost | head&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CTDB  ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Verify CTDB cluster status&lt;br /&gt;
ctdb status&lt;br /&gt;
&lt;br /&gt;
# Show the allocated IP addresses and to which nodes they&#039;re bound&lt;br /&gt;
ctdb ip&lt;br /&gt;
&lt;br /&gt;
# See the status of all CTDB-scripts&lt;br /&gt;
ctdb scriptstatus&lt;br /&gt;
ctdb event status&lt;br /&gt;
&lt;br /&gt;
# Show the time of the last failover the duration it took to recover&lt;br /&gt;
ctdb uptime&lt;br /&gt;
&lt;br /&gt;
# See various statistics and data&lt;br /&gt;
ctdb statistics&lt;br /&gt;
&lt;br /&gt;
# Use the onnode command to execute a command on all cluster nodes&lt;br /&gt;
onnode all ctdb status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Stop a ctdb cluster member&lt;br /&gt;
ctdb stop&lt;br /&gt;
&lt;br /&gt;
# Start a stopped ctdb cluster member&lt;br /&gt;
ctdb continue&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Firewalls ===&lt;br /&gt;
==== UFW ====&lt;br /&gt;
===== Checks =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show summary of UFW status&lt;br /&gt;
ufw status&lt;br /&gt;
&lt;br /&gt;
# Show verbose UFW status&lt;br /&gt;
ufw status verbose&lt;br /&gt;
&lt;br /&gt;
# Show UFW rules numbered&lt;br /&gt;
ufw status numbered&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Commands =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Allow access from a specific IP to a port and add a comment that show in the status&lt;br /&gt;
ufw allow from 10.0.0.253 to any port 22 proto tcp comment &#039;Allow SSH access from XYZ location&#039;&lt;br /&gt;
&lt;br /&gt;
# Delete numbered Firewall rule 56&lt;br /&gt;
ufw delete 56&lt;br /&gt;
&lt;br /&gt;
# Disable UFW logging (prevent syslog spam)&lt;br /&gt;
ufw logging off&lt;br /&gt;
&lt;br /&gt;
# Set UFW logging back to the default&lt;br /&gt;
ufw logging low&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Firewalld ====&lt;br /&gt;
===== SNMP access =====&lt;br /&gt;
* https://unix.stackexchange.com/questions/214388/how-to-let-the-firewall-of-rhel7-the-snmp-connection-passing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/firewalld/services/snmp.xml&lt;br /&gt;
&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;service&amp;gt;&lt;br /&gt;
  &amp;lt;short&amp;gt;SNMP&amp;lt;/short&amp;gt;&lt;br /&gt;
  &amp;lt;description&amp;gt;SNMP protocol&amp;lt;/description&amp;gt;&lt;br /&gt;
  &amp;lt;port protocol=&amp;quot;udp&amp;quot; port=&amp;quot;161&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/service&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
firewall-cmd --zone=public --add-service snmp --permanent&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Firewall-cmd =====&lt;br /&gt;
====== Checks ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all available commands&lt;br /&gt;
firewall-cmd -h&lt;br /&gt;
&lt;br /&gt;
# Check the configuration file of the firewall for errors&lt;br /&gt;
firewall-cmd --check-config&lt;br /&gt;
&lt;br /&gt;
# Display the current state of firewall-cmd (running/shutdown)&lt;br /&gt;
firewall-cmd --state&lt;br /&gt;
&lt;br /&gt;
# Display all available zones&lt;br /&gt;
firewall-cmd --get-zones&lt;br /&gt;
&lt;br /&gt;
# List all whitelisted services&lt;br /&gt;
firewall-cmd --list-services&lt;br /&gt;
&lt;br /&gt;
# List all services you can potentially enable&lt;br /&gt;
firewall-cmd --get-services&lt;br /&gt;
&lt;br /&gt;
# List all added or enabled services and ports in more detail&lt;br /&gt;
firewall-cmd --list-all&lt;br /&gt;
&lt;br /&gt;
# List verbose information for all zones&lt;br /&gt;
firewall-cmd --list-all-zones&lt;br /&gt;
&lt;br /&gt;
# List verbose information for the public zone&lt;br /&gt;
firewall-cmd --list-all --zone=public&lt;br /&gt;
&lt;br /&gt;
# See what port(s) are associated with the dns service&lt;br /&gt;
firewall-cmd --info-service dns&lt;br /&gt;
&lt;br /&gt;
# List all opened ports&lt;br /&gt;
firewall-cmd --list-ports&lt;br /&gt;
&lt;br /&gt;
# List kernel ruleset generated for nftables(?)&lt;br /&gt;
nft list ruleset&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Commands ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reload the firewall&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Whitelist the dns service, persistently even after reboot&lt;br /&gt;
firewall-cmd --add-service=dns ; sudo firewall-cmd --runtime-to-permanent; firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Whitelist the http service, persistently even after reboot&lt;br /&gt;
firewall-cmd --add-service=http ; sudo firewall-cmd --runtime-to-permanent; firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Remove the http service from the whitelist&lt;br /&gt;
firewall-cmd --remove-service=http&lt;br /&gt;
&lt;br /&gt;
# Add port 1234 (tcp) to the whitelist&lt;br /&gt;
firewall-cmd --add-port=1234/tcp&lt;br /&gt;
&lt;br /&gt;
# Remove port 1234 (tcp) from the whitelist&lt;br /&gt;
firewall-cmd --remove-port=1234/tcp&lt;br /&gt;
&lt;br /&gt;
# Add port 2345 (udp) to the whitelist in zone external&lt;br /&gt;
firewall-cmd --zone=external --add-port=2345/udp&lt;br /&gt;
&lt;br /&gt;
# Remove port 2345 (udp) from the whitelist for zone external&lt;br /&gt;
firewall-cmd --zone=external --add-port=2345/udp&lt;br /&gt;
&lt;br /&gt;
# Add current configuration to configuration permanently&lt;br /&gt;
firewall-cmd –runtime-to-permanent&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;DANGEROUS&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# SHUT IT DOWN DOC - DROP ALL PACKETS AND EXPIRE EXISTING CONNECTIONS&lt;br /&gt;
firewall-cmd --panic-on&lt;br /&gt;
&lt;br /&gt;
# ACCEPT PACKETS AGAIN&lt;br /&gt;
firewall-cmd --panic-off&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== CSF ====&lt;br /&gt;
ConfigServer Security and Firewall&lt;br /&gt;
&lt;br /&gt;
===== General =====&lt;br /&gt;
* Common configuration: /etc/csf/csf.conf &lt;br /&gt;
* Blacklist: /etc/csf/csf.deny &lt;br /&gt;
* Whitelist: /etc/csf/csf.allow &lt;br /&gt;
&lt;br /&gt;
===== Installation =====&lt;br /&gt;
From the official instructions: https://download.configserver.com/csf/install.txt&lt;br /&gt;
&lt;br /&gt;
====== Prerequisites ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Perl Modules&lt;br /&gt;
============&lt;br /&gt;
While most should be installed on a standard perl installation the following&lt;br /&gt;
may need to be installed manually:&lt;br /&gt;
&lt;br /&gt;
# On rpm based systems:&lt;br /&gt;
yum install perl-libwww-perl.noarch perl-LWP-Protocol-https.noarch perl-GDGraph&lt;br /&gt;
&lt;br /&gt;
# On APT based systems:&lt;br /&gt;
apt-get install libwww-perl liblwp-protocol-https-perl libgd-graph-perl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Install ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cd /usr/src&lt;br /&gt;
rm -fv csf.tgz&lt;br /&gt;
wget https://download.configserver.com/csf.tgz&lt;br /&gt;
tar -xzf csf.tgz&lt;br /&gt;
cd csf&lt;br /&gt;
sh install.sh&lt;br /&gt;
&lt;br /&gt;
# Next, test whether you have the required iptables modules:&lt;br /&gt;
perl /usr/local/csf/bin/csftest.pl&lt;br /&gt;
&lt;br /&gt;
# Don&#039;t worry if you cannot run all the features, so long as the script doesn&#039;t report any FATAL errors&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Checks =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check the running status of csf&lt;br /&gt;
csf status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Commands =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Commit config changes by restarting csf&lt;br /&gt;
csf -r&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== csf.conf =====&lt;br /&gt;
Some common changes within the configuration file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Set testing to 0 when your CSF configuration is &#039;production&#039; ready&lt;br /&gt;
TESTING = &amp;quot;0&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow access to any service you&#039;re hosting locally, for example https&lt;br /&gt;
TCP_IN = &amp;quot;443&amp;quot;&lt;br /&gt;
UDP_IN = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow all outwards HTTP/HTTPS traffic so you can yum/apt update&lt;br /&gt;
TCP_OUT = &amp;quot;80,443&amp;quot; &lt;br /&gt;
&lt;br /&gt;
# Allow outgoing traceroute&lt;br /&gt;
UDP_OUT = &amp;quot;33434:33523&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow your server to be pinged&lt;br /&gt;
ICMP_IN = &amp;quot;0&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Formatting =====&lt;br /&gt;
The varying styles of formatting used in allow.conf&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Allow anything relating to the following IPs/ranges&lt;br /&gt;
192.168.10.0/24 # Our application breaks without this range&lt;br /&gt;
192.168.1.1 # Our gateway or something&lt;br /&gt;
&lt;br /&gt;
# Detailed entries based on Transport protocol, direction, Application protocol and IP&lt;br /&gt;
tcp:in:d=22:s=7.7.7.7 # SSH access from our VPN&lt;br /&gt;
udp:in:d=161:s=10.11.12.100 # SNMP Access&lt;br /&gt;
tcp|in|d=22|s=fe80::1:/16 # IPV6 SSH access from our jumpgateway&lt;br /&gt;
udp|in|d=3389|s=10.1.0.0/24 # RDP Access from our entire office range&lt;br /&gt;
tcp|out|d=80,443|d=1.2.3.4/32 # Allow outgoing HTTP/HTTPS access via port 80 and 443&lt;br /&gt;
&lt;br /&gt;
# Allow sending Syslog messages to our Syslog server&lt;br /&gt;
udp|out|d=514|d=192.168.20.5 # UDP syslog server&lt;br /&gt;
tcp|out|d=10514|d=192.168.20.5 # UDP syslog server&lt;br /&gt;
&lt;br /&gt;
# Allow sending queries to some DNS servers&lt;br /&gt;
tcp|out|s=53|d=8.8.8.8&lt;br /&gt;
udp|out|s=53|d=1.1.1.1&lt;br /&gt;
udp|out|s=53|d=2606:4700:4700::1111 # Cloudflare IPv6 DNS Server&lt;br /&gt;
&lt;br /&gt;
# Include an external configuration file&lt;br /&gt;
Include /etc/csf/csf.custom-config&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rsyslog ===&lt;br /&gt;
&amp;lt;section begin=&amp;quot;linuxsyslog&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* https://www.rsyslog.com/doc/reference/templates/templates-reserved-names.html#ref-templates-reserved-names&lt;br /&gt;
* https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/6/html/deployment_guide/s2-templates&lt;br /&gt;
&lt;br /&gt;
==== Legacy ====&lt;br /&gt;
Send all logs to a rsyslog server and specify a port, @ is equal to using UDP. @@ is equal to TCP&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/75-local-to-rsyslog-server.conf&lt;br /&gt;
*.* @10.77.0.1:514&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Custom template where hostname is defined, then sent to the syslog server - include the priority number as first extra variable&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#/etc/rsyslog.d/70-local-to-rsyslog-server.conf&lt;br /&gt;
$template SendHostname, &amp;quot;%PRI%1 %timestamp% myhost.mydomain.nl %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.warning @10.77.0.1;SendHostname&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Send messages to a syslog server, using a template aligned to IETF protocol 23&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/61-qwe.conf&lt;br /&gt;
*.* @10.77.0.1;RSYSLOG_SyslogProtocol23Format&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Send messages to a syslog server, using a template aligned to IETF protocol 23, but specifying a custom hostname&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/60-asd.conf&lt;br /&gt;
$template custom_IETFprotocol_23,&amp;quot;%PRI%1 %TIMESTAMP:::date-rfc3339% prive.host.nl %APP-NAME% %PROCID% %MSGID% %STRUCTURED-DATA% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* @10.77.0.1;custom_IETFprotocol_23&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Log to the local server with a static hostname, using a custom structure&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/62-asd.conf&lt;br /&gt;
$template NewHostname, &amp;quot;%timestamp% tester.mydomain.nl %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* /var/log/wewuzerrors.txt;NewHostname&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An alternative to the contents above, specifying different/more fields&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
## /etc/rsyslog.d/65-customtemplate.conf&lt;br /&gt;
# https://stackoverflow.com/questions/57890176/extending-rsyslogs-default-logging-template&lt;br /&gt;
$template mynewtemplate,&amp;quot;%timegenerated% %HOSTNAME% %syslogfacility-text%.%syslogseverity-text% %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* /var/log/wazanda.txt;mynewtemplate&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rainerscript ====&lt;br /&gt;
Rainerscript: https://rsyslog.readthedocs.io/en/latest/rainerscript/control_structures.html&lt;br /&gt;
&lt;br /&gt;
Write all local messages to a specific file&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/60-asd.conf&lt;br /&gt;
action(type=&amp;quot;omfile&amp;quot; file=&amp;quot;/var/log/isaidhey.txt&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Send message to a syslog server using IETF protocol 23&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/70-local-to-rsyslog-server.conf&lt;br /&gt;
template(name=&amp;quot;RSYSLOG_SyslogProtocol23Format&amp;quot; type=&amp;quot;string&amp;quot;&lt;br /&gt;
     string=&amp;quot;&amp;lt;%PRI%&amp;gt;1 %TIMESTAMP:::date-rfc3339% %HOSTNAME% %APP-NAME% %PROCID% %MSGID% %STRUCTURED-DATA% %msg%\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Send all logs to the target server&lt;br /&gt;
action(type=&amp;quot;omfwd&amp;quot; Target=&amp;quot;192.168.5.21&amp;quot; Template=&amp;quot;RSYSLOG_SyslogProtocol23Format&amp;quot; Port=&amp;quot;514&amp;quot; Protocol=&amp;quot;udp&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Define a template aligned to IETF protocol 23 but specify a hostname to send as:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/71-local-to-rsyslog-server.conf&lt;br /&gt;
template(name=&amp;quot;SendHostname&amp;quot; type=&amp;quot;string&amp;quot;&lt;br /&gt;
     string=&amp;quot;&amp;lt;%PRI%&amp;gt;1 %TIMESTAMP:::date-rfc3339% myhost.mydomain.nl %APP-NAME% %PROCID% %MSGID% %STRUCTURED-DATA% %msg%\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Send all logs to target syslog server and port&lt;br /&gt;
action(type=&amp;quot;omfwd&amp;quot; Target=&amp;quot;10.0.33.10&amp;quot; Template=&amp;quot;SendHostname&amp;quot; Port=&amp;quot;514&amp;quot; Protocol=&amp;quot;udp&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Testing ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use the logger tool to test syslog server reception&lt;br /&gt;
logger -p local0.error &#039;Hello World!&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section end=&amp;quot;linuxsyslog&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== named ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Perform a test load of all primary zones within named.conf, as the named user&lt;br /&gt;
sudo -u named named-checkconf -z&lt;br /&gt;
&lt;br /&gt;
# Check zone file 192.168.77.0 defined in the 77.168.192.in-addr.arpa zone&lt;br /&gt;
named-checkzone 77.168.192.in-addr.arpa 192.168.77.0&lt;br /&gt;
&lt;br /&gt;
# Check zone file brammerloo.nl defined in the brammerloo.nl zone&lt;br /&gt;
named-checkzone brammerloo.nl brammerloo.nl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Basic configuration for the options field in &#039;&#039;&#039;/etc/named.conf&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
options {&lt;br /&gt;
# Define on what IP to listen on, for port 53&lt;br /&gt;
        listen-on port 53 { 127.0.0.1; 192.168.0.1; 192.168.1.1; };&lt;br /&gt;
        directory       &amp;quot;/var/named&amp;quot;;&lt;br /&gt;
        dump-file       &amp;quot;/var/named/data/cache_dump.db&amp;quot;;&lt;br /&gt;
        statistics-file &amp;quot;/var/named/data/named_stats.txt&amp;quot;;&lt;br /&gt;
        memstatistics-file &amp;quot;/var/named/data/named_mem_stats.txt&amp;quot;;&lt;br /&gt;
        secroots-file   &amp;quot;/var/named/data/named.secroots&amp;quot;;&lt;br /&gt;
        recursing-file  &amp;quot;/var/named/data/named.recursing&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# Only allow DNS queries from specific local subnets&lt;br /&gt;
# To allow from anything use: allow query { any; };&lt;br /&gt;
        allow-query     { localhost; 127.0.0.1; 192.168.0.0/24; 192.168.1.0/24; };&lt;br /&gt;
&lt;br /&gt;
# If the server can&#039;t resolve an address locally, use the following DNS servers for help&lt;br /&gt;
        forwarders {&lt;br /&gt;
        8.8.8.8;&lt;br /&gt;
        1.1.1.1;&lt;br /&gt;
        };&lt;br /&gt;
&lt;br /&gt;
        recursion yes;&lt;br /&gt;
        dnssec-validation no;&lt;br /&gt;
&lt;br /&gt;
        managed-keys-directory &amp;quot;/var/named/dynamic&amp;quot;;&lt;br /&gt;
        geoip-directory &amp;quot;/usr/share/GeoIP&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
        pid-file &amp;quot;/run/named/named.pid&amp;quot;;&lt;br /&gt;
        session-keyfile &amp;quot;/run/named/session.key&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
        /* https://fedoraproject.org/wiki/Changes/CryptoPolicy */&lt;br /&gt;
        include &amp;quot;/etc/crypto-policies/back-ends/bind.config&amp;quot;;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone defnitions: &#039;&#039;&#039;/etc/named.rfc1912.zones&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Define zones to listen for&lt;br /&gt;
zone &amp;quot;brammerloo.nl&amp;quot; IN {&lt;br /&gt;
        type master;&lt;br /&gt;
        file &amp;quot;brammerloo.nl&amp;quot;;&lt;br /&gt;
        allow-update { none; };&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
zone &amp;quot;1.168.192.in-addr.arpa&amp;quot; IN {&lt;br /&gt;
        type master;&lt;br /&gt;
        file &amp;quot;192.168.1.0&amp;quot;;&lt;br /&gt;
        allow-update { none; };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone file for Reverse lookup: &#039;&#039;&#039;/var/named/192.168.1.0&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$TTL 300&lt;br /&gt;
@       IN SOA  ns1.brammerloo.nl. admin.brammerloo.nl. (&lt;br /&gt;
                                        2023101102 ; serial&lt;br /&gt;
                                        180     ; refresh&lt;br /&gt;
                                        60      ; retry&lt;br /&gt;
                                        108000  ; expire&lt;br /&gt;
                                        60 )    ; minimum&lt;br /&gt;
    IN      NS      ns1.brammerloo.nl.&lt;br /&gt;
; PTR Records&lt;br /&gt;
11    IN   PTR   node1.&lt;br /&gt;
21    IN   PTR   server1.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone file for domain: &#039;&#039;&#039;/var/named/brammerloo.nl&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$TTL 300&lt;br /&gt;
@       IN SOA  ns1.brammerloo.nl. admin.brammerloo.nl. (&lt;br /&gt;
                                        2023101306 ; serial&lt;br /&gt;
                                        180     ; refresh&lt;br /&gt;
                                        60      ; retry&lt;br /&gt;
                                        108000  ; expire&lt;br /&gt;
                                        60 )    ; minimum&lt;br /&gt;
    IN      NS      ns1.brammerloo.nl.&lt;br /&gt;
@                  IN      A     192.168.1.6   ; domain brammerloo.nl is me!&lt;br /&gt;
ns1.brammerloo.nl. IN      A     192.168.78.31 ; FQDN for my domain&lt;br /&gt;
node1              IN      A     192.168.78.31 ; Basic A-record&lt;br /&gt;
www                IN      CNAME node1         ; Point my website to my node1 A-record&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== dhcpd ===&lt;br /&gt;
==== dhclient ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Request DHCP addresses where applicable&lt;br /&gt;
dhclient&lt;br /&gt;
&lt;br /&gt;
# Request an IPv4 adres from a DHCP server&lt;br /&gt;
dhclient -4&lt;br /&gt;
&lt;br /&gt;
# Show verbose information when requesting an IPv4 adres from a DHCP server&lt;br /&gt;
dhclient -4 -v&lt;br /&gt;
&lt;br /&gt;
# Release a DHCP lease&lt;br /&gt;
dhclient -r&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Basic configuration options in the &#039;&#039;&#039;/etc/dhcp/dhcpd.conf&#039;&#039;&#039; file&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Set the domain clients should use when resolving hostnames (equivalent to search domain)&lt;br /&gt;
option domain-name &amp;quot;brammerloo.nl&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# Set the domain name servers for DHCP clients&lt;br /&gt;
option domain-name-servers ns1.brammerloo.nl, 8.8.8.8;&lt;br /&gt;
&lt;br /&gt;
default-lease-time 600;&lt;br /&gt;
max-lease-time 7200;&lt;br /&gt;
log-facility local7;&lt;br /&gt;
&lt;br /&gt;
# Best practice = define any connected subnets, but don&#039;t configure DHCP for them&lt;br /&gt;
subnet 192.168.1.0 netmask 255.255.255.0 {&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Basic DHCP for a subnet configuration&lt;br /&gt;
subnet 192.168.0.0 netmask 255.255.255.0 {&lt;br /&gt;
  range 192.168.0.100 192.168.0.150;&lt;br /&gt;
  option routers 192.168.0.1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== smbd / Samba / CIFS ===&lt;br /&gt;
https://linuxconfig.org/install-samba-on-redhat-8&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List available shares on an IP or host&lt;br /&gt;
smbclient -L //172.17.0.2&lt;br /&gt;
&lt;br /&gt;
# Samba status checks&lt;br /&gt;
smbstatus&lt;br /&gt;
smbstatus -S&lt;br /&gt;
smbstatus -b&lt;br /&gt;
&lt;br /&gt;
# Samba set debug mode&lt;br /&gt;
smbcontrol smbd debug 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Basic configuration ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install and enable&lt;br /&gt;
dnf install samba samba-client&lt;br /&gt;
systemctl enable --now {smb,nmb}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a client-user to authenticate with&lt;br /&gt;
sudo useradd samba-user&lt;br /&gt;
&lt;br /&gt;
# Give the user a password to authenticate with&lt;br /&gt;
sudo smbpasswd -a samba-user&lt;br /&gt;
&lt;br /&gt;
# Create a group to associate with the samba share&lt;br /&gt;
sudo groupadd sambagroup&lt;br /&gt;
&lt;br /&gt;
# Add the user to the group we will be configuring for the share&lt;br /&gt;
sudo usermod -a -G sambagroup samba-user&lt;br /&gt;
&lt;br /&gt;
# Create the folder we will be sharing&lt;br /&gt;
sudo mkdir /var/shares/myshare&lt;br /&gt;
&lt;br /&gt;
# Apply proper permission&lt;br /&gt;
sudo chown -R samba-user:sambagroup /var/shares/myshare/&lt;br /&gt;
sudo chmod -R 0770 /var/shares/myshare/&lt;br /&gt;
&lt;br /&gt;
# Apply proper permission for SELinux&lt;br /&gt;
sudo chcon -t samba_share_t /var/shares/myshare/&lt;br /&gt;
&lt;br /&gt;
# Backup the default config&lt;br /&gt;
cp /etc/samba/smb.conf /etc/samba/smb.conf~&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/samba/smb.conf&lt;br /&gt;
[global]&lt;br /&gt;
 workgroup = &amp;lt;DOMAIN-OR-WORKGROUP&amp;gt;&lt;br /&gt;
 server string = Samba Server %v&lt;br /&gt;
 netbios name = &amp;lt;SERVER-HOSTNAME&amp;gt;&lt;br /&gt;
 security = user&lt;br /&gt;
 map to guest = bad user&lt;br /&gt;
 dns proxy = no&lt;br /&gt;
&lt;br /&gt;
#==================== Share Definitions ======================&lt;br /&gt;
[share001]&lt;br /&gt;
 path = /var/shares/myshare&lt;br /&gt;
 valid users = @sambagroup&lt;br /&gt;
 guest ok = no&lt;br /&gt;
 writable = yes&lt;br /&gt;
 browsable = yes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reload Samba services&lt;br /&gt;
systemctl reload {smb,nmb}&lt;br /&gt;
&lt;br /&gt;
# Mount in Windows&lt;br /&gt;
\\&amp;lt;SERVER-IP&amp;gt;\share001&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user: samba-user&lt;br /&gt;
pass: &amp;lt;Whatever password you filled in with smbpasswd -a&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Docker ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List Docker containers &lt;br /&gt;
docker ps&lt;br /&gt;
&lt;br /&gt;
# List all Docker container IDs&lt;br /&gt;
docker ps -aq&lt;br /&gt;
&lt;br /&gt;
# List logs for container 987sdh3qrasdhj&lt;br /&gt;
docker logs 987sdh3qrasdhj&lt;br /&gt;
&lt;br /&gt;
# List RAM/CPU usage for Docker container asdlkasd67k&lt;br /&gt;
docker stats asdlkasd67k&lt;br /&gt;
&lt;br /&gt;
# Show verbose container information such as commands run, network, ID, etc&lt;br /&gt;
docker inspect oiu2398sda87&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enter the shell inside a docker container&lt;br /&gt;
docker exec -ti a89sd98sa7d /bin/bash&lt;br /&gt;
&lt;br /&gt;
# Execute a command inside a container as a specific user, root in this case&lt;br /&gt;
docker exec -it -u root asd87289hasdadz tail /var/log/nginx/access.log&lt;br /&gt;
docker exec -u 0 -it as892asnj2as /bin/bash&lt;br /&gt;
&lt;br /&gt;
# Restart docker container yoga&lt;br /&gt;
docker restart yoga&lt;br /&gt;
&lt;br /&gt;
# Restart the 3 given containers&lt;br /&gt;
docker restart 79f71c7f4d91 bbb3d3f5c3b1 b0a3204d4098&lt;br /&gt;
&lt;br /&gt;
# Start this container&lt;br /&gt;
docker start as9823nzxc0&lt;br /&gt;
&lt;br /&gt;
# Stop this container&lt;br /&gt;
docker stop as9823nzxc0&lt;br /&gt;
&lt;br /&gt;
# Restart all unhealthy Docker containers&lt;br /&gt;
for i in $(docker ps | grep unhealthy | awk &#039;{print $1}&#039;); do docker restart &amp;quot;$i&amp;quot;; done;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PowerDNS ===&lt;br /&gt;
* https://doc.powerdns.com/authoritative/index.html&lt;br /&gt;
* https://doc.powerdns.com/authoritative/manpages/pdns_server.1.html&lt;br /&gt;
* https://doc.powerdns.com/authoritative/manpages/pdnsutil.1.html&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# List commands&lt;br /&gt;
pdns_server --help&lt;br /&gt;
&lt;br /&gt;
# Check config and parse for errors&lt;br /&gt;
pdns_server --config=check&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# List available commands &lt;br /&gt;
pdnsutil --help&lt;br /&gt;
&lt;br /&gt;
# Check config and parse for errors&lt;br /&gt;
pdnsutil --config=check&lt;br /&gt;
&lt;br /&gt;
# List all available zones&lt;br /&gt;
pdnsutil list-all-zones&lt;br /&gt;
&lt;br /&gt;
# List all domains in the primary zone&lt;br /&gt;
pdnsutil list-all-zones primary&lt;br /&gt;
&lt;br /&gt;
# See zone information for a specific domain&lt;br /&gt;
pdnsutil show-zone mydomain.com&lt;br /&gt;
pdnsutil show-zone 77.5.10.in-addr.arpa&lt;br /&gt;
&lt;br /&gt;
# Check zone for errors&lt;br /&gt;
pdnsutil check-zone mydomain.com&lt;br /&gt;
&lt;br /&gt;
# List all created TSIG keys&lt;br /&gt;
pdnsutil list-tsig-keys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# Activate TSIG key for domain &amp;quot;myexample.com&amp;quot; in the primary zone&lt;br /&gt;
pdnsutil &amp;quot; myexample.com transfer primary&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MAAS ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Logs in either place:&lt;br /&gt;
/var/log/maas/&lt;br /&gt;
/var/snap/maas/common/log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List status of MAAS services&lt;br /&gt;
maas status&lt;br /&gt;
&lt;br /&gt;
# List MAAS commands&lt;br /&gt;
maas --help&lt;br /&gt;
&lt;br /&gt;
# List available arguments for the init command&lt;br /&gt;
maas init --help&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section end=&amp;quot;linuxservices&amp;quot;/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Services&amp;diff=856</id>
		<title>Linux:Services</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Services&amp;diff=856"/>
		<updated>2025-10-29T13:33:55Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* dhclient */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet|Cheatsheets]]&lt;br /&gt;
&lt;br /&gt;
== Services ==&lt;br /&gt;
&amp;lt;section begin=&amp;quot;linuxservices&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Common ===&lt;br /&gt;
==== systemctl ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all services that are running or exited&lt;br /&gt;
systemctl&lt;br /&gt;
&lt;br /&gt;
# List all services, running or otherwise&lt;br /&gt;
systemctl --all&lt;br /&gt;
&lt;br /&gt;
# List all failed services&lt;br /&gt;
systemctl --state=failed&lt;br /&gt;
&lt;br /&gt;
# Reset the failed service &amp;quot;nginx&amp;quot;&lt;br /&gt;
systemctl reset-failed nginx&lt;br /&gt;
&lt;br /&gt;
# View the status of the &amp;quot;nfs-server&amp;quot; service&lt;br /&gt;
systemctl status nfs-server&lt;br /&gt;
&lt;br /&gt;
# Output the config file of &amp;quot;rsyslog&amp;quot; to the shell&lt;br /&gt;
systemctl cat rsyslog&lt;br /&gt;
&lt;br /&gt;
# Restart the &amp;quot;sshd&amp;quot; service, terminating established connections and re-parsing the configuration&lt;br /&gt;
systemctl restart sshd&lt;br /&gt;
&lt;br /&gt;
# Reload the &amp;quot;nginx&amp;quot; service so that it only re-parses the configuration&lt;br /&gt;
systemctl reload nginx&lt;br /&gt;
&lt;br /&gt;
# Stop the &amp;quot;nfs-ganesha&amp;quot; service so that it stops being run&lt;br /&gt;
systemctl stop nfs-ganesha&lt;br /&gt;
&lt;br /&gt;
# Start the &amp;quot;nfs-ganesha&amp;quot; service so that it starts being run again&lt;br /&gt;
systemctl start nfs-ganesha&lt;br /&gt;
&lt;br /&gt;
# Disable the &amp;quot;mariadb&amp;quot; service so that it doesn&#039;t start after the next boot&lt;br /&gt;
systemctl disable mariadb&lt;br /&gt;
&lt;br /&gt;
# Enable the &amp;quot;mariadb&amp;quot; service so that it starts after the next boot.&lt;br /&gt;
systemctl enable mariadb&lt;br /&gt;
&lt;br /&gt;
# Check the logs for all failed services&lt;br /&gt;
for i in $(systemctl --state=failed | head -n -4 | tail -n +2 | awk &#039;{print $1}&#039;); do systemctl --no-pager status &amp;quot;$i&amp;quot;; done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== NTP ===&lt;br /&gt;
==== Timedatectl ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show the current status of timedatectl&lt;br /&gt;
timedatectl&lt;br /&gt;
&lt;br /&gt;
# List available timezones&lt;br /&gt;
timedatectl list-timezones&lt;br /&gt;
&lt;br /&gt;
# Set the timezone to Amsterdam&lt;br /&gt;
timedatectl set-timezone Europe/Amsterdam&lt;br /&gt;
&lt;br /&gt;
# Show verbose sync information&lt;br /&gt;
timedatectl timesync-status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SNMP ===&lt;br /&gt;
==== V3 client installation ====&lt;br /&gt;
* https://kifarunix.com/quick-way-to-install-and-configure-snmp-on-ubuntu-20-04/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
apt install snmpd snmp libsnmp-dev&lt;br /&gt;
cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.bak&lt;br /&gt;
systemctl stop snmpd&lt;br /&gt;
net-snmp-create-v3-user -ro -X &amp;lt;CRYPTO-PASSWORD&amp;gt; -a SHA -X &amp;lt;PASSWORD&amp;gt; -x AES &amp;lt;USERNAME&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/snmp/snmpd.conf&lt;br /&gt;
sysLocation    NL;Zuid-Holland;Rotterdam, 78 MyStreet;2nd Floor;Server Room;Rack&lt;br /&gt;
sysContact     Me &amp;lt;me@example.org&amp;gt;&lt;br /&gt;
agentaddress   192.168.0.10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
systemctl start snmpd&lt;br /&gt;
systemctl enable snmpd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Test&lt;br /&gt;
snmpwalk -v3 -a SHA -A &amp;quot;AUTHENTICATION PASSWORD&amp;quot; -x AES -X &amp;quot;CRYPTO PASSWORD&amp;quot; -l authPriv -u &amp;quot;MYUSER&amp;quot; localhost | head&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CTDB  ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Verify CTDB cluster status&lt;br /&gt;
ctdb status&lt;br /&gt;
&lt;br /&gt;
# Show the allocated IP addresses and to which nodes they&#039;re bound&lt;br /&gt;
ctdb ip&lt;br /&gt;
&lt;br /&gt;
# See the status of all CTDB-scripts&lt;br /&gt;
ctdb scriptstatus&lt;br /&gt;
ctdb event status&lt;br /&gt;
&lt;br /&gt;
# Show the time of the last failover the duration it took to recover&lt;br /&gt;
ctdb uptime&lt;br /&gt;
&lt;br /&gt;
# See various statistics and data&lt;br /&gt;
ctdb statistics&lt;br /&gt;
&lt;br /&gt;
# Use the onnode command to execute a command on all cluster nodes&lt;br /&gt;
onnode all ctdb status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Stop a ctdb cluster member&lt;br /&gt;
ctdb stop&lt;br /&gt;
&lt;br /&gt;
# Start a stopped ctdb cluster member&lt;br /&gt;
ctdb continue&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Firewalls ===&lt;br /&gt;
==== UFW ====&lt;br /&gt;
===== Checks =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show summary of UFW status&lt;br /&gt;
ufw status&lt;br /&gt;
&lt;br /&gt;
# Show verbose UFW status&lt;br /&gt;
ufw status verbose&lt;br /&gt;
&lt;br /&gt;
# Show UFW rules numbered&lt;br /&gt;
ufw status numbered&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Commands =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Allow access from a specific IP to a port and add a comment that show in the status&lt;br /&gt;
ufw allow from 10.0.0.253 to any port 22 proto tcp comment &#039;Allow SSH access from XYZ location&#039;&lt;br /&gt;
&lt;br /&gt;
# Delete numbered Firewall rule 56&lt;br /&gt;
ufw delete 56&lt;br /&gt;
&lt;br /&gt;
# Disable UFW logging (prevent syslog spam)&lt;br /&gt;
ufw logging off&lt;br /&gt;
&lt;br /&gt;
# Set UFW logging back to the default&lt;br /&gt;
ufw logging low&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Firewalld ====&lt;br /&gt;
===== SNMP access =====&lt;br /&gt;
* https://unix.stackexchange.com/questions/214388/how-to-let-the-firewall-of-rhel7-the-snmp-connection-passing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/firewalld/services/snmp.xml&lt;br /&gt;
&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;service&amp;gt;&lt;br /&gt;
  &amp;lt;short&amp;gt;SNMP&amp;lt;/short&amp;gt;&lt;br /&gt;
  &amp;lt;description&amp;gt;SNMP protocol&amp;lt;/description&amp;gt;&lt;br /&gt;
  &amp;lt;port protocol=&amp;quot;udp&amp;quot; port=&amp;quot;161&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/service&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
firewall-cmd --zone=public --add-service snmp --permanent&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Firewall-cmd =====&lt;br /&gt;
====== Checks ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all available commands&lt;br /&gt;
firewall-cmd -h&lt;br /&gt;
&lt;br /&gt;
# Check the configuration file of the firewall for errors&lt;br /&gt;
firewall-cmd --check-config&lt;br /&gt;
&lt;br /&gt;
# Display the current state of firewall-cmd (running/shutdown)&lt;br /&gt;
firewall-cmd --state&lt;br /&gt;
&lt;br /&gt;
# Display all available zones&lt;br /&gt;
firewall-cmd --get-zones&lt;br /&gt;
&lt;br /&gt;
# List all whitelisted services&lt;br /&gt;
firewall-cmd --list-services&lt;br /&gt;
&lt;br /&gt;
# List all services you can potentially enable&lt;br /&gt;
firewall-cmd --get-services&lt;br /&gt;
&lt;br /&gt;
# List all added or enabled services and ports in more detail&lt;br /&gt;
firewall-cmd --list-all&lt;br /&gt;
&lt;br /&gt;
# List verbose information for all zones&lt;br /&gt;
firewall-cmd --list-all-zones&lt;br /&gt;
&lt;br /&gt;
# List verbose information for the public zone&lt;br /&gt;
firewall-cmd --list-all --zone=public&lt;br /&gt;
&lt;br /&gt;
# See what port(s) are associated with the dns service&lt;br /&gt;
firewall-cmd --info-service dns&lt;br /&gt;
&lt;br /&gt;
# List all opened ports&lt;br /&gt;
firewall-cmd --list-ports&lt;br /&gt;
&lt;br /&gt;
# List kernel ruleset generated for nftables(?)&lt;br /&gt;
nft list ruleset&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Commands ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reload the firewall&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Whitelist the dns service, persistently even after reboot&lt;br /&gt;
firewall-cmd --add-service=dns ; sudo firewall-cmd --runtime-to-permanent; firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Whitelist the http service, persistently even after reboot&lt;br /&gt;
firewall-cmd --add-service=http ; sudo firewall-cmd --runtime-to-permanent; firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Remove the http service from the whitelist&lt;br /&gt;
firewall-cmd --remove-service=http&lt;br /&gt;
&lt;br /&gt;
# Add port 1234 (tcp) to the whitelist&lt;br /&gt;
firewall-cmd --add-port=1234/tcp&lt;br /&gt;
&lt;br /&gt;
# Remove port 1234 (tcp) from the whitelist&lt;br /&gt;
firewall-cmd --remove-port=1234/tcp&lt;br /&gt;
&lt;br /&gt;
# Add port 2345 (udp) to the whitelist in zone external&lt;br /&gt;
firewall-cmd --zone=external --add-port=2345/udp&lt;br /&gt;
&lt;br /&gt;
# Remove port 2345 (udp) from the whitelist for zone external&lt;br /&gt;
firewall-cmd --zone=external --add-port=2345/udp&lt;br /&gt;
&lt;br /&gt;
# Add current configuration to configuration permanently&lt;br /&gt;
firewall-cmd –runtime-to-permanent&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;DANGEROUS&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# SHUT IT DOWN DOC - DROP ALL PACKETS AND EXPIRE EXISTING CONNECTIONS&lt;br /&gt;
firewall-cmd --panic-on&lt;br /&gt;
&lt;br /&gt;
# ACCEPT PACKETS AGAIN&lt;br /&gt;
firewall-cmd --panic-off&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== CSF ====&lt;br /&gt;
ConfigServer Security and Firewall&lt;br /&gt;
&lt;br /&gt;
===== General =====&lt;br /&gt;
* Common configuration: /etc/csf/csf.conf &lt;br /&gt;
* Blacklist: /etc/csf/csf.deny &lt;br /&gt;
* Whitelist: /etc/csf/csf.allow &lt;br /&gt;
&lt;br /&gt;
===== Installation =====&lt;br /&gt;
From the official instructions: https://download.configserver.com/csf/install.txt&lt;br /&gt;
&lt;br /&gt;
====== Prerequisites ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Perl Modules&lt;br /&gt;
============&lt;br /&gt;
While most should be installed on a standard perl installation the following&lt;br /&gt;
may need to be installed manually:&lt;br /&gt;
&lt;br /&gt;
# On rpm based systems:&lt;br /&gt;
yum install perl-libwww-perl.noarch perl-LWP-Protocol-https.noarch perl-GDGraph&lt;br /&gt;
&lt;br /&gt;
# On APT based systems:&lt;br /&gt;
apt-get install libwww-perl liblwp-protocol-https-perl libgd-graph-perl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Install ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cd /usr/src&lt;br /&gt;
rm -fv csf.tgz&lt;br /&gt;
wget https://download.configserver.com/csf.tgz&lt;br /&gt;
tar -xzf csf.tgz&lt;br /&gt;
cd csf&lt;br /&gt;
sh install.sh&lt;br /&gt;
&lt;br /&gt;
# Next, test whether you have the required iptables modules:&lt;br /&gt;
perl /usr/local/csf/bin/csftest.pl&lt;br /&gt;
&lt;br /&gt;
# Don&#039;t worry if you cannot run all the features, so long as the script doesn&#039;t report any FATAL errors&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Checks =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check the running status of csf&lt;br /&gt;
csf status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Commands =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Commit config changes by restarting csf&lt;br /&gt;
csf -r&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== csf.conf =====&lt;br /&gt;
Some common changes within the configuration file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Set testing to 0 when your CSF configuration is &#039;production&#039; ready&lt;br /&gt;
TESTING = &amp;quot;0&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow access to any service you&#039;re hosting locally, for example https&lt;br /&gt;
TCP_IN = &amp;quot;443&amp;quot;&lt;br /&gt;
UDP_IN = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow all outwards HTTP/HTTPS traffic so you can yum/apt update&lt;br /&gt;
TCP_OUT = &amp;quot;80,443&amp;quot; &lt;br /&gt;
&lt;br /&gt;
# Allow outgoing traceroute&lt;br /&gt;
UDP_OUT = &amp;quot;33434:33523&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow your server to be pinged&lt;br /&gt;
ICMP_IN = &amp;quot;0&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Formatting =====&lt;br /&gt;
The varying styles of formatting used in allow.conf&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Allow anything relating to the following IPs/ranges&lt;br /&gt;
192.168.10.0/24 # Our application breaks without this range&lt;br /&gt;
192.168.1.1 # Our gateway or something&lt;br /&gt;
&lt;br /&gt;
# Detailed entries based on Transport protocol, direction, Application protocol and IP&lt;br /&gt;
tcp:in:d=22:s=7.7.7.7 # SSH access from our VPN&lt;br /&gt;
udp:in:d=161:s=10.11.12.100 # SNMP Access&lt;br /&gt;
tcp|in|d=22|s=fe80::1:/16 # IPV6 SSH access from our jumpgateway&lt;br /&gt;
udp|in|d=3389|s=10.1.0.0/24 # RDP Access from our entire office range&lt;br /&gt;
tcp|out|d=80,443|d=1.2.3.4/32 # Allow outgoing HTTP/HTTPS access via port 80 and 443&lt;br /&gt;
&lt;br /&gt;
# Allow sending Syslog messages to our Syslog server&lt;br /&gt;
udp|out|d=514|d=192.168.20.5 # UDP syslog server&lt;br /&gt;
tcp|out|d=10514|d=192.168.20.5 # UDP syslog server&lt;br /&gt;
&lt;br /&gt;
# Allow sending queries to some DNS servers&lt;br /&gt;
tcp|out|s=53|d=8.8.8.8&lt;br /&gt;
udp|out|s=53|d=1.1.1.1&lt;br /&gt;
udp|out|s=53|d=2606:4700:4700::1111 # Cloudflare IPv6 DNS Server&lt;br /&gt;
&lt;br /&gt;
# Include an external configuration file&lt;br /&gt;
Include /etc/csf/csf.custom-config&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rsyslog ===&lt;br /&gt;
&amp;lt;section begin=&amp;quot;linuxsyslog&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* https://www.rsyslog.com/doc/reference/templates/templates-reserved-names.html#ref-templates-reserved-names&lt;br /&gt;
* https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/6/html/deployment_guide/s2-templates&lt;br /&gt;
&lt;br /&gt;
==== Legacy ====&lt;br /&gt;
Send all logs to a rsyslog server and specify a port, @ is equal to using UDP. @@ is equal to TCP&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/75-local-to-rsyslog-server.conf&lt;br /&gt;
*.* @10.77.0.1:514&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Custom template where hostname is defined, then sent to the syslog server - include the priority number as first extra variable&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#/etc/rsyslog.d/70-local-to-rsyslog-server.conf&lt;br /&gt;
$template SendHostname, &amp;quot;%PRI%1 %timestamp% myhost.mydomain.nl %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.warning @10.77.0.1;SendHostname&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Send messages to a syslog server, using a template aligned to IETF protocol 23&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/61-qwe.conf&lt;br /&gt;
*.* @10.77.0.1;RSYSLOG_SyslogProtocol23Format&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Send messages to a syslog server, using a template aligned to IETF protocol 23, but specifying a custom hostname&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/60-asd.conf&lt;br /&gt;
$template custom_IETFprotocol_23,&amp;quot;%PRI%1 %TIMESTAMP:::date-rfc3339% prive.host.nl %APP-NAME% %PROCID% %MSGID% %STRUCTURED-DATA% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* @10.77.0.1;custom_IETFprotocol_23&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Log to the local server with a static hostname, using a custom structure&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/62-asd.conf&lt;br /&gt;
$template NewHostname, &amp;quot;%timestamp% tester.mydomain.nl %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* /var/log/wewuzerrors.txt;NewHostname&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An alternative to the contents above, specifying different/more fields&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
## /etc/rsyslog.d/65-customtemplate.conf&lt;br /&gt;
# https://stackoverflow.com/questions/57890176/extending-rsyslogs-default-logging-template&lt;br /&gt;
$template mynewtemplate,&amp;quot;%timegenerated% %HOSTNAME% %syslogfacility-text%.%syslogseverity-text% %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* /var/log/wazanda.txt;mynewtemplate&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rainerscript ====&lt;br /&gt;
Rainerscript: https://rsyslog.readthedocs.io/en/latest/rainerscript/control_structures.html&lt;br /&gt;
&lt;br /&gt;
Write all local messages to a specific file&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/60-asd.conf&lt;br /&gt;
action(type=&amp;quot;omfile&amp;quot; file=&amp;quot;/var/log/isaidhey.txt&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Send message to a syslog server using IETF protocol 23&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/70-local-to-rsyslog-server.conf&lt;br /&gt;
template(name=&amp;quot;RSYSLOG_SyslogProtocol23Format&amp;quot; type=&amp;quot;string&amp;quot;&lt;br /&gt;
     string=&amp;quot;&amp;lt;%PRI%&amp;gt;1 %TIMESTAMP:::date-rfc3339% %HOSTNAME% %APP-NAME% %PROCID% %MSGID% %STRUCTURED-DATA% %msg%\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Send all logs to the target server&lt;br /&gt;
action(type=&amp;quot;omfwd&amp;quot; Target=&amp;quot;192.168.5.21&amp;quot; Template=&amp;quot;RSYSLOG_SyslogProtocol23Format&amp;quot; Port=&amp;quot;514&amp;quot; Protocol=&amp;quot;udp&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Define a template aligned to IETF protocol 23 but specify a hostname to send as:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/71-local-to-rsyslog-server.conf&lt;br /&gt;
template(name=&amp;quot;SendHostname&amp;quot; type=&amp;quot;string&amp;quot;&lt;br /&gt;
     string=&amp;quot;&amp;lt;%PRI%&amp;gt;1 %TIMESTAMP:::date-rfc3339% myhost.mydomain.nl %APP-NAME% %PROCID% %MSGID% %STRUCTURED-DATA% %msg%\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Send all logs to target syslog server and port&lt;br /&gt;
action(type=&amp;quot;omfwd&amp;quot; Target=&amp;quot;10.0.33.10&amp;quot; Template=&amp;quot;SendHostname&amp;quot; Port=&amp;quot;514&amp;quot; Protocol=&amp;quot;udp&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Testing ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use the logger tool to test syslog server reception&lt;br /&gt;
logger -p local0.error &#039;Hello World!&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section end=&amp;quot;linuxsyslog&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== named ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Perform a test load of all primary zones within named.conf, as the named user&lt;br /&gt;
sudo -u named named-checkconf -z&lt;br /&gt;
&lt;br /&gt;
# Check zone file 192.168.77.0 defined in the 77.168.192.in-addr.arpa zone&lt;br /&gt;
named-checkzone 77.168.192.in-addr.arpa 192.168.77.0&lt;br /&gt;
&lt;br /&gt;
# Check zone file brammerloo.nl defined in the brammerloo.nl zone&lt;br /&gt;
named-checkzone brammerloo.nl brammerloo.nl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Basic configuration for the options field in &#039;&#039;&#039;/etc/named.conf&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
options {&lt;br /&gt;
# Define on what IP to listen on, for port 53&lt;br /&gt;
        listen-on port 53 { 127.0.0.1; 192.168.0.1; 192.168.1.1; };&lt;br /&gt;
        directory       &amp;quot;/var/named&amp;quot;;&lt;br /&gt;
        dump-file       &amp;quot;/var/named/data/cache_dump.db&amp;quot;;&lt;br /&gt;
        statistics-file &amp;quot;/var/named/data/named_stats.txt&amp;quot;;&lt;br /&gt;
        memstatistics-file &amp;quot;/var/named/data/named_mem_stats.txt&amp;quot;;&lt;br /&gt;
        secroots-file   &amp;quot;/var/named/data/named.secroots&amp;quot;;&lt;br /&gt;
        recursing-file  &amp;quot;/var/named/data/named.recursing&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# Only allow DNS queries from specific local subnets&lt;br /&gt;
# To allow from anything use: allow query { any; };&lt;br /&gt;
        allow-query     { localhost; 127.0.0.1; 192.168.0.0/24; 192.168.1.0/24; };&lt;br /&gt;
&lt;br /&gt;
# If the server can&#039;t resolve an address locally, use the following DNS servers for help&lt;br /&gt;
        forwarders {&lt;br /&gt;
        8.8.8.8;&lt;br /&gt;
        1.1.1.1;&lt;br /&gt;
        };&lt;br /&gt;
&lt;br /&gt;
        recursion yes;&lt;br /&gt;
        dnssec-validation no;&lt;br /&gt;
&lt;br /&gt;
        managed-keys-directory &amp;quot;/var/named/dynamic&amp;quot;;&lt;br /&gt;
        geoip-directory &amp;quot;/usr/share/GeoIP&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
        pid-file &amp;quot;/run/named/named.pid&amp;quot;;&lt;br /&gt;
        session-keyfile &amp;quot;/run/named/session.key&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
        /* https://fedoraproject.org/wiki/Changes/CryptoPolicy */&lt;br /&gt;
        include &amp;quot;/etc/crypto-policies/back-ends/bind.config&amp;quot;;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone defnitions: &#039;&#039;&#039;/etc/named.rfc1912.zones&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Define zones to listen for&lt;br /&gt;
zone &amp;quot;brammerloo.nl&amp;quot; IN {&lt;br /&gt;
        type master;&lt;br /&gt;
        file &amp;quot;brammerloo.nl&amp;quot;;&lt;br /&gt;
        allow-update { none; };&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
zone &amp;quot;1.168.192.in-addr.arpa&amp;quot; IN {&lt;br /&gt;
        type master;&lt;br /&gt;
        file &amp;quot;192.168.1.0&amp;quot;;&lt;br /&gt;
        allow-update { none; };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone file for Reverse lookup: &#039;&#039;&#039;/var/named/192.168.1.0&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$TTL 300&lt;br /&gt;
@       IN SOA  ns1.brammerloo.nl. admin.brammerloo.nl. (&lt;br /&gt;
                                        2023101102 ; serial&lt;br /&gt;
                                        180     ; refresh&lt;br /&gt;
                                        60      ; retry&lt;br /&gt;
                                        108000  ; expire&lt;br /&gt;
                                        60 )    ; minimum&lt;br /&gt;
    IN      NS      ns1.brammerloo.nl.&lt;br /&gt;
; PTR Records&lt;br /&gt;
11    IN   PTR   node1.&lt;br /&gt;
21    IN   PTR   server1.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone file for domain: &#039;&#039;&#039;/var/named/brammerloo.nl&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$TTL 300&lt;br /&gt;
@       IN SOA  ns1.brammerloo.nl. admin.brammerloo.nl. (&lt;br /&gt;
                                        2023101306 ; serial&lt;br /&gt;
                                        180     ; refresh&lt;br /&gt;
                                        60      ; retry&lt;br /&gt;
                                        108000  ; expire&lt;br /&gt;
                                        60 )    ; minimum&lt;br /&gt;
    IN      NS      ns1.brammerloo.nl.&lt;br /&gt;
@                  IN      A     192.168.1.6   ; domain brammerloo.nl is me!&lt;br /&gt;
ns1.brammerloo.nl. IN      A     192.168.78.31 ; FQDN for my domain&lt;br /&gt;
node1              IN      A     192.168.78.31 ; Basic A-record&lt;br /&gt;
www                IN      CNAME node1         ; Point my website to my node1 A-record&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== dhcpd ===&lt;br /&gt;
==== dhclient ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Request DHCP addresses where applicable&lt;br /&gt;
dhclient&lt;br /&gt;
&lt;br /&gt;
# Request an IPv4 adres from a DHCP server&lt;br /&gt;
dhclient -4&lt;br /&gt;
&lt;br /&gt;
# Show verbose information when requesting an IPv4 adres from a DHCP server&lt;br /&gt;
dhclient -4 -v&lt;br /&gt;
&lt;br /&gt;
# Release a DHCP lease&lt;br /&gt;
dhclient -r&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Basic configuration options in the &#039;&#039;&#039;/etc/dhcp/dhcpd.conf&#039;&#039;&#039; file&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Set the domain clients should use when resolving hostnames (equivalent to search domain)&lt;br /&gt;
option domain-name &amp;quot;brammerloo.nl&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# Set the domain name servers for DHCP clients&lt;br /&gt;
option domain-name-servers ns1.brammerloo.nl, 8.8.8.8;&lt;br /&gt;
&lt;br /&gt;
default-lease-time 600;&lt;br /&gt;
max-lease-time 7200;&lt;br /&gt;
log-facility local7;&lt;br /&gt;
&lt;br /&gt;
# Best practice = define any connected subnets, but don&#039;t configure DHCP for them&lt;br /&gt;
subnet 192.168.1.0 netmask 255.255.255.0 {&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Basic DHCP for a subnet configuration&lt;br /&gt;
subnet 192.168.0.0 netmask 255.255.255.0 {&lt;br /&gt;
  range 192.168.0.100 192.168.0.150;&lt;br /&gt;
  option routers 192.168.0.1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== smbd / Samba / CIFS ===&lt;br /&gt;
https://linuxconfig.org/install-samba-on-redhat-8&lt;br /&gt;
&lt;br /&gt;
==== Basic configuration ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install and enable&lt;br /&gt;
dnf install samba samba-client&lt;br /&gt;
systemctl enable --now {smb,nmb}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a client-user to authenticate with&lt;br /&gt;
sudo useradd samba-user&lt;br /&gt;
&lt;br /&gt;
# Give the user a password to authenticate with&lt;br /&gt;
sudo smbpasswd -a samba-user&lt;br /&gt;
&lt;br /&gt;
# Create a group to associate with the samba share&lt;br /&gt;
sudo groupadd sambagroup&lt;br /&gt;
&lt;br /&gt;
# Add the user to the group we will be configuring for the share&lt;br /&gt;
sudo usermod -a -G sambagroup samba-user&lt;br /&gt;
&lt;br /&gt;
# Create the folder we will be sharing&lt;br /&gt;
sudo mkdir /var/shares/myshare&lt;br /&gt;
&lt;br /&gt;
# Apply proper permission&lt;br /&gt;
sudo chown -R samba-user:sambagroup /var/shares/myshare/&lt;br /&gt;
sudo chmod -R 0770 /var/shares/myshare/&lt;br /&gt;
&lt;br /&gt;
# Apply proper permission for SELinux&lt;br /&gt;
sudo chcon -t samba_share_t /var/shares/myshare/&lt;br /&gt;
&lt;br /&gt;
# Backup the default config&lt;br /&gt;
cp /etc/samba/smb.conf /etc/samba/smb.conf~&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/samba/smb.conf&lt;br /&gt;
[global]&lt;br /&gt;
 workgroup = &amp;lt;DOMAIN-OR-WORKGROUP&amp;gt;&lt;br /&gt;
 server string = Samba Server %v&lt;br /&gt;
 netbios name = &amp;lt;SERVER-HOSTNAME&amp;gt;&lt;br /&gt;
 security = user&lt;br /&gt;
 map to guest = bad user&lt;br /&gt;
 dns proxy = no&lt;br /&gt;
&lt;br /&gt;
#==================== Share Definitions ======================&lt;br /&gt;
[share001]&lt;br /&gt;
 path = /var/shares/myshare&lt;br /&gt;
 valid users = @sambagroup&lt;br /&gt;
 guest ok = no&lt;br /&gt;
 writable = yes&lt;br /&gt;
 browsable = yes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reload Samba services&lt;br /&gt;
systemctl reload {smb,nmb}&lt;br /&gt;
&lt;br /&gt;
# Mount in Windows&lt;br /&gt;
\\&amp;lt;SERVER-IP&amp;gt;\share001&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user: samba-user&lt;br /&gt;
pass: &amp;lt;Whatever password you filled in with smbpasswd -a&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Samba checks&lt;br /&gt;
smbstatus&lt;br /&gt;
smbstatus -S&lt;br /&gt;
smbstatus -b&lt;br /&gt;
&lt;br /&gt;
# Samba set debug mode&lt;br /&gt;
smbcontrol smbd debug 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Docker ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List Docker containers &lt;br /&gt;
docker ps&lt;br /&gt;
&lt;br /&gt;
# List all Docker container IDs&lt;br /&gt;
docker ps -aq&lt;br /&gt;
&lt;br /&gt;
# List logs for container 987sdh3qrasdhj&lt;br /&gt;
docker logs 987sdh3qrasdhj&lt;br /&gt;
&lt;br /&gt;
# List RAM/CPU usage for Docker container asdlkasd67k&lt;br /&gt;
docker stats asdlkasd67k&lt;br /&gt;
&lt;br /&gt;
# Show verbose container information such as commands run, network, ID, etc&lt;br /&gt;
docker inspect oiu2398sda87&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enter the shell inside a docker container&lt;br /&gt;
docker exec -ti a89sd98sa7d /bin/bash&lt;br /&gt;
&lt;br /&gt;
# Execute a command inside a container as a specific user, root in this case&lt;br /&gt;
docker exec -it -u root asd87289hasdadz tail /var/log/nginx/access.log&lt;br /&gt;
docker exec -u 0 -it as892asnj2as /bin/bash&lt;br /&gt;
&lt;br /&gt;
# Restart docker container yoga&lt;br /&gt;
docker restart yoga&lt;br /&gt;
&lt;br /&gt;
# Restart the 3 given containers&lt;br /&gt;
docker restart 79f71c7f4d91 bbb3d3f5c3b1 b0a3204d4098&lt;br /&gt;
&lt;br /&gt;
# Start this container&lt;br /&gt;
docker start as9823nzxc0&lt;br /&gt;
&lt;br /&gt;
# Stop this container&lt;br /&gt;
docker stop as9823nzxc0&lt;br /&gt;
&lt;br /&gt;
# Restart all unhealthy Docker containers&lt;br /&gt;
for i in $(docker ps | grep unhealthy | awk &#039;{print $1}&#039;); do docker restart &amp;quot;$i&amp;quot;; done;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PowerDNS ===&lt;br /&gt;
* https://doc.powerdns.com/authoritative/index.html&lt;br /&gt;
* https://doc.powerdns.com/authoritative/manpages/pdns_server.1.html&lt;br /&gt;
* https://doc.powerdns.com/authoritative/manpages/pdnsutil.1.html&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# List commands&lt;br /&gt;
pdns_server --help&lt;br /&gt;
&lt;br /&gt;
# Check config and parse for errors&lt;br /&gt;
pdns_server --config=check&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# List available commands &lt;br /&gt;
pdnsutil --help&lt;br /&gt;
&lt;br /&gt;
# Check config and parse for errors&lt;br /&gt;
pdnsutil --config=check&lt;br /&gt;
&lt;br /&gt;
# List all available zones&lt;br /&gt;
pdnsutil list-all-zones&lt;br /&gt;
&lt;br /&gt;
# List all domains in the primary zone&lt;br /&gt;
pdnsutil list-all-zones primary&lt;br /&gt;
&lt;br /&gt;
# See zone information for a specific domain&lt;br /&gt;
pdnsutil show-zone mydomain.com&lt;br /&gt;
pdnsutil show-zone 77.5.10.in-addr.arpa&lt;br /&gt;
&lt;br /&gt;
# Check zone for errors&lt;br /&gt;
pdnsutil check-zone mydomain.com&lt;br /&gt;
&lt;br /&gt;
# List all created TSIG keys&lt;br /&gt;
pdnsutil list-tsig-keys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# Activate TSIG key for domain &amp;quot;myexample.com&amp;quot; in the primary zone&lt;br /&gt;
pdnsutil &amp;quot; myexample.com transfer primary&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MAAS ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Logs in either place:&lt;br /&gt;
/var/log/maas/&lt;br /&gt;
/var/snap/maas/common/log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List status of MAAS services&lt;br /&gt;
maas status&lt;br /&gt;
&lt;br /&gt;
# List MAAS commands&lt;br /&gt;
maas --help&lt;br /&gt;
&lt;br /&gt;
# List available arguments for the init command&lt;br /&gt;
maas init --help&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section end=&amp;quot;linuxservices&amp;quot;/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux&amp;diff=855</id>
		<title>Linux</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux&amp;diff=855"/>
		<updated>2025-10-28T15:39:32Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* Create users and SSH access */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet]]&lt;br /&gt;
&lt;br /&gt;
This page is or will soon be an amalgamation of content from other pages&lt;br /&gt;
* [[Linux:Filesystems]]&lt;br /&gt;
* [[Linux:Services]]&lt;br /&gt;
&lt;br /&gt;
* [[Linux:Bash]]&lt;br /&gt;
* [[Linux:Scripting]]&lt;br /&gt;
* [[Linux:Network]]&lt;br /&gt;
* [[Linux:Tools]]&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
{{#lst:Linux:Bash|bashbasics}}&lt;br /&gt;
&lt;br /&gt;
[[:Linux:Bash#Shortcuts]]&lt;br /&gt;
&lt;br /&gt;
== Common checks ==&lt;br /&gt;
=== Monitoring ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See CPU + RAM usage, system stats and open processes&lt;br /&gt;
top&lt;br /&gt;
&lt;br /&gt;
# Only list processes making active use of the CPU&lt;br /&gt;
top -i&lt;br /&gt;
&lt;br /&gt;
# Only list processes making active use of the CPU, and include the entire command being instead of just the tool-name&lt;br /&gt;
top -ci&lt;br /&gt;
&lt;br /&gt;
# Prettier version of top that can be customized&lt;br /&gt;
htop&lt;br /&gt;
&lt;br /&gt;
# Reimagined version of top, includes network and disk usage by default&lt;br /&gt;
btop&lt;br /&gt;
&lt;br /&gt;
# Reimagined version of top that shows DISK READ and WRITE&lt;br /&gt;
iotop&lt;br /&gt;
&lt;br /&gt;
# List all running processes&lt;br /&gt;
ps aux&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Systemd ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Open journalctl at the beginning&lt;br /&gt;
journalctl -b&lt;br /&gt;
&lt;br /&gt;
# Open journalctl at the end&lt;br /&gt;
journalctl -e&lt;br /&gt;
&lt;br /&gt;
# Open journalctl but include service information&lt;br /&gt;
journalctl -x&lt;br /&gt;
&lt;br /&gt;
# Show journalctl logs for the sshd service, starting from the end&lt;br /&gt;
journalctl -u sshd -e&lt;br /&gt;
&lt;br /&gt;
# Output contents directly to the shell&lt;br /&gt;
journalctl --no-pager&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== OS &amp;amp; Distribution ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Print OS and host information&lt;br /&gt;
hostnamectl&lt;br /&gt;
&lt;br /&gt;
# Show OS and distribution information&lt;br /&gt;
cat /proc/version&lt;br /&gt;
&lt;br /&gt;
# Show OS and distribution information&lt;br /&gt;
cat /etc/os-release&lt;br /&gt;
&lt;br /&gt;
# Print distribution-specific information&lt;br /&gt;
lsb_release -a&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hardware &amp;amp; kernel ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List installed kernel modules&lt;br /&gt;
lsmod&lt;br /&gt;
&lt;br /&gt;
# Print Kernel messages&lt;br /&gt;
dmesg&lt;br /&gt;
&lt;br /&gt;
# Print Kernel messages with humanized timestamps&lt;br /&gt;
dmesg -T&lt;br /&gt;
&lt;br /&gt;
# SCSI hardware information&lt;br /&gt;
cat /proc/scsi/scsi&lt;br /&gt;
&lt;br /&gt;
# Print hardware/BIOS information&lt;br /&gt;
dmidecode &lt;br /&gt;
&lt;br /&gt;
# Print hardware/BIOS information of a specific type&lt;br /&gt;
dmidecode -t 1&lt;br /&gt;
&lt;br /&gt;
# List all connected hardware&lt;br /&gt;
lshw&lt;br /&gt;
&lt;br /&gt;
# List physical network hardware&lt;br /&gt;
lshw -short -class network&lt;br /&gt;
&lt;br /&gt;
# List physical memory hardware&lt;br /&gt;
lshw -class memory&lt;br /&gt;
&lt;br /&gt;
# Show PCI information&lt;br /&gt;
lspci&lt;br /&gt;
&lt;br /&gt;
# Show verbose PCI information&lt;br /&gt;
lspci -v&lt;br /&gt;
&lt;br /&gt;
# Show GPU info&lt;br /&gt;
lshw -C display&lt;br /&gt;
&lt;br /&gt;
# List all block/filesystem devices&lt;br /&gt;
lsblk&lt;br /&gt;
&lt;br /&gt;
# List block devices and partition tables&lt;br /&gt;
fdisk -l&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Pacemaker ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show status of the pacemaker cluster&lt;br /&gt;
pcs cluster status&lt;br /&gt;
&lt;br /&gt;
# Show status of the pacemaker service&lt;br /&gt;
pcs status&lt;br /&gt;
&lt;br /&gt;
# Show configured pacemaker resources&lt;br /&gt;
pcs resource config&lt;br /&gt;
&lt;br /&gt;
# Show a specific configured resource&lt;br /&gt;
pcs resource show ResourceNameHere&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Services ==&lt;br /&gt;
{{#lst:Linux:Services#Services|linuxservices}}&lt;br /&gt;
[[:Linux:Services]]&lt;br /&gt;
&lt;br /&gt;
== Filesystems ==&lt;br /&gt;
{{#lst:Linux:Filesystems|linuxfilesystems}}&lt;br /&gt;
[[:Linux:Filesystems]]&lt;br /&gt;
&lt;br /&gt;
== User management ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create the books group&lt;br /&gt;
groupadd books&lt;br /&gt;
&lt;br /&gt;
# Make myrthe part of the &amp;quot;philosophy&amp;quot; and &amp;quot;books&amp;quot; groups&lt;br /&gt;
usermod myrthe -aG philosophy,books&lt;br /&gt;
&lt;br /&gt;
# See the groups myrthe is part of&lt;br /&gt;
groups myrthe&lt;br /&gt;
&lt;br /&gt;
# The owner gains full control, group and everyone may: read, write and execute&lt;br /&gt;
chmod 755 /home/ring/gollum.txt&lt;br /&gt;
&lt;br /&gt;
# Make ballrog the owner of the /data/sf4/cup folder&lt;br /&gt;
chown ballrog:ballrog /data/sf4/cup&lt;br /&gt;
&lt;br /&gt;
# Make all files located anywhere within the .ssh, owned by the stalin user and soviet group&lt;br /&gt;
chown -R stalin:soviet /home/stalin/.ssh&lt;br /&gt;
&lt;br /&gt;
# Delete the simba user and include his home folder and mail spool&lt;br /&gt;
userdel -r simba&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Create users and SSH access ===&lt;br /&gt;
==== Useradd ====&lt;br /&gt;
===== Variant #1 - RHEL =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
USER=&amp;quot;danielle&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Create user with a home-folder and add him to the wheel group&lt;br /&gt;
useradd -m -G wheel --shell /bin/bash ${USER}&lt;br /&gt;
&lt;br /&gt;
# Create an SSH folder&lt;br /&gt;
mkdir -p /home/${USER}/.ssh&lt;br /&gt;
&lt;br /&gt;
# Add a public key&lt;br /&gt;
cat &amp;lt;&amp;lt; &#039;EOF&#039; &amp;gt;&amp;gt; /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
ssh-ed25519 123980idfas89132hadsckjh871234&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
# Set proper permissions for the .ssh folder and authorized_keys&lt;br /&gt;
chown -R ${USER}:${USER} /home/${USER}/.ssh&lt;br /&gt;
chmod 700 /home/${USER}/.ssh&lt;br /&gt;
chmod 600 /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Variant #2 - UBUNTU =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
USER=&amp;quot;dylan&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Create the admin group if it does not exist already&lt;br /&gt;
groupadd admin&lt;br /&gt;
&lt;br /&gt;
# Create a group that is the same as the username&lt;br /&gt;
groupadd ${USER}&lt;br /&gt;
&lt;br /&gt;
# Create user with a home-folder, set the primary group to his own group and add him to the admin group in addition, set default shell to /bin/bash&lt;br /&gt;
useradd -m -g ${USER} -G admin --shell /bin/bash ${USER}&lt;br /&gt;
&lt;br /&gt;
# Create an SSH folder&lt;br /&gt;
mkdir -p /home/${USER}/.ssh&lt;br /&gt;
&lt;br /&gt;
# Add the public key&lt;br /&gt;
cat &amp;lt;&amp;lt; &#039;EOF&#039; &amp;gt;&amp;gt; /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
ssh-ed25519 AAAqhwekhakdhslsh8712398 keyname&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
# Set proper permissions for user and .ssh folder and authorized_keys&lt;br /&gt;
chown -R ${USER}:${USER} /home/${USER}/&lt;br /&gt;
chmod 700 /home/${USER}/.ssh&lt;br /&gt;
chmod 600 /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Adduser variant - Ubuntu =====&lt;br /&gt;
Create regular user and configure/add SSH public key:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
USER=&amp;quot;dylan&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Create user and homefolder with a disabled password&lt;br /&gt;
adduser --disabled-password ${USER}&lt;br /&gt;
&lt;br /&gt;
# Give the user sudo rights, do mind that you disabled his password in the previous command&lt;br /&gt;
usermod -aG sudo ${USER}&lt;br /&gt;
&lt;br /&gt;
# Create an SSH folder&lt;br /&gt;
mkdir -p /home/${USER}/.ssh&lt;br /&gt;
&lt;br /&gt;
# Add a public key&lt;br /&gt;
cat &amp;lt;&amp;lt; &#039;EOF&#039; &amp;gt;&amp;gt; /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
ssh-ed25519 123980idfas89132hadsckjh871234&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
# Set proper permissions for user and .ssh folder and authorized_keys&lt;br /&gt;
chown -R ${USER}:${USER} /home/${USER}/&lt;br /&gt;
chmod 700 /home/${USER}/.ssh&lt;br /&gt;
chmod 600 /home/${USER}/.ssh/authorized_keys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Add Root user SSH keys ====&lt;br /&gt;
Add/configure SSH public key for root user, assuming no .ssh folder/file exists&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Add SSH-keys for root user&lt;br /&gt;
echo &amp;quot;Creating authorized keys file and setting rights for root user&amp;quot;&lt;br /&gt;
mkdir -p /root/.ssh&lt;br /&gt;
&lt;br /&gt;
# Add the following SSH keys to root&lt;br /&gt;
cat &amp;lt;&amp;lt; &#039;EOF&#039; &amp;gt;&amp;gt; /root/.ssh/authorized_keys&lt;br /&gt;
ssh-ed25519 AAAAC3NzaC1askdjasdsadsad mykeyname&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
chown -R root:root /root/.ssh&lt;br /&gt;
chmod 700 /root/.ssh&lt;br /&gt;
chmod 600 /root/.ssh/authorized_keys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Add regular user SSH keys ====&lt;br /&gt;
Add/configure SSH public key for a regular user, assuming no .ssh folder/file exists&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
USER=&amp;quot;greed&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Add SSH-keys to the defined user&lt;br /&gt;
echo &amp;quot;Creating authorized keys file and settings rights for ${USER} user&amp;quot;&lt;br /&gt;
mkdir -p /home/$USER/.ssh&lt;br /&gt;
&lt;br /&gt;
# Add normal user SSH keys&lt;br /&gt;
cat &amp;lt;&amp;lt; &#039;EOF&#039; &amp;gt;&amp;gt; /home/$USER/.ssh/authorized_keys&lt;br /&gt;
ssh-ed25519 AAAAC3NzaC1askdjasdsadsad mykeyname&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
chown -R ${USER}:${USER} /home/$USER/.ssh&lt;br /&gt;
chmod 700 /home/$USER/.ssh&lt;br /&gt;
chmod 600 /home/$USER/.ssh/authorized_keys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sudoers ===&lt;br /&gt;
* https://www.networkworld.com/article/3237946/building-command-groups-with-sudo.html&lt;br /&gt;
&lt;br /&gt;
Concerns &#039;&#039;&#039;/etc/sudoers&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Allow user jabami to execute any command, without specifying a passwd&lt;br /&gt;
jabami ALL=(ALL) NOPASSWD: ALL&lt;br /&gt;
&lt;br /&gt;
# Allow user &amp;quot;chris&amp;quot; to perform the 2 given commands with sudo, no password.&lt;br /&gt;
## Define user and associate the command group variable &amp;quot;UPDATE_CMDS&amp;quot;&lt;br /&gt;
chris    ALL=(ALL) NOPASSWD: UPDATE_CMDS&lt;br /&gt;
&lt;br /&gt;
## Define commands for the &amp;quot;UPDATE_CMDS&amp;quot; and &amp;quot;UPDATE_CMDS2&amp;quot; variables&lt;br /&gt;
Cmnd_Alias UPDATE_CMDS = /usr/bin/apt-get update, /usr/bin/apt-get upgrade&lt;br /&gt;
Cmnd_Alias UPDATE_CMDS2 = /usr/bin/apt-get update, /usr/bin/apt-get upgrade&lt;br /&gt;
&lt;br /&gt;
# Allow members of the group &amp;quot;researchers&amp;quot; to perform the commands in &amp;quot;UPDATE_CMDS2&amp;quot; with sudo rights, no password.&lt;br /&gt;
## User alias specification&lt;br /&gt;
%researchers    ALL=(ALL) NOPASSWD: UPDATE_CMDS2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Other ==&lt;br /&gt;
=== Performance tests ===&lt;br /&gt;
=== Network bandwidth &amp;amp; throughput ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Test bandwidth throughput with iperf&lt;br /&gt;
# Listen on server-A on port 5101&lt;br /&gt;
iperf3 -s -p 5101&lt;br /&gt;
&lt;br /&gt;
# Connect to server-A from server-B&lt;br /&gt;
iperf3 -c 192.168.0.1 -p 5101&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Filesystem ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Testing disk/share throughput&lt;br /&gt;
# Create &amp;quot;testfile&amp;quot; of size 1710x1M in current folder&lt;br /&gt;
time dd if=/dev/zero of=testfile bs=1M count=1710&lt;br /&gt;
&lt;br /&gt;
# Create &amp;quot;&#039;testfile2&amp;quot; of size 5x1G in current folder&lt;br /&gt;
time dd if=/dev/zero of=testfile2 bs=1G count=5&lt;br /&gt;
&lt;br /&gt;
# Show copy-time of &amp;quot;testfile&amp;quot; to disk or share&lt;br /&gt;
time cp testfile /mnt/btfrs/data/&amp;lt;LOCATION&amp;gt;/&lt;br /&gt;
&lt;br /&gt;
# Methods of testing disk or share throughput&lt;br /&gt;
# show read-time from the mount to null&lt;br /&gt;
time cat /mnt/btfrs/data/&amp;lt;FILE&amp;gt; &amp;gt; /dev/null&lt;br /&gt;
&lt;br /&gt;
# show copy-time from the mount to null&lt;br /&gt;
time dd if=/mnt/btfrs/data/&amp;lt;FILE&amp;gt; of=/dev/null bs=1M&lt;br /&gt;
&lt;br /&gt;
# show copy-time from the mount to the current folder&lt;br /&gt;
time cp /mnt/btfrs/data/&amp;lt;FILE&amp;gt; .&lt;br /&gt;
&lt;br /&gt;
# Copy one folder to another with rsync while showing progress&lt;br /&gt;
rsync -avhW --no-compress --progress &amp;lt;source&amp;gt;/ &amp;lt;destination&amp;gt;/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Create different temp folder ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a temporary TMP folder&lt;br /&gt;
mkdir -p /scratch/tmp/&lt;br /&gt;
&lt;br /&gt;
# Activate temporary TMP folder&lt;br /&gt;
export TMPDIR=/scratch/tmp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
* https://devhints.io/&lt;br /&gt;
* https://github.com/arm-on/linux-essentials&lt;br /&gt;
* https://thediligentdeveloper.com/30-interesting-shell-commands&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Vrp&amp;diff=854</id>
		<title>Vrp</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Vrp&amp;diff=854"/>
		<updated>2025-10-07T10:22:04Z</updated>

		<summary type="html">&lt;p&gt;Patrick: Redirected page to Huawei:VRP&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[Huawei:VRP]]&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Filesystems&amp;diff=853</id>
		<title>Linux:Filesystems</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Filesystems&amp;diff=853"/>
		<updated>2025-10-06T08:14:42Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* RBD-NBD */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet]]&lt;br /&gt;
&lt;br /&gt;
== Filesystems ==&lt;br /&gt;
&amp;lt;section begin=&amp;quot;linuxfilesystems&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List clients connected to local mounts&lt;br /&gt;
showmount&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== NFS ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
* https://www.ibm.com/docs/en/aix/7.2?topic=troubleshooting-identifying-nfs-problems&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# NFS &lt;br /&gt;
nfsstat&lt;br /&gt;
&lt;br /&gt;
# Detailed RPC and package information&lt;br /&gt;
nfsstat -o all&lt;br /&gt;
&lt;br /&gt;
# Every RPC &amp;quot;program&amp;quot; is bound to a specific NFS version. Use NFS/CTDB logs in combination with the program ID to identify the failing component&lt;br /&gt;
rpcinfo -p&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Common ====&lt;br /&gt;
===== Exports =====&lt;br /&gt;
Use file /etc/exports to define exports to cliënts. &amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create the folders before exporting them&lt;br /&gt;
mkdir -p /data/exports/customer1000/finance&lt;br /&gt;
mkdir -p /data/exports/customer1001/backup&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NFSv3&#039;&#039;&#039; example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#////////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
# Customer1000&lt;br /&gt;
/data/exports/customer1000/finance 192.168.20.1(rw,no_root_squash,sync) 192.168.20.2(rw,sync)&lt;br /&gt;
#////////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
# Customer1001&lt;br /&gt;
/data/exports/customer1001/backup 192.168.30.1(rw,no_root_squash) 192.168.30.1(rw,no_root_squash,sync)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reload the NFS server to apply changes within /etc/exports&lt;br /&gt;
systemctl reload nfs-server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Client mount =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install NFS cliënt (Ubuntu)&lt;br /&gt;
apt install nfs-common&lt;br /&gt;
&lt;br /&gt;
# Install NFS cliënt (RHEL)&lt;br /&gt;
yum install nfs-utils&lt;br /&gt;
&lt;br /&gt;
# Mount NFS share located on server 192.168.20.1 on path /data/exports/customer1000/finance, to local server /mnt/nfs/&lt;br /&gt;
mount -v -t nfs 192.168.20.1:/data/exports/customer1000/finance /mnt/nfs/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Optimizations ====&lt;br /&gt;
Change these values depending on your usage and the available resources on your server.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/sysctl.d/nfs-tuning.conf&lt;br /&gt;
net.core.rmem_max=1048576&lt;br /&gt;
net.core.rmem_default=1048576&lt;br /&gt;
net.core.wmem_max=1048576&lt;br /&gt;
net.core.wmem_default=1048576&lt;br /&gt;
net.ipv4.tcp_rmem=4096 1048576 134217728&lt;br /&gt;
net.ipv4.tcp_wmem=4096 1048576 134217728&lt;br /&gt;
vm.min_free_kbytes=8388608&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reload above optimization&lt;br /&gt;
sysctl -p /etc/sysctl.d/nfs-tuning.conf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Raise the number of NFS threads&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/sysconfig/nfs&lt;br /&gt;
&lt;br /&gt;
# Number of nfs server processes to be started.&lt;br /&gt;
# The default is 8.&lt;br /&gt;
#RPCNFSDCOUNT=16&lt;br /&gt;
RPCNFSDCOUNT=128&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Activate NFSD count on the fly&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
rpc.nfsd 64&lt;br /&gt;
&lt;br /&gt;
# Check amount of threads&lt;br /&gt;
/proc/fs/nfsd/threads &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Ceph ===&lt;br /&gt;
* https://sabaini.at/pages/ceph-cheatsheet.html&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Display the running Ceph version&lt;br /&gt;
ceph -v&lt;br /&gt;
&lt;br /&gt;
# Check the clusters&#039; health and status&lt;br /&gt;
ceph -s&lt;br /&gt;
&lt;br /&gt;
# Watch the clusters&#039; health and status in real time&lt;br /&gt;
ceph -w&lt;br /&gt;
&lt;br /&gt;
# Show detailed logs relating to cluster health&lt;br /&gt;
ceph health detail&lt;br /&gt;
&lt;br /&gt;
# List configurations for a lot of stuff&lt;br /&gt;
cephadm ls&lt;br /&gt;
&lt;br /&gt;
# List configurations for a lot of stuff&lt;br /&gt;
ceph config dump&lt;br /&gt;
&lt;br /&gt;
# List all Ceph &#039;containers&#039; and OSDs&lt;br /&gt;
ceph orch ls&lt;br /&gt;
&lt;br /&gt;
# Lists all hosts, labels and basic host resource information&lt;br /&gt;
ceph orch host ls --detail&lt;br /&gt;
&lt;br /&gt;
# List available storage devices&lt;br /&gt;
ceph orch device ls&lt;br /&gt;
&lt;br /&gt;
# List all Ceph daemons&lt;br /&gt;
ceph orch ps&lt;br /&gt;
&lt;br /&gt;
# List Ceph daemons of a specific type&lt;br /&gt;
ceph orch ps --daemon_type=mgr&lt;br /&gt;
&lt;br /&gt;
# Show logs for a specific service&lt;br /&gt;
ceph orch ls --service_name osd.all-available-devices --format yaml&lt;br /&gt;
&lt;br /&gt;
# Re-check the status of a host&lt;br /&gt;
ceph cephadm check-host storage-3&lt;br /&gt;
&lt;br /&gt;
# Check the current number of operations on a primary Ceph node&lt;br /&gt;
ceph daemon /var/run/ceph/ceph-mds.xxxxxxxx.vxokby.asok dump_ops_in_flight&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;OSDs&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all pools&lt;br /&gt;
ceph osd lspools&lt;br /&gt;
&lt;br /&gt;
# See the status of all OSDs&lt;br /&gt;
ceph osd stat&lt;br /&gt;
&lt;br /&gt;
# List all OSDs&lt;br /&gt;
ceph osd tree&lt;br /&gt;
&lt;br /&gt;
# List all OSDs and related information in detail&lt;br /&gt;
ceph osd df tree&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;PGs&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all Placement Groups&lt;br /&gt;
ceph pg dump&lt;br /&gt;
&lt;br /&gt;
# Check the status of Ceph PGs&lt;br /&gt;
ceph pg stat&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Authentication&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all created clients and their permissions&lt;br /&gt;
ceph auth ls&lt;br /&gt;
&lt;br /&gt;
# List permissions for a specific client&lt;br /&gt;
ceph auth get client.cinder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enter the Ceph shell (single cluster)&lt;br /&gt;
cephadm shell&lt;br /&gt;
&lt;br /&gt;
# Enter the Ceph shell for a specific cluster&lt;br /&gt;
sudo /usr/sbin/cephadm shell --fsid asdjwqe-asjd324-asdki321-821asd-asd241-asdn1234- -c /etc/ceph/ceph.conf -k /etc/ceph/ceph.client.admin2.keyring&lt;br /&gt;
&lt;br /&gt;
# Give node storage-4, which is already a cluster member, the admin tag&lt;br /&gt;
ceph orch host label add storage-4 _admin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Installation (Quincy) ====&lt;br /&gt;
Using Cephadm: https://docs.ceph.com/en/quincy/cephadm/install/&lt;br /&gt;
&lt;br /&gt;
===== Cephadm =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a folder for the cephadm tool&lt;br /&gt;
mkdir cephadm&lt;br /&gt;
cd cephadm/&lt;br /&gt;
&lt;br /&gt;
# Download cephadm (Quincy)&lt;br /&gt;
curl --silent --remote-name --location https://github.com/ceph/ceph/raw/quincy/src/cephadm/cephadm&lt;br /&gt;
chmod +x cephadm&lt;br /&gt;
&lt;br /&gt;
# Output help&lt;br /&gt;
./cephadm -h&lt;br /&gt;
&lt;br /&gt;
# Install cephadm (Quincy) release&lt;br /&gt;
./cephadm add-repo --release quincy&lt;br /&gt;
./cephadm install&lt;br /&gt;
&lt;br /&gt;
# Check if cephadm is properly installed&lt;br /&gt;
which cephadm&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Bootstrap =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Bootstrap node and install Ceph&lt;br /&gt;
cephadm bootstrap --mon-ip 192.168.100.11&lt;br /&gt;
&lt;br /&gt;
# Check the status of the cluster&lt;br /&gt;
cephadm shell -- ceph -s&lt;br /&gt;
docker ps&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
## Optional&lt;br /&gt;
# Enter the Ceph shell (single cluster)&lt;br /&gt;
cephadm shell&lt;br /&gt;
&lt;br /&gt;
# Exit the Ceph shell&lt;br /&gt;
exit&lt;br /&gt;
&lt;br /&gt;
# Install common Ceph packages/tools &lt;br /&gt;
cephadm install ceph-common&lt;br /&gt;
&lt;br /&gt;
# Display the Ceph version&lt;br /&gt;
ceph -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Add additional hosts =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On your bootstrapped node create a key for SSH-access to the other hosts.&lt;br /&gt;
ssh-keygen&lt;br /&gt;
cat .ssh/id_rsa.pub&lt;br /&gt;
&lt;br /&gt;
# Add the newly generated key to the authorized_keys file for the relevant user, on the other hosts.&lt;br /&gt;
&lt;br /&gt;
# Copy the Ceph clusters&#039; public key to the other nodes&lt;br /&gt;
ssh-copy-id -f -i /etc/ceph/ceph.pub root@storage-2&lt;br /&gt;
ssh-copy-id -f -i /etc/ceph/ceph.pub root@storage-3&lt;br /&gt;
&lt;br /&gt;
# Add the other nodes to the cluster, and assign them the admin role&lt;br /&gt;
ceph orch host add storage-2 10.4.20.2 _admin&lt;br /&gt;
ceph orch host add storage-3 10.4.20.3 _admin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
===== OSD creation =====&lt;br /&gt;
* https://github.com/rook/rook/issues/7519&lt;br /&gt;
If you&#039;ve installed ceph-osd on your host, this step will fail horribly with errors such as:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
-1 bluestore(/var/lib/ceph/osd/ceph-1//block) _read_bdev_label failed to open /var/lib/ceph/osd/ceph-1//block: (13) Permission denied&lt;br /&gt;
-1 bdev(0x5571d5f69400 /var/lib/ceph/osd/ceph-1//block) open open got: (13) Permission denied&lt;br /&gt;
-1 OSD::mkfs: ObjectStore::mkfs failed with error (13) Permission denied&lt;br /&gt;
-1 ESC[0;31m ** ERROR: error creating empty object store in /var/lib/ceph/osd/ceph-0/: (13) Permission deniedESC[0m&lt;br /&gt;
 OSD, will rollback changes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Configure all available storage to be used as OSD storage&lt;br /&gt;
ceph orch apply osd --all-available-devices&lt;br /&gt;
&lt;br /&gt;
# Check for OSD problems&lt;br /&gt;
watch ceph -s&lt;br /&gt;
watch ceph osd tree&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Delete pool ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Set ability to remove pools to true&lt;br /&gt;
ceph config set mon mon_allow_pool_delete true&lt;br /&gt;
&lt;br /&gt;
# Remove the pool&lt;br /&gt;
ceph osd pool rm tester tester --yes-i-really-really-mean-it&lt;br /&gt;
&lt;br /&gt;
# Set ability to remove pools to false&lt;br /&gt;
ceph config set mon mon_allow_pool_delete false&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Upgrade ====&lt;br /&gt;
Make sure your cluster status is healthy first!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Upgrade Ceph to a specific version&lt;br /&gt;
ceph orch upgrade start --ceph-version 17.2.0&lt;br /&gt;
&lt;br /&gt;
# Check the status of the Ceph upgrade&lt;br /&gt;
ceph orch upgrade status&lt;br /&gt;
&lt;br /&gt;
# Stop the Ceph upgrade&lt;br /&gt;
ceph orch upgrade stop&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ceph client ====&lt;br /&gt;
===== Via Kernel =====&lt;br /&gt;
Mount a Ceph filesystem share using the kernel, Cephx and 3 mon hosts:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install common Ceph package for your distribution&lt;br /&gt;
apt-get install ceph-common&lt;br /&gt;
&lt;br /&gt;
# Create and fill the ceph.conf file, mind the enter in the end&lt;br /&gt;
cat &amp;lt;&amp;lt; &#039;EOF&#039; &amp;gt;&amp;gt; /etc/ceph/ceph.conf&lt;br /&gt;
# minimal ceph.conf for 492f528f-90ae-49e0-b622-ae58b85e8cf0&lt;br /&gt;
[global]&lt;br /&gt;
        fsid = 492f528f-90ae-49e0-b622-ae58b85e8cf0&lt;br /&gt;
        mon_host = [v2:192.168.0.11:3300/0,v1:192.168.0.11:6789/0] [v2:192.168.0.12:3300/0,v1:192.168.0.12:6789/0] [v2:192.168.0.13:3300/0,v1:192.168.0.13:6789/0]&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
# Add the Cephx used by your user&lt;br /&gt;
cat &amp;lt;&amp;lt; &#039;EOF&#039; &amp;gt;&amp;gt; /etc/ceph/ceph.client.sofie.keyring&lt;br /&gt;
[client.sofie]&lt;br /&gt;
        key = AIAOIWmaskjhqweASKhqwekjhASD==&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
# Mount your Ceph share by referring to the Ceph mons, the share on the Ceph mons, where you want to mount the share, and the userdata you use to connect to said share respectively.&lt;br /&gt;
mount -t ceph 192.168.0.11:6789,192.168:6789.0.12,192.168.0.13:6789:/shares/mycustomer/asd8asd8-as8d83-df4mjvjdf /mnt/ceph/mylocalsharelocation -o name=sofie&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Ceph-fuse =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Mount a Ceph filesystem using the ceph-fuse client&lt;br /&gt;
apt install ceph-fuse&lt;br /&gt;
mkdir myshare/&lt;br /&gt;
&lt;br /&gt;
nano sofie.keyring&lt;br /&gt;
[client.sofie]&lt;br /&gt;
        key = AQCHc7tlvEUqOBasjdHASJD9Lma84nASDJqwe==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
nano ceph.conf&lt;br /&gt;
[client]&lt;br /&gt;
        client quota = true&lt;br /&gt;
        mon host = 192.168.10.1:6789, 192.168.10.2:6789, 192.168.10.3:6789&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
sudo ceph-fuse ~/myshare \&lt;br /&gt;
--id=sofie \&lt;br /&gt;
--conf=./ceph.conf \&lt;br /&gt;
--keyring=./sofie.keyring \&lt;br /&gt;
--client-mountpoint=/volumes/_nogroup/6e99687f-asd2-47b0-8ba1-asduoiqwe/12398asnjd-0126-4cb3-9242-asduio1q23&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Debugmode in case of shit&lt;br /&gt;
sudo ceph-fuse ~/myshare \&lt;br /&gt;
--id=sofie \&lt;br /&gt;
--conf=./ceph.conf \&lt;br /&gt;
--keyring=./sofie.keyring \&lt;br /&gt;
--client-mountpoint=/volumes/_nogroup/6e99687f-asd2-47b0-8ba1-asduoiqwe/12398asnjd-0126-4cb3-9242-asduio1q23 -d -o debug&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== RBD-NBD ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List available volumes within the openstackvolumes pool&lt;br /&gt;
rbd ls openstackhdd&lt;br /&gt;
&lt;br /&gt;
# List all available snapshots for object volume-asd9p12o3-90b2-1238-1209-as980d7213hs, which reside in pool openstackhdd&lt;br /&gt;
rbd snap ls openstackhdd/volume-asd9p12o3-90b2-1238-1209-as980d7213hs&lt;br /&gt;
&lt;br /&gt;
# Map the volume-object to the local filesystem&lt;br /&gt;
rbd-nbd map openstackhdd/volume-asd9p12o3-90b2-1238-1209-as980d7213hs&lt;br /&gt;
&lt;br /&gt;
# Map the volume-object as read-only to the local filesystem&lt;br /&gt;
rbd-nbd map --read-only openstackhdd/volume-asd9p12o3-90b2-1238-1209-as980d7213hs&lt;br /&gt;
&lt;br /&gt;
# List currently mapped objects&lt;br /&gt;
rbd-nbd list-mapped&lt;br /&gt;
&lt;br /&gt;
# Check what filesystem and partition the device contains&lt;br /&gt;
fdisk -l /dev/nbd1&lt;br /&gt;
&lt;br /&gt;
# Mount the device to a local folder&lt;br /&gt;
mount /dev/nbd1p1 /mnt/storage&lt;br /&gt;
&lt;br /&gt;
# Unmount the device from the local folder&lt;br /&gt;
umount /mnt/storage&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# 2 methods to unmap&lt;br /&gt;
# Unmap the mapped object&lt;br /&gt;
rbd-nbd unmap /dev/nbd2&lt;br /&gt;
&lt;br /&gt;
# Unmap the mapped object&lt;br /&gt;
rbd-nbd unmap volume-asd9p12o3-90b2-1238-1209-as980d7213hs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Remove node ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Remove running daemons&lt;br /&gt;
ceph orch host drain storage-3&lt;br /&gt;
&lt;br /&gt;
# Remove host from the cluster&lt;br /&gt;
ceph orch host rm storage-3&lt;br /&gt;
&lt;br /&gt;
# In storage-3, restart the node&lt;br /&gt;
shutdown -r now&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Destroy node =====&lt;br /&gt;
&#039;&#039;&#039;Scorched earth&#039;&#039;&#039; &amp;lt;/br&amp;gt;&lt;br /&gt;
Only execute if you want to &#039;&#039;&#039;annihilate&#039;&#039;&#039; your &#039;&#039;&#039;node and or cluster&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Kill and destroy OSD 0&lt;br /&gt;
ceph osd down 0 &amp;amp;&amp;amp; ceph osd destroy 0 --force&lt;br /&gt;
&lt;br /&gt;
# Stop Ceph services&lt;br /&gt;
systemctl stop ceph-asd82asd-asd8-as92-a889-po89xc732cmn@mon.host-1.service&lt;br /&gt;
systemctl stop ceph-asd82asd-asd8-as92-a889-po89xc732cmn@crash.host-1.service&lt;br /&gt;
systemctl stop ceph-asd82asd-asd8-as92-a889-po89xc732cmn@mgr.host-1.xmatqa.service&lt;br /&gt;
systemctl stop ceph-asd82asd-asd8-as92-a889-po89xc732cmn@mon.host-1.service&lt;br /&gt;
systemctl stop ceph-asd82asd-asd8-as92-a889-po89xc732cmn@node-exporter.host-1.service&lt;br /&gt;
systemctl stop ceph-asd82asd-asd8-as92-a889-po89xc732cmn@prometheus.host-1.service&lt;br /&gt;
systemctl stop ceph-asd82asd-asd8-as92-a889-po89xc732cmn.target&lt;br /&gt;
&lt;br /&gt;
# Disable Ceph services&lt;br /&gt;
systemctl disable ceph-asd82asd-asd8-as92-a889-po89xc732cmn@mon.host-1.service&lt;br /&gt;
systemctl disable ceph-asd82asd-asd8-as92-a889-po89xc732cmn@crash.host-1.service&lt;br /&gt;
systemctl disable ceph-asd82asd-asd8-as92-a889-po89xc732cmn@mgr.host-1.xmatqa.service&lt;br /&gt;
systemctl disable ceph-asd82asd-asd8-as92-a889-po89xc732cmn@mon.host-1.service&lt;br /&gt;
systemctl disable ceph-asd82asd-asd8-as92-a889-po89xc732cmn@node-exporter.host-1.service&lt;br /&gt;
systemctl disable ceph-asd82asd-asd8-as92-a889-po89xc732cmn@prometheus.host-1.service&lt;br /&gt;
systemctl disable ceph-asd82asd-asd8-as92-a889-po89xc732cmn.target&lt;br /&gt;
&lt;br /&gt;
# Destroy everything (packages, containers, configuration)&lt;br /&gt;
ceph-deploy uninstall host-1&lt;br /&gt;
ceph-deploy purge host-1&lt;br /&gt;
rm -rf /var/lib/ceph&lt;br /&gt;
&lt;br /&gt;
# Check for failed services&lt;br /&gt;
systemctl | grep ceph&lt;br /&gt;
&lt;br /&gt;
# Reset them so they disable properly&lt;br /&gt;
systemctl reset-failed ceph-asd82asd-asd8-as92-a889-po89xc732cmn@prometheus.host-1.service&lt;br /&gt;
&lt;br /&gt;
# reboot&lt;br /&gt;
shutdown -r now&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BTRFS ===&lt;br /&gt;
* https://vitux.com/how-to-format-a-harddisk-partition-with-btrfs-on-ubuntu-20-04/&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Using LVM&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install LVM creation tools depending on your OS&lt;br /&gt;
yum install lvm2&lt;br /&gt;
apt install lvm2&lt;br /&gt;
&lt;br /&gt;
# Check and note the disk you need&lt;br /&gt;
fdisk -l&lt;br /&gt;
&lt;br /&gt;
# Format /dev/vdb as BTRFS&lt;br /&gt;
echo -e &amp;quot;n\np\n1\n\n\nt\n8E\np\nw&amp;quot; | fdisk /dev/vdb&lt;br /&gt;
 &lt;br /&gt;
# Create LVM &lt;br /&gt;
pvcreate /dev/vdb1&lt;br /&gt;
vgcreate vdb_vg /dev/vdb1&lt;br /&gt;
lvcreate -l 100%FREE  -n btrfs vdb_vg&lt;br /&gt;
 &lt;br /&gt;
# Check&lt;br /&gt;
pvs&lt;br /&gt;
vgs&lt;br /&gt;
 &lt;br /&gt;
# Create the BTRFS filesystem&lt;br /&gt;
mkfs.btrfs /dev/vdb_vg/btrfs&lt;br /&gt;
 &lt;br /&gt;
# Create a folder for the BTRFS mount&lt;br /&gt;
mkdir -p /mnt/btrfs1&lt;br /&gt;
&lt;br /&gt;
# Mount the BTRFS filesystem&lt;br /&gt;
mount -t btrfs /dev/vdb_vg/btrfs /mnt/btrfs1/&lt;br /&gt;
 &lt;br /&gt;
# Modify fstab so the filesystem get mounted automatically on boot&lt;br /&gt;
cat &amp;lt;&amp;lt; &#039;EOF&#039; &amp;gt;&amp;gt; /etc/fstab&lt;br /&gt;
/dev/mapper/vdb_vg-btrfs  /mnt/btrfs1    btrfs     defaults        0 0&lt;br /&gt;
EOF&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section end=&amp;quot;linuxfilesystems&amp;quot;/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Services&amp;diff=852</id>
		<title>Linux:Services</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Services&amp;diff=852"/>
		<updated>2025-10-01T11:59:51Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* Rainerscript */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet|Cheatsheets]]&lt;br /&gt;
&lt;br /&gt;
== Services ==&lt;br /&gt;
&amp;lt;section begin=&amp;quot;linuxservices&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Common ===&lt;br /&gt;
==== systemctl ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all services that are running or exited&lt;br /&gt;
systemctl&lt;br /&gt;
&lt;br /&gt;
# List all services, running or otherwise&lt;br /&gt;
systemctl --all&lt;br /&gt;
&lt;br /&gt;
# List all failed services&lt;br /&gt;
systemctl --state=failed&lt;br /&gt;
&lt;br /&gt;
# Reset the failed service &amp;quot;nginx&amp;quot;&lt;br /&gt;
systemctl reset-failed nginx&lt;br /&gt;
&lt;br /&gt;
# View the status of the &amp;quot;nfs-server&amp;quot; service&lt;br /&gt;
systemctl status nfs-server&lt;br /&gt;
&lt;br /&gt;
# Output the config file of &amp;quot;rsyslog&amp;quot; to the shell&lt;br /&gt;
systemctl cat rsyslog&lt;br /&gt;
&lt;br /&gt;
# Restart the &amp;quot;sshd&amp;quot; service, terminating established connections and re-parsing the configuration&lt;br /&gt;
systemctl restart sshd&lt;br /&gt;
&lt;br /&gt;
# Reload the &amp;quot;nginx&amp;quot; service so that it only re-parses the configuration&lt;br /&gt;
systemctl reload nginx&lt;br /&gt;
&lt;br /&gt;
# Stop the &amp;quot;nfs-ganesha&amp;quot; service so that it stops being run&lt;br /&gt;
systemctl stop nfs-ganesha&lt;br /&gt;
&lt;br /&gt;
# Start the &amp;quot;nfs-ganesha&amp;quot; service so that it starts being run again&lt;br /&gt;
systemctl start nfs-ganesha&lt;br /&gt;
&lt;br /&gt;
# Disable the &amp;quot;mariadb&amp;quot; service so that it doesn&#039;t start after the next boot&lt;br /&gt;
systemctl disable mariadb&lt;br /&gt;
&lt;br /&gt;
# Enable the &amp;quot;mariadb&amp;quot; service so that it starts after the next boot.&lt;br /&gt;
systemctl enable mariadb&lt;br /&gt;
&lt;br /&gt;
# Check the logs for all failed services&lt;br /&gt;
for i in $(systemctl --state=failed | head -n -4 | tail -n +2 | awk &#039;{print $1}&#039;); do systemctl --no-pager status &amp;quot;$i&amp;quot;; done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== NTP ===&lt;br /&gt;
==== Timedatectl ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show the current status of timedatectl&lt;br /&gt;
timedatectl&lt;br /&gt;
&lt;br /&gt;
# List available timezones&lt;br /&gt;
timedatectl list-timezones&lt;br /&gt;
&lt;br /&gt;
# Set the timezone to Amsterdam&lt;br /&gt;
timedatectl set-timezone Europe/Amsterdam&lt;br /&gt;
&lt;br /&gt;
# Show verbose sync information&lt;br /&gt;
timedatectl timesync-status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SNMP ===&lt;br /&gt;
==== V3 client installation ====&lt;br /&gt;
* https://kifarunix.com/quick-way-to-install-and-configure-snmp-on-ubuntu-20-04/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
apt install snmpd snmp libsnmp-dev&lt;br /&gt;
cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.bak&lt;br /&gt;
systemctl stop snmpd&lt;br /&gt;
net-snmp-create-v3-user -ro -X &amp;lt;CRYPTO-PASSWORD&amp;gt; -a SHA -X &amp;lt;PASSWORD&amp;gt; -x AES &amp;lt;USERNAME&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/snmp/snmpd.conf&lt;br /&gt;
sysLocation    NL;Zuid-Holland;Rotterdam, 78 MyStreet;2nd Floor;Server Room;Rack&lt;br /&gt;
sysContact     Me &amp;lt;me@example.org&amp;gt;&lt;br /&gt;
agentaddress   192.168.0.10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
systemctl start snmpd&lt;br /&gt;
systemctl enable snmpd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Test&lt;br /&gt;
snmpwalk -v3 -a SHA -A &amp;quot;AUTHENTICATION PASSWORD&amp;quot; -x AES -X &amp;quot;CRYPTO PASSWORD&amp;quot; -l authPriv -u &amp;quot;MYUSER&amp;quot; localhost | head&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CTDB  ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Verify CTDB cluster status&lt;br /&gt;
ctdb status&lt;br /&gt;
&lt;br /&gt;
# Show the allocated IP addresses and to which nodes they&#039;re bound&lt;br /&gt;
ctdb ip&lt;br /&gt;
&lt;br /&gt;
# See the status of all CTDB-scripts&lt;br /&gt;
ctdb scriptstatus&lt;br /&gt;
ctdb event status&lt;br /&gt;
&lt;br /&gt;
# Show the time of the last failover the duration it took to recover&lt;br /&gt;
ctdb uptime&lt;br /&gt;
&lt;br /&gt;
# See various statistics and data&lt;br /&gt;
ctdb statistics&lt;br /&gt;
&lt;br /&gt;
# Use the onnode command to execute a command on all cluster nodes&lt;br /&gt;
onnode all ctdb status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Stop a ctdb cluster member&lt;br /&gt;
ctdb stop&lt;br /&gt;
&lt;br /&gt;
# Start a stopped ctdb cluster member&lt;br /&gt;
ctdb continue&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Firewalls ===&lt;br /&gt;
==== UFW ====&lt;br /&gt;
===== Checks =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show summary of UFW status&lt;br /&gt;
ufw status&lt;br /&gt;
&lt;br /&gt;
# Show verbose UFW status&lt;br /&gt;
ufw status verbose&lt;br /&gt;
&lt;br /&gt;
# Show UFW rules numbered&lt;br /&gt;
ufw status numbered&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Commands =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Allow access from a specific IP to a port and add a comment that show in the status&lt;br /&gt;
ufw allow from 10.0.0.253 to any port 22 proto tcp comment &#039;Allow SSH access from XYZ location&#039;&lt;br /&gt;
&lt;br /&gt;
# Delete numbered Firewall rule 56&lt;br /&gt;
ufw delete 56&lt;br /&gt;
&lt;br /&gt;
# Disable UFW logging (prevent syslog spam)&lt;br /&gt;
ufw logging off&lt;br /&gt;
&lt;br /&gt;
# Set UFW logging back to the default&lt;br /&gt;
ufw logging low&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Firewalld ====&lt;br /&gt;
===== SNMP access =====&lt;br /&gt;
* https://unix.stackexchange.com/questions/214388/how-to-let-the-firewall-of-rhel7-the-snmp-connection-passing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/firewalld/services/snmp.xml&lt;br /&gt;
&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;service&amp;gt;&lt;br /&gt;
  &amp;lt;short&amp;gt;SNMP&amp;lt;/short&amp;gt;&lt;br /&gt;
  &amp;lt;description&amp;gt;SNMP protocol&amp;lt;/description&amp;gt;&lt;br /&gt;
  &amp;lt;port protocol=&amp;quot;udp&amp;quot; port=&amp;quot;161&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/service&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
firewall-cmd --zone=public --add-service snmp --permanent&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Firewall-cmd =====&lt;br /&gt;
====== Checks ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all available commands&lt;br /&gt;
firewall-cmd -h&lt;br /&gt;
&lt;br /&gt;
# Check the configuration file of the firewall for errors&lt;br /&gt;
firewall-cmd --check-config&lt;br /&gt;
&lt;br /&gt;
# Display the current state of firewall-cmd (running/shutdown)&lt;br /&gt;
firewall-cmd --state&lt;br /&gt;
&lt;br /&gt;
# Display all available zones&lt;br /&gt;
firewall-cmd --get-zones&lt;br /&gt;
&lt;br /&gt;
# List all whitelisted services&lt;br /&gt;
firewall-cmd --list-services&lt;br /&gt;
&lt;br /&gt;
# List all services you can potentially enable&lt;br /&gt;
firewall-cmd --get-services&lt;br /&gt;
&lt;br /&gt;
# List all added or enabled services and ports in more detail&lt;br /&gt;
firewall-cmd --list-all&lt;br /&gt;
&lt;br /&gt;
# List verbose information for all zones&lt;br /&gt;
firewall-cmd --list-all-zones&lt;br /&gt;
&lt;br /&gt;
# List verbose information for the public zone&lt;br /&gt;
firewall-cmd --list-all --zone=public&lt;br /&gt;
&lt;br /&gt;
# See what port(s) are associated with the dns service&lt;br /&gt;
firewall-cmd --info-service dns&lt;br /&gt;
&lt;br /&gt;
# List all opened ports&lt;br /&gt;
firewall-cmd --list-ports&lt;br /&gt;
&lt;br /&gt;
# List kernel ruleset generated for nftables(?)&lt;br /&gt;
nft list ruleset&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Commands ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reload the firewall&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Whitelist the dns service, persistently even after reboot&lt;br /&gt;
firewall-cmd --add-service=dns ; sudo firewall-cmd --runtime-to-permanent; firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Whitelist the http service, persistently even after reboot&lt;br /&gt;
firewall-cmd --add-service=http ; sudo firewall-cmd --runtime-to-permanent; firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Remove the http service from the whitelist&lt;br /&gt;
firewall-cmd --remove-service=http&lt;br /&gt;
&lt;br /&gt;
# Add port 1234 (tcp) to the whitelist&lt;br /&gt;
firewall-cmd --add-port=1234/tcp&lt;br /&gt;
&lt;br /&gt;
# Remove port 1234 (tcp) from the whitelist&lt;br /&gt;
firewall-cmd --remove-port=1234/tcp&lt;br /&gt;
&lt;br /&gt;
# Add port 2345 (udp) to the whitelist in zone external&lt;br /&gt;
firewall-cmd --zone=external --add-port=2345/udp&lt;br /&gt;
&lt;br /&gt;
# Remove port 2345 (udp) from the whitelist for zone external&lt;br /&gt;
firewall-cmd --zone=external --add-port=2345/udp&lt;br /&gt;
&lt;br /&gt;
# Add current configuration to configuration permanently&lt;br /&gt;
firewall-cmd –runtime-to-permanent&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;DANGEROUS&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# SHUT IT DOWN DOC - DROP ALL PACKETS AND EXPIRE EXISTING CONNECTIONS&lt;br /&gt;
firewall-cmd --panic-on&lt;br /&gt;
&lt;br /&gt;
# ACCEPT PACKETS AGAIN&lt;br /&gt;
firewall-cmd --panic-off&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== CSF ====&lt;br /&gt;
ConfigServer Security and Firewall&lt;br /&gt;
&lt;br /&gt;
===== General =====&lt;br /&gt;
* Common configuration: /etc/csf/csf.conf &lt;br /&gt;
* Blacklist: /etc/csf/csf.deny &lt;br /&gt;
* Whitelist: /etc/csf/csf.allow &lt;br /&gt;
&lt;br /&gt;
===== Installation =====&lt;br /&gt;
From the official instructions: https://download.configserver.com/csf/install.txt&lt;br /&gt;
&lt;br /&gt;
====== Prerequisites ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Perl Modules&lt;br /&gt;
============&lt;br /&gt;
While most should be installed on a standard perl installation the following&lt;br /&gt;
may need to be installed manually:&lt;br /&gt;
&lt;br /&gt;
# On rpm based systems:&lt;br /&gt;
yum install perl-libwww-perl.noarch perl-LWP-Protocol-https.noarch perl-GDGraph&lt;br /&gt;
&lt;br /&gt;
# On APT based systems:&lt;br /&gt;
apt-get install libwww-perl liblwp-protocol-https-perl libgd-graph-perl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Install ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cd /usr/src&lt;br /&gt;
rm -fv csf.tgz&lt;br /&gt;
wget https://download.configserver.com/csf.tgz&lt;br /&gt;
tar -xzf csf.tgz&lt;br /&gt;
cd csf&lt;br /&gt;
sh install.sh&lt;br /&gt;
&lt;br /&gt;
# Next, test whether you have the required iptables modules:&lt;br /&gt;
perl /usr/local/csf/bin/csftest.pl&lt;br /&gt;
&lt;br /&gt;
# Don&#039;t worry if you cannot run all the features, so long as the script doesn&#039;t report any FATAL errors&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Checks =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check the running status of csf&lt;br /&gt;
csf status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Commands =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Commit config changes by restarting csf&lt;br /&gt;
csf -r&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== csf.conf =====&lt;br /&gt;
Some common changes within the configuration file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Set testing to 0 when your CSF configuration is &#039;production&#039; ready&lt;br /&gt;
TESTING = &amp;quot;0&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow access to any service you&#039;re hosting locally, for example https&lt;br /&gt;
TCP_IN = &amp;quot;443&amp;quot;&lt;br /&gt;
UDP_IN = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow all outwards HTTP/HTTPS traffic so you can yum/apt update&lt;br /&gt;
TCP_OUT = &amp;quot;80,443&amp;quot; &lt;br /&gt;
&lt;br /&gt;
# Allow outgoing traceroute&lt;br /&gt;
UDP_OUT = &amp;quot;33434:33523&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow your server to be pinged&lt;br /&gt;
ICMP_IN = &amp;quot;0&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Formatting =====&lt;br /&gt;
The varying styles of formatting used in allow.conf&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Allow anything relating to the following IPs/ranges&lt;br /&gt;
192.168.10.0/24 # Our application breaks without this range&lt;br /&gt;
192.168.1.1 # Our gateway or something&lt;br /&gt;
&lt;br /&gt;
# Detailed entries based on Transport protocol, direction, Application protocol and IP&lt;br /&gt;
tcp:in:d=22:s=7.7.7.7 # SSH access from our VPN&lt;br /&gt;
udp:in:d=161:s=10.11.12.100 # SNMP Access&lt;br /&gt;
tcp|in|d=22|s=fe80::1:/16 # IPV6 SSH access from our jumpgateway&lt;br /&gt;
udp|in|d=3389|s=10.1.0.0/24 # RDP Access from our entire office range&lt;br /&gt;
tcp|out|d=80,443|d=1.2.3.4/32 # Allow outgoing HTTP/HTTPS access via port 80 and 443&lt;br /&gt;
&lt;br /&gt;
# Allow sending Syslog messages to our Syslog server&lt;br /&gt;
udp|out|d=514|d=192.168.20.5 # UDP syslog server&lt;br /&gt;
tcp|out|d=10514|d=192.168.20.5 # UDP syslog server&lt;br /&gt;
&lt;br /&gt;
# Allow sending queries to some DNS servers&lt;br /&gt;
tcp|out|s=53|d=8.8.8.8&lt;br /&gt;
udp|out|s=53|d=1.1.1.1&lt;br /&gt;
udp|out|s=53|d=2606:4700:4700::1111 # Cloudflare IPv6 DNS Server&lt;br /&gt;
&lt;br /&gt;
# Include an external configuration file&lt;br /&gt;
Include /etc/csf/csf.custom-config&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rsyslog ===&lt;br /&gt;
&amp;lt;section begin=&amp;quot;linuxsyslog&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* https://www.rsyslog.com/doc/reference/templates/templates-reserved-names.html#ref-templates-reserved-names&lt;br /&gt;
* https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/6/html/deployment_guide/s2-templates&lt;br /&gt;
&lt;br /&gt;
==== Legacy ====&lt;br /&gt;
Send all logs to a rsyslog server and specify a port, @ is equal to using UDP. @@ is equal to TCP&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/75-local-to-rsyslog-server.conf&lt;br /&gt;
*.* @10.77.0.1:514&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Custom template where hostname is defined, then sent to the syslog server - include the priority number as first extra variable&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#/etc/rsyslog.d/70-local-to-rsyslog-server.conf&lt;br /&gt;
$template SendHostname, &amp;quot;%PRI%1 %timestamp% myhost.mydomain.nl %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.warning @10.77.0.1;SendHostname&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Send messages to a syslog server, using a template aligned to IETF protocol 23&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/61-qwe.conf&lt;br /&gt;
*.* @10.77.0.1;RSYSLOG_SyslogProtocol23Format&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Send messages to a syslog server, using a template aligned to IETF protocol 23, but specifying a custom hostname&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/60-asd.conf&lt;br /&gt;
$template custom_IETFprotocol_23,&amp;quot;%PRI%1 %TIMESTAMP:::date-rfc3339% prive.host.nl %APP-NAME% %PROCID% %MSGID% %STRUCTURED-DATA% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* @10.77.0.1;custom_IETFprotocol_23&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Log to the local server with a static hostname, using a custom structure&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/62-asd.conf&lt;br /&gt;
$template NewHostname, &amp;quot;%timestamp% tester.mydomain.nl %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* /var/log/wewuzerrors.txt;NewHostname&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An alternative to the contents above, specifying different/more fields&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
## /etc/rsyslog.d/65-customtemplate.conf&lt;br /&gt;
# https://stackoverflow.com/questions/57890176/extending-rsyslogs-default-logging-template&lt;br /&gt;
$template mynewtemplate,&amp;quot;%timegenerated% %HOSTNAME% %syslogfacility-text%.%syslogseverity-text% %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* /var/log/wazanda.txt;mynewtemplate&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rainerscript ====&lt;br /&gt;
Rainerscript: https://rsyslog.readthedocs.io/en/latest/rainerscript/control_structures.html&lt;br /&gt;
&lt;br /&gt;
Write all local messages to a specific file&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/60-asd.conf&lt;br /&gt;
action(type=&amp;quot;omfile&amp;quot; file=&amp;quot;/var/log/isaidhey.txt&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Send message to a syslog server using IETF protocol 23&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/70-local-to-rsyslog-server.conf&lt;br /&gt;
template(name=&amp;quot;RSYSLOG_SyslogProtocol23Format&amp;quot; type=&amp;quot;string&amp;quot;&lt;br /&gt;
     string=&amp;quot;&amp;lt;%PRI%&amp;gt;1 %TIMESTAMP:::date-rfc3339% %HOSTNAME% %APP-NAME% %PROCID% %MSGID% %STRUCTURED-DATA% %msg%\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Send all logs to the target server&lt;br /&gt;
action(type=&amp;quot;omfwd&amp;quot; Target=&amp;quot;192.168.5.21&amp;quot; Template=&amp;quot;RSYSLOG_SyslogProtocol23Format&amp;quot; Port=&amp;quot;514&amp;quot; Protocol=&amp;quot;udp&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Define a template aligned to IETF protocol 23 but specify a hostname to send as:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/71-local-to-rsyslog-server.conf&lt;br /&gt;
template(name=&amp;quot;SendHostname&amp;quot; type=&amp;quot;string&amp;quot;&lt;br /&gt;
     string=&amp;quot;&amp;lt;%PRI%&amp;gt;1 %TIMESTAMP:::date-rfc3339% myhost.mydomain.nl %APP-NAME% %PROCID% %MSGID% %STRUCTURED-DATA% %msg%\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Send all logs to target syslog server and port&lt;br /&gt;
action(type=&amp;quot;omfwd&amp;quot; Target=&amp;quot;10.0.33.10&amp;quot; Template=&amp;quot;SendHostname&amp;quot; Port=&amp;quot;514&amp;quot; Protocol=&amp;quot;udp&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Testing ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use the logger tool to test syslog server reception&lt;br /&gt;
logger -p local0.error &#039;Hello World!&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section end=&amp;quot;linuxsyslog&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== named ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Perform a test load of all primary zones within named.conf, as the named user&lt;br /&gt;
sudo -u named named-checkconf -z&lt;br /&gt;
&lt;br /&gt;
# Check zone file 192.168.77.0 defined in the 77.168.192.in-addr.arpa zone&lt;br /&gt;
named-checkzone 77.168.192.in-addr.arpa 192.168.77.0&lt;br /&gt;
&lt;br /&gt;
# Check zone file brammerloo.nl defined in the brammerloo.nl zone&lt;br /&gt;
named-checkzone brammerloo.nl brammerloo.nl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Basic configuration for the options field in &#039;&#039;&#039;/etc/named.conf&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
options {&lt;br /&gt;
# Define on what IP to listen on, for port 53&lt;br /&gt;
        listen-on port 53 { 127.0.0.1; 192.168.0.1; 192.168.1.1; };&lt;br /&gt;
        directory       &amp;quot;/var/named&amp;quot;;&lt;br /&gt;
        dump-file       &amp;quot;/var/named/data/cache_dump.db&amp;quot;;&lt;br /&gt;
        statistics-file &amp;quot;/var/named/data/named_stats.txt&amp;quot;;&lt;br /&gt;
        memstatistics-file &amp;quot;/var/named/data/named_mem_stats.txt&amp;quot;;&lt;br /&gt;
        secroots-file   &amp;quot;/var/named/data/named.secroots&amp;quot;;&lt;br /&gt;
        recursing-file  &amp;quot;/var/named/data/named.recursing&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# Only allow DNS queries from specific local subnets&lt;br /&gt;
# To allow from anything use: allow query { any; };&lt;br /&gt;
        allow-query     { localhost; 127.0.0.1; 192.168.0.0/24; 192.168.1.0/24; };&lt;br /&gt;
&lt;br /&gt;
# If the server can&#039;t resolve an address locally, use the following DNS servers for help&lt;br /&gt;
        forwarders {&lt;br /&gt;
        8.8.8.8;&lt;br /&gt;
        1.1.1.1;&lt;br /&gt;
        };&lt;br /&gt;
&lt;br /&gt;
        recursion yes;&lt;br /&gt;
        dnssec-validation no;&lt;br /&gt;
&lt;br /&gt;
        managed-keys-directory &amp;quot;/var/named/dynamic&amp;quot;;&lt;br /&gt;
        geoip-directory &amp;quot;/usr/share/GeoIP&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
        pid-file &amp;quot;/run/named/named.pid&amp;quot;;&lt;br /&gt;
        session-keyfile &amp;quot;/run/named/session.key&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
        /* https://fedoraproject.org/wiki/Changes/CryptoPolicy */&lt;br /&gt;
        include &amp;quot;/etc/crypto-policies/back-ends/bind.config&amp;quot;;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone defnitions: &#039;&#039;&#039;/etc/named.rfc1912.zones&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Define zones to listen for&lt;br /&gt;
zone &amp;quot;brammerloo.nl&amp;quot; IN {&lt;br /&gt;
        type master;&lt;br /&gt;
        file &amp;quot;brammerloo.nl&amp;quot;;&lt;br /&gt;
        allow-update { none; };&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
zone &amp;quot;1.168.192.in-addr.arpa&amp;quot; IN {&lt;br /&gt;
        type master;&lt;br /&gt;
        file &amp;quot;192.168.1.0&amp;quot;;&lt;br /&gt;
        allow-update { none; };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone file for Reverse lookup: &#039;&#039;&#039;/var/named/192.168.1.0&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$TTL 300&lt;br /&gt;
@       IN SOA  ns1.brammerloo.nl. admin.brammerloo.nl. (&lt;br /&gt;
                                        2023101102 ; serial&lt;br /&gt;
                                        180     ; refresh&lt;br /&gt;
                                        60      ; retry&lt;br /&gt;
                                        108000  ; expire&lt;br /&gt;
                                        60 )    ; minimum&lt;br /&gt;
    IN      NS      ns1.brammerloo.nl.&lt;br /&gt;
; PTR Records&lt;br /&gt;
11    IN   PTR   node1.&lt;br /&gt;
21    IN   PTR   server1.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone file for domain: &#039;&#039;&#039;/var/named/brammerloo.nl&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$TTL 300&lt;br /&gt;
@       IN SOA  ns1.brammerloo.nl. admin.brammerloo.nl. (&lt;br /&gt;
                                        2023101306 ; serial&lt;br /&gt;
                                        180     ; refresh&lt;br /&gt;
                                        60      ; retry&lt;br /&gt;
                                        108000  ; expire&lt;br /&gt;
                                        60 )    ; minimum&lt;br /&gt;
    IN      NS      ns1.brammerloo.nl.&lt;br /&gt;
@                  IN      A     192.168.1.6   ; domain brammerloo.nl is me!&lt;br /&gt;
ns1.brammerloo.nl. IN      A     192.168.78.31 ; FQDN for my domain&lt;br /&gt;
node1              IN      A     192.168.78.31 ; Basic A-record&lt;br /&gt;
www                IN      CNAME node1         ; Point my website to my node1 A-record&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== dhcpd ===&lt;br /&gt;
==== dhclient ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Request an IPv4 adres from a DHCP server&lt;br /&gt;
dhclient -4&lt;br /&gt;
&lt;br /&gt;
# Show verbose information when requesting an IPv4 adres from a DHCP server&lt;br /&gt;
dhclient -4 -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Basic configuration options in the &#039;&#039;&#039;/etc/dhcp/dhcpd.conf&#039;&#039;&#039; file&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Set the domain clients should use when resolving hostnames (equivalent to search domain)&lt;br /&gt;
option domain-name &amp;quot;brammerloo.nl&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# Set the domain name servers for DHCP clients&lt;br /&gt;
option domain-name-servers ns1.brammerloo.nl, 8.8.8.8;&lt;br /&gt;
&lt;br /&gt;
default-lease-time 600;&lt;br /&gt;
max-lease-time 7200;&lt;br /&gt;
log-facility local7;&lt;br /&gt;
&lt;br /&gt;
# Best practice = define any connected subnets, but don&#039;t configure DHCP for them&lt;br /&gt;
subnet 192.168.1.0 netmask 255.255.255.0 {&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Basic DHCP for a subnet configuration&lt;br /&gt;
subnet 192.168.0.0 netmask 255.255.255.0 {&lt;br /&gt;
  range 192.168.0.100 192.168.0.150;&lt;br /&gt;
  option routers 192.168.0.1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== smbd / Samba / CIFS ===&lt;br /&gt;
https://linuxconfig.org/install-samba-on-redhat-8&lt;br /&gt;
&lt;br /&gt;
==== Basic configuration ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install and enable&lt;br /&gt;
dnf install samba samba-client&lt;br /&gt;
systemctl enable --now {smb,nmb}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a client-user to authenticate with&lt;br /&gt;
sudo useradd samba-user&lt;br /&gt;
&lt;br /&gt;
# Give the user a password to authenticate with&lt;br /&gt;
sudo smbpasswd -a samba-user&lt;br /&gt;
&lt;br /&gt;
# Create a group to associate with the samba share&lt;br /&gt;
sudo groupadd sambagroup&lt;br /&gt;
&lt;br /&gt;
# Add the user to the group we will be configuring for the share&lt;br /&gt;
sudo usermod -a -G sambagroup samba-user&lt;br /&gt;
&lt;br /&gt;
# Create the folder we will be sharing&lt;br /&gt;
sudo mkdir /var/shares/myshare&lt;br /&gt;
&lt;br /&gt;
# Apply proper permission&lt;br /&gt;
sudo chown -R samba-user:sambagroup /var/shares/myshare/&lt;br /&gt;
sudo chmod -R 0770 /var/shares/myshare/&lt;br /&gt;
&lt;br /&gt;
# Apply proper permission for SELinux&lt;br /&gt;
sudo chcon -t samba_share_t /var/shares/myshare/&lt;br /&gt;
&lt;br /&gt;
# Backup the default config&lt;br /&gt;
cp /etc/samba/smb.conf /etc/samba/smb.conf~&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/samba/smb.conf&lt;br /&gt;
[global]&lt;br /&gt;
 workgroup = &amp;lt;DOMAIN-OR-WORKGROUP&amp;gt;&lt;br /&gt;
 server string = Samba Server %v&lt;br /&gt;
 netbios name = &amp;lt;SERVER-HOSTNAME&amp;gt;&lt;br /&gt;
 security = user&lt;br /&gt;
 map to guest = bad user&lt;br /&gt;
 dns proxy = no&lt;br /&gt;
&lt;br /&gt;
#==================== Share Definitions ======================&lt;br /&gt;
[share001]&lt;br /&gt;
 path = /var/shares/myshare&lt;br /&gt;
 valid users = @sambagroup&lt;br /&gt;
 guest ok = no&lt;br /&gt;
 writable = yes&lt;br /&gt;
 browsable = yes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reload Samba services&lt;br /&gt;
systemctl reload {smb,nmb}&lt;br /&gt;
&lt;br /&gt;
# Mount in Windows&lt;br /&gt;
\\&amp;lt;SERVER-IP&amp;gt;\share001&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user: samba-user&lt;br /&gt;
pass: &amp;lt;Whatever password you filled in with smbpasswd -a&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Samba checks&lt;br /&gt;
smbstatus&lt;br /&gt;
smbstatus -S&lt;br /&gt;
smbstatus -b&lt;br /&gt;
&lt;br /&gt;
# Samba set debug mode&lt;br /&gt;
smbcontrol smbd debug 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Docker ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List Docker containers &lt;br /&gt;
docker ps&lt;br /&gt;
&lt;br /&gt;
# List all Docker container IDs&lt;br /&gt;
docker ps -aq&lt;br /&gt;
&lt;br /&gt;
# List logs for container 987sdh3qrasdhj&lt;br /&gt;
docker logs 987sdh3qrasdhj&lt;br /&gt;
&lt;br /&gt;
# List RAM/CPU usage for Docker container asdlkasd67k&lt;br /&gt;
docker stats asdlkasd67k&lt;br /&gt;
&lt;br /&gt;
# Show verbose container information such as commands run, network, ID, etc&lt;br /&gt;
docker inspect oiu2398sda87&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enter the shell inside a docker container&lt;br /&gt;
docker exec -ti a89sd98sa7d /bin/bash&lt;br /&gt;
&lt;br /&gt;
# Execute a command inside a container as a specific user, root in this case&lt;br /&gt;
docker exec -it -u root asd87289hasdadz tail /var/log/nginx/access.log&lt;br /&gt;
docker exec -u 0 -it as892asnj2as /bin/bash&lt;br /&gt;
&lt;br /&gt;
# Restart docker container yoga&lt;br /&gt;
docker restart yoga&lt;br /&gt;
&lt;br /&gt;
# Restart the 3 given containers&lt;br /&gt;
docker restart 79f71c7f4d91 bbb3d3f5c3b1 b0a3204d4098&lt;br /&gt;
&lt;br /&gt;
# Start this container&lt;br /&gt;
docker start as9823nzxc0&lt;br /&gt;
&lt;br /&gt;
# Stop this container&lt;br /&gt;
docker stop as9823nzxc0&lt;br /&gt;
&lt;br /&gt;
# Restart all unhealthy Docker containers&lt;br /&gt;
for i in $(docker ps | grep unhealthy | awk &#039;{print $1}&#039;); do docker restart &amp;quot;$i&amp;quot;; done;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PowerDNS ===&lt;br /&gt;
* https://doc.powerdns.com/authoritative/index.html&lt;br /&gt;
* https://doc.powerdns.com/authoritative/manpages/pdns_server.1.html&lt;br /&gt;
* https://doc.powerdns.com/authoritative/manpages/pdnsutil.1.html&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# List commands&lt;br /&gt;
pdns_server --help&lt;br /&gt;
&lt;br /&gt;
# Check config and parse for errors&lt;br /&gt;
pdns_server --config=check&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# List available commands &lt;br /&gt;
pdnsutil --help&lt;br /&gt;
&lt;br /&gt;
# Check config and parse for errors&lt;br /&gt;
pdnsutil --config=check&lt;br /&gt;
&lt;br /&gt;
# List all available zones&lt;br /&gt;
pdnsutil list-all-zones&lt;br /&gt;
&lt;br /&gt;
# List all domains in the primary zone&lt;br /&gt;
pdnsutil list-all-zones primary&lt;br /&gt;
&lt;br /&gt;
# See zone information for a specific domain&lt;br /&gt;
pdnsutil show-zone mydomain.com&lt;br /&gt;
pdnsutil show-zone 77.5.10.in-addr.arpa&lt;br /&gt;
&lt;br /&gt;
# Check zone for errors&lt;br /&gt;
pdnsutil check-zone mydomain.com&lt;br /&gt;
&lt;br /&gt;
# List all created TSIG keys&lt;br /&gt;
pdnsutil list-tsig-keys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# Activate TSIG key for domain &amp;quot;myexample.com&amp;quot; in the primary zone&lt;br /&gt;
pdnsutil &amp;quot; myexample.com transfer primary&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MAAS ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Logs in either place:&lt;br /&gt;
/var/log/maas/&lt;br /&gt;
/var/snap/maas/common/log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List status of MAAS services&lt;br /&gt;
maas status&lt;br /&gt;
&lt;br /&gt;
# List MAAS commands&lt;br /&gt;
maas --help&lt;br /&gt;
&lt;br /&gt;
# List available arguments for the init command&lt;br /&gt;
maas init --help&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section end=&amp;quot;linuxservices&amp;quot;/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Services&amp;diff=851</id>
		<title>Linux:Services</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Services&amp;diff=851"/>
		<updated>2025-10-01T11:59:32Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* Rainerscript */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet|Cheatsheets]]&lt;br /&gt;
&lt;br /&gt;
== Services ==&lt;br /&gt;
&amp;lt;section begin=&amp;quot;linuxservices&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Common ===&lt;br /&gt;
==== systemctl ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all services that are running or exited&lt;br /&gt;
systemctl&lt;br /&gt;
&lt;br /&gt;
# List all services, running or otherwise&lt;br /&gt;
systemctl --all&lt;br /&gt;
&lt;br /&gt;
# List all failed services&lt;br /&gt;
systemctl --state=failed&lt;br /&gt;
&lt;br /&gt;
# Reset the failed service &amp;quot;nginx&amp;quot;&lt;br /&gt;
systemctl reset-failed nginx&lt;br /&gt;
&lt;br /&gt;
# View the status of the &amp;quot;nfs-server&amp;quot; service&lt;br /&gt;
systemctl status nfs-server&lt;br /&gt;
&lt;br /&gt;
# Output the config file of &amp;quot;rsyslog&amp;quot; to the shell&lt;br /&gt;
systemctl cat rsyslog&lt;br /&gt;
&lt;br /&gt;
# Restart the &amp;quot;sshd&amp;quot; service, terminating established connections and re-parsing the configuration&lt;br /&gt;
systemctl restart sshd&lt;br /&gt;
&lt;br /&gt;
# Reload the &amp;quot;nginx&amp;quot; service so that it only re-parses the configuration&lt;br /&gt;
systemctl reload nginx&lt;br /&gt;
&lt;br /&gt;
# Stop the &amp;quot;nfs-ganesha&amp;quot; service so that it stops being run&lt;br /&gt;
systemctl stop nfs-ganesha&lt;br /&gt;
&lt;br /&gt;
# Start the &amp;quot;nfs-ganesha&amp;quot; service so that it starts being run again&lt;br /&gt;
systemctl start nfs-ganesha&lt;br /&gt;
&lt;br /&gt;
# Disable the &amp;quot;mariadb&amp;quot; service so that it doesn&#039;t start after the next boot&lt;br /&gt;
systemctl disable mariadb&lt;br /&gt;
&lt;br /&gt;
# Enable the &amp;quot;mariadb&amp;quot; service so that it starts after the next boot.&lt;br /&gt;
systemctl enable mariadb&lt;br /&gt;
&lt;br /&gt;
# Check the logs for all failed services&lt;br /&gt;
for i in $(systemctl --state=failed | head -n -4 | tail -n +2 | awk &#039;{print $1}&#039;); do systemctl --no-pager status &amp;quot;$i&amp;quot;; done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== NTP ===&lt;br /&gt;
==== Timedatectl ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show the current status of timedatectl&lt;br /&gt;
timedatectl&lt;br /&gt;
&lt;br /&gt;
# List available timezones&lt;br /&gt;
timedatectl list-timezones&lt;br /&gt;
&lt;br /&gt;
# Set the timezone to Amsterdam&lt;br /&gt;
timedatectl set-timezone Europe/Amsterdam&lt;br /&gt;
&lt;br /&gt;
# Show verbose sync information&lt;br /&gt;
timedatectl timesync-status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SNMP ===&lt;br /&gt;
==== V3 client installation ====&lt;br /&gt;
* https://kifarunix.com/quick-way-to-install-and-configure-snmp-on-ubuntu-20-04/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
apt install snmpd snmp libsnmp-dev&lt;br /&gt;
cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.bak&lt;br /&gt;
systemctl stop snmpd&lt;br /&gt;
net-snmp-create-v3-user -ro -X &amp;lt;CRYPTO-PASSWORD&amp;gt; -a SHA -X &amp;lt;PASSWORD&amp;gt; -x AES &amp;lt;USERNAME&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/snmp/snmpd.conf&lt;br /&gt;
sysLocation    NL;Zuid-Holland;Rotterdam, 78 MyStreet;2nd Floor;Server Room;Rack&lt;br /&gt;
sysContact     Me &amp;lt;me@example.org&amp;gt;&lt;br /&gt;
agentaddress   192.168.0.10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
systemctl start snmpd&lt;br /&gt;
systemctl enable snmpd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Test&lt;br /&gt;
snmpwalk -v3 -a SHA -A &amp;quot;AUTHENTICATION PASSWORD&amp;quot; -x AES -X &amp;quot;CRYPTO PASSWORD&amp;quot; -l authPriv -u &amp;quot;MYUSER&amp;quot; localhost | head&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CTDB  ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Verify CTDB cluster status&lt;br /&gt;
ctdb status&lt;br /&gt;
&lt;br /&gt;
# Show the allocated IP addresses and to which nodes they&#039;re bound&lt;br /&gt;
ctdb ip&lt;br /&gt;
&lt;br /&gt;
# See the status of all CTDB-scripts&lt;br /&gt;
ctdb scriptstatus&lt;br /&gt;
ctdb event status&lt;br /&gt;
&lt;br /&gt;
# Show the time of the last failover the duration it took to recover&lt;br /&gt;
ctdb uptime&lt;br /&gt;
&lt;br /&gt;
# See various statistics and data&lt;br /&gt;
ctdb statistics&lt;br /&gt;
&lt;br /&gt;
# Use the onnode command to execute a command on all cluster nodes&lt;br /&gt;
onnode all ctdb status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Stop a ctdb cluster member&lt;br /&gt;
ctdb stop&lt;br /&gt;
&lt;br /&gt;
# Start a stopped ctdb cluster member&lt;br /&gt;
ctdb continue&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Firewalls ===&lt;br /&gt;
==== UFW ====&lt;br /&gt;
===== Checks =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show summary of UFW status&lt;br /&gt;
ufw status&lt;br /&gt;
&lt;br /&gt;
# Show verbose UFW status&lt;br /&gt;
ufw status verbose&lt;br /&gt;
&lt;br /&gt;
# Show UFW rules numbered&lt;br /&gt;
ufw status numbered&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Commands =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Allow access from a specific IP to a port and add a comment that show in the status&lt;br /&gt;
ufw allow from 10.0.0.253 to any port 22 proto tcp comment &#039;Allow SSH access from XYZ location&#039;&lt;br /&gt;
&lt;br /&gt;
# Delete numbered Firewall rule 56&lt;br /&gt;
ufw delete 56&lt;br /&gt;
&lt;br /&gt;
# Disable UFW logging (prevent syslog spam)&lt;br /&gt;
ufw logging off&lt;br /&gt;
&lt;br /&gt;
# Set UFW logging back to the default&lt;br /&gt;
ufw logging low&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Firewalld ====&lt;br /&gt;
===== SNMP access =====&lt;br /&gt;
* https://unix.stackexchange.com/questions/214388/how-to-let-the-firewall-of-rhel7-the-snmp-connection-passing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/firewalld/services/snmp.xml&lt;br /&gt;
&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;service&amp;gt;&lt;br /&gt;
  &amp;lt;short&amp;gt;SNMP&amp;lt;/short&amp;gt;&lt;br /&gt;
  &amp;lt;description&amp;gt;SNMP protocol&amp;lt;/description&amp;gt;&lt;br /&gt;
  &amp;lt;port protocol=&amp;quot;udp&amp;quot; port=&amp;quot;161&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/service&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
firewall-cmd --zone=public --add-service snmp --permanent&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Firewall-cmd =====&lt;br /&gt;
====== Checks ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all available commands&lt;br /&gt;
firewall-cmd -h&lt;br /&gt;
&lt;br /&gt;
# Check the configuration file of the firewall for errors&lt;br /&gt;
firewall-cmd --check-config&lt;br /&gt;
&lt;br /&gt;
# Display the current state of firewall-cmd (running/shutdown)&lt;br /&gt;
firewall-cmd --state&lt;br /&gt;
&lt;br /&gt;
# Display all available zones&lt;br /&gt;
firewall-cmd --get-zones&lt;br /&gt;
&lt;br /&gt;
# List all whitelisted services&lt;br /&gt;
firewall-cmd --list-services&lt;br /&gt;
&lt;br /&gt;
# List all services you can potentially enable&lt;br /&gt;
firewall-cmd --get-services&lt;br /&gt;
&lt;br /&gt;
# List all added or enabled services and ports in more detail&lt;br /&gt;
firewall-cmd --list-all&lt;br /&gt;
&lt;br /&gt;
# List verbose information for all zones&lt;br /&gt;
firewall-cmd --list-all-zones&lt;br /&gt;
&lt;br /&gt;
# List verbose information for the public zone&lt;br /&gt;
firewall-cmd --list-all --zone=public&lt;br /&gt;
&lt;br /&gt;
# See what port(s) are associated with the dns service&lt;br /&gt;
firewall-cmd --info-service dns&lt;br /&gt;
&lt;br /&gt;
# List all opened ports&lt;br /&gt;
firewall-cmd --list-ports&lt;br /&gt;
&lt;br /&gt;
# List kernel ruleset generated for nftables(?)&lt;br /&gt;
nft list ruleset&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Commands ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reload the firewall&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Whitelist the dns service, persistently even after reboot&lt;br /&gt;
firewall-cmd --add-service=dns ; sudo firewall-cmd --runtime-to-permanent; firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Whitelist the http service, persistently even after reboot&lt;br /&gt;
firewall-cmd --add-service=http ; sudo firewall-cmd --runtime-to-permanent; firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Remove the http service from the whitelist&lt;br /&gt;
firewall-cmd --remove-service=http&lt;br /&gt;
&lt;br /&gt;
# Add port 1234 (tcp) to the whitelist&lt;br /&gt;
firewall-cmd --add-port=1234/tcp&lt;br /&gt;
&lt;br /&gt;
# Remove port 1234 (tcp) from the whitelist&lt;br /&gt;
firewall-cmd --remove-port=1234/tcp&lt;br /&gt;
&lt;br /&gt;
# Add port 2345 (udp) to the whitelist in zone external&lt;br /&gt;
firewall-cmd --zone=external --add-port=2345/udp&lt;br /&gt;
&lt;br /&gt;
# Remove port 2345 (udp) from the whitelist for zone external&lt;br /&gt;
firewall-cmd --zone=external --add-port=2345/udp&lt;br /&gt;
&lt;br /&gt;
# Add current configuration to configuration permanently&lt;br /&gt;
firewall-cmd –runtime-to-permanent&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;DANGEROUS&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# SHUT IT DOWN DOC - DROP ALL PACKETS AND EXPIRE EXISTING CONNECTIONS&lt;br /&gt;
firewall-cmd --panic-on&lt;br /&gt;
&lt;br /&gt;
# ACCEPT PACKETS AGAIN&lt;br /&gt;
firewall-cmd --panic-off&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== CSF ====&lt;br /&gt;
ConfigServer Security and Firewall&lt;br /&gt;
&lt;br /&gt;
===== General =====&lt;br /&gt;
* Common configuration: /etc/csf/csf.conf &lt;br /&gt;
* Blacklist: /etc/csf/csf.deny &lt;br /&gt;
* Whitelist: /etc/csf/csf.allow &lt;br /&gt;
&lt;br /&gt;
===== Installation =====&lt;br /&gt;
From the official instructions: https://download.configserver.com/csf/install.txt&lt;br /&gt;
&lt;br /&gt;
====== Prerequisites ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Perl Modules&lt;br /&gt;
============&lt;br /&gt;
While most should be installed on a standard perl installation the following&lt;br /&gt;
may need to be installed manually:&lt;br /&gt;
&lt;br /&gt;
# On rpm based systems:&lt;br /&gt;
yum install perl-libwww-perl.noarch perl-LWP-Protocol-https.noarch perl-GDGraph&lt;br /&gt;
&lt;br /&gt;
# On APT based systems:&lt;br /&gt;
apt-get install libwww-perl liblwp-protocol-https-perl libgd-graph-perl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Install ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cd /usr/src&lt;br /&gt;
rm -fv csf.tgz&lt;br /&gt;
wget https://download.configserver.com/csf.tgz&lt;br /&gt;
tar -xzf csf.tgz&lt;br /&gt;
cd csf&lt;br /&gt;
sh install.sh&lt;br /&gt;
&lt;br /&gt;
# Next, test whether you have the required iptables modules:&lt;br /&gt;
perl /usr/local/csf/bin/csftest.pl&lt;br /&gt;
&lt;br /&gt;
# Don&#039;t worry if you cannot run all the features, so long as the script doesn&#039;t report any FATAL errors&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Checks =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check the running status of csf&lt;br /&gt;
csf status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Commands =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Commit config changes by restarting csf&lt;br /&gt;
csf -r&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== csf.conf =====&lt;br /&gt;
Some common changes within the configuration file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Set testing to 0 when your CSF configuration is &#039;production&#039; ready&lt;br /&gt;
TESTING = &amp;quot;0&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow access to any service you&#039;re hosting locally, for example https&lt;br /&gt;
TCP_IN = &amp;quot;443&amp;quot;&lt;br /&gt;
UDP_IN = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow all outwards HTTP/HTTPS traffic so you can yum/apt update&lt;br /&gt;
TCP_OUT = &amp;quot;80,443&amp;quot; &lt;br /&gt;
&lt;br /&gt;
# Allow outgoing traceroute&lt;br /&gt;
UDP_OUT = &amp;quot;33434:33523&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow your server to be pinged&lt;br /&gt;
ICMP_IN = &amp;quot;0&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Formatting =====&lt;br /&gt;
The varying styles of formatting used in allow.conf&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Allow anything relating to the following IPs/ranges&lt;br /&gt;
192.168.10.0/24 # Our application breaks without this range&lt;br /&gt;
192.168.1.1 # Our gateway or something&lt;br /&gt;
&lt;br /&gt;
# Detailed entries based on Transport protocol, direction, Application protocol and IP&lt;br /&gt;
tcp:in:d=22:s=7.7.7.7 # SSH access from our VPN&lt;br /&gt;
udp:in:d=161:s=10.11.12.100 # SNMP Access&lt;br /&gt;
tcp|in|d=22|s=fe80::1:/16 # IPV6 SSH access from our jumpgateway&lt;br /&gt;
udp|in|d=3389|s=10.1.0.0/24 # RDP Access from our entire office range&lt;br /&gt;
tcp|out|d=80,443|d=1.2.3.4/32 # Allow outgoing HTTP/HTTPS access via port 80 and 443&lt;br /&gt;
&lt;br /&gt;
# Allow sending Syslog messages to our Syslog server&lt;br /&gt;
udp|out|d=514|d=192.168.20.5 # UDP syslog server&lt;br /&gt;
tcp|out|d=10514|d=192.168.20.5 # UDP syslog server&lt;br /&gt;
&lt;br /&gt;
# Allow sending queries to some DNS servers&lt;br /&gt;
tcp|out|s=53|d=8.8.8.8&lt;br /&gt;
udp|out|s=53|d=1.1.1.1&lt;br /&gt;
udp|out|s=53|d=2606:4700:4700::1111 # Cloudflare IPv6 DNS Server&lt;br /&gt;
&lt;br /&gt;
# Include an external configuration file&lt;br /&gt;
Include /etc/csf/csf.custom-config&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rsyslog ===&lt;br /&gt;
&amp;lt;section begin=&amp;quot;linuxsyslog&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* https://www.rsyslog.com/doc/reference/templates/templates-reserved-names.html#ref-templates-reserved-names&lt;br /&gt;
* https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/6/html/deployment_guide/s2-templates&lt;br /&gt;
&lt;br /&gt;
==== Legacy ====&lt;br /&gt;
Send all logs to a rsyslog server and specify a port, @ is equal to using UDP. @@ is equal to TCP&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/75-local-to-rsyslog-server.conf&lt;br /&gt;
*.* @10.77.0.1:514&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Custom template where hostname is defined, then sent to the syslog server - include the priority number as first extra variable&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#/etc/rsyslog.d/70-local-to-rsyslog-server.conf&lt;br /&gt;
$template SendHostname, &amp;quot;%PRI%1 %timestamp% myhost.mydomain.nl %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.warning @10.77.0.1;SendHostname&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Send messages to a syslog server, using a template aligned to IETF protocol 23&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/61-qwe.conf&lt;br /&gt;
*.* @10.77.0.1;RSYSLOG_SyslogProtocol23Format&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Send messages to a syslog server, using a template aligned to IETF protocol 23, but specifying a custom hostname&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/60-asd.conf&lt;br /&gt;
$template custom_IETFprotocol_23,&amp;quot;%PRI%1 %TIMESTAMP:::date-rfc3339% prive.host.nl %APP-NAME% %PROCID% %MSGID% %STRUCTURED-DATA% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* @10.77.0.1;custom_IETFprotocol_23&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Log to the local server with a static hostname, using a custom structure&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/62-asd.conf&lt;br /&gt;
$template NewHostname, &amp;quot;%timestamp% tester.mydomain.nl %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* /var/log/wewuzerrors.txt;NewHostname&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An alternative to the contents above, specifying different/more fields&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
## /etc/rsyslog.d/65-customtemplate.conf&lt;br /&gt;
# https://stackoverflow.com/questions/57890176/extending-rsyslogs-default-logging-template&lt;br /&gt;
$template mynewtemplate,&amp;quot;%timegenerated% %HOSTNAME% %syslogfacility-text%.%syslogseverity-text% %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* /var/log/wazanda.txt;mynewtemplate&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rainerscript ====&lt;br /&gt;
Rainerscript: https://rsyslog.readthedocs.io/en/latest/rainerscript/control_structures.html&lt;br /&gt;
&lt;br /&gt;
Write all local messages to a specific file&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/60-asd.conf&lt;br /&gt;
action(type=&amp;quot;omfile&amp;quot; file=&amp;quot;/var/log/isaidhey.txt&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Send message to a syslog server using IETF protocol 23&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/70-local-to-rsyslog-server.conf&lt;br /&gt;
template(name=&amp;quot;RSYSLOG_SyslogProtocol23Format&amp;quot; type=&amp;quot;string&amp;quot;&lt;br /&gt;
     string=&amp;quot;&amp;lt;%PRI%&amp;gt;1 %TIMESTAMP:::date-rfc3339% %HOSTNAME% %APP-NAME% %PROCID% %MSGID% %STRUCTURED-DATA% %msg%\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Send all logs to the target server&lt;br /&gt;
action(type=&amp;quot;omfwd&amp;quot; Target=&amp;quot;192.168.5.21&amp;quot; Template=&amp;quot;RSYSLOG_SyslogProtocol23Format&amp;quot; Port=&amp;quot;514&amp;quot; Protocol=&amp;quot;udp&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Define a template aligned to IETF protocol 23 and specify a hostname to send as:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/71-local-to-rsyslog-server.conf&lt;br /&gt;
template(name=&amp;quot;SendHostname&amp;quot; type=&amp;quot;string&amp;quot;&lt;br /&gt;
     string=&amp;quot;&amp;lt;%PRI%&amp;gt;1 %TIMESTAMP:::date-rfc3339% myhost.mydomain.nl %APP-NAME% %PROCID% %MSGID% %STRUCTURED-DATA% %msg%\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Send all logs to target syslog server and port&lt;br /&gt;
action(type=&amp;quot;omfwd&amp;quot; Target=&amp;quot;10.0.33.10&amp;quot; Template=&amp;quot;SendHostname&amp;quot; Port=&amp;quot;514&amp;quot; Protocol=&amp;quot;udp&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Testing ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use the logger tool to test syslog server reception&lt;br /&gt;
logger -p local0.error &#039;Hello World!&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section end=&amp;quot;linuxsyslog&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== named ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Perform a test load of all primary zones within named.conf, as the named user&lt;br /&gt;
sudo -u named named-checkconf -z&lt;br /&gt;
&lt;br /&gt;
# Check zone file 192.168.77.0 defined in the 77.168.192.in-addr.arpa zone&lt;br /&gt;
named-checkzone 77.168.192.in-addr.arpa 192.168.77.0&lt;br /&gt;
&lt;br /&gt;
# Check zone file brammerloo.nl defined in the brammerloo.nl zone&lt;br /&gt;
named-checkzone brammerloo.nl brammerloo.nl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Basic configuration for the options field in &#039;&#039;&#039;/etc/named.conf&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
options {&lt;br /&gt;
# Define on what IP to listen on, for port 53&lt;br /&gt;
        listen-on port 53 { 127.0.0.1; 192.168.0.1; 192.168.1.1; };&lt;br /&gt;
        directory       &amp;quot;/var/named&amp;quot;;&lt;br /&gt;
        dump-file       &amp;quot;/var/named/data/cache_dump.db&amp;quot;;&lt;br /&gt;
        statistics-file &amp;quot;/var/named/data/named_stats.txt&amp;quot;;&lt;br /&gt;
        memstatistics-file &amp;quot;/var/named/data/named_mem_stats.txt&amp;quot;;&lt;br /&gt;
        secroots-file   &amp;quot;/var/named/data/named.secroots&amp;quot;;&lt;br /&gt;
        recursing-file  &amp;quot;/var/named/data/named.recursing&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# Only allow DNS queries from specific local subnets&lt;br /&gt;
# To allow from anything use: allow query { any; };&lt;br /&gt;
        allow-query     { localhost; 127.0.0.1; 192.168.0.0/24; 192.168.1.0/24; };&lt;br /&gt;
&lt;br /&gt;
# If the server can&#039;t resolve an address locally, use the following DNS servers for help&lt;br /&gt;
        forwarders {&lt;br /&gt;
        8.8.8.8;&lt;br /&gt;
        1.1.1.1;&lt;br /&gt;
        };&lt;br /&gt;
&lt;br /&gt;
        recursion yes;&lt;br /&gt;
        dnssec-validation no;&lt;br /&gt;
&lt;br /&gt;
        managed-keys-directory &amp;quot;/var/named/dynamic&amp;quot;;&lt;br /&gt;
        geoip-directory &amp;quot;/usr/share/GeoIP&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
        pid-file &amp;quot;/run/named/named.pid&amp;quot;;&lt;br /&gt;
        session-keyfile &amp;quot;/run/named/session.key&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
        /* https://fedoraproject.org/wiki/Changes/CryptoPolicy */&lt;br /&gt;
        include &amp;quot;/etc/crypto-policies/back-ends/bind.config&amp;quot;;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone defnitions: &#039;&#039;&#039;/etc/named.rfc1912.zones&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Define zones to listen for&lt;br /&gt;
zone &amp;quot;brammerloo.nl&amp;quot; IN {&lt;br /&gt;
        type master;&lt;br /&gt;
        file &amp;quot;brammerloo.nl&amp;quot;;&lt;br /&gt;
        allow-update { none; };&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
zone &amp;quot;1.168.192.in-addr.arpa&amp;quot; IN {&lt;br /&gt;
        type master;&lt;br /&gt;
        file &amp;quot;192.168.1.0&amp;quot;;&lt;br /&gt;
        allow-update { none; };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone file for Reverse lookup: &#039;&#039;&#039;/var/named/192.168.1.0&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$TTL 300&lt;br /&gt;
@       IN SOA  ns1.brammerloo.nl. admin.brammerloo.nl. (&lt;br /&gt;
                                        2023101102 ; serial&lt;br /&gt;
                                        180     ; refresh&lt;br /&gt;
                                        60      ; retry&lt;br /&gt;
                                        108000  ; expire&lt;br /&gt;
                                        60 )    ; minimum&lt;br /&gt;
    IN      NS      ns1.brammerloo.nl.&lt;br /&gt;
; PTR Records&lt;br /&gt;
11    IN   PTR   node1.&lt;br /&gt;
21    IN   PTR   server1.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone file for domain: &#039;&#039;&#039;/var/named/brammerloo.nl&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$TTL 300&lt;br /&gt;
@       IN SOA  ns1.brammerloo.nl. admin.brammerloo.nl. (&lt;br /&gt;
                                        2023101306 ; serial&lt;br /&gt;
                                        180     ; refresh&lt;br /&gt;
                                        60      ; retry&lt;br /&gt;
                                        108000  ; expire&lt;br /&gt;
                                        60 )    ; minimum&lt;br /&gt;
    IN      NS      ns1.brammerloo.nl.&lt;br /&gt;
@                  IN      A     192.168.1.6   ; domain brammerloo.nl is me!&lt;br /&gt;
ns1.brammerloo.nl. IN      A     192.168.78.31 ; FQDN for my domain&lt;br /&gt;
node1              IN      A     192.168.78.31 ; Basic A-record&lt;br /&gt;
www                IN      CNAME node1         ; Point my website to my node1 A-record&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== dhcpd ===&lt;br /&gt;
==== dhclient ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Request an IPv4 adres from a DHCP server&lt;br /&gt;
dhclient -4&lt;br /&gt;
&lt;br /&gt;
# Show verbose information when requesting an IPv4 adres from a DHCP server&lt;br /&gt;
dhclient -4 -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Basic configuration options in the &#039;&#039;&#039;/etc/dhcp/dhcpd.conf&#039;&#039;&#039; file&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Set the domain clients should use when resolving hostnames (equivalent to search domain)&lt;br /&gt;
option domain-name &amp;quot;brammerloo.nl&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# Set the domain name servers for DHCP clients&lt;br /&gt;
option domain-name-servers ns1.brammerloo.nl, 8.8.8.8;&lt;br /&gt;
&lt;br /&gt;
default-lease-time 600;&lt;br /&gt;
max-lease-time 7200;&lt;br /&gt;
log-facility local7;&lt;br /&gt;
&lt;br /&gt;
# Best practice = define any connected subnets, but don&#039;t configure DHCP for them&lt;br /&gt;
subnet 192.168.1.0 netmask 255.255.255.0 {&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Basic DHCP for a subnet configuration&lt;br /&gt;
subnet 192.168.0.0 netmask 255.255.255.0 {&lt;br /&gt;
  range 192.168.0.100 192.168.0.150;&lt;br /&gt;
  option routers 192.168.0.1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== smbd / Samba / CIFS ===&lt;br /&gt;
https://linuxconfig.org/install-samba-on-redhat-8&lt;br /&gt;
&lt;br /&gt;
==== Basic configuration ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install and enable&lt;br /&gt;
dnf install samba samba-client&lt;br /&gt;
systemctl enable --now {smb,nmb}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a client-user to authenticate with&lt;br /&gt;
sudo useradd samba-user&lt;br /&gt;
&lt;br /&gt;
# Give the user a password to authenticate with&lt;br /&gt;
sudo smbpasswd -a samba-user&lt;br /&gt;
&lt;br /&gt;
# Create a group to associate with the samba share&lt;br /&gt;
sudo groupadd sambagroup&lt;br /&gt;
&lt;br /&gt;
# Add the user to the group we will be configuring for the share&lt;br /&gt;
sudo usermod -a -G sambagroup samba-user&lt;br /&gt;
&lt;br /&gt;
# Create the folder we will be sharing&lt;br /&gt;
sudo mkdir /var/shares/myshare&lt;br /&gt;
&lt;br /&gt;
# Apply proper permission&lt;br /&gt;
sudo chown -R samba-user:sambagroup /var/shares/myshare/&lt;br /&gt;
sudo chmod -R 0770 /var/shares/myshare/&lt;br /&gt;
&lt;br /&gt;
# Apply proper permission for SELinux&lt;br /&gt;
sudo chcon -t samba_share_t /var/shares/myshare/&lt;br /&gt;
&lt;br /&gt;
# Backup the default config&lt;br /&gt;
cp /etc/samba/smb.conf /etc/samba/smb.conf~&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/samba/smb.conf&lt;br /&gt;
[global]&lt;br /&gt;
 workgroup = &amp;lt;DOMAIN-OR-WORKGROUP&amp;gt;&lt;br /&gt;
 server string = Samba Server %v&lt;br /&gt;
 netbios name = &amp;lt;SERVER-HOSTNAME&amp;gt;&lt;br /&gt;
 security = user&lt;br /&gt;
 map to guest = bad user&lt;br /&gt;
 dns proxy = no&lt;br /&gt;
&lt;br /&gt;
#==================== Share Definitions ======================&lt;br /&gt;
[share001]&lt;br /&gt;
 path = /var/shares/myshare&lt;br /&gt;
 valid users = @sambagroup&lt;br /&gt;
 guest ok = no&lt;br /&gt;
 writable = yes&lt;br /&gt;
 browsable = yes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reload Samba services&lt;br /&gt;
systemctl reload {smb,nmb}&lt;br /&gt;
&lt;br /&gt;
# Mount in Windows&lt;br /&gt;
\\&amp;lt;SERVER-IP&amp;gt;\share001&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user: samba-user&lt;br /&gt;
pass: &amp;lt;Whatever password you filled in with smbpasswd -a&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Samba checks&lt;br /&gt;
smbstatus&lt;br /&gt;
smbstatus -S&lt;br /&gt;
smbstatus -b&lt;br /&gt;
&lt;br /&gt;
# Samba set debug mode&lt;br /&gt;
smbcontrol smbd debug 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Docker ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List Docker containers &lt;br /&gt;
docker ps&lt;br /&gt;
&lt;br /&gt;
# List all Docker container IDs&lt;br /&gt;
docker ps -aq&lt;br /&gt;
&lt;br /&gt;
# List logs for container 987sdh3qrasdhj&lt;br /&gt;
docker logs 987sdh3qrasdhj&lt;br /&gt;
&lt;br /&gt;
# List RAM/CPU usage for Docker container asdlkasd67k&lt;br /&gt;
docker stats asdlkasd67k&lt;br /&gt;
&lt;br /&gt;
# Show verbose container information such as commands run, network, ID, etc&lt;br /&gt;
docker inspect oiu2398sda87&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enter the shell inside a docker container&lt;br /&gt;
docker exec -ti a89sd98sa7d /bin/bash&lt;br /&gt;
&lt;br /&gt;
# Execute a command inside a container as a specific user, root in this case&lt;br /&gt;
docker exec -it -u root asd87289hasdadz tail /var/log/nginx/access.log&lt;br /&gt;
docker exec -u 0 -it as892asnj2as /bin/bash&lt;br /&gt;
&lt;br /&gt;
# Restart docker container yoga&lt;br /&gt;
docker restart yoga&lt;br /&gt;
&lt;br /&gt;
# Restart the 3 given containers&lt;br /&gt;
docker restart 79f71c7f4d91 bbb3d3f5c3b1 b0a3204d4098&lt;br /&gt;
&lt;br /&gt;
# Start this container&lt;br /&gt;
docker start as9823nzxc0&lt;br /&gt;
&lt;br /&gt;
# Stop this container&lt;br /&gt;
docker stop as9823nzxc0&lt;br /&gt;
&lt;br /&gt;
# Restart all unhealthy Docker containers&lt;br /&gt;
for i in $(docker ps | grep unhealthy | awk &#039;{print $1}&#039;); do docker restart &amp;quot;$i&amp;quot;; done;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PowerDNS ===&lt;br /&gt;
* https://doc.powerdns.com/authoritative/index.html&lt;br /&gt;
* https://doc.powerdns.com/authoritative/manpages/pdns_server.1.html&lt;br /&gt;
* https://doc.powerdns.com/authoritative/manpages/pdnsutil.1.html&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# List commands&lt;br /&gt;
pdns_server --help&lt;br /&gt;
&lt;br /&gt;
# Check config and parse for errors&lt;br /&gt;
pdns_server --config=check&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# List available commands &lt;br /&gt;
pdnsutil --help&lt;br /&gt;
&lt;br /&gt;
# Check config and parse for errors&lt;br /&gt;
pdnsutil --config=check&lt;br /&gt;
&lt;br /&gt;
# List all available zones&lt;br /&gt;
pdnsutil list-all-zones&lt;br /&gt;
&lt;br /&gt;
# List all domains in the primary zone&lt;br /&gt;
pdnsutil list-all-zones primary&lt;br /&gt;
&lt;br /&gt;
# See zone information for a specific domain&lt;br /&gt;
pdnsutil show-zone mydomain.com&lt;br /&gt;
pdnsutil show-zone 77.5.10.in-addr.arpa&lt;br /&gt;
&lt;br /&gt;
# Check zone for errors&lt;br /&gt;
pdnsutil check-zone mydomain.com&lt;br /&gt;
&lt;br /&gt;
# List all created TSIG keys&lt;br /&gt;
pdnsutil list-tsig-keys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# Activate TSIG key for domain &amp;quot;myexample.com&amp;quot; in the primary zone&lt;br /&gt;
pdnsutil &amp;quot; myexample.com transfer primary&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MAAS ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Logs in either place:&lt;br /&gt;
/var/log/maas/&lt;br /&gt;
/var/snap/maas/common/log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List status of MAAS services&lt;br /&gt;
maas status&lt;br /&gt;
&lt;br /&gt;
# List MAAS commands&lt;br /&gt;
maas --help&lt;br /&gt;
&lt;br /&gt;
# List available arguments for the init command&lt;br /&gt;
maas init --help&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section end=&amp;quot;linuxservices&amp;quot;/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Services&amp;diff=850</id>
		<title>Linux:Services</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Services&amp;diff=850"/>
		<updated>2025-10-01T11:59:13Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* Rainerscript */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet|Cheatsheets]]&lt;br /&gt;
&lt;br /&gt;
== Services ==&lt;br /&gt;
&amp;lt;section begin=&amp;quot;linuxservices&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Common ===&lt;br /&gt;
==== systemctl ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all services that are running or exited&lt;br /&gt;
systemctl&lt;br /&gt;
&lt;br /&gt;
# List all services, running or otherwise&lt;br /&gt;
systemctl --all&lt;br /&gt;
&lt;br /&gt;
# List all failed services&lt;br /&gt;
systemctl --state=failed&lt;br /&gt;
&lt;br /&gt;
# Reset the failed service &amp;quot;nginx&amp;quot;&lt;br /&gt;
systemctl reset-failed nginx&lt;br /&gt;
&lt;br /&gt;
# View the status of the &amp;quot;nfs-server&amp;quot; service&lt;br /&gt;
systemctl status nfs-server&lt;br /&gt;
&lt;br /&gt;
# Output the config file of &amp;quot;rsyslog&amp;quot; to the shell&lt;br /&gt;
systemctl cat rsyslog&lt;br /&gt;
&lt;br /&gt;
# Restart the &amp;quot;sshd&amp;quot; service, terminating established connections and re-parsing the configuration&lt;br /&gt;
systemctl restart sshd&lt;br /&gt;
&lt;br /&gt;
# Reload the &amp;quot;nginx&amp;quot; service so that it only re-parses the configuration&lt;br /&gt;
systemctl reload nginx&lt;br /&gt;
&lt;br /&gt;
# Stop the &amp;quot;nfs-ganesha&amp;quot; service so that it stops being run&lt;br /&gt;
systemctl stop nfs-ganesha&lt;br /&gt;
&lt;br /&gt;
# Start the &amp;quot;nfs-ganesha&amp;quot; service so that it starts being run again&lt;br /&gt;
systemctl start nfs-ganesha&lt;br /&gt;
&lt;br /&gt;
# Disable the &amp;quot;mariadb&amp;quot; service so that it doesn&#039;t start after the next boot&lt;br /&gt;
systemctl disable mariadb&lt;br /&gt;
&lt;br /&gt;
# Enable the &amp;quot;mariadb&amp;quot; service so that it starts after the next boot.&lt;br /&gt;
systemctl enable mariadb&lt;br /&gt;
&lt;br /&gt;
# Check the logs for all failed services&lt;br /&gt;
for i in $(systemctl --state=failed | head -n -4 | tail -n +2 | awk &#039;{print $1}&#039;); do systemctl --no-pager status &amp;quot;$i&amp;quot;; done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== NTP ===&lt;br /&gt;
==== Timedatectl ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show the current status of timedatectl&lt;br /&gt;
timedatectl&lt;br /&gt;
&lt;br /&gt;
# List available timezones&lt;br /&gt;
timedatectl list-timezones&lt;br /&gt;
&lt;br /&gt;
# Set the timezone to Amsterdam&lt;br /&gt;
timedatectl set-timezone Europe/Amsterdam&lt;br /&gt;
&lt;br /&gt;
# Show verbose sync information&lt;br /&gt;
timedatectl timesync-status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SNMP ===&lt;br /&gt;
==== V3 client installation ====&lt;br /&gt;
* https://kifarunix.com/quick-way-to-install-and-configure-snmp-on-ubuntu-20-04/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
apt install snmpd snmp libsnmp-dev&lt;br /&gt;
cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.bak&lt;br /&gt;
systemctl stop snmpd&lt;br /&gt;
net-snmp-create-v3-user -ro -X &amp;lt;CRYPTO-PASSWORD&amp;gt; -a SHA -X &amp;lt;PASSWORD&amp;gt; -x AES &amp;lt;USERNAME&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/snmp/snmpd.conf&lt;br /&gt;
sysLocation    NL;Zuid-Holland;Rotterdam, 78 MyStreet;2nd Floor;Server Room;Rack&lt;br /&gt;
sysContact     Me &amp;lt;me@example.org&amp;gt;&lt;br /&gt;
agentaddress   192.168.0.10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
systemctl start snmpd&lt;br /&gt;
systemctl enable snmpd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Test&lt;br /&gt;
snmpwalk -v3 -a SHA -A &amp;quot;AUTHENTICATION PASSWORD&amp;quot; -x AES -X &amp;quot;CRYPTO PASSWORD&amp;quot; -l authPriv -u &amp;quot;MYUSER&amp;quot; localhost | head&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CTDB  ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Verify CTDB cluster status&lt;br /&gt;
ctdb status&lt;br /&gt;
&lt;br /&gt;
# Show the allocated IP addresses and to which nodes they&#039;re bound&lt;br /&gt;
ctdb ip&lt;br /&gt;
&lt;br /&gt;
# See the status of all CTDB-scripts&lt;br /&gt;
ctdb scriptstatus&lt;br /&gt;
ctdb event status&lt;br /&gt;
&lt;br /&gt;
# Show the time of the last failover the duration it took to recover&lt;br /&gt;
ctdb uptime&lt;br /&gt;
&lt;br /&gt;
# See various statistics and data&lt;br /&gt;
ctdb statistics&lt;br /&gt;
&lt;br /&gt;
# Use the onnode command to execute a command on all cluster nodes&lt;br /&gt;
onnode all ctdb status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Stop a ctdb cluster member&lt;br /&gt;
ctdb stop&lt;br /&gt;
&lt;br /&gt;
# Start a stopped ctdb cluster member&lt;br /&gt;
ctdb continue&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Firewalls ===&lt;br /&gt;
==== UFW ====&lt;br /&gt;
===== Checks =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show summary of UFW status&lt;br /&gt;
ufw status&lt;br /&gt;
&lt;br /&gt;
# Show verbose UFW status&lt;br /&gt;
ufw status verbose&lt;br /&gt;
&lt;br /&gt;
# Show UFW rules numbered&lt;br /&gt;
ufw status numbered&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Commands =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Allow access from a specific IP to a port and add a comment that show in the status&lt;br /&gt;
ufw allow from 10.0.0.253 to any port 22 proto tcp comment &#039;Allow SSH access from XYZ location&#039;&lt;br /&gt;
&lt;br /&gt;
# Delete numbered Firewall rule 56&lt;br /&gt;
ufw delete 56&lt;br /&gt;
&lt;br /&gt;
# Disable UFW logging (prevent syslog spam)&lt;br /&gt;
ufw logging off&lt;br /&gt;
&lt;br /&gt;
# Set UFW logging back to the default&lt;br /&gt;
ufw logging low&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Firewalld ====&lt;br /&gt;
===== SNMP access =====&lt;br /&gt;
* https://unix.stackexchange.com/questions/214388/how-to-let-the-firewall-of-rhel7-the-snmp-connection-passing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/firewalld/services/snmp.xml&lt;br /&gt;
&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;service&amp;gt;&lt;br /&gt;
  &amp;lt;short&amp;gt;SNMP&amp;lt;/short&amp;gt;&lt;br /&gt;
  &amp;lt;description&amp;gt;SNMP protocol&amp;lt;/description&amp;gt;&lt;br /&gt;
  &amp;lt;port protocol=&amp;quot;udp&amp;quot; port=&amp;quot;161&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/service&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
firewall-cmd --zone=public --add-service snmp --permanent&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Firewall-cmd =====&lt;br /&gt;
====== Checks ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all available commands&lt;br /&gt;
firewall-cmd -h&lt;br /&gt;
&lt;br /&gt;
# Check the configuration file of the firewall for errors&lt;br /&gt;
firewall-cmd --check-config&lt;br /&gt;
&lt;br /&gt;
# Display the current state of firewall-cmd (running/shutdown)&lt;br /&gt;
firewall-cmd --state&lt;br /&gt;
&lt;br /&gt;
# Display all available zones&lt;br /&gt;
firewall-cmd --get-zones&lt;br /&gt;
&lt;br /&gt;
# List all whitelisted services&lt;br /&gt;
firewall-cmd --list-services&lt;br /&gt;
&lt;br /&gt;
# List all services you can potentially enable&lt;br /&gt;
firewall-cmd --get-services&lt;br /&gt;
&lt;br /&gt;
# List all added or enabled services and ports in more detail&lt;br /&gt;
firewall-cmd --list-all&lt;br /&gt;
&lt;br /&gt;
# List verbose information for all zones&lt;br /&gt;
firewall-cmd --list-all-zones&lt;br /&gt;
&lt;br /&gt;
# List verbose information for the public zone&lt;br /&gt;
firewall-cmd --list-all --zone=public&lt;br /&gt;
&lt;br /&gt;
# See what port(s) are associated with the dns service&lt;br /&gt;
firewall-cmd --info-service dns&lt;br /&gt;
&lt;br /&gt;
# List all opened ports&lt;br /&gt;
firewall-cmd --list-ports&lt;br /&gt;
&lt;br /&gt;
# List kernel ruleset generated for nftables(?)&lt;br /&gt;
nft list ruleset&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Commands ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reload the firewall&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Whitelist the dns service, persistently even after reboot&lt;br /&gt;
firewall-cmd --add-service=dns ; sudo firewall-cmd --runtime-to-permanent; firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Whitelist the http service, persistently even after reboot&lt;br /&gt;
firewall-cmd --add-service=http ; sudo firewall-cmd --runtime-to-permanent; firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Remove the http service from the whitelist&lt;br /&gt;
firewall-cmd --remove-service=http&lt;br /&gt;
&lt;br /&gt;
# Add port 1234 (tcp) to the whitelist&lt;br /&gt;
firewall-cmd --add-port=1234/tcp&lt;br /&gt;
&lt;br /&gt;
# Remove port 1234 (tcp) from the whitelist&lt;br /&gt;
firewall-cmd --remove-port=1234/tcp&lt;br /&gt;
&lt;br /&gt;
# Add port 2345 (udp) to the whitelist in zone external&lt;br /&gt;
firewall-cmd --zone=external --add-port=2345/udp&lt;br /&gt;
&lt;br /&gt;
# Remove port 2345 (udp) from the whitelist for zone external&lt;br /&gt;
firewall-cmd --zone=external --add-port=2345/udp&lt;br /&gt;
&lt;br /&gt;
# Add current configuration to configuration permanently&lt;br /&gt;
firewall-cmd –runtime-to-permanent&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;DANGEROUS&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# SHUT IT DOWN DOC - DROP ALL PACKETS AND EXPIRE EXISTING CONNECTIONS&lt;br /&gt;
firewall-cmd --panic-on&lt;br /&gt;
&lt;br /&gt;
# ACCEPT PACKETS AGAIN&lt;br /&gt;
firewall-cmd --panic-off&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== CSF ====&lt;br /&gt;
ConfigServer Security and Firewall&lt;br /&gt;
&lt;br /&gt;
===== General =====&lt;br /&gt;
* Common configuration: /etc/csf/csf.conf &lt;br /&gt;
* Blacklist: /etc/csf/csf.deny &lt;br /&gt;
* Whitelist: /etc/csf/csf.allow &lt;br /&gt;
&lt;br /&gt;
===== Installation =====&lt;br /&gt;
From the official instructions: https://download.configserver.com/csf/install.txt&lt;br /&gt;
&lt;br /&gt;
====== Prerequisites ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Perl Modules&lt;br /&gt;
============&lt;br /&gt;
While most should be installed on a standard perl installation the following&lt;br /&gt;
may need to be installed manually:&lt;br /&gt;
&lt;br /&gt;
# On rpm based systems:&lt;br /&gt;
yum install perl-libwww-perl.noarch perl-LWP-Protocol-https.noarch perl-GDGraph&lt;br /&gt;
&lt;br /&gt;
# On APT based systems:&lt;br /&gt;
apt-get install libwww-perl liblwp-protocol-https-perl libgd-graph-perl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Install ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cd /usr/src&lt;br /&gt;
rm -fv csf.tgz&lt;br /&gt;
wget https://download.configserver.com/csf.tgz&lt;br /&gt;
tar -xzf csf.tgz&lt;br /&gt;
cd csf&lt;br /&gt;
sh install.sh&lt;br /&gt;
&lt;br /&gt;
# Next, test whether you have the required iptables modules:&lt;br /&gt;
perl /usr/local/csf/bin/csftest.pl&lt;br /&gt;
&lt;br /&gt;
# Don&#039;t worry if you cannot run all the features, so long as the script doesn&#039;t report any FATAL errors&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Checks =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check the running status of csf&lt;br /&gt;
csf status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Commands =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Commit config changes by restarting csf&lt;br /&gt;
csf -r&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== csf.conf =====&lt;br /&gt;
Some common changes within the configuration file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Set testing to 0 when your CSF configuration is &#039;production&#039; ready&lt;br /&gt;
TESTING = &amp;quot;0&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow access to any service you&#039;re hosting locally, for example https&lt;br /&gt;
TCP_IN = &amp;quot;443&amp;quot;&lt;br /&gt;
UDP_IN = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow all outwards HTTP/HTTPS traffic so you can yum/apt update&lt;br /&gt;
TCP_OUT = &amp;quot;80,443&amp;quot; &lt;br /&gt;
&lt;br /&gt;
# Allow outgoing traceroute&lt;br /&gt;
UDP_OUT = &amp;quot;33434:33523&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow your server to be pinged&lt;br /&gt;
ICMP_IN = &amp;quot;0&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Formatting =====&lt;br /&gt;
The varying styles of formatting used in allow.conf&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Allow anything relating to the following IPs/ranges&lt;br /&gt;
192.168.10.0/24 # Our application breaks without this range&lt;br /&gt;
192.168.1.1 # Our gateway or something&lt;br /&gt;
&lt;br /&gt;
# Detailed entries based on Transport protocol, direction, Application protocol and IP&lt;br /&gt;
tcp:in:d=22:s=7.7.7.7 # SSH access from our VPN&lt;br /&gt;
udp:in:d=161:s=10.11.12.100 # SNMP Access&lt;br /&gt;
tcp|in|d=22|s=fe80::1:/16 # IPV6 SSH access from our jumpgateway&lt;br /&gt;
udp|in|d=3389|s=10.1.0.0/24 # RDP Access from our entire office range&lt;br /&gt;
tcp|out|d=80,443|d=1.2.3.4/32 # Allow outgoing HTTP/HTTPS access via port 80 and 443&lt;br /&gt;
&lt;br /&gt;
# Allow sending Syslog messages to our Syslog server&lt;br /&gt;
udp|out|d=514|d=192.168.20.5 # UDP syslog server&lt;br /&gt;
tcp|out|d=10514|d=192.168.20.5 # UDP syslog server&lt;br /&gt;
&lt;br /&gt;
# Allow sending queries to some DNS servers&lt;br /&gt;
tcp|out|s=53|d=8.8.8.8&lt;br /&gt;
udp|out|s=53|d=1.1.1.1&lt;br /&gt;
udp|out|s=53|d=2606:4700:4700::1111 # Cloudflare IPv6 DNS Server&lt;br /&gt;
&lt;br /&gt;
# Include an external configuration file&lt;br /&gt;
Include /etc/csf/csf.custom-config&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rsyslog ===&lt;br /&gt;
&amp;lt;section begin=&amp;quot;linuxsyslog&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* https://www.rsyslog.com/doc/reference/templates/templates-reserved-names.html#ref-templates-reserved-names&lt;br /&gt;
* https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/6/html/deployment_guide/s2-templates&lt;br /&gt;
&lt;br /&gt;
==== Legacy ====&lt;br /&gt;
Send all logs to a rsyslog server and specify a port, @ is equal to using UDP. @@ is equal to TCP&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/75-local-to-rsyslog-server.conf&lt;br /&gt;
*.* @10.77.0.1:514&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Custom template where hostname is defined, then sent to the syslog server - include the priority number as first extra variable&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#/etc/rsyslog.d/70-local-to-rsyslog-server.conf&lt;br /&gt;
$template SendHostname, &amp;quot;%PRI%1 %timestamp% myhost.mydomain.nl %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.warning @10.77.0.1;SendHostname&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Send messages to a syslog server, using a template aligned to IETF protocol 23&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/61-qwe.conf&lt;br /&gt;
*.* @10.77.0.1;RSYSLOG_SyslogProtocol23Format&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Send messages to a syslog server, using a template aligned to IETF protocol 23, but specifying a custom hostname&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/60-asd.conf&lt;br /&gt;
$template custom_IETFprotocol_23,&amp;quot;%PRI%1 %TIMESTAMP:::date-rfc3339% prive.host.nl %APP-NAME% %PROCID% %MSGID% %STRUCTURED-DATA% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* @10.77.0.1;custom_IETFprotocol_23&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Log to the local server with a static hostname, using a custom structure&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/62-asd.conf&lt;br /&gt;
$template NewHostname, &amp;quot;%timestamp% tester.mydomain.nl %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* /var/log/wewuzerrors.txt;NewHostname&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An alternative to the contents above, specifying different/more fields&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
## /etc/rsyslog.d/65-customtemplate.conf&lt;br /&gt;
# https://stackoverflow.com/questions/57890176/extending-rsyslogs-default-logging-template&lt;br /&gt;
$template mynewtemplate,&amp;quot;%timegenerated% %HOSTNAME% %syslogfacility-text%.%syslogseverity-text% %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* /var/log/wazanda.txt;mynewtemplate&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rainerscript ====&lt;br /&gt;
Rainerscript: https://rsyslog.readthedocs.io/en/latest/rainerscript/control_structures.html&lt;br /&gt;
&lt;br /&gt;
Write all messages to &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/60-asd.conf&lt;br /&gt;
action(type=&amp;quot;omfile&amp;quot; file=&amp;quot;/var/log/isaidhey.txt&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Send message to a syslog server using IETF protocol 23&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/70-local-to-rsyslog-server.conf&lt;br /&gt;
template(name=&amp;quot;RSYSLOG_SyslogProtocol23Format&amp;quot; type=&amp;quot;string&amp;quot;&lt;br /&gt;
     string=&amp;quot;&amp;lt;%PRI%&amp;gt;1 %TIMESTAMP:::date-rfc3339% %HOSTNAME% %APP-NAME% %PROCID% %MSGID% %STRUCTURED-DATA% %msg%\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Send all logs to the target server&lt;br /&gt;
action(type=&amp;quot;omfwd&amp;quot; Target=&amp;quot;192.168.5.21&amp;quot; Template=&amp;quot;RSYSLOG_SyslogProtocol23Format&amp;quot; Port=&amp;quot;514&amp;quot; Protocol=&amp;quot;udp&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Define a template aligned to IETF protocol 23 and specify a hostname to send as:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/71-local-to-rsyslog-server.conf&lt;br /&gt;
template(name=&amp;quot;SendHostname&amp;quot; type=&amp;quot;string&amp;quot;&lt;br /&gt;
     string=&amp;quot;&amp;lt;%PRI%&amp;gt;1 %TIMESTAMP:::date-rfc3339% myhost.mydomain.nl %APP-NAME% %PROCID% %MSGID% %STRUCTURED-DATA% %msg%\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Send all logs to target syslog server and port&lt;br /&gt;
action(type=&amp;quot;omfwd&amp;quot; Target=&amp;quot;10.0.33.10&amp;quot; Template=&amp;quot;SendHostname&amp;quot; Port=&amp;quot;514&amp;quot; Protocol=&amp;quot;udp&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Testing ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use the logger tool to test syslog server reception&lt;br /&gt;
logger -p local0.error &#039;Hello World!&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section end=&amp;quot;linuxsyslog&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== named ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Perform a test load of all primary zones within named.conf, as the named user&lt;br /&gt;
sudo -u named named-checkconf -z&lt;br /&gt;
&lt;br /&gt;
# Check zone file 192.168.77.0 defined in the 77.168.192.in-addr.arpa zone&lt;br /&gt;
named-checkzone 77.168.192.in-addr.arpa 192.168.77.0&lt;br /&gt;
&lt;br /&gt;
# Check zone file brammerloo.nl defined in the brammerloo.nl zone&lt;br /&gt;
named-checkzone brammerloo.nl brammerloo.nl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Basic configuration for the options field in &#039;&#039;&#039;/etc/named.conf&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
options {&lt;br /&gt;
# Define on what IP to listen on, for port 53&lt;br /&gt;
        listen-on port 53 { 127.0.0.1; 192.168.0.1; 192.168.1.1; };&lt;br /&gt;
        directory       &amp;quot;/var/named&amp;quot;;&lt;br /&gt;
        dump-file       &amp;quot;/var/named/data/cache_dump.db&amp;quot;;&lt;br /&gt;
        statistics-file &amp;quot;/var/named/data/named_stats.txt&amp;quot;;&lt;br /&gt;
        memstatistics-file &amp;quot;/var/named/data/named_mem_stats.txt&amp;quot;;&lt;br /&gt;
        secroots-file   &amp;quot;/var/named/data/named.secroots&amp;quot;;&lt;br /&gt;
        recursing-file  &amp;quot;/var/named/data/named.recursing&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# Only allow DNS queries from specific local subnets&lt;br /&gt;
# To allow from anything use: allow query { any; };&lt;br /&gt;
        allow-query     { localhost; 127.0.0.1; 192.168.0.0/24; 192.168.1.0/24; };&lt;br /&gt;
&lt;br /&gt;
# If the server can&#039;t resolve an address locally, use the following DNS servers for help&lt;br /&gt;
        forwarders {&lt;br /&gt;
        8.8.8.8;&lt;br /&gt;
        1.1.1.1;&lt;br /&gt;
        };&lt;br /&gt;
&lt;br /&gt;
        recursion yes;&lt;br /&gt;
        dnssec-validation no;&lt;br /&gt;
&lt;br /&gt;
        managed-keys-directory &amp;quot;/var/named/dynamic&amp;quot;;&lt;br /&gt;
        geoip-directory &amp;quot;/usr/share/GeoIP&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
        pid-file &amp;quot;/run/named/named.pid&amp;quot;;&lt;br /&gt;
        session-keyfile &amp;quot;/run/named/session.key&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
        /* https://fedoraproject.org/wiki/Changes/CryptoPolicy */&lt;br /&gt;
        include &amp;quot;/etc/crypto-policies/back-ends/bind.config&amp;quot;;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone defnitions: &#039;&#039;&#039;/etc/named.rfc1912.zones&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Define zones to listen for&lt;br /&gt;
zone &amp;quot;brammerloo.nl&amp;quot; IN {&lt;br /&gt;
        type master;&lt;br /&gt;
        file &amp;quot;brammerloo.nl&amp;quot;;&lt;br /&gt;
        allow-update { none; };&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
zone &amp;quot;1.168.192.in-addr.arpa&amp;quot; IN {&lt;br /&gt;
        type master;&lt;br /&gt;
        file &amp;quot;192.168.1.0&amp;quot;;&lt;br /&gt;
        allow-update { none; };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone file for Reverse lookup: &#039;&#039;&#039;/var/named/192.168.1.0&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$TTL 300&lt;br /&gt;
@       IN SOA  ns1.brammerloo.nl. admin.brammerloo.nl. (&lt;br /&gt;
                                        2023101102 ; serial&lt;br /&gt;
                                        180     ; refresh&lt;br /&gt;
                                        60      ; retry&lt;br /&gt;
                                        108000  ; expire&lt;br /&gt;
                                        60 )    ; minimum&lt;br /&gt;
    IN      NS      ns1.brammerloo.nl.&lt;br /&gt;
; PTR Records&lt;br /&gt;
11    IN   PTR   node1.&lt;br /&gt;
21    IN   PTR   server1.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone file for domain: &#039;&#039;&#039;/var/named/brammerloo.nl&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$TTL 300&lt;br /&gt;
@       IN SOA  ns1.brammerloo.nl. admin.brammerloo.nl. (&lt;br /&gt;
                                        2023101306 ; serial&lt;br /&gt;
                                        180     ; refresh&lt;br /&gt;
                                        60      ; retry&lt;br /&gt;
                                        108000  ; expire&lt;br /&gt;
                                        60 )    ; minimum&lt;br /&gt;
    IN      NS      ns1.brammerloo.nl.&lt;br /&gt;
@                  IN      A     192.168.1.6   ; domain brammerloo.nl is me!&lt;br /&gt;
ns1.brammerloo.nl. IN      A     192.168.78.31 ; FQDN for my domain&lt;br /&gt;
node1              IN      A     192.168.78.31 ; Basic A-record&lt;br /&gt;
www                IN      CNAME node1         ; Point my website to my node1 A-record&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== dhcpd ===&lt;br /&gt;
==== dhclient ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Request an IPv4 adres from a DHCP server&lt;br /&gt;
dhclient -4&lt;br /&gt;
&lt;br /&gt;
# Show verbose information when requesting an IPv4 adres from a DHCP server&lt;br /&gt;
dhclient -4 -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Basic configuration options in the &#039;&#039;&#039;/etc/dhcp/dhcpd.conf&#039;&#039;&#039; file&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Set the domain clients should use when resolving hostnames (equivalent to search domain)&lt;br /&gt;
option domain-name &amp;quot;brammerloo.nl&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# Set the domain name servers for DHCP clients&lt;br /&gt;
option domain-name-servers ns1.brammerloo.nl, 8.8.8.8;&lt;br /&gt;
&lt;br /&gt;
default-lease-time 600;&lt;br /&gt;
max-lease-time 7200;&lt;br /&gt;
log-facility local7;&lt;br /&gt;
&lt;br /&gt;
# Best practice = define any connected subnets, but don&#039;t configure DHCP for them&lt;br /&gt;
subnet 192.168.1.0 netmask 255.255.255.0 {&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Basic DHCP for a subnet configuration&lt;br /&gt;
subnet 192.168.0.0 netmask 255.255.255.0 {&lt;br /&gt;
  range 192.168.0.100 192.168.0.150;&lt;br /&gt;
  option routers 192.168.0.1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== smbd / Samba / CIFS ===&lt;br /&gt;
https://linuxconfig.org/install-samba-on-redhat-8&lt;br /&gt;
&lt;br /&gt;
==== Basic configuration ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install and enable&lt;br /&gt;
dnf install samba samba-client&lt;br /&gt;
systemctl enable --now {smb,nmb}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a client-user to authenticate with&lt;br /&gt;
sudo useradd samba-user&lt;br /&gt;
&lt;br /&gt;
# Give the user a password to authenticate with&lt;br /&gt;
sudo smbpasswd -a samba-user&lt;br /&gt;
&lt;br /&gt;
# Create a group to associate with the samba share&lt;br /&gt;
sudo groupadd sambagroup&lt;br /&gt;
&lt;br /&gt;
# Add the user to the group we will be configuring for the share&lt;br /&gt;
sudo usermod -a -G sambagroup samba-user&lt;br /&gt;
&lt;br /&gt;
# Create the folder we will be sharing&lt;br /&gt;
sudo mkdir /var/shares/myshare&lt;br /&gt;
&lt;br /&gt;
# Apply proper permission&lt;br /&gt;
sudo chown -R samba-user:sambagroup /var/shares/myshare/&lt;br /&gt;
sudo chmod -R 0770 /var/shares/myshare/&lt;br /&gt;
&lt;br /&gt;
# Apply proper permission for SELinux&lt;br /&gt;
sudo chcon -t samba_share_t /var/shares/myshare/&lt;br /&gt;
&lt;br /&gt;
# Backup the default config&lt;br /&gt;
cp /etc/samba/smb.conf /etc/samba/smb.conf~&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/samba/smb.conf&lt;br /&gt;
[global]&lt;br /&gt;
 workgroup = &amp;lt;DOMAIN-OR-WORKGROUP&amp;gt;&lt;br /&gt;
 server string = Samba Server %v&lt;br /&gt;
 netbios name = &amp;lt;SERVER-HOSTNAME&amp;gt;&lt;br /&gt;
 security = user&lt;br /&gt;
 map to guest = bad user&lt;br /&gt;
 dns proxy = no&lt;br /&gt;
&lt;br /&gt;
#==================== Share Definitions ======================&lt;br /&gt;
[share001]&lt;br /&gt;
 path = /var/shares/myshare&lt;br /&gt;
 valid users = @sambagroup&lt;br /&gt;
 guest ok = no&lt;br /&gt;
 writable = yes&lt;br /&gt;
 browsable = yes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reload Samba services&lt;br /&gt;
systemctl reload {smb,nmb}&lt;br /&gt;
&lt;br /&gt;
# Mount in Windows&lt;br /&gt;
\\&amp;lt;SERVER-IP&amp;gt;\share001&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user: samba-user&lt;br /&gt;
pass: &amp;lt;Whatever password you filled in with smbpasswd -a&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Samba checks&lt;br /&gt;
smbstatus&lt;br /&gt;
smbstatus -S&lt;br /&gt;
smbstatus -b&lt;br /&gt;
&lt;br /&gt;
# Samba set debug mode&lt;br /&gt;
smbcontrol smbd debug 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Docker ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List Docker containers &lt;br /&gt;
docker ps&lt;br /&gt;
&lt;br /&gt;
# List all Docker container IDs&lt;br /&gt;
docker ps -aq&lt;br /&gt;
&lt;br /&gt;
# List logs for container 987sdh3qrasdhj&lt;br /&gt;
docker logs 987sdh3qrasdhj&lt;br /&gt;
&lt;br /&gt;
# List RAM/CPU usage for Docker container asdlkasd67k&lt;br /&gt;
docker stats asdlkasd67k&lt;br /&gt;
&lt;br /&gt;
# Show verbose container information such as commands run, network, ID, etc&lt;br /&gt;
docker inspect oiu2398sda87&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enter the shell inside a docker container&lt;br /&gt;
docker exec -ti a89sd98sa7d /bin/bash&lt;br /&gt;
&lt;br /&gt;
# Execute a command inside a container as a specific user, root in this case&lt;br /&gt;
docker exec -it -u root asd87289hasdadz tail /var/log/nginx/access.log&lt;br /&gt;
docker exec -u 0 -it as892asnj2as /bin/bash&lt;br /&gt;
&lt;br /&gt;
# Restart docker container yoga&lt;br /&gt;
docker restart yoga&lt;br /&gt;
&lt;br /&gt;
# Restart the 3 given containers&lt;br /&gt;
docker restart 79f71c7f4d91 bbb3d3f5c3b1 b0a3204d4098&lt;br /&gt;
&lt;br /&gt;
# Start this container&lt;br /&gt;
docker start as9823nzxc0&lt;br /&gt;
&lt;br /&gt;
# Stop this container&lt;br /&gt;
docker stop as9823nzxc0&lt;br /&gt;
&lt;br /&gt;
# Restart all unhealthy Docker containers&lt;br /&gt;
for i in $(docker ps | grep unhealthy | awk &#039;{print $1}&#039;); do docker restart &amp;quot;$i&amp;quot;; done;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PowerDNS ===&lt;br /&gt;
* https://doc.powerdns.com/authoritative/index.html&lt;br /&gt;
* https://doc.powerdns.com/authoritative/manpages/pdns_server.1.html&lt;br /&gt;
* https://doc.powerdns.com/authoritative/manpages/pdnsutil.1.html&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# List commands&lt;br /&gt;
pdns_server --help&lt;br /&gt;
&lt;br /&gt;
# Check config and parse for errors&lt;br /&gt;
pdns_server --config=check&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# List available commands &lt;br /&gt;
pdnsutil --help&lt;br /&gt;
&lt;br /&gt;
# Check config and parse for errors&lt;br /&gt;
pdnsutil --config=check&lt;br /&gt;
&lt;br /&gt;
# List all available zones&lt;br /&gt;
pdnsutil list-all-zones&lt;br /&gt;
&lt;br /&gt;
# List all domains in the primary zone&lt;br /&gt;
pdnsutil list-all-zones primary&lt;br /&gt;
&lt;br /&gt;
# See zone information for a specific domain&lt;br /&gt;
pdnsutil show-zone mydomain.com&lt;br /&gt;
pdnsutil show-zone 77.5.10.in-addr.arpa&lt;br /&gt;
&lt;br /&gt;
# Check zone for errors&lt;br /&gt;
pdnsutil check-zone mydomain.com&lt;br /&gt;
&lt;br /&gt;
# List all created TSIG keys&lt;br /&gt;
pdnsutil list-tsig-keys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# Activate TSIG key for domain &amp;quot;myexample.com&amp;quot; in the primary zone&lt;br /&gt;
pdnsutil &amp;quot; myexample.com transfer primary&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MAAS ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Logs in either place:&lt;br /&gt;
/var/log/maas/&lt;br /&gt;
/var/snap/maas/common/log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List status of MAAS services&lt;br /&gt;
maas status&lt;br /&gt;
&lt;br /&gt;
# List MAAS commands&lt;br /&gt;
maas --help&lt;br /&gt;
&lt;br /&gt;
# List available arguments for the init command&lt;br /&gt;
maas init --help&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section end=&amp;quot;linuxservices&amp;quot;/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Services&amp;diff=849</id>
		<title>Linux:Services</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Services&amp;diff=849"/>
		<updated>2025-10-01T11:55:49Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* Rainerscript */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet|Cheatsheets]]&lt;br /&gt;
&lt;br /&gt;
== Services ==&lt;br /&gt;
&amp;lt;section begin=&amp;quot;linuxservices&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Common ===&lt;br /&gt;
==== systemctl ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all services that are running or exited&lt;br /&gt;
systemctl&lt;br /&gt;
&lt;br /&gt;
# List all services, running or otherwise&lt;br /&gt;
systemctl --all&lt;br /&gt;
&lt;br /&gt;
# List all failed services&lt;br /&gt;
systemctl --state=failed&lt;br /&gt;
&lt;br /&gt;
# Reset the failed service &amp;quot;nginx&amp;quot;&lt;br /&gt;
systemctl reset-failed nginx&lt;br /&gt;
&lt;br /&gt;
# View the status of the &amp;quot;nfs-server&amp;quot; service&lt;br /&gt;
systemctl status nfs-server&lt;br /&gt;
&lt;br /&gt;
# Output the config file of &amp;quot;rsyslog&amp;quot; to the shell&lt;br /&gt;
systemctl cat rsyslog&lt;br /&gt;
&lt;br /&gt;
# Restart the &amp;quot;sshd&amp;quot; service, terminating established connections and re-parsing the configuration&lt;br /&gt;
systemctl restart sshd&lt;br /&gt;
&lt;br /&gt;
# Reload the &amp;quot;nginx&amp;quot; service so that it only re-parses the configuration&lt;br /&gt;
systemctl reload nginx&lt;br /&gt;
&lt;br /&gt;
# Stop the &amp;quot;nfs-ganesha&amp;quot; service so that it stops being run&lt;br /&gt;
systemctl stop nfs-ganesha&lt;br /&gt;
&lt;br /&gt;
# Start the &amp;quot;nfs-ganesha&amp;quot; service so that it starts being run again&lt;br /&gt;
systemctl start nfs-ganesha&lt;br /&gt;
&lt;br /&gt;
# Disable the &amp;quot;mariadb&amp;quot; service so that it doesn&#039;t start after the next boot&lt;br /&gt;
systemctl disable mariadb&lt;br /&gt;
&lt;br /&gt;
# Enable the &amp;quot;mariadb&amp;quot; service so that it starts after the next boot.&lt;br /&gt;
systemctl enable mariadb&lt;br /&gt;
&lt;br /&gt;
# Check the logs for all failed services&lt;br /&gt;
for i in $(systemctl --state=failed | head -n -4 | tail -n +2 | awk &#039;{print $1}&#039;); do systemctl --no-pager status &amp;quot;$i&amp;quot;; done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== NTP ===&lt;br /&gt;
==== Timedatectl ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show the current status of timedatectl&lt;br /&gt;
timedatectl&lt;br /&gt;
&lt;br /&gt;
# List available timezones&lt;br /&gt;
timedatectl list-timezones&lt;br /&gt;
&lt;br /&gt;
# Set the timezone to Amsterdam&lt;br /&gt;
timedatectl set-timezone Europe/Amsterdam&lt;br /&gt;
&lt;br /&gt;
# Show verbose sync information&lt;br /&gt;
timedatectl timesync-status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SNMP ===&lt;br /&gt;
==== V3 client installation ====&lt;br /&gt;
* https://kifarunix.com/quick-way-to-install-and-configure-snmp-on-ubuntu-20-04/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
apt install snmpd snmp libsnmp-dev&lt;br /&gt;
cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.bak&lt;br /&gt;
systemctl stop snmpd&lt;br /&gt;
net-snmp-create-v3-user -ro -X &amp;lt;CRYPTO-PASSWORD&amp;gt; -a SHA -X &amp;lt;PASSWORD&amp;gt; -x AES &amp;lt;USERNAME&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/snmp/snmpd.conf&lt;br /&gt;
sysLocation    NL;Zuid-Holland;Rotterdam, 78 MyStreet;2nd Floor;Server Room;Rack&lt;br /&gt;
sysContact     Me &amp;lt;me@example.org&amp;gt;&lt;br /&gt;
agentaddress   192.168.0.10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
systemctl start snmpd&lt;br /&gt;
systemctl enable snmpd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Test&lt;br /&gt;
snmpwalk -v3 -a SHA -A &amp;quot;AUTHENTICATION PASSWORD&amp;quot; -x AES -X &amp;quot;CRYPTO PASSWORD&amp;quot; -l authPriv -u &amp;quot;MYUSER&amp;quot; localhost | head&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CTDB  ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Verify CTDB cluster status&lt;br /&gt;
ctdb status&lt;br /&gt;
&lt;br /&gt;
# Show the allocated IP addresses and to which nodes they&#039;re bound&lt;br /&gt;
ctdb ip&lt;br /&gt;
&lt;br /&gt;
# See the status of all CTDB-scripts&lt;br /&gt;
ctdb scriptstatus&lt;br /&gt;
ctdb event status&lt;br /&gt;
&lt;br /&gt;
# Show the time of the last failover the duration it took to recover&lt;br /&gt;
ctdb uptime&lt;br /&gt;
&lt;br /&gt;
# See various statistics and data&lt;br /&gt;
ctdb statistics&lt;br /&gt;
&lt;br /&gt;
# Use the onnode command to execute a command on all cluster nodes&lt;br /&gt;
onnode all ctdb status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Stop a ctdb cluster member&lt;br /&gt;
ctdb stop&lt;br /&gt;
&lt;br /&gt;
# Start a stopped ctdb cluster member&lt;br /&gt;
ctdb continue&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Firewalls ===&lt;br /&gt;
==== UFW ====&lt;br /&gt;
===== Checks =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show summary of UFW status&lt;br /&gt;
ufw status&lt;br /&gt;
&lt;br /&gt;
# Show verbose UFW status&lt;br /&gt;
ufw status verbose&lt;br /&gt;
&lt;br /&gt;
# Show UFW rules numbered&lt;br /&gt;
ufw status numbered&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Commands =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Allow access from a specific IP to a port and add a comment that show in the status&lt;br /&gt;
ufw allow from 10.0.0.253 to any port 22 proto tcp comment &#039;Allow SSH access from XYZ location&#039;&lt;br /&gt;
&lt;br /&gt;
# Delete numbered Firewall rule 56&lt;br /&gt;
ufw delete 56&lt;br /&gt;
&lt;br /&gt;
# Disable UFW logging (prevent syslog spam)&lt;br /&gt;
ufw logging off&lt;br /&gt;
&lt;br /&gt;
# Set UFW logging back to the default&lt;br /&gt;
ufw logging low&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Firewalld ====&lt;br /&gt;
===== SNMP access =====&lt;br /&gt;
* https://unix.stackexchange.com/questions/214388/how-to-let-the-firewall-of-rhel7-the-snmp-connection-passing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/firewalld/services/snmp.xml&lt;br /&gt;
&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;service&amp;gt;&lt;br /&gt;
  &amp;lt;short&amp;gt;SNMP&amp;lt;/short&amp;gt;&lt;br /&gt;
  &amp;lt;description&amp;gt;SNMP protocol&amp;lt;/description&amp;gt;&lt;br /&gt;
  &amp;lt;port protocol=&amp;quot;udp&amp;quot; port=&amp;quot;161&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/service&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
firewall-cmd --zone=public --add-service snmp --permanent&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Firewall-cmd =====&lt;br /&gt;
====== Checks ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all available commands&lt;br /&gt;
firewall-cmd -h&lt;br /&gt;
&lt;br /&gt;
# Check the configuration file of the firewall for errors&lt;br /&gt;
firewall-cmd --check-config&lt;br /&gt;
&lt;br /&gt;
# Display the current state of firewall-cmd (running/shutdown)&lt;br /&gt;
firewall-cmd --state&lt;br /&gt;
&lt;br /&gt;
# Display all available zones&lt;br /&gt;
firewall-cmd --get-zones&lt;br /&gt;
&lt;br /&gt;
# List all whitelisted services&lt;br /&gt;
firewall-cmd --list-services&lt;br /&gt;
&lt;br /&gt;
# List all services you can potentially enable&lt;br /&gt;
firewall-cmd --get-services&lt;br /&gt;
&lt;br /&gt;
# List all added or enabled services and ports in more detail&lt;br /&gt;
firewall-cmd --list-all&lt;br /&gt;
&lt;br /&gt;
# List verbose information for all zones&lt;br /&gt;
firewall-cmd --list-all-zones&lt;br /&gt;
&lt;br /&gt;
# List verbose information for the public zone&lt;br /&gt;
firewall-cmd --list-all --zone=public&lt;br /&gt;
&lt;br /&gt;
# See what port(s) are associated with the dns service&lt;br /&gt;
firewall-cmd --info-service dns&lt;br /&gt;
&lt;br /&gt;
# List all opened ports&lt;br /&gt;
firewall-cmd --list-ports&lt;br /&gt;
&lt;br /&gt;
# List kernel ruleset generated for nftables(?)&lt;br /&gt;
nft list ruleset&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Commands ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reload the firewall&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Whitelist the dns service, persistently even after reboot&lt;br /&gt;
firewall-cmd --add-service=dns ; sudo firewall-cmd --runtime-to-permanent; firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Whitelist the http service, persistently even after reboot&lt;br /&gt;
firewall-cmd --add-service=http ; sudo firewall-cmd --runtime-to-permanent; firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Remove the http service from the whitelist&lt;br /&gt;
firewall-cmd --remove-service=http&lt;br /&gt;
&lt;br /&gt;
# Add port 1234 (tcp) to the whitelist&lt;br /&gt;
firewall-cmd --add-port=1234/tcp&lt;br /&gt;
&lt;br /&gt;
# Remove port 1234 (tcp) from the whitelist&lt;br /&gt;
firewall-cmd --remove-port=1234/tcp&lt;br /&gt;
&lt;br /&gt;
# Add port 2345 (udp) to the whitelist in zone external&lt;br /&gt;
firewall-cmd --zone=external --add-port=2345/udp&lt;br /&gt;
&lt;br /&gt;
# Remove port 2345 (udp) from the whitelist for zone external&lt;br /&gt;
firewall-cmd --zone=external --add-port=2345/udp&lt;br /&gt;
&lt;br /&gt;
# Add current configuration to configuration permanently&lt;br /&gt;
firewall-cmd –runtime-to-permanent&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;DANGEROUS&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# SHUT IT DOWN DOC - DROP ALL PACKETS AND EXPIRE EXISTING CONNECTIONS&lt;br /&gt;
firewall-cmd --panic-on&lt;br /&gt;
&lt;br /&gt;
# ACCEPT PACKETS AGAIN&lt;br /&gt;
firewall-cmd --panic-off&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== CSF ====&lt;br /&gt;
ConfigServer Security and Firewall&lt;br /&gt;
&lt;br /&gt;
===== General =====&lt;br /&gt;
* Common configuration: /etc/csf/csf.conf &lt;br /&gt;
* Blacklist: /etc/csf/csf.deny &lt;br /&gt;
* Whitelist: /etc/csf/csf.allow &lt;br /&gt;
&lt;br /&gt;
===== Installation =====&lt;br /&gt;
From the official instructions: https://download.configserver.com/csf/install.txt&lt;br /&gt;
&lt;br /&gt;
====== Prerequisites ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Perl Modules&lt;br /&gt;
============&lt;br /&gt;
While most should be installed on a standard perl installation the following&lt;br /&gt;
may need to be installed manually:&lt;br /&gt;
&lt;br /&gt;
# On rpm based systems:&lt;br /&gt;
yum install perl-libwww-perl.noarch perl-LWP-Protocol-https.noarch perl-GDGraph&lt;br /&gt;
&lt;br /&gt;
# On APT based systems:&lt;br /&gt;
apt-get install libwww-perl liblwp-protocol-https-perl libgd-graph-perl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Install ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cd /usr/src&lt;br /&gt;
rm -fv csf.tgz&lt;br /&gt;
wget https://download.configserver.com/csf.tgz&lt;br /&gt;
tar -xzf csf.tgz&lt;br /&gt;
cd csf&lt;br /&gt;
sh install.sh&lt;br /&gt;
&lt;br /&gt;
# Next, test whether you have the required iptables modules:&lt;br /&gt;
perl /usr/local/csf/bin/csftest.pl&lt;br /&gt;
&lt;br /&gt;
# Don&#039;t worry if you cannot run all the features, so long as the script doesn&#039;t report any FATAL errors&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Checks =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check the running status of csf&lt;br /&gt;
csf status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Commands =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Commit config changes by restarting csf&lt;br /&gt;
csf -r&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== csf.conf =====&lt;br /&gt;
Some common changes within the configuration file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Set testing to 0 when your CSF configuration is &#039;production&#039; ready&lt;br /&gt;
TESTING = &amp;quot;0&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow access to any service you&#039;re hosting locally, for example https&lt;br /&gt;
TCP_IN = &amp;quot;443&amp;quot;&lt;br /&gt;
UDP_IN = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow all outwards HTTP/HTTPS traffic so you can yum/apt update&lt;br /&gt;
TCP_OUT = &amp;quot;80,443&amp;quot; &lt;br /&gt;
&lt;br /&gt;
# Allow outgoing traceroute&lt;br /&gt;
UDP_OUT = &amp;quot;33434:33523&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow your server to be pinged&lt;br /&gt;
ICMP_IN = &amp;quot;0&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Formatting =====&lt;br /&gt;
The varying styles of formatting used in allow.conf&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Allow anything relating to the following IPs/ranges&lt;br /&gt;
192.168.10.0/24 # Our application breaks without this range&lt;br /&gt;
192.168.1.1 # Our gateway or something&lt;br /&gt;
&lt;br /&gt;
# Detailed entries based on Transport protocol, direction, Application protocol and IP&lt;br /&gt;
tcp:in:d=22:s=7.7.7.7 # SSH access from our VPN&lt;br /&gt;
udp:in:d=161:s=10.11.12.100 # SNMP Access&lt;br /&gt;
tcp|in|d=22|s=fe80::1:/16 # IPV6 SSH access from our jumpgateway&lt;br /&gt;
udp|in|d=3389|s=10.1.0.0/24 # RDP Access from our entire office range&lt;br /&gt;
tcp|out|d=80,443|d=1.2.3.4/32 # Allow outgoing HTTP/HTTPS access via port 80 and 443&lt;br /&gt;
&lt;br /&gt;
# Allow sending Syslog messages to our Syslog server&lt;br /&gt;
udp|out|d=514|d=192.168.20.5 # UDP syslog server&lt;br /&gt;
tcp|out|d=10514|d=192.168.20.5 # UDP syslog server&lt;br /&gt;
&lt;br /&gt;
# Allow sending queries to some DNS servers&lt;br /&gt;
tcp|out|s=53|d=8.8.8.8&lt;br /&gt;
udp|out|s=53|d=1.1.1.1&lt;br /&gt;
udp|out|s=53|d=2606:4700:4700::1111 # Cloudflare IPv6 DNS Server&lt;br /&gt;
&lt;br /&gt;
# Include an external configuration file&lt;br /&gt;
Include /etc/csf/csf.custom-config&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rsyslog ===&lt;br /&gt;
&amp;lt;section begin=&amp;quot;linuxsyslog&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* https://www.rsyslog.com/doc/reference/templates/templates-reserved-names.html#ref-templates-reserved-names&lt;br /&gt;
* https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/6/html/deployment_guide/s2-templates&lt;br /&gt;
&lt;br /&gt;
==== Legacy ====&lt;br /&gt;
Send all logs to a rsyslog server and specify a port, @ is equal to using UDP. @@ is equal to TCP&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/75-local-to-rsyslog-server.conf&lt;br /&gt;
*.* @10.77.0.1:514&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Custom template where hostname is defined, then sent to the syslog server - include the priority number as first extra variable&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#/etc/rsyslog.d/70-local-to-rsyslog-server.conf&lt;br /&gt;
$template SendHostname, &amp;quot;%PRI%1 %timestamp% myhost.mydomain.nl %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.warning @10.77.0.1;SendHostname&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Send messages to a syslog server, using a template aligned to IETF protocol 23&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/61-qwe.conf&lt;br /&gt;
*.* @10.77.0.1;RSYSLOG_SyslogProtocol23Format&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Send messages to a syslog server, using a template aligned to IETF protocol 23, but specifying a custom hostname&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/60-asd.conf&lt;br /&gt;
$template custom_IETFprotocol_23,&amp;quot;%PRI%1 %TIMESTAMP:::date-rfc3339% prive.host.nl %APP-NAME% %PROCID% %MSGID% %STRUCTURED-DATA% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* @10.77.0.1;custom_IETFprotocol_23&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Log to the local server with a static hostname, using a custom structure&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/62-asd.conf&lt;br /&gt;
$template NewHostname, &amp;quot;%timestamp% tester.mydomain.nl %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* /var/log/wewuzerrors.txt;NewHostname&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An alternative to the contents above, specifying different/more fields&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
## /etc/rsyslog.d/65-customtemplate.conf&lt;br /&gt;
# https://stackoverflow.com/questions/57890176/extending-rsyslogs-default-logging-template&lt;br /&gt;
$template mynewtemplate,&amp;quot;%timegenerated% %HOSTNAME% %syslogfacility-text%.%syslogseverity-text% %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* /var/log/wazanda.txt;mynewtemplate&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rainerscript ====&lt;br /&gt;
Rainerscript: https://rsyslog.readthedocs.io/en/latest/rainerscript/control_structures.html&lt;br /&gt;
&lt;br /&gt;
Send message to a syslog server using IETF protocol 23&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/70-local-to-rsyslog-server.conf&lt;br /&gt;
template(name=&amp;quot;RSYSLOG_SyslogProtocol23Format&amp;quot; type=&amp;quot;string&amp;quot;&lt;br /&gt;
     string=&amp;quot;&amp;lt;%PRI%&amp;gt;1 %TIMESTAMP:::date-rfc3339% %HOSTNAME% %APP-NAME% %PROCID% %MSGID% %STRUCTURED-DATA% %msg%\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
*.* action(type=&amp;quot;omfwd&amp;quot; Target=&amp;quot;192.168.5.21&amp;quot; Template=&amp;quot;RSYSLOG_SyslogProtocol23Format&amp;quot; Port=&amp;quot;514&amp;quot; Protocol=&amp;quot;udp&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Define a template aligned to IETF protocol 23 and specify a hostname to send as:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/71-local-to-rsyslog-server.conf&lt;br /&gt;
template(name=&amp;quot;SendHostname&amp;quot; type=&amp;quot;string&amp;quot;&lt;br /&gt;
     string=&amp;quot;&amp;lt;%PRI%&amp;gt;1 %TIMESTAMP:::date-rfc3339% myhost.mydomain.nl %APP-NAME% %PROCID% %MSGID% %STRUCTURED-DATA% %msg%\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Send logs to target syslog server and port&lt;br /&gt;
*.* action(type=&amp;quot;omfwd&amp;quot; Target=&amp;quot;10.0.33.10&amp;quot; Template=&amp;quot;SendHostname&amp;quot; Port=&amp;quot;514&amp;quot; Protocol=&amp;quot;udp&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Testing ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use the logger tool to test syslog server reception&lt;br /&gt;
logger -p local0.error &#039;Hello World!&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section end=&amp;quot;linuxsyslog&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== named ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Perform a test load of all primary zones within named.conf, as the named user&lt;br /&gt;
sudo -u named named-checkconf -z&lt;br /&gt;
&lt;br /&gt;
# Check zone file 192.168.77.0 defined in the 77.168.192.in-addr.arpa zone&lt;br /&gt;
named-checkzone 77.168.192.in-addr.arpa 192.168.77.0&lt;br /&gt;
&lt;br /&gt;
# Check zone file brammerloo.nl defined in the brammerloo.nl zone&lt;br /&gt;
named-checkzone brammerloo.nl brammerloo.nl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Basic configuration for the options field in &#039;&#039;&#039;/etc/named.conf&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
options {&lt;br /&gt;
# Define on what IP to listen on, for port 53&lt;br /&gt;
        listen-on port 53 { 127.0.0.1; 192.168.0.1; 192.168.1.1; };&lt;br /&gt;
        directory       &amp;quot;/var/named&amp;quot;;&lt;br /&gt;
        dump-file       &amp;quot;/var/named/data/cache_dump.db&amp;quot;;&lt;br /&gt;
        statistics-file &amp;quot;/var/named/data/named_stats.txt&amp;quot;;&lt;br /&gt;
        memstatistics-file &amp;quot;/var/named/data/named_mem_stats.txt&amp;quot;;&lt;br /&gt;
        secroots-file   &amp;quot;/var/named/data/named.secroots&amp;quot;;&lt;br /&gt;
        recursing-file  &amp;quot;/var/named/data/named.recursing&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# Only allow DNS queries from specific local subnets&lt;br /&gt;
# To allow from anything use: allow query { any; };&lt;br /&gt;
        allow-query     { localhost; 127.0.0.1; 192.168.0.0/24; 192.168.1.0/24; };&lt;br /&gt;
&lt;br /&gt;
# If the server can&#039;t resolve an address locally, use the following DNS servers for help&lt;br /&gt;
        forwarders {&lt;br /&gt;
        8.8.8.8;&lt;br /&gt;
        1.1.1.1;&lt;br /&gt;
        };&lt;br /&gt;
&lt;br /&gt;
        recursion yes;&lt;br /&gt;
        dnssec-validation no;&lt;br /&gt;
&lt;br /&gt;
        managed-keys-directory &amp;quot;/var/named/dynamic&amp;quot;;&lt;br /&gt;
        geoip-directory &amp;quot;/usr/share/GeoIP&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
        pid-file &amp;quot;/run/named/named.pid&amp;quot;;&lt;br /&gt;
        session-keyfile &amp;quot;/run/named/session.key&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
        /* https://fedoraproject.org/wiki/Changes/CryptoPolicy */&lt;br /&gt;
        include &amp;quot;/etc/crypto-policies/back-ends/bind.config&amp;quot;;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone defnitions: &#039;&#039;&#039;/etc/named.rfc1912.zones&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Define zones to listen for&lt;br /&gt;
zone &amp;quot;brammerloo.nl&amp;quot; IN {&lt;br /&gt;
        type master;&lt;br /&gt;
        file &amp;quot;brammerloo.nl&amp;quot;;&lt;br /&gt;
        allow-update { none; };&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
zone &amp;quot;1.168.192.in-addr.arpa&amp;quot; IN {&lt;br /&gt;
        type master;&lt;br /&gt;
        file &amp;quot;192.168.1.0&amp;quot;;&lt;br /&gt;
        allow-update { none; };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone file for Reverse lookup: &#039;&#039;&#039;/var/named/192.168.1.0&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$TTL 300&lt;br /&gt;
@       IN SOA  ns1.brammerloo.nl. admin.brammerloo.nl. (&lt;br /&gt;
                                        2023101102 ; serial&lt;br /&gt;
                                        180     ; refresh&lt;br /&gt;
                                        60      ; retry&lt;br /&gt;
                                        108000  ; expire&lt;br /&gt;
                                        60 )    ; minimum&lt;br /&gt;
    IN      NS      ns1.brammerloo.nl.&lt;br /&gt;
; PTR Records&lt;br /&gt;
11    IN   PTR   node1.&lt;br /&gt;
21    IN   PTR   server1.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone file for domain: &#039;&#039;&#039;/var/named/brammerloo.nl&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$TTL 300&lt;br /&gt;
@       IN SOA  ns1.brammerloo.nl. admin.brammerloo.nl. (&lt;br /&gt;
                                        2023101306 ; serial&lt;br /&gt;
                                        180     ; refresh&lt;br /&gt;
                                        60      ; retry&lt;br /&gt;
                                        108000  ; expire&lt;br /&gt;
                                        60 )    ; minimum&lt;br /&gt;
    IN      NS      ns1.brammerloo.nl.&lt;br /&gt;
@                  IN      A     192.168.1.6   ; domain brammerloo.nl is me!&lt;br /&gt;
ns1.brammerloo.nl. IN      A     192.168.78.31 ; FQDN for my domain&lt;br /&gt;
node1              IN      A     192.168.78.31 ; Basic A-record&lt;br /&gt;
www                IN      CNAME node1         ; Point my website to my node1 A-record&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== dhcpd ===&lt;br /&gt;
==== dhclient ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Request an IPv4 adres from a DHCP server&lt;br /&gt;
dhclient -4&lt;br /&gt;
&lt;br /&gt;
# Show verbose information when requesting an IPv4 adres from a DHCP server&lt;br /&gt;
dhclient -4 -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Basic configuration options in the &#039;&#039;&#039;/etc/dhcp/dhcpd.conf&#039;&#039;&#039; file&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Set the domain clients should use when resolving hostnames (equivalent to search domain)&lt;br /&gt;
option domain-name &amp;quot;brammerloo.nl&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# Set the domain name servers for DHCP clients&lt;br /&gt;
option domain-name-servers ns1.brammerloo.nl, 8.8.8.8;&lt;br /&gt;
&lt;br /&gt;
default-lease-time 600;&lt;br /&gt;
max-lease-time 7200;&lt;br /&gt;
log-facility local7;&lt;br /&gt;
&lt;br /&gt;
# Best practice = define any connected subnets, but don&#039;t configure DHCP for them&lt;br /&gt;
subnet 192.168.1.0 netmask 255.255.255.0 {&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Basic DHCP for a subnet configuration&lt;br /&gt;
subnet 192.168.0.0 netmask 255.255.255.0 {&lt;br /&gt;
  range 192.168.0.100 192.168.0.150;&lt;br /&gt;
  option routers 192.168.0.1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== smbd / Samba / CIFS ===&lt;br /&gt;
https://linuxconfig.org/install-samba-on-redhat-8&lt;br /&gt;
&lt;br /&gt;
==== Basic configuration ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install and enable&lt;br /&gt;
dnf install samba samba-client&lt;br /&gt;
systemctl enable --now {smb,nmb}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a client-user to authenticate with&lt;br /&gt;
sudo useradd samba-user&lt;br /&gt;
&lt;br /&gt;
# Give the user a password to authenticate with&lt;br /&gt;
sudo smbpasswd -a samba-user&lt;br /&gt;
&lt;br /&gt;
# Create a group to associate with the samba share&lt;br /&gt;
sudo groupadd sambagroup&lt;br /&gt;
&lt;br /&gt;
# Add the user to the group we will be configuring for the share&lt;br /&gt;
sudo usermod -a -G sambagroup samba-user&lt;br /&gt;
&lt;br /&gt;
# Create the folder we will be sharing&lt;br /&gt;
sudo mkdir /var/shares/myshare&lt;br /&gt;
&lt;br /&gt;
# Apply proper permission&lt;br /&gt;
sudo chown -R samba-user:sambagroup /var/shares/myshare/&lt;br /&gt;
sudo chmod -R 0770 /var/shares/myshare/&lt;br /&gt;
&lt;br /&gt;
# Apply proper permission for SELinux&lt;br /&gt;
sudo chcon -t samba_share_t /var/shares/myshare/&lt;br /&gt;
&lt;br /&gt;
# Backup the default config&lt;br /&gt;
cp /etc/samba/smb.conf /etc/samba/smb.conf~&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/samba/smb.conf&lt;br /&gt;
[global]&lt;br /&gt;
 workgroup = &amp;lt;DOMAIN-OR-WORKGROUP&amp;gt;&lt;br /&gt;
 server string = Samba Server %v&lt;br /&gt;
 netbios name = &amp;lt;SERVER-HOSTNAME&amp;gt;&lt;br /&gt;
 security = user&lt;br /&gt;
 map to guest = bad user&lt;br /&gt;
 dns proxy = no&lt;br /&gt;
&lt;br /&gt;
#==================== Share Definitions ======================&lt;br /&gt;
[share001]&lt;br /&gt;
 path = /var/shares/myshare&lt;br /&gt;
 valid users = @sambagroup&lt;br /&gt;
 guest ok = no&lt;br /&gt;
 writable = yes&lt;br /&gt;
 browsable = yes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reload Samba services&lt;br /&gt;
systemctl reload {smb,nmb}&lt;br /&gt;
&lt;br /&gt;
# Mount in Windows&lt;br /&gt;
\\&amp;lt;SERVER-IP&amp;gt;\share001&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user: samba-user&lt;br /&gt;
pass: &amp;lt;Whatever password you filled in with smbpasswd -a&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Samba checks&lt;br /&gt;
smbstatus&lt;br /&gt;
smbstatus -S&lt;br /&gt;
smbstatus -b&lt;br /&gt;
&lt;br /&gt;
# Samba set debug mode&lt;br /&gt;
smbcontrol smbd debug 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Docker ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List Docker containers &lt;br /&gt;
docker ps&lt;br /&gt;
&lt;br /&gt;
# List all Docker container IDs&lt;br /&gt;
docker ps -aq&lt;br /&gt;
&lt;br /&gt;
# List logs for container 987sdh3qrasdhj&lt;br /&gt;
docker logs 987sdh3qrasdhj&lt;br /&gt;
&lt;br /&gt;
# List RAM/CPU usage for Docker container asdlkasd67k&lt;br /&gt;
docker stats asdlkasd67k&lt;br /&gt;
&lt;br /&gt;
# Show verbose container information such as commands run, network, ID, etc&lt;br /&gt;
docker inspect oiu2398sda87&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enter the shell inside a docker container&lt;br /&gt;
docker exec -ti a89sd98sa7d /bin/bash&lt;br /&gt;
&lt;br /&gt;
# Execute a command inside a container as a specific user, root in this case&lt;br /&gt;
docker exec -it -u root asd87289hasdadz tail /var/log/nginx/access.log&lt;br /&gt;
docker exec -u 0 -it as892asnj2as /bin/bash&lt;br /&gt;
&lt;br /&gt;
# Restart docker container yoga&lt;br /&gt;
docker restart yoga&lt;br /&gt;
&lt;br /&gt;
# Restart the 3 given containers&lt;br /&gt;
docker restart 79f71c7f4d91 bbb3d3f5c3b1 b0a3204d4098&lt;br /&gt;
&lt;br /&gt;
# Start this container&lt;br /&gt;
docker start as9823nzxc0&lt;br /&gt;
&lt;br /&gt;
# Stop this container&lt;br /&gt;
docker stop as9823nzxc0&lt;br /&gt;
&lt;br /&gt;
# Restart all unhealthy Docker containers&lt;br /&gt;
for i in $(docker ps | grep unhealthy | awk &#039;{print $1}&#039;); do docker restart &amp;quot;$i&amp;quot;; done;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PowerDNS ===&lt;br /&gt;
* https://doc.powerdns.com/authoritative/index.html&lt;br /&gt;
* https://doc.powerdns.com/authoritative/manpages/pdns_server.1.html&lt;br /&gt;
* https://doc.powerdns.com/authoritative/manpages/pdnsutil.1.html&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# List commands&lt;br /&gt;
pdns_server --help&lt;br /&gt;
&lt;br /&gt;
# Check config and parse for errors&lt;br /&gt;
pdns_server --config=check&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# List available commands &lt;br /&gt;
pdnsutil --help&lt;br /&gt;
&lt;br /&gt;
# Check config and parse for errors&lt;br /&gt;
pdnsutil --config=check&lt;br /&gt;
&lt;br /&gt;
# List all available zones&lt;br /&gt;
pdnsutil list-all-zones&lt;br /&gt;
&lt;br /&gt;
# List all domains in the primary zone&lt;br /&gt;
pdnsutil list-all-zones primary&lt;br /&gt;
&lt;br /&gt;
# See zone information for a specific domain&lt;br /&gt;
pdnsutil show-zone mydomain.com&lt;br /&gt;
pdnsutil show-zone 77.5.10.in-addr.arpa&lt;br /&gt;
&lt;br /&gt;
# Check zone for errors&lt;br /&gt;
pdnsutil check-zone mydomain.com&lt;br /&gt;
&lt;br /&gt;
# List all created TSIG keys&lt;br /&gt;
pdnsutil list-tsig-keys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# Activate TSIG key for domain &amp;quot;myexample.com&amp;quot; in the primary zone&lt;br /&gt;
pdnsutil &amp;quot; myexample.com transfer primary&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MAAS ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Logs in either place:&lt;br /&gt;
/var/log/maas/&lt;br /&gt;
/var/snap/maas/common/log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List status of MAAS services&lt;br /&gt;
maas status&lt;br /&gt;
&lt;br /&gt;
# List MAAS commands&lt;br /&gt;
maas --help&lt;br /&gt;
&lt;br /&gt;
# List available arguments for the init command&lt;br /&gt;
maas init --help&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section end=&amp;quot;linuxservices&amp;quot;/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Services&amp;diff=848</id>
		<title>Linux:Services</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Services&amp;diff=848"/>
		<updated>2025-10-01T11:55:04Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* Legacy */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet|Cheatsheets]]&lt;br /&gt;
&lt;br /&gt;
== Services ==&lt;br /&gt;
&amp;lt;section begin=&amp;quot;linuxservices&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Common ===&lt;br /&gt;
==== systemctl ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all services that are running or exited&lt;br /&gt;
systemctl&lt;br /&gt;
&lt;br /&gt;
# List all services, running or otherwise&lt;br /&gt;
systemctl --all&lt;br /&gt;
&lt;br /&gt;
# List all failed services&lt;br /&gt;
systemctl --state=failed&lt;br /&gt;
&lt;br /&gt;
# Reset the failed service &amp;quot;nginx&amp;quot;&lt;br /&gt;
systemctl reset-failed nginx&lt;br /&gt;
&lt;br /&gt;
# View the status of the &amp;quot;nfs-server&amp;quot; service&lt;br /&gt;
systemctl status nfs-server&lt;br /&gt;
&lt;br /&gt;
# Output the config file of &amp;quot;rsyslog&amp;quot; to the shell&lt;br /&gt;
systemctl cat rsyslog&lt;br /&gt;
&lt;br /&gt;
# Restart the &amp;quot;sshd&amp;quot; service, terminating established connections and re-parsing the configuration&lt;br /&gt;
systemctl restart sshd&lt;br /&gt;
&lt;br /&gt;
# Reload the &amp;quot;nginx&amp;quot; service so that it only re-parses the configuration&lt;br /&gt;
systemctl reload nginx&lt;br /&gt;
&lt;br /&gt;
# Stop the &amp;quot;nfs-ganesha&amp;quot; service so that it stops being run&lt;br /&gt;
systemctl stop nfs-ganesha&lt;br /&gt;
&lt;br /&gt;
# Start the &amp;quot;nfs-ganesha&amp;quot; service so that it starts being run again&lt;br /&gt;
systemctl start nfs-ganesha&lt;br /&gt;
&lt;br /&gt;
# Disable the &amp;quot;mariadb&amp;quot; service so that it doesn&#039;t start after the next boot&lt;br /&gt;
systemctl disable mariadb&lt;br /&gt;
&lt;br /&gt;
# Enable the &amp;quot;mariadb&amp;quot; service so that it starts after the next boot.&lt;br /&gt;
systemctl enable mariadb&lt;br /&gt;
&lt;br /&gt;
# Check the logs for all failed services&lt;br /&gt;
for i in $(systemctl --state=failed | head -n -4 | tail -n +2 | awk &#039;{print $1}&#039;); do systemctl --no-pager status &amp;quot;$i&amp;quot;; done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== NTP ===&lt;br /&gt;
==== Timedatectl ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show the current status of timedatectl&lt;br /&gt;
timedatectl&lt;br /&gt;
&lt;br /&gt;
# List available timezones&lt;br /&gt;
timedatectl list-timezones&lt;br /&gt;
&lt;br /&gt;
# Set the timezone to Amsterdam&lt;br /&gt;
timedatectl set-timezone Europe/Amsterdam&lt;br /&gt;
&lt;br /&gt;
# Show verbose sync information&lt;br /&gt;
timedatectl timesync-status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SNMP ===&lt;br /&gt;
==== V3 client installation ====&lt;br /&gt;
* https://kifarunix.com/quick-way-to-install-and-configure-snmp-on-ubuntu-20-04/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
apt install snmpd snmp libsnmp-dev&lt;br /&gt;
cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.bak&lt;br /&gt;
systemctl stop snmpd&lt;br /&gt;
net-snmp-create-v3-user -ro -X &amp;lt;CRYPTO-PASSWORD&amp;gt; -a SHA -X &amp;lt;PASSWORD&amp;gt; -x AES &amp;lt;USERNAME&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/snmp/snmpd.conf&lt;br /&gt;
sysLocation    NL;Zuid-Holland;Rotterdam, 78 MyStreet;2nd Floor;Server Room;Rack&lt;br /&gt;
sysContact     Me &amp;lt;me@example.org&amp;gt;&lt;br /&gt;
agentaddress   192.168.0.10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
systemctl start snmpd&lt;br /&gt;
systemctl enable snmpd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Test&lt;br /&gt;
snmpwalk -v3 -a SHA -A &amp;quot;AUTHENTICATION PASSWORD&amp;quot; -x AES -X &amp;quot;CRYPTO PASSWORD&amp;quot; -l authPriv -u &amp;quot;MYUSER&amp;quot; localhost | head&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CTDB  ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Verify CTDB cluster status&lt;br /&gt;
ctdb status&lt;br /&gt;
&lt;br /&gt;
# Show the allocated IP addresses and to which nodes they&#039;re bound&lt;br /&gt;
ctdb ip&lt;br /&gt;
&lt;br /&gt;
# See the status of all CTDB-scripts&lt;br /&gt;
ctdb scriptstatus&lt;br /&gt;
ctdb event status&lt;br /&gt;
&lt;br /&gt;
# Show the time of the last failover the duration it took to recover&lt;br /&gt;
ctdb uptime&lt;br /&gt;
&lt;br /&gt;
# See various statistics and data&lt;br /&gt;
ctdb statistics&lt;br /&gt;
&lt;br /&gt;
# Use the onnode command to execute a command on all cluster nodes&lt;br /&gt;
onnode all ctdb status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Stop a ctdb cluster member&lt;br /&gt;
ctdb stop&lt;br /&gt;
&lt;br /&gt;
# Start a stopped ctdb cluster member&lt;br /&gt;
ctdb continue&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Firewalls ===&lt;br /&gt;
==== UFW ====&lt;br /&gt;
===== Checks =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show summary of UFW status&lt;br /&gt;
ufw status&lt;br /&gt;
&lt;br /&gt;
# Show verbose UFW status&lt;br /&gt;
ufw status verbose&lt;br /&gt;
&lt;br /&gt;
# Show UFW rules numbered&lt;br /&gt;
ufw status numbered&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Commands =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Allow access from a specific IP to a port and add a comment that show in the status&lt;br /&gt;
ufw allow from 10.0.0.253 to any port 22 proto tcp comment &#039;Allow SSH access from XYZ location&#039;&lt;br /&gt;
&lt;br /&gt;
# Delete numbered Firewall rule 56&lt;br /&gt;
ufw delete 56&lt;br /&gt;
&lt;br /&gt;
# Disable UFW logging (prevent syslog spam)&lt;br /&gt;
ufw logging off&lt;br /&gt;
&lt;br /&gt;
# Set UFW logging back to the default&lt;br /&gt;
ufw logging low&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Firewalld ====&lt;br /&gt;
===== SNMP access =====&lt;br /&gt;
* https://unix.stackexchange.com/questions/214388/how-to-let-the-firewall-of-rhel7-the-snmp-connection-passing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/firewalld/services/snmp.xml&lt;br /&gt;
&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;service&amp;gt;&lt;br /&gt;
  &amp;lt;short&amp;gt;SNMP&amp;lt;/short&amp;gt;&lt;br /&gt;
  &amp;lt;description&amp;gt;SNMP protocol&amp;lt;/description&amp;gt;&lt;br /&gt;
  &amp;lt;port protocol=&amp;quot;udp&amp;quot; port=&amp;quot;161&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/service&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
firewall-cmd --zone=public --add-service snmp --permanent&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Firewall-cmd =====&lt;br /&gt;
====== Checks ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all available commands&lt;br /&gt;
firewall-cmd -h&lt;br /&gt;
&lt;br /&gt;
# Check the configuration file of the firewall for errors&lt;br /&gt;
firewall-cmd --check-config&lt;br /&gt;
&lt;br /&gt;
# Display the current state of firewall-cmd (running/shutdown)&lt;br /&gt;
firewall-cmd --state&lt;br /&gt;
&lt;br /&gt;
# Display all available zones&lt;br /&gt;
firewall-cmd --get-zones&lt;br /&gt;
&lt;br /&gt;
# List all whitelisted services&lt;br /&gt;
firewall-cmd --list-services&lt;br /&gt;
&lt;br /&gt;
# List all services you can potentially enable&lt;br /&gt;
firewall-cmd --get-services&lt;br /&gt;
&lt;br /&gt;
# List all added or enabled services and ports in more detail&lt;br /&gt;
firewall-cmd --list-all&lt;br /&gt;
&lt;br /&gt;
# List verbose information for all zones&lt;br /&gt;
firewall-cmd --list-all-zones&lt;br /&gt;
&lt;br /&gt;
# List verbose information for the public zone&lt;br /&gt;
firewall-cmd --list-all --zone=public&lt;br /&gt;
&lt;br /&gt;
# See what port(s) are associated with the dns service&lt;br /&gt;
firewall-cmd --info-service dns&lt;br /&gt;
&lt;br /&gt;
# List all opened ports&lt;br /&gt;
firewall-cmd --list-ports&lt;br /&gt;
&lt;br /&gt;
# List kernel ruleset generated for nftables(?)&lt;br /&gt;
nft list ruleset&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Commands ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reload the firewall&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Whitelist the dns service, persistently even after reboot&lt;br /&gt;
firewall-cmd --add-service=dns ; sudo firewall-cmd --runtime-to-permanent; firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Whitelist the http service, persistently even after reboot&lt;br /&gt;
firewall-cmd --add-service=http ; sudo firewall-cmd --runtime-to-permanent; firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Remove the http service from the whitelist&lt;br /&gt;
firewall-cmd --remove-service=http&lt;br /&gt;
&lt;br /&gt;
# Add port 1234 (tcp) to the whitelist&lt;br /&gt;
firewall-cmd --add-port=1234/tcp&lt;br /&gt;
&lt;br /&gt;
# Remove port 1234 (tcp) from the whitelist&lt;br /&gt;
firewall-cmd --remove-port=1234/tcp&lt;br /&gt;
&lt;br /&gt;
# Add port 2345 (udp) to the whitelist in zone external&lt;br /&gt;
firewall-cmd --zone=external --add-port=2345/udp&lt;br /&gt;
&lt;br /&gt;
# Remove port 2345 (udp) from the whitelist for zone external&lt;br /&gt;
firewall-cmd --zone=external --add-port=2345/udp&lt;br /&gt;
&lt;br /&gt;
# Add current configuration to configuration permanently&lt;br /&gt;
firewall-cmd –runtime-to-permanent&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;DANGEROUS&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# SHUT IT DOWN DOC - DROP ALL PACKETS AND EXPIRE EXISTING CONNECTIONS&lt;br /&gt;
firewall-cmd --panic-on&lt;br /&gt;
&lt;br /&gt;
# ACCEPT PACKETS AGAIN&lt;br /&gt;
firewall-cmd --panic-off&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== CSF ====&lt;br /&gt;
ConfigServer Security and Firewall&lt;br /&gt;
&lt;br /&gt;
===== General =====&lt;br /&gt;
* Common configuration: /etc/csf/csf.conf &lt;br /&gt;
* Blacklist: /etc/csf/csf.deny &lt;br /&gt;
* Whitelist: /etc/csf/csf.allow &lt;br /&gt;
&lt;br /&gt;
===== Installation =====&lt;br /&gt;
From the official instructions: https://download.configserver.com/csf/install.txt&lt;br /&gt;
&lt;br /&gt;
====== Prerequisites ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Perl Modules&lt;br /&gt;
============&lt;br /&gt;
While most should be installed on a standard perl installation the following&lt;br /&gt;
may need to be installed manually:&lt;br /&gt;
&lt;br /&gt;
# On rpm based systems:&lt;br /&gt;
yum install perl-libwww-perl.noarch perl-LWP-Protocol-https.noarch perl-GDGraph&lt;br /&gt;
&lt;br /&gt;
# On APT based systems:&lt;br /&gt;
apt-get install libwww-perl liblwp-protocol-https-perl libgd-graph-perl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Install ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cd /usr/src&lt;br /&gt;
rm -fv csf.tgz&lt;br /&gt;
wget https://download.configserver.com/csf.tgz&lt;br /&gt;
tar -xzf csf.tgz&lt;br /&gt;
cd csf&lt;br /&gt;
sh install.sh&lt;br /&gt;
&lt;br /&gt;
# Next, test whether you have the required iptables modules:&lt;br /&gt;
perl /usr/local/csf/bin/csftest.pl&lt;br /&gt;
&lt;br /&gt;
# Don&#039;t worry if you cannot run all the features, so long as the script doesn&#039;t report any FATAL errors&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Checks =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check the running status of csf&lt;br /&gt;
csf status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Commands =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Commit config changes by restarting csf&lt;br /&gt;
csf -r&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== csf.conf =====&lt;br /&gt;
Some common changes within the configuration file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Set testing to 0 when your CSF configuration is &#039;production&#039; ready&lt;br /&gt;
TESTING = &amp;quot;0&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow access to any service you&#039;re hosting locally, for example https&lt;br /&gt;
TCP_IN = &amp;quot;443&amp;quot;&lt;br /&gt;
UDP_IN = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow all outwards HTTP/HTTPS traffic so you can yum/apt update&lt;br /&gt;
TCP_OUT = &amp;quot;80,443&amp;quot; &lt;br /&gt;
&lt;br /&gt;
# Allow outgoing traceroute&lt;br /&gt;
UDP_OUT = &amp;quot;33434:33523&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow your server to be pinged&lt;br /&gt;
ICMP_IN = &amp;quot;0&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Formatting =====&lt;br /&gt;
The varying styles of formatting used in allow.conf&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Allow anything relating to the following IPs/ranges&lt;br /&gt;
192.168.10.0/24 # Our application breaks without this range&lt;br /&gt;
192.168.1.1 # Our gateway or something&lt;br /&gt;
&lt;br /&gt;
# Detailed entries based on Transport protocol, direction, Application protocol and IP&lt;br /&gt;
tcp:in:d=22:s=7.7.7.7 # SSH access from our VPN&lt;br /&gt;
udp:in:d=161:s=10.11.12.100 # SNMP Access&lt;br /&gt;
tcp|in|d=22|s=fe80::1:/16 # IPV6 SSH access from our jumpgateway&lt;br /&gt;
udp|in|d=3389|s=10.1.0.0/24 # RDP Access from our entire office range&lt;br /&gt;
tcp|out|d=80,443|d=1.2.3.4/32 # Allow outgoing HTTP/HTTPS access via port 80 and 443&lt;br /&gt;
&lt;br /&gt;
# Allow sending Syslog messages to our Syslog server&lt;br /&gt;
udp|out|d=514|d=192.168.20.5 # UDP syslog server&lt;br /&gt;
tcp|out|d=10514|d=192.168.20.5 # UDP syslog server&lt;br /&gt;
&lt;br /&gt;
# Allow sending queries to some DNS servers&lt;br /&gt;
tcp|out|s=53|d=8.8.8.8&lt;br /&gt;
udp|out|s=53|d=1.1.1.1&lt;br /&gt;
udp|out|s=53|d=2606:4700:4700::1111 # Cloudflare IPv6 DNS Server&lt;br /&gt;
&lt;br /&gt;
# Include an external configuration file&lt;br /&gt;
Include /etc/csf/csf.custom-config&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rsyslog ===&lt;br /&gt;
&amp;lt;section begin=&amp;quot;linuxsyslog&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* https://www.rsyslog.com/doc/reference/templates/templates-reserved-names.html#ref-templates-reserved-names&lt;br /&gt;
* https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/6/html/deployment_guide/s2-templates&lt;br /&gt;
&lt;br /&gt;
==== Legacy ====&lt;br /&gt;
Send all logs to a rsyslog server and specify a port, @ is equal to using UDP. @@ is equal to TCP&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/75-local-to-rsyslog-server.conf&lt;br /&gt;
*.* @10.77.0.1:514&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Custom template where hostname is defined, then sent to the syslog server - include the priority number as first extra variable&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#/etc/rsyslog.d/70-local-to-rsyslog-server.conf&lt;br /&gt;
$template SendHostname, &amp;quot;%PRI%1 %timestamp% myhost.mydomain.nl %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.warning @10.77.0.1;SendHostname&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Send messages to a syslog server, using a template aligned to IETF protocol 23&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/61-qwe.conf&lt;br /&gt;
*.* @10.77.0.1;RSYSLOG_SyslogProtocol23Format&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Send messages to a syslog server, using a template aligned to IETF protocol 23, but specifying a custom hostname&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/60-asd.conf&lt;br /&gt;
$template custom_IETFprotocol_23,&amp;quot;%PRI%1 %TIMESTAMP:::date-rfc3339% prive.host.nl %APP-NAME% %PROCID% %MSGID% %STRUCTURED-DATA% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* @10.77.0.1;custom_IETFprotocol_23&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Log to the local server with a static hostname, using a custom structure&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/62-asd.conf&lt;br /&gt;
$template NewHostname, &amp;quot;%timestamp% tester.mydomain.nl %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* /var/log/wewuzerrors.txt;NewHostname&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An alternative to the contents above, specifying different/more fields&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
## /etc/rsyslog.d/65-customtemplate.conf&lt;br /&gt;
# https://stackoverflow.com/questions/57890176/extending-rsyslogs-default-logging-template&lt;br /&gt;
$template mynewtemplate,&amp;quot;%timegenerated% %HOSTNAME% %syslogfacility-text%.%syslogseverity-text% %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* /var/log/wazanda.txt;mynewtemplate&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rainerscript ====&lt;br /&gt;
Rainerscript: https://rsyslog.readthedocs.io/en/latest/rainerscript/control_structures.html&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/70-local-to-rsyslog-server.conf&lt;br /&gt;
# Send message to a syslog server using IETF protocol 23&lt;br /&gt;
template(name=&amp;quot;RSYSLOG_SyslogProtocol23Format&amp;quot; type=&amp;quot;string&amp;quot;&lt;br /&gt;
     string=&amp;quot;&amp;lt;%PRI%&amp;gt;1 %TIMESTAMP:::date-rfc3339% %HOSTNAME% %APP-NAME% %PROCID% %MSGID% %STRUCTURED-DATA% %msg%\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
*.* action(type=&amp;quot;omfwd&amp;quot; Target=&amp;quot;192.168.5.21&amp;quot; Template=&amp;quot;RSYSLOG_SyslogProtocol23Format&amp;quot; Port=&amp;quot;514&amp;quot; Protocol=&amp;quot;udp&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/71-local-to-rsyslog-server.conf&lt;br /&gt;
# Define a template aligned to IETF protocol 23 and specify a hostname to send as:&lt;br /&gt;
template(name=&amp;quot;SendHostname&amp;quot; type=&amp;quot;string&amp;quot;&lt;br /&gt;
     string=&amp;quot;&amp;lt;%PRI%&amp;gt;1 %TIMESTAMP:::date-rfc3339% myhost.mydomain.nl %APP-NAME% %PROCID% %MSGID% %STRUCTURED-DATA% %msg%\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Send logs to target syslog server and port&lt;br /&gt;
*.* action(type=&amp;quot;omfwd&amp;quot; Target=&amp;quot;10.0.33.10&amp;quot; Template=&amp;quot;SendHostname&amp;quot; Port=&amp;quot;514&amp;quot; Protocol=&amp;quot;udp&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Testing ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use the logger tool to test syslog server reception&lt;br /&gt;
logger -p local0.error &#039;Hello World!&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section end=&amp;quot;linuxsyslog&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== named ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Perform a test load of all primary zones within named.conf, as the named user&lt;br /&gt;
sudo -u named named-checkconf -z&lt;br /&gt;
&lt;br /&gt;
# Check zone file 192.168.77.0 defined in the 77.168.192.in-addr.arpa zone&lt;br /&gt;
named-checkzone 77.168.192.in-addr.arpa 192.168.77.0&lt;br /&gt;
&lt;br /&gt;
# Check zone file brammerloo.nl defined in the brammerloo.nl zone&lt;br /&gt;
named-checkzone brammerloo.nl brammerloo.nl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Basic configuration for the options field in &#039;&#039;&#039;/etc/named.conf&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
options {&lt;br /&gt;
# Define on what IP to listen on, for port 53&lt;br /&gt;
        listen-on port 53 { 127.0.0.1; 192.168.0.1; 192.168.1.1; };&lt;br /&gt;
        directory       &amp;quot;/var/named&amp;quot;;&lt;br /&gt;
        dump-file       &amp;quot;/var/named/data/cache_dump.db&amp;quot;;&lt;br /&gt;
        statistics-file &amp;quot;/var/named/data/named_stats.txt&amp;quot;;&lt;br /&gt;
        memstatistics-file &amp;quot;/var/named/data/named_mem_stats.txt&amp;quot;;&lt;br /&gt;
        secroots-file   &amp;quot;/var/named/data/named.secroots&amp;quot;;&lt;br /&gt;
        recursing-file  &amp;quot;/var/named/data/named.recursing&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# Only allow DNS queries from specific local subnets&lt;br /&gt;
# To allow from anything use: allow query { any; };&lt;br /&gt;
        allow-query     { localhost; 127.0.0.1; 192.168.0.0/24; 192.168.1.0/24; };&lt;br /&gt;
&lt;br /&gt;
# If the server can&#039;t resolve an address locally, use the following DNS servers for help&lt;br /&gt;
        forwarders {&lt;br /&gt;
        8.8.8.8;&lt;br /&gt;
        1.1.1.1;&lt;br /&gt;
        };&lt;br /&gt;
&lt;br /&gt;
        recursion yes;&lt;br /&gt;
        dnssec-validation no;&lt;br /&gt;
&lt;br /&gt;
        managed-keys-directory &amp;quot;/var/named/dynamic&amp;quot;;&lt;br /&gt;
        geoip-directory &amp;quot;/usr/share/GeoIP&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
        pid-file &amp;quot;/run/named/named.pid&amp;quot;;&lt;br /&gt;
        session-keyfile &amp;quot;/run/named/session.key&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
        /* https://fedoraproject.org/wiki/Changes/CryptoPolicy */&lt;br /&gt;
        include &amp;quot;/etc/crypto-policies/back-ends/bind.config&amp;quot;;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone defnitions: &#039;&#039;&#039;/etc/named.rfc1912.zones&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Define zones to listen for&lt;br /&gt;
zone &amp;quot;brammerloo.nl&amp;quot; IN {&lt;br /&gt;
        type master;&lt;br /&gt;
        file &amp;quot;brammerloo.nl&amp;quot;;&lt;br /&gt;
        allow-update { none; };&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
zone &amp;quot;1.168.192.in-addr.arpa&amp;quot; IN {&lt;br /&gt;
        type master;&lt;br /&gt;
        file &amp;quot;192.168.1.0&amp;quot;;&lt;br /&gt;
        allow-update { none; };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone file for Reverse lookup: &#039;&#039;&#039;/var/named/192.168.1.0&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$TTL 300&lt;br /&gt;
@       IN SOA  ns1.brammerloo.nl. admin.brammerloo.nl. (&lt;br /&gt;
                                        2023101102 ; serial&lt;br /&gt;
                                        180     ; refresh&lt;br /&gt;
                                        60      ; retry&lt;br /&gt;
                                        108000  ; expire&lt;br /&gt;
                                        60 )    ; minimum&lt;br /&gt;
    IN      NS      ns1.brammerloo.nl.&lt;br /&gt;
; PTR Records&lt;br /&gt;
11    IN   PTR   node1.&lt;br /&gt;
21    IN   PTR   server1.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone file for domain: &#039;&#039;&#039;/var/named/brammerloo.nl&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$TTL 300&lt;br /&gt;
@       IN SOA  ns1.brammerloo.nl. admin.brammerloo.nl. (&lt;br /&gt;
                                        2023101306 ; serial&lt;br /&gt;
                                        180     ; refresh&lt;br /&gt;
                                        60      ; retry&lt;br /&gt;
                                        108000  ; expire&lt;br /&gt;
                                        60 )    ; minimum&lt;br /&gt;
    IN      NS      ns1.brammerloo.nl.&lt;br /&gt;
@                  IN      A     192.168.1.6   ; domain brammerloo.nl is me!&lt;br /&gt;
ns1.brammerloo.nl. IN      A     192.168.78.31 ; FQDN for my domain&lt;br /&gt;
node1              IN      A     192.168.78.31 ; Basic A-record&lt;br /&gt;
www                IN      CNAME node1         ; Point my website to my node1 A-record&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== dhcpd ===&lt;br /&gt;
==== dhclient ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Request an IPv4 adres from a DHCP server&lt;br /&gt;
dhclient -4&lt;br /&gt;
&lt;br /&gt;
# Show verbose information when requesting an IPv4 adres from a DHCP server&lt;br /&gt;
dhclient -4 -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Basic configuration options in the &#039;&#039;&#039;/etc/dhcp/dhcpd.conf&#039;&#039;&#039; file&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Set the domain clients should use when resolving hostnames (equivalent to search domain)&lt;br /&gt;
option domain-name &amp;quot;brammerloo.nl&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# Set the domain name servers for DHCP clients&lt;br /&gt;
option domain-name-servers ns1.brammerloo.nl, 8.8.8.8;&lt;br /&gt;
&lt;br /&gt;
default-lease-time 600;&lt;br /&gt;
max-lease-time 7200;&lt;br /&gt;
log-facility local7;&lt;br /&gt;
&lt;br /&gt;
# Best practice = define any connected subnets, but don&#039;t configure DHCP for them&lt;br /&gt;
subnet 192.168.1.0 netmask 255.255.255.0 {&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Basic DHCP for a subnet configuration&lt;br /&gt;
subnet 192.168.0.0 netmask 255.255.255.0 {&lt;br /&gt;
  range 192.168.0.100 192.168.0.150;&lt;br /&gt;
  option routers 192.168.0.1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== smbd / Samba / CIFS ===&lt;br /&gt;
https://linuxconfig.org/install-samba-on-redhat-8&lt;br /&gt;
&lt;br /&gt;
==== Basic configuration ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install and enable&lt;br /&gt;
dnf install samba samba-client&lt;br /&gt;
systemctl enable --now {smb,nmb}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a client-user to authenticate with&lt;br /&gt;
sudo useradd samba-user&lt;br /&gt;
&lt;br /&gt;
# Give the user a password to authenticate with&lt;br /&gt;
sudo smbpasswd -a samba-user&lt;br /&gt;
&lt;br /&gt;
# Create a group to associate with the samba share&lt;br /&gt;
sudo groupadd sambagroup&lt;br /&gt;
&lt;br /&gt;
# Add the user to the group we will be configuring for the share&lt;br /&gt;
sudo usermod -a -G sambagroup samba-user&lt;br /&gt;
&lt;br /&gt;
# Create the folder we will be sharing&lt;br /&gt;
sudo mkdir /var/shares/myshare&lt;br /&gt;
&lt;br /&gt;
# Apply proper permission&lt;br /&gt;
sudo chown -R samba-user:sambagroup /var/shares/myshare/&lt;br /&gt;
sudo chmod -R 0770 /var/shares/myshare/&lt;br /&gt;
&lt;br /&gt;
# Apply proper permission for SELinux&lt;br /&gt;
sudo chcon -t samba_share_t /var/shares/myshare/&lt;br /&gt;
&lt;br /&gt;
# Backup the default config&lt;br /&gt;
cp /etc/samba/smb.conf /etc/samba/smb.conf~&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/samba/smb.conf&lt;br /&gt;
[global]&lt;br /&gt;
 workgroup = &amp;lt;DOMAIN-OR-WORKGROUP&amp;gt;&lt;br /&gt;
 server string = Samba Server %v&lt;br /&gt;
 netbios name = &amp;lt;SERVER-HOSTNAME&amp;gt;&lt;br /&gt;
 security = user&lt;br /&gt;
 map to guest = bad user&lt;br /&gt;
 dns proxy = no&lt;br /&gt;
&lt;br /&gt;
#==================== Share Definitions ======================&lt;br /&gt;
[share001]&lt;br /&gt;
 path = /var/shares/myshare&lt;br /&gt;
 valid users = @sambagroup&lt;br /&gt;
 guest ok = no&lt;br /&gt;
 writable = yes&lt;br /&gt;
 browsable = yes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reload Samba services&lt;br /&gt;
systemctl reload {smb,nmb}&lt;br /&gt;
&lt;br /&gt;
# Mount in Windows&lt;br /&gt;
\\&amp;lt;SERVER-IP&amp;gt;\share001&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user: samba-user&lt;br /&gt;
pass: &amp;lt;Whatever password you filled in with smbpasswd -a&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Samba checks&lt;br /&gt;
smbstatus&lt;br /&gt;
smbstatus -S&lt;br /&gt;
smbstatus -b&lt;br /&gt;
&lt;br /&gt;
# Samba set debug mode&lt;br /&gt;
smbcontrol smbd debug 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Docker ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List Docker containers &lt;br /&gt;
docker ps&lt;br /&gt;
&lt;br /&gt;
# List all Docker container IDs&lt;br /&gt;
docker ps -aq&lt;br /&gt;
&lt;br /&gt;
# List logs for container 987sdh3qrasdhj&lt;br /&gt;
docker logs 987sdh3qrasdhj&lt;br /&gt;
&lt;br /&gt;
# List RAM/CPU usage for Docker container asdlkasd67k&lt;br /&gt;
docker stats asdlkasd67k&lt;br /&gt;
&lt;br /&gt;
# Show verbose container information such as commands run, network, ID, etc&lt;br /&gt;
docker inspect oiu2398sda87&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enter the shell inside a docker container&lt;br /&gt;
docker exec -ti a89sd98sa7d /bin/bash&lt;br /&gt;
&lt;br /&gt;
# Execute a command inside a container as a specific user, root in this case&lt;br /&gt;
docker exec -it -u root asd87289hasdadz tail /var/log/nginx/access.log&lt;br /&gt;
docker exec -u 0 -it as892asnj2as /bin/bash&lt;br /&gt;
&lt;br /&gt;
# Restart docker container yoga&lt;br /&gt;
docker restart yoga&lt;br /&gt;
&lt;br /&gt;
# Restart the 3 given containers&lt;br /&gt;
docker restart 79f71c7f4d91 bbb3d3f5c3b1 b0a3204d4098&lt;br /&gt;
&lt;br /&gt;
# Start this container&lt;br /&gt;
docker start as9823nzxc0&lt;br /&gt;
&lt;br /&gt;
# Stop this container&lt;br /&gt;
docker stop as9823nzxc0&lt;br /&gt;
&lt;br /&gt;
# Restart all unhealthy Docker containers&lt;br /&gt;
for i in $(docker ps | grep unhealthy | awk &#039;{print $1}&#039;); do docker restart &amp;quot;$i&amp;quot;; done;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PowerDNS ===&lt;br /&gt;
* https://doc.powerdns.com/authoritative/index.html&lt;br /&gt;
* https://doc.powerdns.com/authoritative/manpages/pdns_server.1.html&lt;br /&gt;
* https://doc.powerdns.com/authoritative/manpages/pdnsutil.1.html&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# List commands&lt;br /&gt;
pdns_server --help&lt;br /&gt;
&lt;br /&gt;
# Check config and parse for errors&lt;br /&gt;
pdns_server --config=check&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# List available commands &lt;br /&gt;
pdnsutil --help&lt;br /&gt;
&lt;br /&gt;
# Check config and parse for errors&lt;br /&gt;
pdnsutil --config=check&lt;br /&gt;
&lt;br /&gt;
# List all available zones&lt;br /&gt;
pdnsutil list-all-zones&lt;br /&gt;
&lt;br /&gt;
# List all domains in the primary zone&lt;br /&gt;
pdnsutil list-all-zones primary&lt;br /&gt;
&lt;br /&gt;
# See zone information for a specific domain&lt;br /&gt;
pdnsutil show-zone mydomain.com&lt;br /&gt;
pdnsutil show-zone 77.5.10.in-addr.arpa&lt;br /&gt;
&lt;br /&gt;
# Check zone for errors&lt;br /&gt;
pdnsutil check-zone mydomain.com&lt;br /&gt;
&lt;br /&gt;
# List all created TSIG keys&lt;br /&gt;
pdnsutil list-tsig-keys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# Activate TSIG key for domain &amp;quot;myexample.com&amp;quot; in the primary zone&lt;br /&gt;
pdnsutil &amp;quot; myexample.com transfer primary&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MAAS ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Logs in either place:&lt;br /&gt;
/var/log/maas/&lt;br /&gt;
/var/snap/maas/common/log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List status of MAAS services&lt;br /&gt;
maas status&lt;br /&gt;
&lt;br /&gt;
# List MAAS commands&lt;br /&gt;
maas --help&lt;br /&gt;
&lt;br /&gt;
# List available arguments for the init command&lt;br /&gt;
maas init --help&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section end=&amp;quot;linuxservices&amp;quot;/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Services&amp;diff=847</id>
		<title>Linux:Services</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Services&amp;diff=847"/>
		<updated>2025-10-01T11:54:19Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* rsyslog */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet|Cheatsheets]]&lt;br /&gt;
&lt;br /&gt;
== Services ==&lt;br /&gt;
&amp;lt;section begin=&amp;quot;linuxservices&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Common ===&lt;br /&gt;
==== systemctl ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all services that are running or exited&lt;br /&gt;
systemctl&lt;br /&gt;
&lt;br /&gt;
# List all services, running or otherwise&lt;br /&gt;
systemctl --all&lt;br /&gt;
&lt;br /&gt;
# List all failed services&lt;br /&gt;
systemctl --state=failed&lt;br /&gt;
&lt;br /&gt;
# Reset the failed service &amp;quot;nginx&amp;quot;&lt;br /&gt;
systemctl reset-failed nginx&lt;br /&gt;
&lt;br /&gt;
# View the status of the &amp;quot;nfs-server&amp;quot; service&lt;br /&gt;
systemctl status nfs-server&lt;br /&gt;
&lt;br /&gt;
# Output the config file of &amp;quot;rsyslog&amp;quot; to the shell&lt;br /&gt;
systemctl cat rsyslog&lt;br /&gt;
&lt;br /&gt;
# Restart the &amp;quot;sshd&amp;quot; service, terminating established connections and re-parsing the configuration&lt;br /&gt;
systemctl restart sshd&lt;br /&gt;
&lt;br /&gt;
# Reload the &amp;quot;nginx&amp;quot; service so that it only re-parses the configuration&lt;br /&gt;
systemctl reload nginx&lt;br /&gt;
&lt;br /&gt;
# Stop the &amp;quot;nfs-ganesha&amp;quot; service so that it stops being run&lt;br /&gt;
systemctl stop nfs-ganesha&lt;br /&gt;
&lt;br /&gt;
# Start the &amp;quot;nfs-ganesha&amp;quot; service so that it starts being run again&lt;br /&gt;
systemctl start nfs-ganesha&lt;br /&gt;
&lt;br /&gt;
# Disable the &amp;quot;mariadb&amp;quot; service so that it doesn&#039;t start after the next boot&lt;br /&gt;
systemctl disable mariadb&lt;br /&gt;
&lt;br /&gt;
# Enable the &amp;quot;mariadb&amp;quot; service so that it starts after the next boot.&lt;br /&gt;
systemctl enable mariadb&lt;br /&gt;
&lt;br /&gt;
# Check the logs for all failed services&lt;br /&gt;
for i in $(systemctl --state=failed | head -n -4 | tail -n +2 | awk &#039;{print $1}&#039;); do systemctl --no-pager status &amp;quot;$i&amp;quot;; done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== NTP ===&lt;br /&gt;
==== Timedatectl ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show the current status of timedatectl&lt;br /&gt;
timedatectl&lt;br /&gt;
&lt;br /&gt;
# List available timezones&lt;br /&gt;
timedatectl list-timezones&lt;br /&gt;
&lt;br /&gt;
# Set the timezone to Amsterdam&lt;br /&gt;
timedatectl set-timezone Europe/Amsterdam&lt;br /&gt;
&lt;br /&gt;
# Show verbose sync information&lt;br /&gt;
timedatectl timesync-status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SNMP ===&lt;br /&gt;
==== V3 client installation ====&lt;br /&gt;
* https://kifarunix.com/quick-way-to-install-and-configure-snmp-on-ubuntu-20-04/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
apt install snmpd snmp libsnmp-dev&lt;br /&gt;
cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.bak&lt;br /&gt;
systemctl stop snmpd&lt;br /&gt;
net-snmp-create-v3-user -ro -X &amp;lt;CRYPTO-PASSWORD&amp;gt; -a SHA -X &amp;lt;PASSWORD&amp;gt; -x AES &amp;lt;USERNAME&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/snmp/snmpd.conf&lt;br /&gt;
sysLocation    NL;Zuid-Holland;Rotterdam, 78 MyStreet;2nd Floor;Server Room;Rack&lt;br /&gt;
sysContact     Me &amp;lt;me@example.org&amp;gt;&lt;br /&gt;
agentaddress   192.168.0.10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
systemctl start snmpd&lt;br /&gt;
systemctl enable snmpd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Test&lt;br /&gt;
snmpwalk -v3 -a SHA -A &amp;quot;AUTHENTICATION PASSWORD&amp;quot; -x AES -X &amp;quot;CRYPTO PASSWORD&amp;quot; -l authPriv -u &amp;quot;MYUSER&amp;quot; localhost | head&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CTDB  ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Verify CTDB cluster status&lt;br /&gt;
ctdb status&lt;br /&gt;
&lt;br /&gt;
# Show the allocated IP addresses and to which nodes they&#039;re bound&lt;br /&gt;
ctdb ip&lt;br /&gt;
&lt;br /&gt;
# See the status of all CTDB-scripts&lt;br /&gt;
ctdb scriptstatus&lt;br /&gt;
ctdb event status&lt;br /&gt;
&lt;br /&gt;
# Show the time of the last failover the duration it took to recover&lt;br /&gt;
ctdb uptime&lt;br /&gt;
&lt;br /&gt;
# See various statistics and data&lt;br /&gt;
ctdb statistics&lt;br /&gt;
&lt;br /&gt;
# Use the onnode command to execute a command on all cluster nodes&lt;br /&gt;
onnode all ctdb status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Stop a ctdb cluster member&lt;br /&gt;
ctdb stop&lt;br /&gt;
&lt;br /&gt;
# Start a stopped ctdb cluster member&lt;br /&gt;
ctdb continue&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Firewalls ===&lt;br /&gt;
==== UFW ====&lt;br /&gt;
===== Checks =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show summary of UFW status&lt;br /&gt;
ufw status&lt;br /&gt;
&lt;br /&gt;
# Show verbose UFW status&lt;br /&gt;
ufw status verbose&lt;br /&gt;
&lt;br /&gt;
# Show UFW rules numbered&lt;br /&gt;
ufw status numbered&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Commands =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Allow access from a specific IP to a port and add a comment that show in the status&lt;br /&gt;
ufw allow from 10.0.0.253 to any port 22 proto tcp comment &#039;Allow SSH access from XYZ location&#039;&lt;br /&gt;
&lt;br /&gt;
# Delete numbered Firewall rule 56&lt;br /&gt;
ufw delete 56&lt;br /&gt;
&lt;br /&gt;
# Disable UFW logging (prevent syslog spam)&lt;br /&gt;
ufw logging off&lt;br /&gt;
&lt;br /&gt;
# Set UFW logging back to the default&lt;br /&gt;
ufw logging low&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Firewalld ====&lt;br /&gt;
===== SNMP access =====&lt;br /&gt;
* https://unix.stackexchange.com/questions/214388/how-to-let-the-firewall-of-rhel7-the-snmp-connection-passing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/firewalld/services/snmp.xml&lt;br /&gt;
&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;service&amp;gt;&lt;br /&gt;
  &amp;lt;short&amp;gt;SNMP&amp;lt;/short&amp;gt;&lt;br /&gt;
  &amp;lt;description&amp;gt;SNMP protocol&amp;lt;/description&amp;gt;&lt;br /&gt;
  &amp;lt;port protocol=&amp;quot;udp&amp;quot; port=&amp;quot;161&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/service&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
firewall-cmd --zone=public --add-service snmp --permanent&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Firewall-cmd =====&lt;br /&gt;
====== Checks ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all available commands&lt;br /&gt;
firewall-cmd -h&lt;br /&gt;
&lt;br /&gt;
# Check the configuration file of the firewall for errors&lt;br /&gt;
firewall-cmd --check-config&lt;br /&gt;
&lt;br /&gt;
# Display the current state of firewall-cmd (running/shutdown)&lt;br /&gt;
firewall-cmd --state&lt;br /&gt;
&lt;br /&gt;
# Display all available zones&lt;br /&gt;
firewall-cmd --get-zones&lt;br /&gt;
&lt;br /&gt;
# List all whitelisted services&lt;br /&gt;
firewall-cmd --list-services&lt;br /&gt;
&lt;br /&gt;
# List all services you can potentially enable&lt;br /&gt;
firewall-cmd --get-services&lt;br /&gt;
&lt;br /&gt;
# List all added or enabled services and ports in more detail&lt;br /&gt;
firewall-cmd --list-all&lt;br /&gt;
&lt;br /&gt;
# List verbose information for all zones&lt;br /&gt;
firewall-cmd --list-all-zones&lt;br /&gt;
&lt;br /&gt;
# List verbose information for the public zone&lt;br /&gt;
firewall-cmd --list-all --zone=public&lt;br /&gt;
&lt;br /&gt;
# See what port(s) are associated with the dns service&lt;br /&gt;
firewall-cmd --info-service dns&lt;br /&gt;
&lt;br /&gt;
# List all opened ports&lt;br /&gt;
firewall-cmd --list-ports&lt;br /&gt;
&lt;br /&gt;
# List kernel ruleset generated for nftables(?)&lt;br /&gt;
nft list ruleset&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Commands ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reload the firewall&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Whitelist the dns service, persistently even after reboot&lt;br /&gt;
firewall-cmd --add-service=dns ; sudo firewall-cmd --runtime-to-permanent; firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Whitelist the http service, persistently even after reboot&lt;br /&gt;
firewall-cmd --add-service=http ; sudo firewall-cmd --runtime-to-permanent; firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Remove the http service from the whitelist&lt;br /&gt;
firewall-cmd --remove-service=http&lt;br /&gt;
&lt;br /&gt;
# Add port 1234 (tcp) to the whitelist&lt;br /&gt;
firewall-cmd --add-port=1234/tcp&lt;br /&gt;
&lt;br /&gt;
# Remove port 1234 (tcp) from the whitelist&lt;br /&gt;
firewall-cmd --remove-port=1234/tcp&lt;br /&gt;
&lt;br /&gt;
# Add port 2345 (udp) to the whitelist in zone external&lt;br /&gt;
firewall-cmd --zone=external --add-port=2345/udp&lt;br /&gt;
&lt;br /&gt;
# Remove port 2345 (udp) from the whitelist for zone external&lt;br /&gt;
firewall-cmd --zone=external --add-port=2345/udp&lt;br /&gt;
&lt;br /&gt;
# Add current configuration to configuration permanently&lt;br /&gt;
firewall-cmd –runtime-to-permanent&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;DANGEROUS&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# SHUT IT DOWN DOC - DROP ALL PACKETS AND EXPIRE EXISTING CONNECTIONS&lt;br /&gt;
firewall-cmd --panic-on&lt;br /&gt;
&lt;br /&gt;
# ACCEPT PACKETS AGAIN&lt;br /&gt;
firewall-cmd --panic-off&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== CSF ====&lt;br /&gt;
ConfigServer Security and Firewall&lt;br /&gt;
&lt;br /&gt;
===== General =====&lt;br /&gt;
* Common configuration: /etc/csf/csf.conf &lt;br /&gt;
* Blacklist: /etc/csf/csf.deny &lt;br /&gt;
* Whitelist: /etc/csf/csf.allow &lt;br /&gt;
&lt;br /&gt;
===== Installation =====&lt;br /&gt;
From the official instructions: https://download.configserver.com/csf/install.txt&lt;br /&gt;
&lt;br /&gt;
====== Prerequisites ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Perl Modules&lt;br /&gt;
============&lt;br /&gt;
While most should be installed on a standard perl installation the following&lt;br /&gt;
may need to be installed manually:&lt;br /&gt;
&lt;br /&gt;
# On rpm based systems:&lt;br /&gt;
yum install perl-libwww-perl.noarch perl-LWP-Protocol-https.noarch perl-GDGraph&lt;br /&gt;
&lt;br /&gt;
# On APT based systems:&lt;br /&gt;
apt-get install libwww-perl liblwp-protocol-https-perl libgd-graph-perl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Install ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cd /usr/src&lt;br /&gt;
rm -fv csf.tgz&lt;br /&gt;
wget https://download.configserver.com/csf.tgz&lt;br /&gt;
tar -xzf csf.tgz&lt;br /&gt;
cd csf&lt;br /&gt;
sh install.sh&lt;br /&gt;
&lt;br /&gt;
# Next, test whether you have the required iptables modules:&lt;br /&gt;
perl /usr/local/csf/bin/csftest.pl&lt;br /&gt;
&lt;br /&gt;
# Don&#039;t worry if you cannot run all the features, so long as the script doesn&#039;t report any FATAL errors&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Checks =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check the running status of csf&lt;br /&gt;
csf status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Commands =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Commit config changes by restarting csf&lt;br /&gt;
csf -r&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== csf.conf =====&lt;br /&gt;
Some common changes within the configuration file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Set testing to 0 when your CSF configuration is &#039;production&#039; ready&lt;br /&gt;
TESTING = &amp;quot;0&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow access to any service you&#039;re hosting locally, for example https&lt;br /&gt;
TCP_IN = &amp;quot;443&amp;quot;&lt;br /&gt;
UDP_IN = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow all outwards HTTP/HTTPS traffic so you can yum/apt update&lt;br /&gt;
TCP_OUT = &amp;quot;80,443&amp;quot; &lt;br /&gt;
&lt;br /&gt;
# Allow outgoing traceroute&lt;br /&gt;
UDP_OUT = &amp;quot;33434:33523&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow your server to be pinged&lt;br /&gt;
ICMP_IN = &amp;quot;0&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Formatting =====&lt;br /&gt;
The varying styles of formatting used in allow.conf&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Allow anything relating to the following IPs/ranges&lt;br /&gt;
192.168.10.0/24 # Our application breaks without this range&lt;br /&gt;
192.168.1.1 # Our gateway or something&lt;br /&gt;
&lt;br /&gt;
# Detailed entries based on Transport protocol, direction, Application protocol and IP&lt;br /&gt;
tcp:in:d=22:s=7.7.7.7 # SSH access from our VPN&lt;br /&gt;
udp:in:d=161:s=10.11.12.100 # SNMP Access&lt;br /&gt;
tcp|in|d=22|s=fe80::1:/16 # IPV6 SSH access from our jumpgateway&lt;br /&gt;
udp|in|d=3389|s=10.1.0.0/24 # RDP Access from our entire office range&lt;br /&gt;
tcp|out|d=80,443|d=1.2.3.4/32 # Allow outgoing HTTP/HTTPS access via port 80 and 443&lt;br /&gt;
&lt;br /&gt;
# Allow sending Syslog messages to our Syslog server&lt;br /&gt;
udp|out|d=514|d=192.168.20.5 # UDP syslog server&lt;br /&gt;
tcp|out|d=10514|d=192.168.20.5 # UDP syslog server&lt;br /&gt;
&lt;br /&gt;
# Allow sending queries to some DNS servers&lt;br /&gt;
tcp|out|s=53|d=8.8.8.8&lt;br /&gt;
udp|out|s=53|d=1.1.1.1&lt;br /&gt;
udp|out|s=53|d=2606:4700:4700::1111 # Cloudflare IPv6 DNS Server&lt;br /&gt;
&lt;br /&gt;
# Include an external configuration file&lt;br /&gt;
Include /etc/csf/csf.custom-config&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rsyslog ===&lt;br /&gt;
&amp;lt;section begin=&amp;quot;linuxsyslog&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* https://www.rsyslog.com/doc/reference/templates/templates-reserved-names.html#ref-templates-reserved-names&lt;br /&gt;
* https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/6/html/deployment_guide/s2-templates&lt;br /&gt;
&lt;br /&gt;
==== Legacy ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/75-local-to-rsyslog-server.conf&lt;br /&gt;
# Send all logs to a rsyslog server and specify a port, @ is equal to using UDP. @@ is equl to TCP&lt;br /&gt;
*.* @10.77.0.1:514&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#/etc/rsyslog.d/70-local-to-rsyslog-server.conf&lt;br /&gt;
# Custom template where hostname is defined, then sent to the syslog server - include the priority number as first extra variable&lt;br /&gt;
$template SendHostname, &amp;quot;%PRI%1 %timestamp% myhost.mydomain.nl %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.warning @10.77.0.1;SendHostname&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/61-qwe.conf&lt;br /&gt;
# Send messages to a syslog server, using a template aligned to IETF protocol 23&lt;br /&gt;
*.* @10.77.0.1;RSYSLOG_SyslogProtocol23Format&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/60-asd.conf&lt;br /&gt;
# Send messages to a syslog server, using a template aligned to IETF protocol 23, but specifying a custom hostname&lt;br /&gt;
$template custom_IETFprotocol_23,&amp;quot;%PRI%1 %TIMESTAMP:::date-rfc3339% prive.host.nl %APP-NAME% %PROCID% %MSGID% %STRUCTURED-DATA% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* @10.77.0.1;custom_IETFprotocol_23&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/62-asd.conf&lt;br /&gt;
# Log to the local server with a static hostname, using a custom structure&lt;br /&gt;
$template NewHostname, &amp;quot;%timestamp% tester.mydomain.nl %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* /var/log/wewuzerrors.txt;NewHostname&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
## /etc/rsyslog.d/65-customtemplate.conf&lt;br /&gt;
# https://stackoverflow.com/questions/57890176/extending-rsyslogs-default-logging-template&lt;br /&gt;
# An alternative to the contents above, specifying different/more fields&lt;br /&gt;
$template mynewtemplate,&amp;quot;%timegenerated% %HOSTNAME% %syslogfacility-text%.%syslogseverity-text% %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* /var/log/wazanda.txt;mynewtemplate&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rainerscript ====&lt;br /&gt;
Rainerscript: https://rsyslog.readthedocs.io/en/latest/rainerscript/control_structures.html&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/70-local-to-rsyslog-server.conf&lt;br /&gt;
# Send message to a syslog server using IETF protocol 23&lt;br /&gt;
template(name=&amp;quot;RSYSLOG_SyslogProtocol23Format&amp;quot; type=&amp;quot;string&amp;quot;&lt;br /&gt;
     string=&amp;quot;&amp;lt;%PRI%&amp;gt;1 %TIMESTAMP:::date-rfc3339% %HOSTNAME% %APP-NAME% %PROCID% %MSGID% %STRUCTURED-DATA% %msg%\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
*.* action(type=&amp;quot;omfwd&amp;quot; Target=&amp;quot;192.168.5.21&amp;quot; Template=&amp;quot;RSYSLOG_SyslogProtocol23Format&amp;quot; Port=&amp;quot;514&amp;quot; Protocol=&amp;quot;udp&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/71-local-to-rsyslog-server.conf&lt;br /&gt;
# Define a template aligned to IETF protocol 23 and specify a hostname to send as:&lt;br /&gt;
template(name=&amp;quot;SendHostname&amp;quot; type=&amp;quot;string&amp;quot;&lt;br /&gt;
     string=&amp;quot;&amp;lt;%PRI%&amp;gt;1 %TIMESTAMP:::date-rfc3339% myhost.mydomain.nl %APP-NAME% %PROCID% %MSGID% %STRUCTURED-DATA% %msg%\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Send logs to target syslog server and port&lt;br /&gt;
*.* action(type=&amp;quot;omfwd&amp;quot; Target=&amp;quot;10.0.33.10&amp;quot; Template=&amp;quot;SendHostname&amp;quot; Port=&amp;quot;514&amp;quot; Protocol=&amp;quot;udp&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Testing ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use the logger tool to test syslog server reception&lt;br /&gt;
logger -p local0.error &#039;Hello World!&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section end=&amp;quot;linuxsyslog&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== named ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Perform a test load of all primary zones within named.conf, as the named user&lt;br /&gt;
sudo -u named named-checkconf -z&lt;br /&gt;
&lt;br /&gt;
# Check zone file 192.168.77.0 defined in the 77.168.192.in-addr.arpa zone&lt;br /&gt;
named-checkzone 77.168.192.in-addr.arpa 192.168.77.0&lt;br /&gt;
&lt;br /&gt;
# Check zone file brammerloo.nl defined in the brammerloo.nl zone&lt;br /&gt;
named-checkzone brammerloo.nl brammerloo.nl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Basic configuration for the options field in &#039;&#039;&#039;/etc/named.conf&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
options {&lt;br /&gt;
# Define on what IP to listen on, for port 53&lt;br /&gt;
        listen-on port 53 { 127.0.0.1; 192.168.0.1; 192.168.1.1; };&lt;br /&gt;
        directory       &amp;quot;/var/named&amp;quot;;&lt;br /&gt;
        dump-file       &amp;quot;/var/named/data/cache_dump.db&amp;quot;;&lt;br /&gt;
        statistics-file &amp;quot;/var/named/data/named_stats.txt&amp;quot;;&lt;br /&gt;
        memstatistics-file &amp;quot;/var/named/data/named_mem_stats.txt&amp;quot;;&lt;br /&gt;
        secroots-file   &amp;quot;/var/named/data/named.secroots&amp;quot;;&lt;br /&gt;
        recursing-file  &amp;quot;/var/named/data/named.recursing&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# Only allow DNS queries from specific local subnets&lt;br /&gt;
# To allow from anything use: allow query { any; };&lt;br /&gt;
        allow-query     { localhost; 127.0.0.1; 192.168.0.0/24; 192.168.1.0/24; };&lt;br /&gt;
&lt;br /&gt;
# If the server can&#039;t resolve an address locally, use the following DNS servers for help&lt;br /&gt;
        forwarders {&lt;br /&gt;
        8.8.8.8;&lt;br /&gt;
        1.1.1.1;&lt;br /&gt;
        };&lt;br /&gt;
&lt;br /&gt;
        recursion yes;&lt;br /&gt;
        dnssec-validation no;&lt;br /&gt;
&lt;br /&gt;
        managed-keys-directory &amp;quot;/var/named/dynamic&amp;quot;;&lt;br /&gt;
        geoip-directory &amp;quot;/usr/share/GeoIP&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
        pid-file &amp;quot;/run/named/named.pid&amp;quot;;&lt;br /&gt;
        session-keyfile &amp;quot;/run/named/session.key&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
        /* https://fedoraproject.org/wiki/Changes/CryptoPolicy */&lt;br /&gt;
        include &amp;quot;/etc/crypto-policies/back-ends/bind.config&amp;quot;;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone defnitions: &#039;&#039;&#039;/etc/named.rfc1912.zones&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Define zones to listen for&lt;br /&gt;
zone &amp;quot;brammerloo.nl&amp;quot; IN {&lt;br /&gt;
        type master;&lt;br /&gt;
        file &amp;quot;brammerloo.nl&amp;quot;;&lt;br /&gt;
        allow-update { none; };&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
zone &amp;quot;1.168.192.in-addr.arpa&amp;quot; IN {&lt;br /&gt;
        type master;&lt;br /&gt;
        file &amp;quot;192.168.1.0&amp;quot;;&lt;br /&gt;
        allow-update { none; };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone file for Reverse lookup: &#039;&#039;&#039;/var/named/192.168.1.0&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$TTL 300&lt;br /&gt;
@       IN SOA  ns1.brammerloo.nl. admin.brammerloo.nl. (&lt;br /&gt;
                                        2023101102 ; serial&lt;br /&gt;
                                        180     ; refresh&lt;br /&gt;
                                        60      ; retry&lt;br /&gt;
                                        108000  ; expire&lt;br /&gt;
                                        60 )    ; minimum&lt;br /&gt;
    IN      NS      ns1.brammerloo.nl.&lt;br /&gt;
; PTR Records&lt;br /&gt;
11    IN   PTR   node1.&lt;br /&gt;
21    IN   PTR   server1.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone file for domain: &#039;&#039;&#039;/var/named/brammerloo.nl&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$TTL 300&lt;br /&gt;
@       IN SOA  ns1.brammerloo.nl. admin.brammerloo.nl. (&lt;br /&gt;
                                        2023101306 ; serial&lt;br /&gt;
                                        180     ; refresh&lt;br /&gt;
                                        60      ; retry&lt;br /&gt;
                                        108000  ; expire&lt;br /&gt;
                                        60 )    ; minimum&lt;br /&gt;
    IN      NS      ns1.brammerloo.nl.&lt;br /&gt;
@                  IN      A     192.168.1.6   ; domain brammerloo.nl is me!&lt;br /&gt;
ns1.brammerloo.nl. IN      A     192.168.78.31 ; FQDN for my domain&lt;br /&gt;
node1              IN      A     192.168.78.31 ; Basic A-record&lt;br /&gt;
www                IN      CNAME node1         ; Point my website to my node1 A-record&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== dhcpd ===&lt;br /&gt;
==== dhclient ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Request an IPv4 adres from a DHCP server&lt;br /&gt;
dhclient -4&lt;br /&gt;
&lt;br /&gt;
# Show verbose information when requesting an IPv4 adres from a DHCP server&lt;br /&gt;
dhclient -4 -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Basic configuration options in the &#039;&#039;&#039;/etc/dhcp/dhcpd.conf&#039;&#039;&#039; file&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Set the domain clients should use when resolving hostnames (equivalent to search domain)&lt;br /&gt;
option domain-name &amp;quot;brammerloo.nl&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# Set the domain name servers for DHCP clients&lt;br /&gt;
option domain-name-servers ns1.brammerloo.nl, 8.8.8.8;&lt;br /&gt;
&lt;br /&gt;
default-lease-time 600;&lt;br /&gt;
max-lease-time 7200;&lt;br /&gt;
log-facility local7;&lt;br /&gt;
&lt;br /&gt;
# Best practice = define any connected subnets, but don&#039;t configure DHCP for them&lt;br /&gt;
subnet 192.168.1.0 netmask 255.255.255.0 {&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Basic DHCP for a subnet configuration&lt;br /&gt;
subnet 192.168.0.0 netmask 255.255.255.0 {&lt;br /&gt;
  range 192.168.0.100 192.168.0.150;&lt;br /&gt;
  option routers 192.168.0.1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== smbd / Samba / CIFS ===&lt;br /&gt;
https://linuxconfig.org/install-samba-on-redhat-8&lt;br /&gt;
&lt;br /&gt;
==== Basic configuration ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install and enable&lt;br /&gt;
dnf install samba samba-client&lt;br /&gt;
systemctl enable --now {smb,nmb}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a client-user to authenticate with&lt;br /&gt;
sudo useradd samba-user&lt;br /&gt;
&lt;br /&gt;
# Give the user a password to authenticate with&lt;br /&gt;
sudo smbpasswd -a samba-user&lt;br /&gt;
&lt;br /&gt;
# Create a group to associate with the samba share&lt;br /&gt;
sudo groupadd sambagroup&lt;br /&gt;
&lt;br /&gt;
# Add the user to the group we will be configuring for the share&lt;br /&gt;
sudo usermod -a -G sambagroup samba-user&lt;br /&gt;
&lt;br /&gt;
# Create the folder we will be sharing&lt;br /&gt;
sudo mkdir /var/shares/myshare&lt;br /&gt;
&lt;br /&gt;
# Apply proper permission&lt;br /&gt;
sudo chown -R samba-user:sambagroup /var/shares/myshare/&lt;br /&gt;
sudo chmod -R 0770 /var/shares/myshare/&lt;br /&gt;
&lt;br /&gt;
# Apply proper permission for SELinux&lt;br /&gt;
sudo chcon -t samba_share_t /var/shares/myshare/&lt;br /&gt;
&lt;br /&gt;
# Backup the default config&lt;br /&gt;
cp /etc/samba/smb.conf /etc/samba/smb.conf~&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/samba/smb.conf&lt;br /&gt;
[global]&lt;br /&gt;
 workgroup = &amp;lt;DOMAIN-OR-WORKGROUP&amp;gt;&lt;br /&gt;
 server string = Samba Server %v&lt;br /&gt;
 netbios name = &amp;lt;SERVER-HOSTNAME&amp;gt;&lt;br /&gt;
 security = user&lt;br /&gt;
 map to guest = bad user&lt;br /&gt;
 dns proxy = no&lt;br /&gt;
&lt;br /&gt;
#==================== Share Definitions ======================&lt;br /&gt;
[share001]&lt;br /&gt;
 path = /var/shares/myshare&lt;br /&gt;
 valid users = @sambagroup&lt;br /&gt;
 guest ok = no&lt;br /&gt;
 writable = yes&lt;br /&gt;
 browsable = yes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reload Samba services&lt;br /&gt;
systemctl reload {smb,nmb}&lt;br /&gt;
&lt;br /&gt;
# Mount in Windows&lt;br /&gt;
\\&amp;lt;SERVER-IP&amp;gt;\share001&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user: samba-user&lt;br /&gt;
pass: &amp;lt;Whatever password you filled in with smbpasswd -a&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Samba checks&lt;br /&gt;
smbstatus&lt;br /&gt;
smbstatus -S&lt;br /&gt;
smbstatus -b&lt;br /&gt;
&lt;br /&gt;
# Samba set debug mode&lt;br /&gt;
smbcontrol smbd debug 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Docker ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List Docker containers &lt;br /&gt;
docker ps&lt;br /&gt;
&lt;br /&gt;
# List all Docker container IDs&lt;br /&gt;
docker ps -aq&lt;br /&gt;
&lt;br /&gt;
# List logs for container 987sdh3qrasdhj&lt;br /&gt;
docker logs 987sdh3qrasdhj&lt;br /&gt;
&lt;br /&gt;
# List RAM/CPU usage for Docker container asdlkasd67k&lt;br /&gt;
docker stats asdlkasd67k&lt;br /&gt;
&lt;br /&gt;
# Show verbose container information such as commands run, network, ID, etc&lt;br /&gt;
docker inspect oiu2398sda87&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enter the shell inside a docker container&lt;br /&gt;
docker exec -ti a89sd98sa7d /bin/bash&lt;br /&gt;
&lt;br /&gt;
# Execute a command inside a container as a specific user, root in this case&lt;br /&gt;
docker exec -it -u root asd87289hasdadz tail /var/log/nginx/access.log&lt;br /&gt;
docker exec -u 0 -it as892asnj2as /bin/bash&lt;br /&gt;
&lt;br /&gt;
# Restart docker container yoga&lt;br /&gt;
docker restart yoga&lt;br /&gt;
&lt;br /&gt;
# Restart the 3 given containers&lt;br /&gt;
docker restart 79f71c7f4d91 bbb3d3f5c3b1 b0a3204d4098&lt;br /&gt;
&lt;br /&gt;
# Start this container&lt;br /&gt;
docker start as9823nzxc0&lt;br /&gt;
&lt;br /&gt;
# Stop this container&lt;br /&gt;
docker stop as9823nzxc0&lt;br /&gt;
&lt;br /&gt;
# Restart all unhealthy Docker containers&lt;br /&gt;
for i in $(docker ps | grep unhealthy | awk &#039;{print $1}&#039;); do docker restart &amp;quot;$i&amp;quot;; done;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PowerDNS ===&lt;br /&gt;
* https://doc.powerdns.com/authoritative/index.html&lt;br /&gt;
* https://doc.powerdns.com/authoritative/manpages/pdns_server.1.html&lt;br /&gt;
* https://doc.powerdns.com/authoritative/manpages/pdnsutil.1.html&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# List commands&lt;br /&gt;
pdns_server --help&lt;br /&gt;
&lt;br /&gt;
# Check config and parse for errors&lt;br /&gt;
pdns_server --config=check&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# List available commands &lt;br /&gt;
pdnsutil --help&lt;br /&gt;
&lt;br /&gt;
# Check config and parse for errors&lt;br /&gt;
pdnsutil --config=check&lt;br /&gt;
&lt;br /&gt;
# List all available zones&lt;br /&gt;
pdnsutil list-all-zones&lt;br /&gt;
&lt;br /&gt;
# List all domains in the primary zone&lt;br /&gt;
pdnsutil list-all-zones primary&lt;br /&gt;
&lt;br /&gt;
# See zone information for a specific domain&lt;br /&gt;
pdnsutil show-zone mydomain.com&lt;br /&gt;
pdnsutil show-zone 77.5.10.in-addr.arpa&lt;br /&gt;
&lt;br /&gt;
# Check zone for errors&lt;br /&gt;
pdnsutil check-zone mydomain.com&lt;br /&gt;
&lt;br /&gt;
# List all created TSIG keys&lt;br /&gt;
pdnsutil list-tsig-keys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# Activate TSIG key for domain &amp;quot;myexample.com&amp;quot; in the primary zone&lt;br /&gt;
pdnsutil &amp;quot; myexample.com transfer primary&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MAAS ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Logs in either place:&lt;br /&gt;
/var/log/maas/&lt;br /&gt;
/var/snap/maas/common/log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List status of MAAS services&lt;br /&gt;
maas status&lt;br /&gt;
&lt;br /&gt;
# List MAAS commands&lt;br /&gt;
maas --help&lt;br /&gt;
&lt;br /&gt;
# List available arguments for the init command&lt;br /&gt;
maas init --help&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section end=&amp;quot;linuxservices&amp;quot;/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Services&amp;diff=846</id>
		<title>Linux:Services</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Services&amp;diff=846"/>
		<updated>2025-10-01T11:50:56Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* rsyslog */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet|Cheatsheets]]&lt;br /&gt;
&lt;br /&gt;
== Services ==&lt;br /&gt;
&amp;lt;section begin=&amp;quot;linuxservices&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Common ===&lt;br /&gt;
==== systemctl ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all services that are running or exited&lt;br /&gt;
systemctl&lt;br /&gt;
&lt;br /&gt;
# List all services, running or otherwise&lt;br /&gt;
systemctl --all&lt;br /&gt;
&lt;br /&gt;
# List all failed services&lt;br /&gt;
systemctl --state=failed&lt;br /&gt;
&lt;br /&gt;
# Reset the failed service &amp;quot;nginx&amp;quot;&lt;br /&gt;
systemctl reset-failed nginx&lt;br /&gt;
&lt;br /&gt;
# View the status of the &amp;quot;nfs-server&amp;quot; service&lt;br /&gt;
systemctl status nfs-server&lt;br /&gt;
&lt;br /&gt;
# Output the config file of &amp;quot;rsyslog&amp;quot; to the shell&lt;br /&gt;
systemctl cat rsyslog&lt;br /&gt;
&lt;br /&gt;
# Restart the &amp;quot;sshd&amp;quot; service, terminating established connections and re-parsing the configuration&lt;br /&gt;
systemctl restart sshd&lt;br /&gt;
&lt;br /&gt;
# Reload the &amp;quot;nginx&amp;quot; service so that it only re-parses the configuration&lt;br /&gt;
systemctl reload nginx&lt;br /&gt;
&lt;br /&gt;
# Stop the &amp;quot;nfs-ganesha&amp;quot; service so that it stops being run&lt;br /&gt;
systemctl stop nfs-ganesha&lt;br /&gt;
&lt;br /&gt;
# Start the &amp;quot;nfs-ganesha&amp;quot; service so that it starts being run again&lt;br /&gt;
systemctl start nfs-ganesha&lt;br /&gt;
&lt;br /&gt;
# Disable the &amp;quot;mariadb&amp;quot; service so that it doesn&#039;t start after the next boot&lt;br /&gt;
systemctl disable mariadb&lt;br /&gt;
&lt;br /&gt;
# Enable the &amp;quot;mariadb&amp;quot; service so that it starts after the next boot.&lt;br /&gt;
systemctl enable mariadb&lt;br /&gt;
&lt;br /&gt;
# Check the logs for all failed services&lt;br /&gt;
for i in $(systemctl --state=failed | head -n -4 | tail -n +2 | awk &#039;{print $1}&#039;); do systemctl --no-pager status &amp;quot;$i&amp;quot;; done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== NTP ===&lt;br /&gt;
==== Timedatectl ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show the current status of timedatectl&lt;br /&gt;
timedatectl&lt;br /&gt;
&lt;br /&gt;
# List available timezones&lt;br /&gt;
timedatectl list-timezones&lt;br /&gt;
&lt;br /&gt;
# Set the timezone to Amsterdam&lt;br /&gt;
timedatectl set-timezone Europe/Amsterdam&lt;br /&gt;
&lt;br /&gt;
# Show verbose sync information&lt;br /&gt;
timedatectl timesync-status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SNMP ===&lt;br /&gt;
==== V3 client installation ====&lt;br /&gt;
* https://kifarunix.com/quick-way-to-install-and-configure-snmp-on-ubuntu-20-04/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
apt install snmpd snmp libsnmp-dev&lt;br /&gt;
cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.bak&lt;br /&gt;
systemctl stop snmpd&lt;br /&gt;
net-snmp-create-v3-user -ro -X &amp;lt;CRYPTO-PASSWORD&amp;gt; -a SHA -X &amp;lt;PASSWORD&amp;gt; -x AES &amp;lt;USERNAME&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/snmp/snmpd.conf&lt;br /&gt;
sysLocation    NL;Zuid-Holland;Rotterdam, 78 MyStreet;2nd Floor;Server Room;Rack&lt;br /&gt;
sysContact     Me &amp;lt;me@example.org&amp;gt;&lt;br /&gt;
agentaddress   192.168.0.10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
systemctl start snmpd&lt;br /&gt;
systemctl enable snmpd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Test&lt;br /&gt;
snmpwalk -v3 -a SHA -A &amp;quot;AUTHENTICATION PASSWORD&amp;quot; -x AES -X &amp;quot;CRYPTO PASSWORD&amp;quot; -l authPriv -u &amp;quot;MYUSER&amp;quot; localhost | head&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CTDB  ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Verify CTDB cluster status&lt;br /&gt;
ctdb status&lt;br /&gt;
&lt;br /&gt;
# Show the allocated IP addresses and to which nodes they&#039;re bound&lt;br /&gt;
ctdb ip&lt;br /&gt;
&lt;br /&gt;
# See the status of all CTDB-scripts&lt;br /&gt;
ctdb scriptstatus&lt;br /&gt;
ctdb event status&lt;br /&gt;
&lt;br /&gt;
# Show the time of the last failover the duration it took to recover&lt;br /&gt;
ctdb uptime&lt;br /&gt;
&lt;br /&gt;
# See various statistics and data&lt;br /&gt;
ctdb statistics&lt;br /&gt;
&lt;br /&gt;
# Use the onnode command to execute a command on all cluster nodes&lt;br /&gt;
onnode all ctdb status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Stop a ctdb cluster member&lt;br /&gt;
ctdb stop&lt;br /&gt;
&lt;br /&gt;
# Start a stopped ctdb cluster member&lt;br /&gt;
ctdb continue&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Firewalls ===&lt;br /&gt;
==== UFW ====&lt;br /&gt;
===== Checks =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show summary of UFW status&lt;br /&gt;
ufw status&lt;br /&gt;
&lt;br /&gt;
# Show verbose UFW status&lt;br /&gt;
ufw status verbose&lt;br /&gt;
&lt;br /&gt;
# Show UFW rules numbered&lt;br /&gt;
ufw status numbered&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Commands =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Allow access from a specific IP to a port and add a comment that show in the status&lt;br /&gt;
ufw allow from 10.0.0.253 to any port 22 proto tcp comment &#039;Allow SSH access from XYZ location&#039;&lt;br /&gt;
&lt;br /&gt;
# Delete numbered Firewall rule 56&lt;br /&gt;
ufw delete 56&lt;br /&gt;
&lt;br /&gt;
# Disable UFW logging (prevent syslog spam)&lt;br /&gt;
ufw logging off&lt;br /&gt;
&lt;br /&gt;
# Set UFW logging back to the default&lt;br /&gt;
ufw logging low&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Firewalld ====&lt;br /&gt;
===== SNMP access =====&lt;br /&gt;
* https://unix.stackexchange.com/questions/214388/how-to-let-the-firewall-of-rhel7-the-snmp-connection-passing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/firewalld/services/snmp.xml&lt;br /&gt;
&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;service&amp;gt;&lt;br /&gt;
  &amp;lt;short&amp;gt;SNMP&amp;lt;/short&amp;gt;&lt;br /&gt;
  &amp;lt;description&amp;gt;SNMP protocol&amp;lt;/description&amp;gt;&lt;br /&gt;
  &amp;lt;port protocol=&amp;quot;udp&amp;quot; port=&amp;quot;161&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/service&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
firewall-cmd --zone=public --add-service snmp --permanent&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Firewall-cmd =====&lt;br /&gt;
====== Checks ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all available commands&lt;br /&gt;
firewall-cmd -h&lt;br /&gt;
&lt;br /&gt;
# Check the configuration file of the firewall for errors&lt;br /&gt;
firewall-cmd --check-config&lt;br /&gt;
&lt;br /&gt;
# Display the current state of firewall-cmd (running/shutdown)&lt;br /&gt;
firewall-cmd --state&lt;br /&gt;
&lt;br /&gt;
# Display all available zones&lt;br /&gt;
firewall-cmd --get-zones&lt;br /&gt;
&lt;br /&gt;
# List all whitelisted services&lt;br /&gt;
firewall-cmd --list-services&lt;br /&gt;
&lt;br /&gt;
# List all services you can potentially enable&lt;br /&gt;
firewall-cmd --get-services&lt;br /&gt;
&lt;br /&gt;
# List all added or enabled services and ports in more detail&lt;br /&gt;
firewall-cmd --list-all&lt;br /&gt;
&lt;br /&gt;
# List verbose information for all zones&lt;br /&gt;
firewall-cmd --list-all-zones&lt;br /&gt;
&lt;br /&gt;
# List verbose information for the public zone&lt;br /&gt;
firewall-cmd --list-all --zone=public&lt;br /&gt;
&lt;br /&gt;
# See what port(s) are associated with the dns service&lt;br /&gt;
firewall-cmd --info-service dns&lt;br /&gt;
&lt;br /&gt;
# List all opened ports&lt;br /&gt;
firewall-cmd --list-ports&lt;br /&gt;
&lt;br /&gt;
# List kernel ruleset generated for nftables(?)&lt;br /&gt;
nft list ruleset&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Commands ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reload the firewall&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Whitelist the dns service, persistently even after reboot&lt;br /&gt;
firewall-cmd --add-service=dns ; sudo firewall-cmd --runtime-to-permanent; firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Whitelist the http service, persistently even after reboot&lt;br /&gt;
firewall-cmd --add-service=http ; sudo firewall-cmd --runtime-to-permanent; firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Remove the http service from the whitelist&lt;br /&gt;
firewall-cmd --remove-service=http&lt;br /&gt;
&lt;br /&gt;
# Add port 1234 (tcp) to the whitelist&lt;br /&gt;
firewall-cmd --add-port=1234/tcp&lt;br /&gt;
&lt;br /&gt;
# Remove port 1234 (tcp) from the whitelist&lt;br /&gt;
firewall-cmd --remove-port=1234/tcp&lt;br /&gt;
&lt;br /&gt;
# Add port 2345 (udp) to the whitelist in zone external&lt;br /&gt;
firewall-cmd --zone=external --add-port=2345/udp&lt;br /&gt;
&lt;br /&gt;
# Remove port 2345 (udp) from the whitelist for zone external&lt;br /&gt;
firewall-cmd --zone=external --add-port=2345/udp&lt;br /&gt;
&lt;br /&gt;
# Add current configuration to configuration permanently&lt;br /&gt;
firewall-cmd –runtime-to-permanent&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;DANGEROUS&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# SHUT IT DOWN DOC - DROP ALL PACKETS AND EXPIRE EXISTING CONNECTIONS&lt;br /&gt;
firewall-cmd --panic-on&lt;br /&gt;
&lt;br /&gt;
# ACCEPT PACKETS AGAIN&lt;br /&gt;
firewall-cmd --panic-off&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== CSF ====&lt;br /&gt;
ConfigServer Security and Firewall&lt;br /&gt;
&lt;br /&gt;
===== General =====&lt;br /&gt;
* Common configuration: /etc/csf/csf.conf &lt;br /&gt;
* Blacklist: /etc/csf/csf.deny &lt;br /&gt;
* Whitelist: /etc/csf/csf.allow &lt;br /&gt;
&lt;br /&gt;
===== Installation =====&lt;br /&gt;
From the official instructions: https://download.configserver.com/csf/install.txt&lt;br /&gt;
&lt;br /&gt;
====== Prerequisites ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Perl Modules&lt;br /&gt;
============&lt;br /&gt;
While most should be installed on a standard perl installation the following&lt;br /&gt;
may need to be installed manually:&lt;br /&gt;
&lt;br /&gt;
# On rpm based systems:&lt;br /&gt;
yum install perl-libwww-perl.noarch perl-LWP-Protocol-https.noarch perl-GDGraph&lt;br /&gt;
&lt;br /&gt;
# On APT based systems:&lt;br /&gt;
apt-get install libwww-perl liblwp-protocol-https-perl libgd-graph-perl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Install ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cd /usr/src&lt;br /&gt;
rm -fv csf.tgz&lt;br /&gt;
wget https://download.configserver.com/csf.tgz&lt;br /&gt;
tar -xzf csf.tgz&lt;br /&gt;
cd csf&lt;br /&gt;
sh install.sh&lt;br /&gt;
&lt;br /&gt;
# Next, test whether you have the required iptables modules:&lt;br /&gt;
perl /usr/local/csf/bin/csftest.pl&lt;br /&gt;
&lt;br /&gt;
# Don&#039;t worry if you cannot run all the features, so long as the script doesn&#039;t report any FATAL errors&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Checks =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check the running status of csf&lt;br /&gt;
csf status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Commands =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Commit config changes by restarting csf&lt;br /&gt;
csf -r&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== csf.conf =====&lt;br /&gt;
Some common changes within the configuration file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Set testing to 0 when your CSF configuration is &#039;production&#039; ready&lt;br /&gt;
TESTING = &amp;quot;0&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow access to any service you&#039;re hosting locally, for example https&lt;br /&gt;
TCP_IN = &amp;quot;443&amp;quot;&lt;br /&gt;
UDP_IN = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow all outwards HTTP/HTTPS traffic so you can yum/apt update&lt;br /&gt;
TCP_OUT = &amp;quot;80,443&amp;quot; &lt;br /&gt;
&lt;br /&gt;
# Allow outgoing traceroute&lt;br /&gt;
UDP_OUT = &amp;quot;33434:33523&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow your server to be pinged&lt;br /&gt;
ICMP_IN = &amp;quot;0&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Formatting =====&lt;br /&gt;
The varying styles of formatting used in allow.conf&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Allow anything relating to the following IPs/ranges&lt;br /&gt;
192.168.10.0/24 # Our application breaks without this range&lt;br /&gt;
192.168.1.1 # Our gateway or something&lt;br /&gt;
&lt;br /&gt;
# Detailed entries based on Transport protocol, direction, Application protocol and IP&lt;br /&gt;
tcp:in:d=22:s=7.7.7.7 # SSH access from our VPN&lt;br /&gt;
udp:in:d=161:s=10.11.12.100 # SNMP Access&lt;br /&gt;
tcp|in|d=22|s=fe80::1:/16 # IPV6 SSH access from our jumpgateway&lt;br /&gt;
udp|in|d=3389|s=10.1.0.0/24 # RDP Access from our entire office range&lt;br /&gt;
tcp|out|d=80,443|d=1.2.3.4/32 # Allow outgoing HTTP/HTTPS access via port 80 and 443&lt;br /&gt;
&lt;br /&gt;
# Allow sending Syslog messages to our Syslog server&lt;br /&gt;
udp|out|d=514|d=192.168.20.5 # UDP syslog server&lt;br /&gt;
tcp|out|d=10514|d=192.168.20.5 # UDP syslog server&lt;br /&gt;
&lt;br /&gt;
# Allow sending queries to some DNS servers&lt;br /&gt;
tcp|out|s=53|d=8.8.8.8&lt;br /&gt;
udp|out|s=53|d=1.1.1.1&lt;br /&gt;
udp|out|s=53|d=2606:4700:4700::1111 # Cloudflare IPv6 DNS Server&lt;br /&gt;
&lt;br /&gt;
# Include an external configuration file&lt;br /&gt;
Include /etc/csf/csf.custom-config&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rsyslog ===&lt;br /&gt;
&amp;lt;section begin=&amp;quot;linuxsyslog&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* https://www.rsyslog.com/doc/reference/templates/templates-reserved-names.html#ref-templates-reserved-names&lt;br /&gt;
* https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/6/html/deployment_guide/s2-templates&lt;br /&gt;
&lt;br /&gt;
==== Legacy ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/75-local-to-rsyslog-server.conf&lt;br /&gt;
# Send all logs to a rsyslog server and specify a port, @ is equal to using UDP. @@ is equl to TCP&lt;br /&gt;
*.* @10.77.0.1:514&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#/etc/rsyslog.d/70-local-to-rsyslog-server.conf&lt;br /&gt;
# Custom template where hostname is defined, then sent to the syslog server - include the priority number as first extra variable&lt;br /&gt;
$template SendHostname, &amp;quot;%PRI%1 %timestamp% myhost.mydomain.nl %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.warning @10.77.0.1;SendHostname&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/60-asd.conf&lt;br /&gt;
# Send messages to a syslog server, using a template aligned to IETF protocol 23, but specifying a custom hostname&lt;br /&gt;
$template custom_IETFprotocol_23,&amp;quot;%PRI%1 %TIMESTAMP:::date-rfc3339% prive.host.nl %APP-NAME% %PROCID% %MSGID% %STRUCTURED-DATA% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* @10.77.0.1;custom_IETFprotocol_23&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/62-asd.conf&lt;br /&gt;
# Log to the local server with a static hostname, using a custom structure&lt;br /&gt;
$template NewHostname, &amp;quot;%timestamp% tester.mydomain.nl %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* /var/log/wewuzerrors.txt;NewHostname&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
## /etc/rsyslog.d/65-customtemplate.conf&lt;br /&gt;
# https://stackoverflow.com/questions/57890176/extending-rsyslogs-default-logging-template&lt;br /&gt;
# An alternative to the contents above, specifying different/more fields&lt;br /&gt;
$template mynewtemplate,&amp;quot;%timegenerated% %HOSTNAME% %syslogfacility-text%.%syslogseverity-text% %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* /var/log/wazanda.txt;mynewtemplate&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rainerscript ====&lt;br /&gt;
Rainerscript: https://rsyslog.readthedocs.io/en/latest/rainerscript/control_structures.html&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/70-local-to-rsyslog-server.conf&lt;br /&gt;
# Send message to a syslog server using IETF protocol 23&lt;br /&gt;
template(name=&amp;quot;RSYSLOG_SyslogProtocol23Format&amp;quot; type=&amp;quot;string&amp;quot;&lt;br /&gt;
     string=&amp;quot;&amp;lt;%PRI%&amp;gt;1 %TIMESTAMP:::date-rfc3339% %HOSTNAME% %APP-NAME% %PROCID% %MSGID% %STRUCTURED-DATA% %msg%\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
*.* action(type=&amp;quot;omfwd&amp;quot; Target=&amp;quot;192.168.5.21&amp;quot; Template=&amp;quot;RSYSLOG_SyslogProtocol23Format&amp;quot; Port=&amp;quot;514&amp;quot; Protocol=&amp;quot;udp&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/71-local-to-rsyslog-server.conf&lt;br /&gt;
# Define a template aligned to IETF protocol 23 and specify a hostname to send as:&lt;br /&gt;
template(name=&amp;quot;SendHostname&amp;quot; type=&amp;quot;string&amp;quot;&lt;br /&gt;
     string=&amp;quot;&amp;lt;%PRI%&amp;gt;1 %TIMESTAMP:::date-rfc3339% myhost.mydomain.nl %APP-NAME% %PROCID% %MSGID% %STRUCTURED-DATA% %msg%\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Send logs to target syslog server and port&lt;br /&gt;
*.* action(type=&amp;quot;omfwd&amp;quot; Target=&amp;quot;10.0.33.10&amp;quot; Template=&amp;quot;SendHostname&amp;quot; Port=&amp;quot;514&amp;quot; Protocol=&amp;quot;udp&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Testing ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use the logger tool to test syslog server reception&lt;br /&gt;
logger -p local0.error &#039;Hello World!&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section end=&amp;quot;linuxsyslog&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== named ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Perform a test load of all primary zones within named.conf, as the named user&lt;br /&gt;
sudo -u named named-checkconf -z&lt;br /&gt;
&lt;br /&gt;
# Check zone file 192.168.77.0 defined in the 77.168.192.in-addr.arpa zone&lt;br /&gt;
named-checkzone 77.168.192.in-addr.arpa 192.168.77.0&lt;br /&gt;
&lt;br /&gt;
# Check zone file brammerloo.nl defined in the brammerloo.nl zone&lt;br /&gt;
named-checkzone brammerloo.nl brammerloo.nl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Basic configuration for the options field in &#039;&#039;&#039;/etc/named.conf&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
options {&lt;br /&gt;
# Define on what IP to listen on, for port 53&lt;br /&gt;
        listen-on port 53 { 127.0.0.1; 192.168.0.1; 192.168.1.1; };&lt;br /&gt;
        directory       &amp;quot;/var/named&amp;quot;;&lt;br /&gt;
        dump-file       &amp;quot;/var/named/data/cache_dump.db&amp;quot;;&lt;br /&gt;
        statistics-file &amp;quot;/var/named/data/named_stats.txt&amp;quot;;&lt;br /&gt;
        memstatistics-file &amp;quot;/var/named/data/named_mem_stats.txt&amp;quot;;&lt;br /&gt;
        secroots-file   &amp;quot;/var/named/data/named.secroots&amp;quot;;&lt;br /&gt;
        recursing-file  &amp;quot;/var/named/data/named.recursing&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# Only allow DNS queries from specific local subnets&lt;br /&gt;
# To allow from anything use: allow query { any; };&lt;br /&gt;
        allow-query     { localhost; 127.0.0.1; 192.168.0.0/24; 192.168.1.0/24; };&lt;br /&gt;
&lt;br /&gt;
# If the server can&#039;t resolve an address locally, use the following DNS servers for help&lt;br /&gt;
        forwarders {&lt;br /&gt;
        8.8.8.8;&lt;br /&gt;
        1.1.1.1;&lt;br /&gt;
        };&lt;br /&gt;
&lt;br /&gt;
        recursion yes;&lt;br /&gt;
        dnssec-validation no;&lt;br /&gt;
&lt;br /&gt;
        managed-keys-directory &amp;quot;/var/named/dynamic&amp;quot;;&lt;br /&gt;
        geoip-directory &amp;quot;/usr/share/GeoIP&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
        pid-file &amp;quot;/run/named/named.pid&amp;quot;;&lt;br /&gt;
        session-keyfile &amp;quot;/run/named/session.key&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
        /* https://fedoraproject.org/wiki/Changes/CryptoPolicy */&lt;br /&gt;
        include &amp;quot;/etc/crypto-policies/back-ends/bind.config&amp;quot;;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone defnitions: &#039;&#039;&#039;/etc/named.rfc1912.zones&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Define zones to listen for&lt;br /&gt;
zone &amp;quot;brammerloo.nl&amp;quot; IN {&lt;br /&gt;
        type master;&lt;br /&gt;
        file &amp;quot;brammerloo.nl&amp;quot;;&lt;br /&gt;
        allow-update { none; };&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
zone &amp;quot;1.168.192.in-addr.arpa&amp;quot; IN {&lt;br /&gt;
        type master;&lt;br /&gt;
        file &amp;quot;192.168.1.0&amp;quot;;&lt;br /&gt;
        allow-update { none; };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone file for Reverse lookup: &#039;&#039;&#039;/var/named/192.168.1.0&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$TTL 300&lt;br /&gt;
@       IN SOA  ns1.brammerloo.nl. admin.brammerloo.nl. (&lt;br /&gt;
                                        2023101102 ; serial&lt;br /&gt;
                                        180     ; refresh&lt;br /&gt;
                                        60      ; retry&lt;br /&gt;
                                        108000  ; expire&lt;br /&gt;
                                        60 )    ; minimum&lt;br /&gt;
    IN      NS      ns1.brammerloo.nl.&lt;br /&gt;
; PTR Records&lt;br /&gt;
11    IN   PTR   node1.&lt;br /&gt;
21    IN   PTR   server1.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone file for domain: &#039;&#039;&#039;/var/named/brammerloo.nl&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$TTL 300&lt;br /&gt;
@       IN SOA  ns1.brammerloo.nl. admin.brammerloo.nl. (&lt;br /&gt;
                                        2023101306 ; serial&lt;br /&gt;
                                        180     ; refresh&lt;br /&gt;
                                        60      ; retry&lt;br /&gt;
                                        108000  ; expire&lt;br /&gt;
                                        60 )    ; minimum&lt;br /&gt;
    IN      NS      ns1.brammerloo.nl.&lt;br /&gt;
@                  IN      A     192.168.1.6   ; domain brammerloo.nl is me!&lt;br /&gt;
ns1.brammerloo.nl. IN      A     192.168.78.31 ; FQDN for my domain&lt;br /&gt;
node1              IN      A     192.168.78.31 ; Basic A-record&lt;br /&gt;
www                IN      CNAME node1         ; Point my website to my node1 A-record&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== dhcpd ===&lt;br /&gt;
==== dhclient ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Request an IPv4 adres from a DHCP server&lt;br /&gt;
dhclient -4&lt;br /&gt;
&lt;br /&gt;
# Show verbose information when requesting an IPv4 adres from a DHCP server&lt;br /&gt;
dhclient -4 -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Basic configuration options in the &#039;&#039;&#039;/etc/dhcp/dhcpd.conf&#039;&#039;&#039; file&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Set the domain clients should use when resolving hostnames (equivalent to search domain)&lt;br /&gt;
option domain-name &amp;quot;brammerloo.nl&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# Set the domain name servers for DHCP clients&lt;br /&gt;
option domain-name-servers ns1.brammerloo.nl, 8.8.8.8;&lt;br /&gt;
&lt;br /&gt;
default-lease-time 600;&lt;br /&gt;
max-lease-time 7200;&lt;br /&gt;
log-facility local7;&lt;br /&gt;
&lt;br /&gt;
# Best practice = define any connected subnets, but don&#039;t configure DHCP for them&lt;br /&gt;
subnet 192.168.1.0 netmask 255.255.255.0 {&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Basic DHCP for a subnet configuration&lt;br /&gt;
subnet 192.168.0.0 netmask 255.255.255.0 {&lt;br /&gt;
  range 192.168.0.100 192.168.0.150;&lt;br /&gt;
  option routers 192.168.0.1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== smbd / Samba / CIFS ===&lt;br /&gt;
https://linuxconfig.org/install-samba-on-redhat-8&lt;br /&gt;
&lt;br /&gt;
==== Basic configuration ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install and enable&lt;br /&gt;
dnf install samba samba-client&lt;br /&gt;
systemctl enable --now {smb,nmb}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a client-user to authenticate with&lt;br /&gt;
sudo useradd samba-user&lt;br /&gt;
&lt;br /&gt;
# Give the user a password to authenticate with&lt;br /&gt;
sudo smbpasswd -a samba-user&lt;br /&gt;
&lt;br /&gt;
# Create a group to associate with the samba share&lt;br /&gt;
sudo groupadd sambagroup&lt;br /&gt;
&lt;br /&gt;
# Add the user to the group we will be configuring for the share&lt;br /&gt;
sudo usermod -a -G sambagroup samba-user&lt;br /&gt;
&lt;br /&gt;
# Create the folder we will be sharing&lt;br /&gt;
sudo mkdir /var/shares/myshare&lt;br /&gt;
&lt;br /&gt;
# Apply proper permission&lt;br /&gt;
sudo chown -R samba-user:sambagroup /var/shares/myshare/&lt;br /&gt;
sudo chmod -R 0770 /var/shares/myshare/&lt;br /&gt;
&lt;br /&gt;
# Apply proper permission for SELinux&lt;br /&gt;
sudo chcon -t samba_share_t /var/shares/myshare/&lt;br /&gt;
&lt;br /&gt;
# Backup the default config&lt;br /&gt;
cp /etc/samba/smb.conf /etc/samba/smb.conf~&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/samba/smb.conf&lt;br /&gt;
[global]&lt;br /&gt;
 workgroup = &amp;lt;DOMAIN-OR-WORKGROUP&amp;gt;&lt;br /&gt;
 server string = Samba Server %v&lt;br /&gt;
 netbios name = &amp;lt;SERVER-HOSTNAME&amp;gt;&lt;br /&gt;
 security = user&lt;br /&gt;
 map to guest = bad user&lt;br /&gt;
 dns proxy = no&lt;br /&gt;
&lt;br /&gt;
#==================== Share Definitions ======================&lt;br /&gt;
[share001]&lt;br /&gt;
 path = /var/shares/myshare&lt;br /&gt;
 valid users = @sambagroup&lt;br /&gt;
 guest ok = no&lt;br /&gt;
 writable = yes&lt;br /&gt;
 browsable = yes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reload Samba services&lt;br /&gt;
systemctl reload {smb,nmb}&lt;br /&gt;
&lt;br /&gt;
# Mount in Windows&lt;br /&gt;
\\&amp;lt;SERVER-IP&amp;gt;\share001&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user: samba-user&lt;br /&gt;
pass: &amp;lt;Whatever password you filled in with smbpasswd -a&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Samba checks&lt;br /&gt;
smbstatus&lt;br /&gt;
smbstatus -S&lt;br /&gt;
smbstatus -b&lt;br /&gt;
&lt;br /&gt;
# Samba set debug mode&lt;br /&gt;
smbcontrol smbd debug 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Docker ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List Docker containers &lt;br /&gt;
docker ps&lt;br /&gt;
&lt;br /&gt;
# List all Docker container IDs&lt;br /&gt;
docker ps -aq&lt;br /&gt;
&lt;br /&gt;
# List logs for container 987sdh3qrasdhj&lt;br /&gt;
docker logs 987sdh3qrasdhj&lt;br /&gt;
&lt;br /&gt;
# List RAM/CPU usage for Docker container asdlkasd67k&lt;br /&gt;
docker stats asdlkasd67k&lt;br /&gt;
&lt;br /&gt;
# Show verbose container information such as commands run, network, ID, etc&lt;br /&gt;
docker inspect oiu2398sda87&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enter the shell inside a docker container&lt;br /&gt;
docker exec -ti a89sd98sa7d /bin/bash&lt;br /&gt;
&lt;br /&gt;
# Execute a command inside a container as a specific user, root in this case&lt;br /&gt;
docker exec -it -u root asd87289hasdadz tail /var/log/nginx/access.log&lt;br /&gt;
docker exec -u 0 -it as892asnj2as /bin/bash&lt;br /&gt;
&lt;br /&gt;
# Restart docker container yoga&lt;br /&gt;
docker restart yoga&lt;br /&gt;
&lt;br /&gt;
# Restart the 3 given containers&lt;br /&gt;
docker restart 79f71c7f4d91 bbb3d3f5c3b1 b0a3204d4098&lt;br /&gt;
&lt;br /&gt;
# Start this container&lt;br /&gt;
docker start as9823nzxc0&lt;br /&gt;
&lt;br /&gt;
# Stop this container&lt;br /&gt;
docker stop as9823nzxc0&lt;br /&gt;
&lt;br /&gt;
# Restart all unhealthy Docker containers&lt;br /&gt;
for i in $(docker ps | grep unhealthy | awk &#039;{print $1}&#039;); do docker restart &amp;quot;$i&amp;quot;; done;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PowerDNS ===&lt;br /&gt;
* https://doc.powerdns.com/authoritative/index.html&lt;br /&gt;
* https://doc.powerdns.com/authoritative/manpages/pdns_server.1.html&lt;br /&gt;
* https://doc.powerdns.com/authoritative/manpages/pdnsutil.1.html&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# List commands&lt;br /&gt;
pdns_server --help&lt;br /&gt;
&lt;br /&gt;
# Check config and parse for errors&lt;br /&gt;
pdns_server --config=check&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# List available commands &lt;br /&gt;
pdnsutil --help&lt;br /&gt;
&lt;br /&gt;
# Check config and parse for errors&lt;br /&gt;
pdnsutil --config=check&lt;br /&gt;
&lt;br /&gt;
# List all available zones&lt;br /&gt;
pdnsutil list-all-zones&lt;br /&gt;
&lt;br /&gt;
# List all domains in the primary zone&lt;br /&gt;
pdnsutil list-all-zones primary&lt;br /&gt;
&lt;br /&gt;
# See zone information for a specific domain&lt;br /&gt;
pdnsutil show-zone mydomain.com&lt;br /&gt;
pdnsutil show-zone 77.5.10.in-addr.arpa&lt;br /&gt;
&lt;br /&gt;
# Check zone for errors&lt;br /&gt;
pdnsutil check-zone mydomain.com&lt;br /&gt;
&lt;br /&gt;
# List all created TSIG keys&lt;br /&gt;
pdnsutil list-tsig-keys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# Activate TSIG key for domain &amp;quot;myexample.com&amp;quot; in the primary zone&lt;br /&gt;
pdnsutil &amp;quot; myexample.com transfer primary&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MAAS ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Logs in either place:&lt;br /&gt;
/var/log/maas/&lt;br /&gt;
/var/snap/maas/common/log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List status of MAAS services&lt;br /&gt;
maas status&lt;br /&gt;
&lt;br /&gt;
# List MAAS commands&lt;br /&gt;
maas --help&lt;br /&gt;
&lt;br /&gt;
# List available arguments for the init command&lt;br /&gt;
maas init --help&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section end=&amp;quot;linuxservices&amp;quot;/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Services&amp;diff=845</id>
		<title>Linux:Services</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Services&amp;diff=845"/>
		<updated>2025-10-01T11:48:15Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* Rainerscript */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet|Cheatsheets]]&lt;br /&gt;
&lt;br /&gt;
== Services ==&lt;br /&gt;
&amp;lt;section begin=&amp;quot;linuxservices&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Common ===&lt;br /&gt;
==== systemctl ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all services that are running or exited&lt;br /&gt;
systemctl&lt;br /&gt;
&lt;br /&gt;
# List all services, running or otherwise&lt;br /&gt;
systemctl --all&lt;br /&gt;
&lt;br /&gt;
# List all failed services&lt;br /&gt;
systemctl --state=failed&lt;br /&gt;
&lt;br /&gt;
# Reset the failed service &amp;quot;nginx&amp;quot;&lt;br /&gt;
systemctl reset-failed nginx&lt;br /&gt;
&lt;br /&gt;
# View the status of the &amp;quot;nfs-server&amp;quot; service&lt;br /&gt;
systemctl status nfs-server&lt;br /&gt;
&lt;br /&gt;
# Output the config file of &amp;quot;rsyslog&amp;quot; to the shell&lt;br /&gt;
systemctl cat rsyslog&lt;br /&gt;
&lt;br /&gt;
# Restart the &amp;quot;sshd&amp;quot; service, terminating established connections and re-parsing the configuration&lt;br /&gt;
systemctl restart sshd&lt;br /&gt;
&lt;br /&gt;
# Reload the &amp;quot;nginx&amp;quot; service so that it only re-parses the configuration&lt;br /&gt;
systemctl reload nginx&lt;br /&gt;
&lt;br /&gt;
# Stop the &amp;quot;nfs-ganesha&amp;quot; service so that it stops being run&lt;br /&gt;
systemctl stop nfs-ganesha&lt;br /&gt;
&lt;br /&gt;
# Start the &amp;quot;nfs-ganesha&amp;quot; service so that it starts being run again&lt;br /&gt;
systemctl start nfs-ganesha&lt;br /&gt;
&lt;br /&gt;
# Disable the &amp;quot;mariadb&amp;quot; service so that it doesn&#039;t start after the next boot&lt;br /&gt;
systemctl disable mariadb&lt;br /&gt;
&lt;br /&gt;
# Enable the &amp;quot;mariadb&amp;quot; service so that it starts after the next boot.&lt;br /&gt;
systemctl enable mariadb&lt;br /&gt;
&lt;br /&gt;
# Check the logs for all failed services&lt;br /&gt;
for i in $(systemctl --state=failed | head -n -4 | tail -n +2 | awk &#039;{print $1}&#039;); do systemctl --no-pager status &amp;quot;$i&amp;quot;; done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== NTP ===&lt;br /&gt;
==== Timedatectl ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show the current status of timedatectl&lt;br /&gt;
timedatectl&lt;br /&gt;
&lt;br /&gt;
# List available timezones&lt;br /&gt;
timedatectl list-timezones&lt;br /&gt;
&lt;br /&gt;
# Set the timezone to Amsterdam&lt;br /&gt;
timedatectl set-timezone Europe/Amsterdam&lt;br /&gt;
&lt;br /&gt;
# Show verbose sync information&lt;br /&gt;
timedatectl timesync-status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SNMP ===&lt;br /&gt;
==== V3 client installation ====&lt;br /&gt;
* https://kifarunix.com/quick-way-to-install-and-configure-snmp-on-ubuntu-20-04/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
apt install snmpd snmp libsnmp-dev&lt;br /&gt;
cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.bak&lt;br /&gt;
systemctl stop snmpd&lt;br /&gt;
net-snmp-create-v3-user -ro -X &amp;lt;CRYPTO-PASSWORD&amp;gt; -a SHA -X &amp;lt;PASSWORD&amp;gt; -x AES &amp;lt;USERNAME&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/snmp/snmpd.conf&lt;br /&gt;
sysLocation    NL;Zuid-Holland;Rotterdam, 78 MyStreet;2nd Floor;Server Room;Rack&lt;br /&gt;
sysContact     Me &amp;lt;me@example.org&amp;gt;&lt;br /&gt;
agentaddress   192.168.0.10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
systemctl start snmpd&lt;br /&gt;
systemctl enable snmpd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Test&lt;br /&gt;
snmpwalk -v3 -a SHA -A &amp;quot;AUTHENTICATION PASSWORD&amp;quot; -x AES -X &amp;quot;CRYPTO PASSWORD&amp;quot; -l authPriv -u &amp;quot;MYUSER&amp;quot; localhost | head&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CTDB  ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Verify CTDB cluster status&lt;br /&gt;
ctdb status&lt;br /&gt;
&lt;br /&gt;
# Show the allocated IP addresses and to which nodes they&#039;re bound&lt;br /&gt;
ctdb ip&lt;br /&gt;
&lt;br /&gt;
# See the status of all CTDB-scripts&lt;br /&gt;
ctdb scriptstatus&lt;br /&gt;
ctdb event status&lt;br /&gt;
&lt;br /&gt;
# Show the time of the last failover the duration it took to recover&lt;br /&gt;
ctdb uptime&lt;br /&gt;
&lt;br /&gt;
# See various statistics and data&lt;br /&gt;
ctdb statistics&lt;br /&gt;
&lt;br /&gt;
# Use the onnode command to execute a command on all cluster nodes&lt;br /&gt;
onnode all ctdb status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Stop a ctdb cluster member&lt;br /&gt;
ctdb stop&lt;br /&gt;
&lt;br /&gt;
# Start a stopped ctdb cluster member&lt;br /&gt;
ctdb continue&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Firewalls ===&lt;br /&gt;
==== UFW ====&lt;br /&gt;
===== Checks =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show summary of UFW status&lt;br /&gt;
ufw status&lt;br /&gt;
&lt;br /&gt;
# Show verbose UFW status&lt;br /&gt;
ufw status verbose&lt;br /&gt;
&lt;br /&gt;
# Show UFW rules numbered&lt;br /&gt;
ufw status numbered&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Commands =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Allow access from a specific IP to a port and add a comment that show in the status&lt;br /&gt;
ufw allow from 10.0.0.253 to any port 22 proto tcp comment &#039;Allow SSH access from XYZ location&#039;&lt;br /&gt;
&lt;br /&gt;
# Delete numbered Firewall rule 56&lt;br /&gt;
ufw delete 56&lt;br /&gt;
&lt;br /&gt;
# Disable UFW logging (prevent syslog spam)&lt;br /&gt;
ufw logging off&lt;br /&gt;
&lt;br /&gt;
# Set UFW logging back to the default&lt;br /&gt;
ufw logging low&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Firewalld ====&lt;br /&gt;
===== SNMP access =====&lt;br /&gt;
* https://unix.stackexchange.com/questions/214388/how-to-let-the-firewall-of-rhel7-the-snmp-connection-passing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/firewalld/services/snmp.xml&lt;br /&gt;
&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;service&amp;gt;&lt;br /&gt;
  &amp;lt;short&amp;gt;SNMP&amp;lt;/short&amp;gt;&lt;br /&gt;
  &amp;lt;description&amp;gt;SNMP protocol&amp;lt;/description&amp;gt;&lt;br /&gt;
  &amp;lt;port protocol=&amp;quot;udp&amp;quot; port=&amp;quot;161&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/service&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
firewall-cmd --zone=public --add-service snmp --permanent&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Firewall-cmd =====&lt;br /&gt;
====== Checks ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all available commands&lt;br /&gt;
firewall-cmd -h&lt;br /&gt;
&lt;br /&gt;
# Check the configuration file of the firewall for errors&lt;br /&gt;
firewall-cmd --check-config&lt;br /&gt;
&lt;br /&gt;
# Display the current state of firewall-cmd (running/shutdown)&lt;br /&gt;
firewall-cmd --state&lt;br /&gt;
&lt;br /&gt;
# Display all available zones&lt;br /&gt;
firewall-cmd --get-zones&lt;br /&gt;
&lt;br /&gt;
# List all whitelisted services&lt;br /&gt;
firewall-cmd --list-services&lt;br /&gt;
&lt;br /&gt;
# List all services you can potentially enable&lt;br /&gt;
firewall-cmd --get-services&lt;br /&gt;
&lt;br /&gt;
# List all added or enabled services and ports in more detail&lt;br /&gt;
firewall-cmd --list-all&lt;br /&gt;
&lt;br /&gt;
# List verbose information for all zones&lt;br /&gt;
firewall-cmd --list-all-zones&lt;br /&gt;
&lt;br /&gt;
# List verbose information for the public zone&lt;br /&gt;
firewall-cmd --list-all --zone=public&lt;br /&gt;
&lt;br /&gt;
# See what port(s) are associated with the dns service&lt;br /&gt;
firewall-cmd --info-service dns&lt;br /&gt;
&lt;br /&gt;
# List all opened ports&lt;br /&gt;
firewall-cmd --list-ports&lt;br /&gt;
&lt;br /&gt;
# List kernel ruleset generated for nftables(?)&lt;br /&gt;
nft list ruleset&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Commands ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reload the firewall&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Whitelist the dns service, persistently even after reboot&lt;br /&gt;
firewall-cmd --add-service=dns ; sudo firewall-cmd --runtime-to-permanent; firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Whitelist the http service, persistently even after reboot&lt;br /&gt;
firewall-cmd --add-service=http ; sudo firewall-cmd --runtime-to-permanent; firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Remove the http service from the whitelist&lt;br /&gt;
firewall-cmd --remove-service=http&lt;br /&gt;
&lt;br /&gt;
# Add port 1234 (tcp) to the whitelist&lt;br /&gt;
firewall-cmd --add-port=1234/tcp&lt;br /&gt;
&lt;br /&gt;
# Remove port 1234 (tcp) from the whitelist&lt;br /&gt;
firewall-cmd --remove-port=1234/tcp&lt;br /&gt;
&lt;br /&gt;
# Add port 2345 (udp) to the whitelist in zone external&lt;br /&gt;
firewall-cmd --zone=external --add-port=2345/udp&lt;br /&gt;
&lt;br /&gt;
# Remove port 2345 (udp) from the whitelist for zone external&lt;br /&gt;
firewall-cmd --zone=external --add-port=2345/udp&lt;br /&gt;
&lt;br /&gt;
# Add current configuration to configuration permanently&lt;br /&gt;
firewall-cmd –runtime-to-permanent&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;DANGEROUS&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# SHUT IT DOWN DOC - DROP ALL PACKETS AND EXPIRE EXISTING CONNECTIONS&lt;br /&gt;
firewall-cmd --panic-on&lt;br /&gt;
&lt;br /&gt;
# ACCEPT PACKETS AGAIN&lt;br /&gt;
firewall-cmd --panic-off&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== CSF ====&lt;br /&gt;
ConfigServer Security and Firewall&lt;br /&gt;
&lt;br /&gt;
===== General =====&lt;br /&gt;
* Common configuration: /etc/csf/csf.conf &lt;br /&gt;
* Blacklist: /etc/csf/csf.deny &lt;br /&gt;
* Whitelist: /etc/csf/csf.allow &lt;br /&gt;
&lt;br /&gt;
===== Installation =====&lt;br /&gt;
From the official instructions: https://download.configserver.com/csf/install.txt&lt;br /&gt;
&lt;br /&gt;
====== Prerequisites ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Perl Modules&lt;br /&gt;
============&lt;br /&gt;
While most should be installed on a standard perl installation the following&lt;br /&gt;
may need to be installed manually:&lt;br /&gt;
&lt;br /&gt;
# On rpm based systems:&lt;br /&gt;
yum install perl-libwww-perl.noarch perl-LWP-Protocol-https.noarch perl-GDGraph&lt;br /&gt;
&lt;br /&gt;
# On APT based systems:&lt;br /&gt;
apt-get install libwww-perl liblwp-protocol-https-perl libgd-graph-perl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Install ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cd /usr/src&lt;br /&gt;
rm -fv csf.tgz&lt;br /&gt;
wget https://download.configserver.com/csf.tgz&lt;br /&gt;
tar -xzf csf.tgz&lt;br /&gt;
cd csf&lt;br /&gt;
sh install.sh&lt;br /&gt;
&lt;br /&gt;
# Next, test whether you have the required iptables modules:&lt;br /&gt;
perl /usr/local/csf/bin/csftest.pl&lt;br /&gt;
&lt;br /&gt;
# Don&#039;t worry if you cannot run all the features, so long as the script doesn&#039;t report any FATAL errors&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Checks =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check the running status of csf&lt;br /&gt;
csf status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Commands =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Commit config changes by restarting csf&lt;br /&gt;
csf -r&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== csf.conf =====&lt;br /&gt;
Some common changes within the configuration file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Set testing to 0 when your CSF configuration is &#039;production&#039; ready&lt;br /&gt;
TESTING = &amp;quot;0&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow access to any service you&#039;re hosting locally, for example https&lt;br /&gt;
TCP_IN = &amp;quot;443&amp;quot;&lt;br /&gt;
UDP_IN = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow all outwards HTTP/HTTPS traffic so you can yum/apt update&lt;br /&gt;
TCP_OUT = &amp;quot;80,443&amp;quot; &lt;br /&gt;
&lt;br /&gt;
# Allow outgoing traceroute&lt;br /&gt;
UDP_OUT = &amp;quot;33434:33523&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow your server to be pinged&lt;br /&gt;
ICMP_IN = &amp;quot;0&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Formatting =====&lt;br /&gt;
The varying styles of formatting used in allow.conf&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Allow anything relating to the following IPs/ranges&lt;br /&gt;
192.168.10.0/24 # Our application breaks without this range&lt;br /&gt;
192.168.1.1 # Our gateway or something&lt;br /&gt;
&lt;br /&gt;
# Detailed entries based on Transport protocol, direction, Application protocol and IP&lt;br /&gt;
tcp:in:d=22:s=7.7.7.7 # SSH access from our VPN&lt;br /&gt;
udp:in:d=161:s=10.11.12.100 # SNMP Access&lt;br /&gt;
tcp|in|d=22|s=fe80::1:/16 # IPV6 SSH access from our jumpgateway&lt;br /&gt;
udp|in|d=3389|s=10.1.0.0/24 # RDP Access from our entire office range&lt;br /&gt;
tcp|out|d=80,443|d=1.2.3.4/32 # Allow outgoing HTTP/HTTPS access via port 80 and 443&lt;br /&gt;
&lt;br /&gt;
# Allow sending Syslog messages to our Syslog server&lt;br /&gt;
udp|out|d=514|d=192.168.20.5 # UDP syslog server&lt;br /&gt;
tcp|out|d=10514|d=192.168.20.5 # UDP syslog server&lt;br /&gt;
&lt;br /&gt;
# Allow sending queries to some DNS servers&lt;br /&gt;
tcp|out|s=53|d=8.8.8.8&lt;br /&gt;
udp|out|s=53|d=1.1.1.1&lt;br /&gt;
udp|out|s=53|d=2606:4700:4700::1111 # Cloudflare IPv6 DNS Server&lt;br /&gt;
&lt;br /&gt;
# Include an external configuration file&lt;br /&gt;
Include /etc/csf/csf.custom-config&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rsyslog ===&lt;br /&gt;
&amp;lt;section begin=&amp;quot;linuxsyslog&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Legacy ====&lt;br /&gt;
* https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/6/html/deployment_guide/s2-templates&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/75-local-to-rsyslog-server.conf&lt;br /&gt;
# Send all logs to a rsyslog server&lt;br /&gt;
*.* @10.77.0.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#/etc/rsyslog.d/70-local-to-rsyslog-server.conf&lt;br /&gt;
# Custom template where hostname is defined, then sent to the syslog server - include the priority number as first extra variable&lt;br /&gt;
$template SendHostname, &amp;quot;%PRI%1 %timestamp% myhost.mydomain.nl %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.warning @10.77.0.1;SendHostname&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/60-asd.conf&lt;br /&gt;
# Send messages to a syslog server, using a template aligned to IETF protocol 23, but specifying a custom hostname&lt;br /&gt;
$template custom_IETFprotocol_23,&amp;quot;%PRI%1 %TIMESTAMP:::date-rfc3339% prive.host.nl %APP-NAME% %PROCID% %MSGID% %STRUCTURED-DATA% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* @10.77.0.1;custom_IETFprotocol_23&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/62-asd.conf&lt;br /&gt;
# Log to the local server with a static hostname, using a custom structure&lt;br /&gt;
$template NewHostname, &amp;quot;%timestamp% tester.mydomain.nl %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* /var/log/wewuzerrors.txt;NewHostname&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
## /etc/rsyslog.d/65-customtemplate.conf&lt;br /&gt;
# https://stackoverflow.com/questions/57890176/extending-rsyslogs-default-logging-template&lt;br /&gt;
# An alternative to the contents above, specifying different/more fields&lt;br /&gt;
$template mynewtemplate,&amp;quot;%timegenerated% %HOSTNAME% %syslogfacility-text%.%syslogseverity-text% %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* /var/log/wazanda.txt;mynewtemplate&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rainerscript ====&lt;br /&gt;
Rainerscript: https://rsyslog.readthedocs.io/en/latest/rainerscript/control_structures.html&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/70-local-to-rsyslog-server.conf&lt;br /&gt;
# Send message to a syslog server using IETF protocol 23&lt;br /&gt;
template(name=&amp;quot;RSYSLOG_SyslogProtocol23Format&amp;quot; type=&amp;quot;string&amp;quot;&lt;br /&gt;
     string=&amp;quot;&amp;lt;%PRI%&amp;gt;1 %TIMESTAMP:::date-rfc3339% %HOSTNAME% %APP-NAME% %PROCID% %MSGID% %STRUCTURED-DATA% %msg%\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
*.* action(type=&amp;quot;omfwd&amp;quot; Target=&amp;quot;192.168.5.21&amp;quot; Template=&amp;quot;RSYSLOG_SyslogProtocol23Format&amp;quot; Port=&amp;quot;514&amp;quot; Protocol=&amp;quot;udp&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/71-local-to-rsyslog-server.conf&lt;br /&gt;
# Define a template aligned to IETF protocol 23 and specify a hostname to send as:&lt;br /&gt;
template(name=&amp;quot;SendHostname&amp;quot; type=&amp;quot;string&amp;quot;&lt;br /&gt;
     string=&amp;quot;&amp;lt;%PRI%&amp;gt;1 %TIMESTAMP:::date-rfc3339% myhost.mydomain.nl %APP-NAME% %PROCID% %MSGID% %STRUCTURED-DATA% %msg%\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Send logs to target syslog server and port&lt;br /&gt;
*.* action(type=&amp;quot;omfwd&amp;quot; Target=&amp;quot;10.0.33.10&amp;quot; Template=&amp;quot;SendHostname&amp;quot; Port=&amp;quot;514&amp;quot; Protocol=&amp;quot;udp&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Testing ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use the logger tool to test syslog server reception&lt;br /&gt;
logger -p local0.error &#039;Hello World!&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section end=&amp;quot;linuxsyslog&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== named ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Perform a test load of all primary zones within named.conf, as the named user&lt;br /&gt;
sudo -u named named-checkconf -z&lt;br /&gt;
&lt;br /&gt;
# Check zone file 192.168.77.0 defined in the 77.168.192.in-addr.arpa zone&lt;br /&gt;
named-checkzone 77.168.192.in-addr.arpa 192.168.77.0&lt;br /&gt;
&lt;br /&gt;
# Check zone file brammerloo.nl defined in the brammerloo.nl zone&lt;br /&gt;
named-checkzone brammerloo.nl brammerloo.nl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Basic configuration for the options field in &#039;&#039;&#039;/etc/named.conf&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
options {&lt;br /&gt;
# Define on what IP to listen on, for port 53&lt;br /&gt;
        listen-on port 53 { 127.0.0.1; 192.168.0.1; 192.168.1.1; };&lt;br /&gt;
        directory       &amp;quot;/var/named&amp;quot;;&lt;br /&gt;
        dump-file       &amp;quot;/var/named/data/cache_dump.db&amp;quot;;&lt;br /&gt;
        statistics-file &amp;quot;/var/named/data/named_stats.txt&amp;quot;;&lt;br /&gt;
        memstatistics-file &amp;quot;/var/named/data/named_mem_stats.txt&amp;quot;;&lt;br /&gt;
        secroots-file   &amp;quot;/var/named/data/named.secroots&amp;quot;;&lt;br /&gt;
        recursing-file  &amp;quot;/var/named/data/named.recursing&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# Only allow DNS queries from specific local subnets&lt;br /&gt;
# To allow from anything use: allow query { any; };&lt;br /&gt;
        allow-query     { localhost; 127.0.0.1; 192.168.0.0/24; 192.168.1.0/24; };&lt;br /&gt;
&lt;br /&gt;
# If the server can&#039;t resolve an address locally, use the following DNS servers for help&lt;br /&gt;
        forwarders {&lt;br /&gt;
        8.8.8.8;&lt;br /&gt;
        1.1.1.1;&lt;br /&gt;
        };&lt;br /&gt;
&lt;br /&gt;
        recursion yes;&lt;br /&gt;
        dnssec-validation no;&lt;br /&gt;
&lt;br /&gt;
        managed-keys-directory &amp;quot;/var/named/dynamic&amp;quot;;&lt;br /&gt;
        geoip-directory &amp;quot;/usr/share/GeoIP&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
        pid-file &amp;quot;/run/named/named.pid&amp;quot;;&lt;br /&gt;
        session-keyfile &amp;quot;/run/named/session.key&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
        /* https://fedoraproject.org/wiki/Changes/CryptoPolicy */&lt;br /&gt;
        include &amp;quot;/etc/crypto-policies/back-ends/bind.config&amp;quot;;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone defnitions: &#039;&#039;&#039;/etc/named.rfc1912.zones&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Define zones to listen for&lt;br /&gt;
zone &amp;quot;brammerloo.nl&amp;quot; IN {&lt;br /&gt;
        type master;&lt;br /&gt;
        file &amp;quot;brammerloo.nl&amp;quot;;&lt;br /&gt;
        allow-update { none; };&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
zone &amp;quot;1.168.192.in-addr.arpa&amp;quot; IN {&lt;br /&gt;
        type master;&lt;br /&gt;
        file &amp;quot;192.168.1.0&amp;quot;;&lt;br /&gt;
        allow-update { none; };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone file for Reverse lookup: &#039;&#039;&#039;/var/named/192.168.1.0&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$TTL 300&lt;br /&gt;
@       IN SOA  ns1.brammerloo.nl. admin.brammerloo.nl. (&lt;br /&gt;
                                        2023101102 ; serial&lt;br /&gt;
                                        180     ; refresh&lt;br /&gt;
                                        60      ; retry&lt;br /&gt;
                                        108000  ; expire&lt;br /&gt;
                                        60 )    ; minimum&lt;br /&gt;
    IN      NS      ns1.brammerloo.nl.&lt;br /&gt;
; PTR Records&lt;br /&gt;
11    IN   PTR   node1.&lt;br /&gt;
21    IN   PTR   server1.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone file for domain: &#039;&#039;&#039;/var/named/brammerloo.nl&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$TTL 300&lt;br /&gt;
@       IN SOA  ns1.brammerloo.nl. admin.brammerloo.nl. (&lt;br /&gt;
                                        2023101306 ; serial&lt;br /&gt;
                                        180     ; refresh&lt;br /&gt;
                                        60      ; retry&lt;br /&gt;
                                        108000  ; expire&lt;br /&gt;
                                        60 )    ; minimum&lt;br /&gt;
    IN      NS      ns1.brammerloo.nl.&lt;br /&gt;
@                  IN      A     192.168.1.6   ; domain brammerloo.nl is me!&lt;br /&gt;
ns1.brammerloo.nl. IN      A     192.168.78.31 ; FQDN for my domain&lt;br /&gt;
node1              IN      A     192.168.78.31 ; Basic A-record&lt;br /&gt;
www                IN      CNAME node1         ; Point my website to my node1 A-record&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== dhcpd ===&lt;br /&gt;
==== dhclient ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Request an IPv4 adres from a DHCP server&lt;br /&gt;
dhclient -4&lt;br /&gt;
&lt;br /&gt;
# Show verbose information when requesting an IPv4 adres from a DHCP server&lt;br /&gt;
dhclient -4 -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Basic configuration options in the &#039;&#039;&#039;/etc/dhcp/dhcpd.conf&#039;&#039;&#039; file&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Set the domain clients should use when resolving hostnames (equivalent to search domain)&lt;br /&gt;
option domain-name &amp;quot;brammerloo.nl&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# Set the domain name servers for DHCP clients&lt;br /&gt;
option domain-name-servers ns1.brammerloo.nl, 8.8.8.8;&lt;br /&gt;
&lt;br /&gt;
default-lease-time 600;&lt;br /&gt;
max-lease-time 7200;&lt;br /&gt;
log-facility local7;&lt;br /&gt;
&lt;br /&gt;
# Best practice = define any connected subnets, but don&#039;t configure DHCP for them&lt;br /&gt;
subnet 192.168.1.0 netmask 255.255.255.0 {&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Basic DHCP for a subnet configuration&lt;br /&gt;
subnet 192.168.0.0 netmask 255.255.255.0 {&lt;br /&gt;
  range 192.168.0.100 192.168.0.150;&lt;br /&gt;
  option routers 192.168.0.1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== smbd / Samba / CIFS ===&lt;br /&gt;
https://linuxconfig.org/install-samba-on-redhat-8&lt;br /&gt;
&lt;br /&gt;
==== Basic configuration ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install and enable&lt;br /&gt;
dnf install samba samba-client&lt;br /&gt;
systemctl enable --now {smb,nmb}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a client-user to authenticate with&lt;br /&gt;
sudo useradd samba-user&lt;br /&gt;
&lt;br /&gt;
# Give the user a password to authenticate with&lt;br /&gt;
sudo smbpasswd -a samba-user&lt;br /&gt;
&lt;br /&gt;
# Create a group to associate with the samba share&lt;br /&gt;
sudo groupadd sambagroup&lt;br /&gt;
&lt;br /&gt;
# Add the user to the group we will be configuring for the share&lt;br /&gt;
sudo usermod -a -G sambagroup samba-user&lt;br /&gt;
&lt;br /&gt;
# Create the folder we will be sharing&lt;br /&gt;
sudo mkdir /var/shares/myshare&lt;br /&gt;
&lt;br /&gt;
# Apply proper permission&lt;br /&gt;
sudo chown -R samba-user:sambagroup /var/shares/myshare/&lt;br /&gt;
sudo chmod -R 0770 /var/shares/myshare/&lt;br /&gt;
&lt;br /&gt;
# Apply proper permission for SELinux&lt;br /&gt;
sudo chcon -t samba_share_t /var/shares/myshare/&lt;br /&gt;
&lt;br /&gt;
# Backup the default config&lt;br /&gt;
cp /etc/samba/smb.conf /etc/samba/smb.conf~&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/samba/smb.conf&lt;br /&gt;
[global]&lt;br /&gt;
 workgroup = &amp;lt;DOMAIN-OR-WORKGROUP&amp;gt;&lt;br /&gt;
 server string = Samba Server %v&lt;br /&gt;
 netbios name = &amp;lt;SERVER-HOSTNAME&amp;gt;&lt;br /&gt;
 security = user&lt;br /&gt;
 map to guest = bad user&lt;br /&gt;
 dns proxy = no&lt;br /&gt;
&lt;br /&gt;
#==================== Share Definitions ======================&lt;br /&gt;
[share001]&lt;br /&gt;
 path = /var/shares/myshare&lt;br /&gt;
 valid users = @sambagroup&lt;br /&gt;
 guest ok = no&lt;br /&gt;
 writable = yes&lt;br /&gt;
 browsable = yes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reload Samba services&lt;br /&gt;
systemctl reload {smb,nmb}&lt;br /&gt;
&lt;br /&gt;
# Mount in Windows&lt;br /&gt;
\\&amp;lt;SERVER-IP&amp;gt;\share001&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user: samba-user&lt;br /&gt;
pass: &amp;lt;Whatever password you filled in with smbpasswd -a&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Samba checks&lt;br /&gt;
smbstatus&lt;br /&gt;
smbstatus -S&lt;br /&gt;
smbstatus -b&lt;br /&gt;
&lt;br /&gt;
# Samba set debug mode&lt;br /&gt;
smbcontrol smbd debug 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Docker ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List Docker containers &lt;br /&gt;
docker ps&lt;br /&gt;
&lt;br /&gt;
# List all Docker container IDs&lt;br /&gt;
docker ps -aq&lt;br /&gt;
&lt;br /&gt;
# List logs for container 987sdh3qrasdhj&lt;br /&gt;
docker logs 987sdh3qrasdhj&lt;br /&gt;
&lt;br /&gt;
# List RAM/CPU usage for Docker container asdlkasd67k&lt;br /&gt;
docker stats asdlkasd67k&lt;br /&gt;
&lt;br /&gt;
# Show verbose container information such as commands run, network, ID, etc&lt;br /&gt;
docker inspect oiu2398sda87&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enter the shell inside a docker container&lt;br /&gt;
docker exec -ti a89sd98sa7d /bin/bash&lt;br /&gt;
&lt;br /&gt;
# Execute a command inside a container as a specific user, root in this case&lt;br /&gt;
docker exec -it -u root asd87289hasdadz tail /var/log/nginx/access.log&lt;br /&gt;
docker exec -u 0 -it as892asnj2as /bin/bash&lt;br /&gt;
&lt;br /&gt;
# Restart docker container yoga&lt;br /&gt;
docker restart yoga&lt;br /&gt;
&lt;br /&gt;
# Restart the 3 given containers&lt;br /&gt;
docker restart 79f71c7f4d91 bbb3d3f5c3b1 b0a3204d4098&lt;br /&gt;
&lt;br /&gt;
# Start this container&lt;br /&gt;
docker start as9823nzxc0&lt;br /&gt;
&lt;br /&gt;
# Stop this container&lt;br /&gt;
docker stop as9823nzxc0&lt;br /&gt;
&lt;br /&gt;
# Restart all unhealthy Docker containers&lt;br /&gt;
for i in $(docker ps | grep unhealthy | awk &#039;{print $1}&#039;); do docker restart &amp;quot;$i&amp;quot;; done;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PowerDNS ===&lt;br /&gt;
* https://doc.powerdns.com/authoritative/index.html&lt;br /&gt;
* https://doc.powerdns.com/authoritative/manpages/pdns_server.1.html&lt;br /&gt;
* https://doc.powerdns.com/authoritative/manpages/pdnsutil.1.html&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# List commands&lt;br /&gt;
pdns_server --help&lt;br /&gt;
&lt;br /&gt;
# Check config and parse for errors&lt;br /&gt;
pdns_server --config=check&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# List available commands &lt;br /&gt;
pdnsutil --help&lt;br /&gt;
&lt;br /&gt;
# Check config and parse for errors&lt;br /&gt;
pdnsutil --config=check&lt;br /&gt;
&lt;br /&gt;
# List all available zones&lt;br /&gt;
pdnsutil list-all-zones&lt;br /&gt;
&lt;br /&gt;
# List all domains in the primary zone&lt;br /&gt;
pdnsutil list-all-zones primary&lt;br /&gt;
&lt;br /&gt;
# See zone information for a specific domain&lt;br /&gt;
pdnsutil show-zone mydomain.com&lt;br /&gt;
pdnsutil show-zone 77.5.10.in-addr.arpa&lt;br /&gt;
&lt;br /&gt;
# Check zone for errors&lt;br /&gt;
pdnsutil check-zone mydomain.com&lt;br /&gt;
&lt;br /&gt;
# List all created TSIG keys&lt;br /&gt;
pdnsutil list-tsig-keys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# Activate TSIG key for domain &amp;quot;myexample.com&amp;quot; in the primary zone&lt;br /&gt;
pdnsutil &amp;quot; myexample.com transfer primary&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MAAS ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Logs in either place:&lt;br /&gt;
/var/log/maas/&lt;br /&gt;
/var/snap/maas/common/log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List status of MAAS services&lt;br /&gt;
maas status&lt;br /&gt;
&lt;br /&gt;
# List MAAS commands&lt;br /&gt;
maas --help&lt;br /&gt;
&lt;br /&gt;
# List available arguments for the init command&lt;br /&gt;
maas init --help&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section end=&amp;quot;linuxservices&amp;quot;/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Services&amp;diff=844</id>
		<title>Linux:Services</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Services&amp;diff=844"/>
		<updated>2025-10-01T11:25:42Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* Legacy */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet|Cheatsheets]]&lt;br /&gt;
&lt;br /&gt;
== Services ==&lt;br /&gt;
&amp;lt;section begin=&amp;quot;linuxservices&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Common ===&lt;br /&gt;
==== systemctl ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all services that are running or exited&lt;br /&gt;
systemctl&lt;br /&gt;
&lt;br /&gt;
# List all services, running or otherwise&lt;br /&gt;
systemctl --all&lt;br /&gt;
&lt;br /&gt;
# List all failed services&lt;br /&gt;
systemctl --state=failed&lt;br /&gt;
&lt;br /&gt;
# Reset the failed service &amp;quot;nginx&amp;quot;&lt;br /&gt;
systemctl reset-failed nginx&lt;br /&gt;
&lt;br /&gt;
# View the status of the &amp;quot;nfs-server&amp;quot; service&lt;br /&gt;
systemctl status nfs-server&lt;br /&gt;
&lt;br /&gt;
# Output the config file of &amp;quot;rsyslog&amp;quot; to the shell&lt;br /&gt;
systemctl cat rsyslog&lt;br /&gt;
&lt;br /&gt;
# Restart the &amp;quot;sshd&amp;quot; service, terminating established connections and re-parsing the configuration&lt;br /&gt;
systemctl restart sshd&lt;br /&gt;
&lt;br /&gt;
# Reload the &amp;quot;nginx&amp;quot; service so that it only re-parses the configuration&lt;br /&gt;
systemctl reload nginx&lt;br /&gt;
&lt;br /&gt;
# Stop the &amp;quot;nfs-ganesha&amp;quot; service so that it stops being run&lt;br /&gt;
systemctl stop nfs-ganesha&lt;br /&gt;
&lt;br /&gt;
# Start the &amp;quot;nfs-ganesha&amp;quot; service so that it starts being run again&lt;br /&gt;
systemctl start nfs-ganesha&lt;br /&gt;
&lt;br /&gt;
# Disable the &amp;quot;mariadb&amp;quot; service so that it doesn&#039;t start after the next boot&lt;br /&gt;
systemctl disable mariadb&lt;br /&gt;
&lt;br /&gt;
# Enable the &amp;quot;mariadb&amp;quot; service so that it starts after the next boot.&lt;br /&gt;
systemctl enable mariadb&lt;br /&gt;
&lt;br /&gt;
# Check the logs for all failed services&lt;br /&gt;
for i in $(systemctl --state=failed | head -n -4 | tail -n +2 | awk &#039;{print $1}&#039;); do systemctl --no-pager status &amp;quot;$i&amp;quot;; done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== NTP ===&lt;br /&gt;
==== Timedatectl ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show the current status of timedatectl&lt;br /&gt;
timedatectl&lt;br /&gt;
&lt;br /&gt;
# List available timezones&lt;br /&gt;
timedatectl list-timezones&lt;br /&gt;
&lt;br /&gt;
# Set the timezone to Amsterdam&lt;br /&gt;
timedatectl set-timezone Europe/Amsterdam&lt;br /&gt;
&lt;br /&gt;
# Show verbose sync information&lt;br /&gt;
timedatectl timesync-status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SNMP ===&lt;br /&gt;
==== V3 client installation ====&lt;br /&gt;
* https://kifarunix.com/quick-way-to-install-and-configure-snmp-on-ubuntu-20-04/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
apt install snmpd snmp libsnmp-dev&lt;br /&gt;
cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.bak&lt;br /&gt;
systemctl stop snmpd&lt;br /&gt;
net-snmp-create-v3-user -ro -X &amp;lt;CRYPTO-PASSWORD&amp;gt; -a SHA -X &amp;lt;PASSWORD&amp;gt; -x AES &amp;lt;USERNAME&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/snmp/snmpd.conf&lt;br /&gt;
sysLocation    NL;Zuid-Holland;Rotterdam, 78 MyStreet;2nd Floor;Server Room;Rack&lt;br /&gt;
sysContact     Me &amp;lt;me@example.org&amp;gt;&lt;br /&gt;
agentaddress   192.168.0.10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
systemctl start snmpd&lt;br /&gt;
systemctl enable snmpd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Test&lt;br /&gt;
snmpwalk -v3 -a SHA -A &amp;quot;AUTHENTICATION PASSWORD&amp;quot; -x AES -X &amp;quot;CRYPTO PASSWORD&amp;quot; -l authPriv -u &amp;quot;MYUSER&amp;quot; localhost | head&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CTDB  ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Verify CTDB cluster status&lt;br /&gt;
ctdb status&lt;br /&gt;
&lt;br /&gt;
# Show the allocated IP addresses and to which nodes they&#039;re bound&lt;br /&gt;
ctdb ip&lt;br /&gt;
&lt;br /&gt;
# See the status of all CTDB-scripts&lt;br /&gt;
ctdb scriptstatus&lt;br /&gt;
ctdb event status&lt;br /&gt;
&lt;br /&gt;
# Show the time of the last failover the duration it took to recover&lt;br /&gt;
ctdb uptime&lt;br /&gt;
&lt;br /&gt;
# See various statistics and data&lt;br /&gt;
ctdb statistics&lt;br /&gt;
&lt;br /&gt;
# Use the onnode command to execute a command on all cluster nodes&lt;br /&gt;
onnode all ctdb status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Stop a ctdb cluster member&lt;br /&gt;
ctdb stop&lt;br /&gt;
&lt;br /&gt;
# Start a stopped ctdb cluster member&lt;br /&gt;
ctdb continue&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Firewalls ===&lt;br /&gt;
==== UFW ====&lt;br /&gt;
===== Checks =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show summary of UFW status&lt;br /&gt;
ufw status&lt;br /&gt;
&lt;br /&gt;
# Show verbose UFW status&lt;br /&gt;
ufw status verbose&lt;br /&gt;
&lt;br /&gt;
# Show UFW rules numbered&lt;br /&gt;
ufw status numbered&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Commands =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Allow access from a specific IP to a port and add a comment that show in the status&lt;br /&gt;
ufw allow from 10.0.0.253 to any port 22 proto tcp comment &#039;Allow SSH access from XYZ location&#039;&lt;br /&gt;
&lt;br /&gt;
# Delete numbered Firewall rule 56&lt;br /&gt;
ufw delete 56&lt;br /&gt;
&lt;br /&gt;
# Disable UFW logging (prevent syslog spam)&lt;br /&gt;
ufw logging off&lt;br /&gt;
&lt;br /&gt;
# Set UFW logging back to the default&lt;br /&gt;
ufw logging low&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Firewalld ====&lt;br /&gt;
===== SNMP access =====&lt;br /&gt;
* https://unix.stackexchange.com/questions/214388/how-to-let-the-firewall-of-rhel7-the-snmp-connection-passing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/firewalld/services/snmp.xml&lt;br /&gt;
&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;service&amp;gt;&lt;br /&gt;
  &amp;lt;short&amp;gt;SNMP&amp;lt;/short&amp;gt;&lt;br /&gt;
  &amp;lt;description&amp;gt;SNMP protocol&amp;lt;/description&amp;gt;&lt;br /&gt;
  &amp;lt;port protocol=&amp;quot;udp&amp;quot; port=&amp;quot;161&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/service&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
firewall-cmd --zone=public --add-service snmp --permanent&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Firewall-cmd =====&lt;br /&gt;
====== Checks ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all available commands&lt;br /&gt;
firewall-cmd -h&lt;br /&gt;
&lt;br /&gt;
# Check the configuration file of the firewall for errors&lt;br /&gt;
firewall-cmd --check-config&lt;br /&gt;
&lt;br /&gt;
# Display the current state of firewall-cmd (running/shutdown)&lt;br /&gt;
firewall-cmd --state&lt;br /&gt;
&lt;br /&gt;
# Display all available zones&lt;br /&gt;
firewall-cmd --get-zones&lt;br /&gt;
&lt;br /&gt;
# List all whitelisted services&lt;br /&gt;
firewall-cmd --list-services&lt;br /&gt;
&lt;br /&gt;
# List all services you can potentially enable&lt;br /&gt;
firewall-cmd --get-services&lt;br /&gt;
&lt;br /&gt;
# List all added or enabled services and ports in more detail&lt;br /&gt;
firewall-cmd --list-all&lt;br /&gt;
&lt;br /&gt;
# List verbose information for all zones&lt;br /&gt;
firewall-cmd --list-all-zones&lt;br /&gt;
&lt;br /&gt;
# List verbose information for the public zone&lt;br /&gt;
firewall-cmd --list-all --zone=public&lt;br /&gt;
&lt;br /&gt;
# See what port(s) are associated with the dns service&lt;br /&gt;
firewall-cmd --info-service dns&lt;br /&gt;
&lt;br /&gt;
# List all opened ports&lt;br /&gt;
firewall-cmd --list-ports&lt;br /&gt;
&lt;br /&gt;
# List kernel ruleset generated for nftables(?)&lt;br /&gt;
nft list ruleset&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Commands ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reload the firewall&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Whitelist the dns service, persistently even after reboot&lt;br /&gt;
firewall-cmd --add-service=dns ; sudo firewall-cmd --runtime-to-permanent; firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Whitelist the http service, persistently even after reboot&lt;br /&gt;
firewall-cmd --add-service=http ; sudo firewall-cmd --runtime-to-permanent; firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Remove the http service from the whitelist&lt;br /&gt;
firewall-cmd --remove-service=http&lt;br /&gt;
&lt;br /&gt;
# Add port 1234 (tcp) to the whitelist&lt;br /&gt;
firewall-cmd --add-port=1234/tcp&lt;br /&gt;
&lt;br /&gt;
# Remove port 1234 (tcp) from the whitelist&lt;br /&gt;
firewall-cmd --remove-port=1234/tcp&lt;br /&gt;
&lt;br /&gt;
# Add port 2345 (udp) to the whitelist in zone external&lt;br /&gt;
firewall-cmd --zone=external --add-port=2345/udp&lt;br /&gt;
&lt;br /&gt;
# Remove port 2345 (udp) from the whitelist for zone external&lt;br /&gt;
firewall-cmd --zone=external --add-port=2345/udp&lt;br /&gt;
&lt;br /&gt;
# Add current configuration to configuration permanently&lt;br /&gt;
firewall-cmd –runtime-to-permanent&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;DANGEROUS&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# SHUT IT DOWN DOC - DROP ALL PACKETS AND EXPIRE EXISTING CONNECTIONS&lt;br /&gt;
firewall-cmd --panic-on&lt;br /&gt;
&lt;br /&gt;
# ACCEPT PACKETS AGAIN&lt;br /&gt;
firewall-cmd --panic-off&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== CSF ====&lt;br /&gt;
ConfigServer Security and Firewall&lt;br /&gt;
&lt;br /&gt;
===== General =====&lt;br /&gt;
* Common configuration: /etc/csf/csf.conf &lt;br /&gt;
* Blacklist: /etc/csf/csf.deny &lt;br /&gt;
* Whitelist: /etc/csf/csf.allow &lt;br /&gt;
&lt;br /&gt;
===== Installation =====&lt;br /&gt;
From the official instructions: https://download.configserver.com/csf/install.txt&lt;br /&gt;
&lt;br /&gt;
====== Prerequisites ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Perl Modules&lt;br /&gt;
============&lt;br /&gt;
While most should be installed on a standard perl installation the following&lt;br /&gt;
may need to be installed manually:&lt;br /&gt;
&lt;br /&gt;
# On rpm based systems:&lt;br /&gt;
yum install perl-libwww-perl.noarch perl-LWP-Protocol-https.noarch perl-GDGraph&lt;br /&gt;
&lt;br /&gt;
# On APT based systems:&lt;br /&gt;
apt-get install libwww-perl liblwp-protocol-https-perl libgd-graph-perl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Install ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cd /usr/src&lt;br /&gt;
rm -fv csf.tgz&lt;br /&gt;
wget https://download.configserver.com/csf.tgz&lt;br /&gt;
tar -xzf csf.tgz&lt;br /&gt;
cd csf&lt;br /&gt;
sh install.sh&lt;br /&gt;
&lt;br /&gt;
# Next, test whether you have the required iptables modules:&lt;br /&gt;
perl /usr/local/csf/bin/csftest.pl&lt;br /&gt;
&lt;br /&gt;
# Don&#039;t worry if you cannot run all the features, so long as the script doesn&#039;t report any FATAL errors&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Checks =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check the running status of csf&lt;br /&gt;
csf status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Commands =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Commit config changes by restarting csf&lt;br /&gt;
csf -r&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== csf.conf =====&lt;br /&gt;
Some common changes within the configuration file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Set testing to 0 when your CSF configuration is &#039;production&#039; ready&lt;br /&gt;
TESTING = &amp;quot;0&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow access to any service you&#039;re hosting locally, for example https&lt;br /&gt;
TCP_IN = &amp;quot;443&amp;quot;&lt;br /&gt;
UDP_IN = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow all outwards HTTP/HTTPS traffic so you can yum/apt update&lt;br /&gt;
TCP_OUT = &amp;quot;80,443&amp;quot; &lt;br /&gt;
&lt;br /&gt;
# Allow outgoing traceroute&lt;br /&gt;
UDP_OUT = &amp;quot;33434:33523&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow your server to be pinged&lt;br /&gt;
ICMP_IN = &amp;quot;0&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Formatting =====&lt;br /&gt;
The varying styles of formatting used in allow.conf&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Allow anything relating to the following IPs/ranges&lt;br /&gt;
192.168.10.0/24 # Our application breaks without this range&lt;br /&gt;
192.168.1.1 # Our gateway or something&lt;br /&gt;
&lt;br /&gt;
# Detailed entries based on Transport protocol, direction, Application protocol and IP&lt;br /&gt;
tcp:in:d=22:s=7.7.7.7 # SSH access from our VPN&lt;br /&gt;
udp:in:d=161:s=10.11.12.100 # SNMP Access&lt;br /&gt;
tcp|in|d=22|s=fe80::1:/16 # IPV6 SSH access from our jumpgateway&lt;br /&gt;
udp|in|d=3389|s=10.1.0.0/24 # RDP Access from our entire office range&lt;br /&gt;
tcp|out|d=80,443|d=1.2.3.4/32 # Allow outgoing HTTP/HTTPS access via port 80 and 443&lt;br /&gt;
&lt;br /&gt;
# Allow sending Syslog messages to our Syslog server&lt;br /&gt;
udp|out|d=514|d=192.168.20.5 # UDP syslog server&lt;br /&gt;
tcp|out|d=10514|d=192.168.20.5 # UDP syslog server&lt;br /&gt;
&lt;br /&gt;
# Allow sending queries to some DNS servers&lt;br /&gt;
tcp|out|s=53|d=8.8.8.8&lt;br /&gt;
udp|out|s=53|d=1.1.1.1&lt;br /&gt;
udp|out|s=53|d=2606:4700:4700::1111 # Cloudflare IPv6 DNS Server&lt;br /&gt;
&lt;br /&gt;
# Include an external configuration file&lt;br /&gt;
Include /etc/csf/csf.custom-config&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rsyslog ===&lt;br /&gt;
&amp;lt;section begin=&amp;quot;linuxsyslog&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Legacy ====&lt;br /&gt;
* https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/6/html/deployment_guide/s2-templates&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/75-local-to-rsyslog-server.conf&lt;br /&gt;
# Send all logs to a rsyslog server&lt;br /&gt;
*.* @10.77.0.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#/etc/rsyslog.d/70-local-to-rsyslog-server.conf&lt;br /&gt;
# Custom template where hostname is defined, then sent to the syslog server - include the priority number as first extra variable&lt;br /&gt;
$template SendHostname, &amp;quot;%PRI%1 %timestamp% myhost.mydomain.nl %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.warning @10.77.0.1;SendHostname&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/60-asd.conf&lt;br /&gt;
# Send messages to a syslog server, using a template aligned to IETF protocol 23, but specifying a custom hostname&lt;br /&gt;
$template custom_IETFprotocol_23,&amp;quot;%PRI%1 %TIMESTAMP:::date-rfc3339% prive.host.nl %APP-NAME% %PROCID% %MSGID% %STRUCTURED-DATA% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* @10.77.0.1;custom_IETFprotocol_23&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/62-asd.conf&lt;br /&gt;
# Log to the local server with a static hostname, using a custom structure&lt;br /&gt;
$template NewHostname, &amp;quot;%timestamp% tester.mydomain.nl %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* /var/log/wewuzerrors.txt;NewHostname&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
## /etc/rsyslog.d/65-customtemplate.conf&lt;br /&gt;
# https://stackoverflow.com/questions/57890176/extending-rsyslogs-default-logging-template&lt;br /&gt;
# An alternative to the contents above, specifying different/more fields&lt;br /&gt;
$template mynewtemplate,&amp;quot;%timegenerated% %HOSTNAME% %syslogfacility-text%.%syslogseverity-text% %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* /var/log/wazanda.txt;mynewtemplate&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rainerscript ====&lt;br /&gt;
Rainerscript: https://rsyslog.readthedocs.io/en/latest/rainerscript/control_structures.html&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/70-local-to-rsyslog-server.conf&lt;br /&gt;
# Define a template and specify a hostname to send as:&lt;br /&gt;
template(name=&amp;quot;SendHostname&amp;quot; type=&amp;quot;string&amp;quot;&lt;br /&gt;
string=&amp;quot;%timestamp% myhost.mydomain.nl %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
# Send logs to target syslog server and port&lt;br /&gt;
*.warning action(type=&amp;quot;omfwd&amp;quot; Target=&amp;quot;10.0.33.10&amp;quot; Template=&amp;quot;SendHostname&amp;quot; Port=&amp;quot;514&amp;quot; Protocol=&amp;quot;udp&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Testing ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use the logger tool to test syslog server reception&lt;br /&gt;
logger -p local0.error &#039;Hello World!&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section end=&amp;quot;linuxsyslog&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== named ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Perform a test load of all primary zones within named.conf, as the named user&lt;br /&gt;
sudo -u named named-checkconf -z&lt;br /&gt;
&lt;br /&gt;
# Check zone file 192.168.77.0 defined in the 77.168.192.in-addr.arpa zone&lt;br /&gt;
named-checkzone 77.168.192.in-addr.arpa 192.168.77.0&lt;br /&gt;
&lt;br /&gt;
# Check zone file brammerloo.nl defined in the brammerloo.nl zone&lt;br /&gt;
named-checkzone brammerloo.nl brammerloo.nl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Basic configuration for the options field in &#039;&#039;&#039;/etc/named.conf&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
options {&lt;br /&gt;
# Define on what IP to listen on, for port 53&lt;br /&gt;
        listen-on port 53 { 127.0.0.1; 192.168.0.1; 192.168.1.1; };&lt;br /&gt;
        directory       &amp;quot;/var/named&amp;quot;;&lt;br /&gt;
        dump-file       &amp;quot;/var/named/data/cache_dump.db&amp;quot;;&lt;br /&gt;
        statistics-file &amp;quot;/var/named/data/named_stats.txt&amp;quot;;&lt;br /&gt;
        memstatistics-file &amp;quot;/var/named/data/named_mem_stats.txt&amp;quot;;&lt;br /&gt;
        secroots-file   &amp;quot;/var/named/data/named.secroots&amp;quot;;&lt;br /&gt;
        recursing-file  &amp;quot;/var/named/data/named.recursing&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# Only allow DNS queries from specific local subnets&lt;br /&gt;
# To allow from anything use: allow query { any; };&lt;br /&gt;
        allow-query     { localhost; 127.0.0.1; 192.168.0.0/24; 192.168.1.0/24; };&lt;br /&gt;
&lt;br /&gt;
# If the server can&#039;t resolve an address locally, use the following DNS servers for help&lt;br /&gt;
        forwarders {&lt;br /&gt;
        8.8.8.8;&lt;br /&gt;
        1.1.1.1;&lt;br /&gt;
        };&lt;br /&gt;
&lt;br /&gt;
        recursion yes;&lt;br /&gt;
        dnssec-validation no;&lt;br /&gt;
&lt;br /&gt;
        managed-keys-directory &amp;quot;/var/named/dynamic&amp;quot;;&lt;br /&gt;
        geoip-directory &amp;quot;/usr/share/GeoIP&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
        pid-file &amp;quot;/run/named/named.pid&amp;quot;;&lt;br /&gt;
        session-keyfile &amp;quot;/run/named/session.key&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
        /* https://fedoraproject.org/wiki/Changes/CryptoPolicy */&lt;br /&gt;
        include &amp;quot;/etc/crypto-policies/back-ends/bind.config&amp;quot;;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone defnitions: &#039;&#039;&#039;/etc/named.rfc1912.zones&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Define zones to listen for&lt;br /&gt;
zone &amp;quot;brammerloo.nl&amp;quot; IN {&lt;br /&gt;
        type master;&lt;br /&gt;
        file &amp;quot;brammerloo.nl&amp;quot;;&lt;br /&gt;
        allow-update { none; };&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
zone &amp;quot;1.168.192.in-addr.arpa&amp;quot; IN {&lt;br /&gt;
        type master;&lt;br /&gt;
        file &amp;quot;192.168.1.0&amp;quot;;&lt;br /&gt;
        allow-update { none; };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone file for Reverse lookup: &#039;&#039;&#039;/var/named/192.168.1.0&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$TTL 300&lt;br /&gt;
@       IN SOA  ns1.brammerloo.nl. admin.brammerloo.nl. (&lt;br /&gt;
                                        2023101102 ; serial&lt;br /&gt;
                                        180     ; refresh&lt;br /&gt;
                                        60      ; retry&lt;br /&gt;
                                        108000  ; expire&lt;br /&gt;
                                        60 )    ; minimum&lt;br /&gt;
    IN      NS      ns1.brammerloo.nl.&lt;br /&gt;
; PTR Records&lt;br /&gt;
11    IN   PTR   node1.&lt;br /&gt;
21    IN   PTR   server1.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone file for domain: &#039;&#039;&#039;/var/named/brammerloo.nl&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$TTL 300&lt;br /&gt;
@       IN SOA  ns1.brammerloo.nl. admin.brammerloo.nl. (&lt;br /&gt;
                                        2023101306 ; serial&lt;br /&gt;
                                        180     ; refresh&lt;br /&gt;
                                        60      ; retry&lt;br /&gt;
                                        108000  ; expire&lt;br /&gt;
                                        60 )    ; minimum&lt;br /&gt;
    IN      NS      ns1.brammerloo.nl.&lt;br /&gt;
@                  IN      A     192.168.1.6   ; domain brammerloo.nl is me!&lt;br /&gt;
ns1.brammerloo.nl. IN      A     192.168.78.31 ; FQDN for my domain&lt;br /&gt;
node1              IN      A     192.168.78.31 ; Basic A-record&lt;br /&gt;
www                IN      CNAME node1         ; Point my website to my node1 A-record&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== dhcpd ===&lt;br /&gt;
==== dhclient ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Request an IPv4 adres from a DHCP server&lt;br /&gt;
dhclient -4&lt;br /&gt;
&lt;br /&gt;
# Show verbose information when requesting an IPv4 adres from a DHCP server&lt;br /&gt;
dhclient -4 -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Basic configuration options in the &#039;&#039;&#039;/etc/dhcp/dhcpd.conf&#039;&#039;&#039; file&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Set the domain clients should use when resolving hostnames (equivalent to search domain)&lt;br /&gt;
option domain-name &amp;quot;brammerloo.nl&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# Set the domain name servers for DHCP clients&lt;br /&gt;
option domain-name-servers ns1.brammerloo.nl, 8.8.8.8;&lt;br /&gt;
&lt;br /&gt;
default-lease-time 600;&lt;br /&gt;
max-lease-time 7200;&lt;br /&gt;
log-facility local7;&lt;br /&gt;
&lt;br /&gt;
# Best practice = define any connected subnets, but don&#039;t configure DHCP for them&lt;br /&gt;
subnet 192.168.1.0 netmask 255.255.255.0 {&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Basic DHCP for a subnet configuration&lt;br /&gt;
subnet 192.168.0.0 netmask 255.255.255.0 {&lt;br /&gt;
  range 192.168.0.100 192.168.0.150;&lt;br /&gt;
  option routers 192.168.0.1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== smbd / Samba / CIFS ===&lt;br /&gt;
https://linuxconfig.org/install-samba-on-redhat-8&lt;br /&gt;
&lt;br /&gt;
==== Basic configuration ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install and enable&lt;br /&gt;
dnf install samba samba-client&lt;br /&gt;
systemctl enable --now {smb,nmb}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a client-user to authenticate with&lt;br /&gt;
sudo useradd samba-user&lt;br /&gt;
&lt;br /&gt;
# Give the user a password to authenticate with&lt;br /&gt;
sudo smbpasswd -a samba-user&lt;br /&gt;
&lt;br /&gt;
# Create a group to associate with the samba share&lt;br /&gt;
sudo groupadd sambagroup&lt;br /&gt;
&lt;br /&gt;
# Add the user to the group we will be configuring for the share&lt;br /&gt;
sudo usermod -a -G sambagroup samba-user&lt;br /&gt;
&lt;br /&gt;
# Create the folder we will be sharing&lt;br /&gt;
sudo mkdir /var/shares/myshare&lt;br /&gt;
&lt;br /&gt;
# Apply proper permission&lt;br /&gt;
sudo chown -R samba-user:sambagroup /var/shares/myshare/&lt;br /&gt;
sudo chmod -R 0770 /var/shares/myshare/&lt;br /&gt;
&lt;br /&gt;
# Apply proper permission for SELinux&lt;br /&gt;
sudo chcon -t samba_share_t /var/shares/myshare/&lt;br /&gt;
&lt;br /&gt;
# Backup the default config&lt;br /&gt;
cp /etc/samba/smb.conf /etc/samba/smb.conf~&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/samba/smb.conf&lt;br /&gt;
[global]&lt;br /&gt;
 workgroup = &amp;lt;DOMAIN-OR-WORKGROUP&amp;gt;&lt;br /&gt;
 server string = Samba Server %v&lt;br /&gt;
 netbios name = &amp;lt;SERVER-HOSTNAME&amp;gt;&lt;br /&gt;
 security = user&lt;br /&gt;
 map to guest = bad user&lt;br /&gt;
 dns proxy = no&lt;br /&gt;
&lt;br /&gt;
#==================== Share Definitions ======================&lt;br /&gt;
[share001]&lt;br /&gt;
 path = /var/shares/myshare&lt;br /&gt;
 valid users = @sambagroup&lt;br /&gt;
 guest ok = no&lt;br /&gt;
 writable = yes&lt;br /&gt;
 browsable = yes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reload Samba services&lt;br /&gt;
systemctl reload {smb,nmb}&lt;br /&gt;
&lt;br /&gt;
# Mount in Windows&lt;br /&gt;
\\&amp;lt;SERVER-IP&amp;gt;\share001&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user: samba-user&lt;br /&gt;
pass: &amp;lt;Whatever password you filled in with smbpasswd -a&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Samba checks&lt;br /&gt;
smbstatus&lt;br /&gt;
smbstatus -S&lt;br /&gt;
smbstatus -b&lt;br /&gt;
&lt;br /&gt;
# Samba set debug mode&lt;br /&gt;
smbcontrol smbd debug 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Docker ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List Docker containers &lt;br /&gt;
docker ps&lt;br /&gt;
&lt;br /&gt;
# List all Docker container IDs&lt;br /&gt;
docker ps -aq&lt;br /&gt;
&lt;br /&gt;
# List logs for container 987sdh3qrasdhj&lt;br /&gt;
docker logs 987sdh3qrasdhj&lt;br /&gt;
&lt;br /&gt;
# List RAM/CPU usage for Docker container asdlkasd67k&lt;br /&gt;
docker stats asdlkasd67k&lt;br /&gt;
&lt;br /&gt;
# Show verbose container information such as commands run, network, ID, etc&lt;br /&gt;
docker inspect oiu2398sda87&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enter the shell inside a docker container&lt;br /&gt;
docker exec -ti a89sd98sa7d /bin/bash&lt;br /&gt;
&lt;br /&gt;
# Execute a command inside a container as a specific user, root in this case&lt;br /&gt;
docker exec -it -u root asd87289hasdadz tail /var/log/nginx/access.log&lt;br /&gt;
docker exec -u 0 -it as892asnj2as /bin/bash&lt;br /&gt;
&lt;br /&gt;
# Restart docker container yoga&lt;br /&gt;
docker restart yoga&lt;br /&gt;
&lt;br /&gt;
# Restart the 3 given containers&lt;br /&gt;
docker restart 79f71c7f4d91 bbb3d3f5c3b1 b0a3204d4098&lt;br /&gt;
&lt;br /&gt;
# Start this container&lt;br /&gt;
docker start as9823nzxc0&lt;br /&gt;
&lt;br /&gt;
# Stop this container&lt;br /&gt;
docker stop as9823nzxc0&lt;br /&gt;
&lt;br /&gt;
# Restart all unhealthy Docker containers&lt;br /&gt;
for i in $(docker ps | grep unhealthy | awk &#039;{print $1}&#039;); do docker restart &amp;quot;$i&amp;quot;; done;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PowerDNS ===&lt;br /&gt;
* https://doc.powerdns.com/authoritative/index.html&lt;br /&gt;
* https://doc.powerdns.com/authoritative/manpages/pdns_server.1.html&lt;br /&gt;
* https://doc.powerdns.com/authoritative/manpages/pdnsutil.1.html&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# List commands&lt;br /&gt;
pdns_server --help&lt;br /&gt;
&lt;br /&gt;
# Check config and parse for errors&lt;br /&gt;
pdns_server --config=check&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# List available commands &lt;br /&gt;
pdnsutil --help&lt;br /&gt;
&lt;br /&gt;
# Check config and parse for errors&lt;br /&gt;
pdnsutil --config=check&lt;br /&gt;
&lt;br /&gt;
# List all available zones&lt;br /&gt;
pdnsutil list-all-zones&lt;br /&gt;
&lt;br /&gt;
# List all domains in the primary zone&lt;br /&gt;
pdnsutil list-all-zones primary&lt;br /&gt;
&lt;br /&gt;
# See zone information for a specific domain&lt;br /&gt;
pdnsutil show-zone mydomain.com&lt;br /&gt;
pdnsutil show-zone 77.5.10.in-addr.arpa&lt;br /&gt;
&lt;br /&gt;
# Check zone for errors&lt;br /&gt;
pdnsutil check-zone mydomain.com&lt;br /&gt;
&lt;br /&gt;
# List all created TSIG keys&lt;br /&gt;
pdnsutil list-tsig-keys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# Activate TSIG key for domain &amp;quot;myexample.com&amp;quot; in the primary zone&lt;br /&gt;
pdnsutil &amp;quot; myexample.com transfer primary&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MAAS ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Logs in either place:&lt;br /&gt;
/var/log/maas/&lt;br /&gt;
/var/snap/maas/common/log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List status of MAAS services&lt;br /&gt;
maas status&lt;br /&gt;
&lt;br /&gt;
# List MAAS commands&lt;br /&gt;
maas --help&lt;br /&gt;
&lt;br /&gt;
# List available arguments for the init command&lt;br /&gt;
maas init --help&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section end=&amp;quot;linuxservices&amp;quot;/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Services&amp;diff=843</id>
		<title>Linux:Services</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Services&amp;diff=843"/>
		<updated>2025-10-01T11:25:09Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* Legacy */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet|Cheatsheets]]&lt;br /&gt;
&lt;br /&gt;
== Services ==&lt;br /&gt;
&amp;lt;section begin=&amp;quot;linuxservices&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Common ===&lt;br /&gt;
==== systemctl ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all services that are running or exited&lt;br /&gt;
systemctl&lt;br /&gt;
&lt;br /&gt;
# List all services, running or otherwise&lt;br /&gt;
systemctl --all&lt;br /&gt;
&lt;br /&gt;
# List all failed services&lt;br /&gt;
systemctl --state=failed&lt;br /&gt;
&lt;br /&gt;
# Reset the failed service &amp;quot;nginx&amp;quot;&lt;br /&gt;
systemctl reset-failed nginx&lt;br /&gt;
&lt;br /&gt;
# View the status of the &amp;quot;nfs-server&amp;quot; service&lt;br /&gt;
systemctl status nfs-server&lt;br /&gt;
&lt;br /&gt;
# Output the config file of &amp;quot;rsyslog&amp;quot; to the shell&lt;br /&gt;
systemctl cat rsyslog&lt;br /&gt;
&lt;br /&gt;
# Restart the &amp;quot;sshd&amp;quot; service, terminating established connections and re-parsing the configuration&lt;br /&gt;
systemctl restart sshd&lt;br /&gt;
&lt;br /&gt;
# Reload the &amp;quot;nginx&amp;quot; service so that it only re-parses the configuration&lt;br /&gt;
systemctl reload nginx&lt;br /&gt;
&lt;br /&gt;
# Stop the &amp;quot;nfs-ganesha&amp;quot; service so that it stops being run&lt;br /&gt;
systemctl stop nfs-ganesha&lt;br /&gt;
&lt;br /&gt;
# Start the &amp;quot;nfs-ganesha&amp;quot; service so that it starts being run again&lt;br /&gt;
systemctl start nfs-ganesha&lt;br /&gt;
&lt;br /&gt;
# Disable the &amp;quot;mariadb&amp;quot; service so that it doesn&#039;t start after the next boot&lt;br /&gt;
systemctl disable mariadb&lt;br /&gt;
&lt;br /&gt;
# Enable the &amp;quot;mariadb&amp;quot; service so that it starts after the next boot.&lt;br /&gt;
systemctl enable mariadb&lt;br /&gt;
&lt;br /&gt;
# Check the logs for all failed services&lt;br /&gt;
for i in $(systemctl --state=failed | head -n -4 | tail -n +2 | awk &#039;{print $1}&#039;); do systemctl --no-pager status &amp;quot;$i&amp;quot;; done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== NTP ===&lt;br /&gt;
==== Timedatectl ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show the current status of timedatectl&lt;br /&gt;
timedatectl&lt;br /&gt;
&lt;br /&gt;
# List available timezones&lt;br /&gt;
timedatectl list-timezones&lt;br /&gt;
&lt;br /&gt;
# Set the timezone to Amsterdam&lt;br /&gt;
timedatectl set-timezone Europe/Amsterdam&lt;br /&gt;
&lt;br /&gt;
# Show verbose sync information&lt;br /&gt;
timedatectl timesync-status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SNMP ===&lt;br /&gt;
==== V3 client installation ====&lt;br /&gt;
* https://kifarunix.com/quick-way-to-install-and-configure-snmp-on-ubuntu-20-04/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
apt install snmpd snmp libsnmp-dev&lt;br /&gt;
cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.bak&lt;br /&gt;
systemctl stop snmpd&lt;br /&gt;
net-snmp-create-v3-user -ro -X &amp;lt;CRYPTO-PASSWORD&amp;gt; -a SHA -X &amp;lt;PASSWORD&amp;gt; -x AES &amp;lt;USERNAME&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/snmp/snmpd.conf&lt;br /&gt;
sysLocation    NL;Zuid-Holland;Rotterdam, 78 MyStreet;2nd Floor;Server Room;Rack&lt;br /&gt;
sysContact     Me &amp;lt;me@example.org&amp;gt;&lt;br /&gt;
agentaddress   192.168.0.10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
systemctl start snmpd&lt;br /&gt;
systemctl enable snmpd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Test&lt;br /&gt;
snmpwalk -v3 -a SHA -A &amp;quot;AUTHENTICATION PASSWORD&amp;quot; -x AES -X &amp;quot;CRYPTO PASSWORD&amp;quot; -l authPriv -u &amp;quot;MYUSER&amp;quot; localhost | head&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CTDB  ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Verify CTDB cluster status&lt;br /&gt;
ctdb status&lt;br /&gt;
&lt;br /&gt;
# Show the allocated IP addresses and to which nodes they&#039;re bound&lt;br /&gt;
ctdb ip&lt;br /&gt;
&lt;br /&gt;
# See the status of all CTDB-scripts&lt;br /&gt;
ctdb scriptstatus&lt;br /&gt;
ctdb event status&lt;br /&gt;
&lt;br /&gt;
# Show the time of the last failover the duration it took to recover&lt;br /&gt;
ctdb uptime&lt;br /&gt;
&lt;br /&gt;
# See various statistics and data&lt;br /&gt;
ctdb statistics&lt;br /&gt;
&lt;br /&gt;
# Use the onnode command to execute a command on all cluster nodes&lt;br /&gt;
onnode all ctdb status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Stop a ctdb cluster member&lt;br /&gt;
ctdb stop&lt;br /&gt;
&lt;br /&gt;
# Start a stopped ctdb cluster member&lt;br /&gt;
ctdb continue&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Firewalls ===&lt;br /&gt;
==== UFW ====&lt;br /&gt;
===== Checks =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show summary of UFW status&lt;br /&gt;
ufw status&lt;br /&gt;
&lt;br /&gt;
# Show verbose UFW status&lt;br /&gt;
ufw status verbose&lt;br /&gt;
&lt;br /&gt;
# Show UFW rules numbered&lt;br /&gt;
ufw status numbered&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Commands =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Allow access from a specific IP to a port and add a comment that show in the status&lt;br /&gt;
ufw allow from 10.0.0.253 to any port 22 proto tcp comment &#039;Allow SSH access from XYZ location&#039;&lt;br /&gt;
&lt;br /&gt;
# Delete numbered Firewall rule 56&lt;br /&gt;
ufw delete 56&lt;br /&gt;
&lt;br /&gt;
# Disable UFW logging (prevent syslog spam)&lt;br /&gt;
ufw logging off&lt;br /&gt;
&lt;br /&gt;
# Set UFW logging back to the default&lt;br /&gt;
ufw logging low&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Firewalld ====&lt;br /&gt;
===== SNMP access =====&lt;br /&gt;
* https://unix.stackexchange.com/questions/214388/how-to-let-the-firewall-of-rhel7-the-snmp-connection-passing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/firewalld/services/snmp.xml&lt;br /&gt;
&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;service&amp;gt;&lt;br /&gt;
  &amp;lt;short&amp;gt;SNMP&amp;lt;/short&amp;gt;&lt;br /&gt;
  &amp;lt;description&amp;gt;SNMP protocol&amp;lt;/description&amp;gt;&lt;br /&gt;
  &amp;lt;port protocol=&amp;quot;udp&amp;quot; port=&amp;quot;161&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/service&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
firewall-cmd --zone=public --add-service snmp --permanent&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Firewall-cmd =====&lt;br /&gt;
====== Checks ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all available commands&lt;br /&gt;
firewall-cmd -h&lt;br /&gt;
&lt;br /&gt;
# Check the configuration file of the firewall for errors&lt;br /&gt;
firewall-cmd --check-config&lt;br /&gt;
&lt;br /&gt;
# Display the current state of firewall-cmd (running/shutdown)&lt;br /&gt;
firewall-cmd --state&lt;br /&gt;
&lt;br /&gt;
# Display all available zones&lt;br /&gt;
firewall-cmd --get-zones&lt;br /&gt;
&lt;br /&gt;
# List all whitelisted services&lt;br /&gt;
firewall-cmd --list-services&lt;br /&gt;
&lt;br /&gt;
# List all services you can potentially enable&lt;br /&gt;
firewall-cmd --get-services&lt;br /&gt;
&lt;br /&gt;
# List all added or enabled services and ports in more detail&lt;br /&gt;
firewall-cmd --list-all&lt;br /&gt;
&lt;br /&gt;
# List verbose information for all zones&lt;br /&gt;
firewall-cmd --list-all-zones&lt;br /&gt;
&lt;br /&gt;
# List verbose information for the public zone&lt;br /&gt;
firewall-cmd --list-all --zone=public&lt;br /&gt;
&lt;br /&gt;
# See what port(s) are associated with the dns service&lt;br /&gt;
firewall-cmd --info-service dns&lt;br /&gt;
&lt;br /&gt;
# List all opened ports&lt;br /&gt;
firewall-cmd --list-ports&lt;br /&gt;
&lt;br /&gt;
# List kernel ruleset generated for nftables(?)&lt;br /&gt;
nft list ruleset&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Commands ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reload the firewall&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Whitelist the dns service, persistently even after reboot&lt;br /&gt;
firewall-cmd --add-service=dns ; sudo firewall-cmd --runtime-to-permanent; firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Whitelist the http service, persistently even after reboot&lt;br /&gt;
firewall-cmd --add-service=http ; sudo firewall-cmd --runtime-to-permanent; firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Remove the http service from the whitelist&lt;br /&gt;
firewall-cmd --remove-service=http&lt;br /&gt;
&lt;br /&gt;
# Add port 1234 (tcp) to the whitelist&lt;br /&gt;
firewall-cmd --add-port=1234/tcp&lt;br /&gt;
&lt;br /&gt;
# Remove port 1234 (tcp) from the whitelist&lt;br /&gt;
firewall-cmd --remove-port=1234/tcp&lt;br /&gt;
&lt;br /&gt;
# Add port 2345 (udp) to the whitelist in zone external&lt;br /&gt;
firewall-cmd --zone=external --add-port=2345/udp&lt;br /&gt;
&lt;br /&gt;
# Remove port 2345 (udp) from the whitelist for zone external&lt;br /&gt;
firewall-cmd --zone=external --add-port=2345/udp&lt;br /&gt;
&lt;br /&gt;
# Add current configuration to configuration permanently&lt;br /&gt;
firewall-cmd –runtime-to-permanent&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;DANGEROUS&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# SHUT IT DOWN DOC - DROP ALL PACKETS AND EXPIRE EXISTING CONNECTIONS&lt;br /&gt;
firewall-cmd --panic-on&lt;br /&gt;
&lt;br /&gt;
# ACCEPT PACKETS AGAIN&lt;br /&gt;
firewall-cmd --panic-off&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== CSF ====&lt;br /&gt;
ConfigServer Security and Firewall&lt;br /&gt;
&lt;br /&gt;
===== General =====&lt;br /&gt;
* Common configuration: /etc/csf/csf.conf &lt;br /&gt;
* Blacklist: /etc/csf/csf.deny &lt;br /&gt;
* Whitelist: /etc/csf/csf.allow &lt;br /&gt;
&lt;br /&gt;
===== Installation =====&lt;br /&gt;
From the official instructions: https://download.configserver.com/csf/install.txt&lt;br /&gt;
&lt;br /&gt;
====== Prerequisites ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Perl Modules&lt;br /&gt;
============&lt;br /&gt;
While most should be installed on a standard perl installation the following&lt;br /&gt;
may need to be installed manually:&lt;br /&gt;
&lt;br /&gt;
# On rpm based systems:&lt;br /&gt;
yum install perl-libwww-perl.noarch perl-LWP-Protocol-https.noarch perl-GDGraph&lt;br /&gt;
&lt;br /&gt;
# On APT based systems:&lt;br /&gt;
apt-get install libwww-perl liblwp-protocol-https-perl libgd-graph-perl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Install ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cd /usr/src&lt;br /&gt;
rm -fv csf.tgz&lt;br /&gt;
wget https://download.configserver.com/csf.tgz&lt;br /&gt;
tar -xzf csf.tgz&lt;br /&gt;
cd csf&lt;br /&gt;
sh install.sh&lt;br /&gt;
&lt;br /&gt;
# Next, test whether you have the required iptables modules:&lt;br /&gt;
perl /usr/local/csf/bin/csftest.pl&lt;br /&gt;
&lt;br /&gt;
# Don&#039;t worry if you cannot run all the features, so long as the script doesn&#039;t report any FATAL errors&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Checks =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check the running status of csf&lt;br /&gt;
csf status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Commands =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Commit config changes by restarting csf&lt;br /&gt;
csf -r&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== csf.conf =====&lt;br /&gt;
Some common changes within the configuration file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Set testing to 0 when your CSF configuration is &#039;production&#039; ready&lt;br /&gt;
TESTING = &amp;quot;0&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow access to any service you&#039;re hosting locally, for example https&lt;br /&gt;
TCP_IN = &amp;quot;443&amp;quot;&lt;br /&gt;
UDP_IN = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow all outwards HTTP/HTTPS traffic so you can yum/apt update&lt;br /&gt;
TCP_OUT = &amp;quot;80,443&amp;quot; &lt;br /&gt;
&lt;br /&gt;
# Allow outgoing traceroute&lt;br /&gt;
UDP_OUT = &amp;quot;33434:33523&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow your server to be pinged&lt;br /&gt;
ICMP_IN = &amp;quot;0&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Formatting =====&lt;br /&gt;
The varying styles of formatting used in allow.conf&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Allow anything relating to the following IPs/ranges&lt;br /&gt;
192.168.10.0/24 # Our application breaks without this range&lt;br /&gt;
192.168.1.1 # Our gateway or something&lt;br /&gt;
&lt;br /&gt;
# Detailed entries based on Transport protocol, direction, Application protocol and IP&lt;br /&gt;
tcp:in:d=22:s=7.7.7.7 # SSH access from our VPN&lt;br /&gt;
udp:in:d=161:s=10.11.12.100 # SNMP Access&lt;br /&gt;
tcp|in|d=22|s=fe80::1:/16 # IPV6 SSH access from our jumpgateway&lt;br /&gt;
udp|in|d=3389|s=10.1.0.0/24 # RDP Access from our entire office range&lt;br /&gt;
tcp|out|d=80,443|d=1.2.3.4/32 # Allow outgoing HTTP/HTTPS access via port 80 and 443&lt;br /&gt;
&lt;br /&gt;
# Allow sending Syslog messages to our Syslog server&lt;br /&gt;
udp|out|d=514|d=192.168.20.5 # UDP syslog server&lt;br /&gt;
tcp|out|d=10514|d=192.168.20.5 # UDP syslog server&lt;br /&gt;
&lt;br /&gt;
# Allow sending queries to some DNS servers&lt;br /&gt;
tcp|out|s=53|d=8.8.8.8&lt;br /&gt;
udp|out|s=53|d=1.1.1.1&lt;br /&gt;
udp|out|s=53|d=2606:4700:4700::1111 # Cloudflare IPv6 DNS Server&lt;br /&gt;
&lt;br /&gt;
# Include an external configuration file&lt;br /&gt;
Include /etc/csf/csf.custom-config&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rsyslog ===&lt;br /&gt;
&amp;lt;section begin=&amp;quot;linuxsyslog&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Legacy ====&lt;br /&gt;
* https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/6/html/deployment_guide/s2-templates&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/75-local-to-rsyslog-server.conf&lt;br /&gt;
# Send all logs to a rsyslog server&lt;br /&gt;
*.* @10.77.0.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#/etc/rsyslog.d/70-local-to-rsyslog-server.conf&lt;br /&gt;
# Define the hostname to send to the syslog server, include the priority number as first extra variable&lt;br /&gt;
$template SendHostname, &amp;quot;%PRI%1 %timestamp% myhost.mydomain.nl %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.warning @10.77.0.1;SendHostname&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/60-asd.conf&lt;br /&gt;
# Send messages to a syslog server, using a template aligned to IETF protocol 23, but specifying a custom hostname&lt;br /&gt;
$template custom_IETFprotocol_23,&amp;quot;%PRI%1 %TIMESTAMP:::date-rfc3339% prive.host.nl %APP-NAME% %PROCID% %MSGID% %STRUCTURED-DATA% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* @10.77.0.1;custom_IETFprotocol_23&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/62-asd.conf&lt;br /&gt;
# Log to the local server with a static hostname, using a custom structure&lt;br /&gt;
$template NewHostname, &amp;quot;%timestamp% tester.mydomain.nl %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* /var/log/wewuzerrors.txt;NewHostname&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
## /etc/rsyslog.d/65-customtemplate.conf&lt;br /&gt;
# https://stackoverflow.com/questions/57890176/extending-rsyslogs-default-logging-template&lt;br /&gt;
# An alternative to the contents above, specifying different/more fields&lt;br /&gt;
$template mynewtemplate,&amp;quot;%timegenerated% %HOSTNAME% %syslogfacility-text%.%syslogseverity-text% %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* /var/log/wazanda.txt;mynewtemplate&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rainerscript ====&lt;br /&gt;
Rainerscript: https://rsyslog.readthedocs.io/en/latest/rainerscript/control_structures.html&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/70-local-to-rsyslog-server.conf&lt;br /&gt;
# Define a template and specify a hostname to send as:&lt;br /&gt;
template(name=&amp;quot;SendHostname&amp;quot; type=&amp;quot;string&amp;quot;&lt;br /&gt;
string=&amp;quot;%timestamp% myhost.mydomain.nl %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
# Send logs to target syslog server and port&lt;br /&gt;
*.warning action(type=&amp;quot;omfwd&amp;quot; Target=&amp;quot;10.0.33.10&amp;quot; Template=&amp;quot;SendHostname&amp;quot; Port=&amp;quot;514&amp;quot; Protocol=&amp;quot;udp&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Testing ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use the logger tool to test syslog server reception&lt;br /&gt;
logger -p local0.error &#039;Hello World!&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section end=&amp;quot;linuxsyslog&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== named ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Perform a test load of all primary zones within named.conf, as the named user&lt;br /&gt;
sudo -u named named-checkconf -z&lt;br /&gt;
&lt;br /&gt;
# Check zone file 192.168.77.0 defined in the 77.168.192.in-addr.arpa zone&lt;br /&gt;
named-checkzone 77.168.192.in-addr.arpa 192.168.77.0&lt;br /&gt;
&lt;br /&gt;
# Check zone file brammerloo.nl defined in the brammerloo.nl zone&lt;br /&gt;
named-checkzone brammerloo.nl brammerloo.nl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Basic configuration for the options field in &#039;&#039;&#039;/etc/named.conf&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
options {&lt;br /&gt;
# Define on what IP to listen on, for port 53&lt;br /&gt;
        listen-on port 53 { 127.0.0.1; 192.168.0.1; 192.168.1.1; };&lt;br /&gt;
        directory       &amp;quot;/var/named&amp;quot;;&lt;br /&gt;
        dump-file       &amp;quot;/var/named/data/cache_dump.db&amp;quot;;&lt;br /&gt;
        statistics-file &amp;quot;/var/named/data/named_stats.txt&amp;quot;;&lt;br /&gt;
        memstatistics-file &amp;quot;/var/named/data/named_mem_stats.txt&amp;quot;;&lt;br /&gt;
        secroots-file   &amp;quot;/var/named/data/named.secroots&amp;quot;;&lt;br /&gt;
        recursing-file  &amp;quot;/var/named/data/named.recursing&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# Only allow DNS queries from specific local subnets&lt;br /&gt;
# To allow from anything use: allow query { any; };&lt;br /&gt;
        allow-query     { localhost; 127.0.0.1; 192.168.0.0/24; 192.168.1.0/24; };&lt;br /&gt;
&lt;br /&gt;
# If the server can&#039;t resolve an address locally, use the following DNS servers for help&lt;br /&gt;
        forwarders {&lt;br /&gt;
        8.8.8.8;&lt;br /&gt;
        1.1.1.1;&lt;br /&gt;
        };&lt;br /&gt;
&lt;br /&gt;
        recursion yes;&lt;br /&gt;
        dnssec-validation no;&lt;br /&gt;
&lt;br /&gt;
        managed-keys-directory &amp;quot;/var/named/dynamic&amp;quot;;&lt;br /&gt;
        geoip-directory &amp;quot;/usr/share/GeoIP&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
        pid-file &amp;quot;/run/named/named.pid&amp;quot;;&lt;br /&gt;
        session-keyfile &amp;quot;/run/named/session.key&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
        /* https://fedoraproject.org/wiki/Changes/CryptoPolicy */&lt;br /&gt;
        include &amp;quot;/etc/crypto-policies/back-ends/bind.config&amp;quot;;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone defnitions: &#039;&#039;&#039;/etc/named.rfc1912.zones&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Define zones to listen for&lt;br /&gt;
zone &amp;quot;brammerloo.nl&amp;quot; IN {&lt;br /&gt;
        type master;&lt;br /&gt;
        file &amp;quot;brammerloo.nl&amp;quot;;&lt;br /&gt;
        allow-update { none; };&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
zone &amp;quot;1.168.192.in-addr.arpa&amp;quot; IN {&lt;br /&gt;
        type master;&lt;br /&gt;
        file &amp;quot;192.168.1.0&amp;quot;;&lt;br /&gt;
        allow-update { none; };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone file for Reverse lookup: &#039;&#039;&#039;/var/named/192.168.1.0&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$TTL 300&lt;br /&gt;
@       IN SOA  ns1.brammerloo.nl. admin.brammerloo.nl. (&lt;br /&gt;
                                        2023101102 ; serial&lt;br /&gt;
                                        180     ; refresh&lt;br /&gt;
                                        60      ; retry&lt;br /&gt;
                                        108000  ; expire&lt;br /&gt;
                                        60 )    ; minimum&lt;br /&gt;
    IN      NS      ns1.brammerloo.nl.&lt;br /&gt;
; PTR Records&lt;br /&gt;
11    IN   PTR   node1.&lt;br /&gt;
21    IN   PTR   server1.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone file for domain: &#039;&#039;&#039;/var/named/brammerloo.nl&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$TTL 300&lt;br /&gt;
@       IN SOA  ns1.brammerloo.nl. admin.brammerloo.nl. (&lt;br /&gt;
                                        2023101306 ; serial&lt;br /&gt;
                                        180     ; refresh&lt;br /&gt;
                                        60      ; retry&lt;br /&gt;
                                        108000  ; expire&lt;br /&gt;
                                        60 )    ; minimum&lt;br /&gt;
    IN      NS      ns1.brammerloo.nl.&lt;br /&gt;
@                  IN      A     192.168.1.6   ; domain brammerloo.nl is me!&lt;br /&gt;
ns1.brammerloo.nl. IN      A     192.168.78.31 ; FQDN for my domain&lt;br /&gt;
node1              IN      A     192.168.78.31 ; Basic A-record&lt;br /&gt;
www                IN      CNAME node1         ; Point my website to my node1 A-record&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== dhcpd ===&lt;br /&gt;
==== dhclient ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Request an IPv4 adres from a DHCP server&lt;br /&gt;
dhclient -4&lt;br /&gt;
&lt;br /&gt;
# Show verbose information when requesting an IPv4 adres from a DHCP server&lt;br /&gt;
dhclient -4 -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Basic configuration options in the &#039;&#039;&#039;/etc/dhcp/dhcpd.conf&#039;&#039;&#039; file&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Set the domain clients should use when resolving hostnames (equivalent to search domain)&lt;br /&gt;
option domain-name &amp;quot;brammerloo.nl&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# Set the domain name servers for DHCP clients&lt;br /&gt;
option domain-name-servers ns1.brammerloo.nl, 8.8.8.8;&lt;br /&gt;
&lt;br /&gt;
default-lease-time 600;&lt;br /&gt;
max-lease-time 7200;&lt;br /&gt;
log-facility local7;&lt;br /&gt;
&lt;br /&gt;
# Best practice = define any connected subnets, but don&#039;t configure DHCP for them&lt;br /&gt;
subnet 192.168.1.0 netmask 255.255.255.0 {&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Basic DHCP for a subnet configuration&lt;br /&gt;
subnet 192.168.0.0 netmask 255.255.255.0 {&lt;br /&gt;
  range 192.168.0.100 192.168.0.150;&lt;br /&gt;
  option routers 192.168.0.1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== smbd / Samba / CIFS ===&lt;br /&gt;
https://linuxconfig.org/install-samba-on-redhat-8&lt;br /&gt;
&lt;br /&gt;
==== Basic configuration ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install and enable&lt;br /&gt;
dnf install samba samba-client&lt;br /&gt;
systemctl enable --now {smb,nmb}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a client-user to authenticate with&lt;br /&gt;
sudo useradd samba-user&lt;br /&gt;
&lt;br /&gt;
# Give the user a password to authenticate with&lt;br /&gt;
sudo smbpasswd -a samba-user&lt;br /&gt;
&lt;br /&gt;
# Create a group to associate with the samba share&lt;br /&gt;
sudo groupadd sambagroup&lt;br /&gt;
&lt;br /&gt;
# Add the user to the group we will be configuring for the share&lt;br /&gt;
sudo usermod -a -G sambagroup samba-user&lt;br /&gt;
&lt;br /&gt;
# Create the folder we will be sharing&lt;br /&gt;
sudo mkdir /var/shares/myshare&lt;br /&gt;
&lt;br /&gt;
# Apply proper permission&lt;br /&gt;
sudo chown -R samba-user:sambagroup /var/shares/myshare/&lt;br /&gt;
sudo chmod -R 0770 /var/shares/myshare/&lt;br /&gt;
&lt;br /&gt;
# Apply proper permission for SELinux&lt;br /&gt;
sudo chcon -t samba_share_t /var/shares/myshare/&lt;br /&gt;
&lt;br /&gt;
# Backup the default config&lt;br /&gt;
cp /etc/samba/smb.conf /etc/samba/smb.conf~&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/samba/smb.conf&lt;br /&gt;
[global]&lt;br /&gt;
 workgroup = &amp;lt;DOMAIN-OR-WORKGROUP&amp;gt;&lt;br /&gt;
 server string = Samba Server %v&lt;br /&gt;
 netbios name = &amp;lt;SERVER-HOSTNAME&amp;gt;&lt;br /&gt;
 security = user&lt;br /&gt;
 map to guest = bad user&lt;br /&gt;
 dns proxy = no&lt;br /&gt;
&lt;br /&gt;
#==================== Share Definitions ======================&lt;br /&gt;
[share001]&lt;br /&gt;
 path = /var/shares/myshare&lt;br /&gt;
 valid users = @sambagroup&lt;br /&gt;
 guest ok = no&lt;br /&gt;
 writable = yes&lt;br /&gt;
 browsable = yes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reload Samba services&lt;br /&gt;
systemctl reload {smb,nmb}&lt;br /&gt;
&lt;br /&gt;
# Mount in Windows&lt;br /&gt;
\\&amp;lt;SERVER-IP&amp;gt;\share001&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user: samba-user&lt;br /&gt;
pass: &amp;lt;Whatever password you filled in with smbpasswd -a&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Samba checks&lt;br /&gt;
smbstatus&lt;br /&gt;
smbstatus -S&lt;br /&gt;
smbstatus -b&lt;br /&gt;
&lt;br /&gt;
# Samba set debug mode&lt;br /&gt;
smbcontrol smbd debug 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Docker ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List Docker containers &lt;br /&gt;
docker ps&lt;br /&gt;
&lt;br /&gt;
# List all Docker container IDs&lt;br /&gt;
docker ps -aq&lt;br /&gt;
&lt;br /&gt;
# List logs for container 987sdh3qrasdhj&lt;br /&gt;
docker logs 987sdh3qrasdhj&lt;br /&gt;
&lt;br /&gt;
# List RAM/CPU usage for Docker container asdlkasd67k&lt;br /&gt;
docker stats asdlkasd67k&lt;br /&gt;
&lt;br /&gt;
# Show verbose container information such as commands run, network, ID, etc&lt;br /&gt;
docker inspect oiu2398sda87&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enter the shell inside a docker container&lt;br /&gt;
docker exec -ti a89sd98sa7d /bin/bash&lt;br /&gt;
&lt;br /&gt;
# Execute a command inside a container as a specific user, root in this case&lt;br /&gt;
docker exec -it -u root asd87289hasdadz tail /var/log/nginx/access.log&lt;br /&gt;
docker exec -u 0 -it as892asnj2as /bin/bash&lt;br /&gt;
&lt;br /&gt;
# Restart docker container yoga&lt;br /&gt;
docker restart yoga&lt;br /&gt;
&lt;br /&gt;
# Restart the 3 given containers&lt;br /&gt;
docker restart 79f71c7f4d91 bbb3d3f5c3b1 b0a3204d4098&lt;br /&gt;
&lt;br /&gt;
# Start this container&lt;br /&gt;
docker start as9823nzxc0&lt;br /&gt;
&lt;br /&gt;
# Stop this container&lt;br /&gt;
docker stop as9823nzxc0&lt;br /&gt;
&lt;br /&gt;
# Restart all unhealthy Docker containers&lt;br /&gt;
for i in $(docker ps | grep unhealthy | awk &#039;{print $1}&#039;); do docker restart &amp;quot;$i&amp;quot;; done;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PowerDNS ===&lt;br /&gt;
* https://doc.powerdns.com/authoritative/index.html&lt;br /&gt;
* https://doc.powerdns.com/authoritative/manpages/pdns_server.1.html&lt;br /&gt;
* https://doc.powerdns.com/authoritative/manpages/pdnsutil.1.html&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# List commands&lt;br /&gt;
pdns_server --help&lt;br /&gt;
&lt;br /&gt;
# Check config and parse for errors&lt;br /&gt;
pdns_server --config=check&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# List available commands &lt;br /&gt;
pdnsutil --help&lt;br /&gt;
&lt;br /&gt;
# Check config and parse for errors&lt;br /&gt;
pdnsutil --config=check&lt;br /&gt;
&lt;br /&gt;
# List all available zones&lt;br /&gt;
pdnsutil list-all-zones&lt;br /&gt;
&lt;br /&gt;
# List all domains in the primary zone&lt;br /&gt;
pdnsutil list-all-zones primary&lt;br /&gt;
&lt;br /&gt;
# See zone information for a specific domain&lt;br /&gt;
pdnsutil show-zone mydomain.com&lt;br /&gt;
pdnsutil show-zone 77.5.10.in-addr.arpa&lt;br /&gt;
&lt;br /&gt;
# Check zone for errors&lt;br /&gt;
pdnsutil check-zone mydomain.com&lt;br /&gt;
&lt;br /&gt;
# List all created TSIG keys&lt;br /&gt;
pdnsutil list-tsig-keys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# Activate TSIG key for domain &amp;quot;myexample.com&amp;quot; in the primary zone&lt;br /&gt;
pdnsutil &amp;quot; myexample.com transfer primary&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MAAS ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Logs in either place:&lt;br /&gt;
/var/log/maas/&lt;br /&gt;
/var/snap/maas/common/log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List status of MAAS services&lt;br /&gt;
maas status&lt;br /&gt;
&lt;br /&gt;
# List MAAS commands&lt;br /&gt;
maas --help&lt;br /&gt;
&lt;br /&gt;
# List available arguments for the init command&lt;br /&gt;
maas init --help&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section end=&amp;quot;linuxservices&amp;quot;/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Services&amp;diff=842</id>
		<title>Linux:Services</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Services&amp;diff=842"/>
		<updated>2025-10-01T11:24:47Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* Legacy */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet|Cheatsheets]]&lt;br /&gt;
&lt;br /&gt;
== Services ==&lt;br /&gt;
&amp;lt;section begin=&amp;quot;linuxservices&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Common ===&lt;br /&gt;
==== systemctl ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all services that are running or exited&lt;br /&gt;
systemctl&lt;br /&gt;
&lt;br /&gt;
# List all services, running or otherwise&lt;br /&gt;
systemctl --all&lt;br /&gt;
&lt;br /&gt;
# List all failed services&lt;br /&gt;
systemctl --state=failed&lt;br /&gt;
&lt;br /&gt;
# Reset the failed service &amp;quot;nginx&amp;quot;&lt;br /&gt;
systemctl reset-failed nginx&lt;br /&gt;
&lt;br /&gt;
# View the status of the &amp;quot;nfs-server&amp;quot; service&lt;br /&gt;
systemctl status nfs-server&lt;br /&gt;
&lt;br /&gt;
# Output the config file of &amp;quot;rsyslog&amp;quot; to the shell&lt;br /&gt;
systemctl cat rsyslog&lt;br /&gt;
&lt;br /&gt;
# Restart the &amp;quot;sshd&amp;quot; service, terminating established connections and re-parsing the configuration&lt;br /&gt;
systemctl restart sshd&lt;br /&gt;
&lt;br /&gt;
# Reload the &amp;quot;nginx&amp;quot; service so that it only re-parses the configuration&lt;br /&gt;
systemctl reload nginx&lt;br /&gt;
&lt;br /&gt;
# Stop the &amp;quot;nfs-ganesha&amp;quot; service so that it stops being run&lt;br /&gt;
systemctl stop nfs-ganesha&lt;br /&gt;
&lt;br /&gt;
# Start the &amp;quot;nfs-ganesha&amp;quot; service so that it starts being run again&lt;br /&gt;
systemctl start nfs-ganesha&lt;br /&gt;
&lt;br /&gt;
# Disable the &amp;quot;mariadb&amp;quot; service so that it doesn&#039;t start after the next boot&lt;br /&gt;
systemctl disable mariadb&lt;br /&gt;
&lt;br /&gt;
# Enable the &amp;quot;mariadb&amp;quot; service so that it starts after the next boot.&lt;br /&gt;
systemctl enable mariadb&lt;br /&gt;
&lt;br /&gt;
# Check the logs for all failed services&lt;br /&gt;
for i in $(systemctl --state=failed | head -n -4 | tail -n +2 | awk &#039;{print $1}&#039;); do systemctl --no-pager status &amp;quot;$i&amp;quot;; done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== NTP ===&lt;br /&gt;
==== Timedatectl ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show the current status of timedatectl&lt;br /&gt;
timedatectl&lt;br /&gt;
&lt;br /&gt;
# List available timezones&lt;br /&gt;
timedatectl list-timezones&lt;br /&gt;
&lt;br /&gt;
# Set the timezone to Amsterdam&lt;br /&gt;
timedatectl set-timezone Europe/Amsterdam&lt;br /&gt;
&lt;br /&gt;
# Show verbose sync information&lt;br /&gt;
timedatectl timesync-status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SNMP ===&lt;br /&gt;
==== V3 client installation ====&lt;br /&gt;
* https://kifarunix.com/quick-way-to-install-and-configure-snmp-on-ubuntu-20-04/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
apt install snmpd snmp libsnmp-dev&lt;br /&gt;
cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.bak&lt;br /&gt;
systemctl stop snmpd&lt;br /&gt;
net-snmp-create-v3-user -ro -X &amp;lt;CRYPTO-PASSWORD&amp;gt; -a SHA -X &amp;lt;PASSWORD&amp;gt; -x AES &amp;lt;USERNAME&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/snmp/snmpd.conf&lt;br /&gt;
sysLocation    NL;Zuid-Holland;Rotterdam, 78 MyStreet;2nd Floor;Server Room;Rack&lt;br /&gt;
sysContact     Me &amp;lt;me@example.org&amp;gt;&lt;br /&gt;
agentaddress   192.168.0.10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
systemctl start snmpd&lt;br /&gt;
systemctl enable snmpd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Test&lt;br /&gt;
snmpwalk -v3 -a SHA -A &amp;quot;AUTHENTICATION PASSWORD&amp;quot; -x AES -X &amp;quot;CRYPTO PASSWORD&amp;quot; -l authPriv -u &amp;quot;MYUSER&amp;quot; localhost | head&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CTDB  ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Verify CTDB cluster status&lt;br /&gt;
ctdb status&lt;br /&gt;
&lt;br /&gt;
# Show the allocated IP addresses and to which nodes they&#039;re bound&lt;br /&gt;
ctdb ip&lt;br /&gt;
&lt;br /&gt;
# See the status of all CTDB-scripts&lt;br /&gt;
ctdb scriptstatus&lt;br /&gt;
ctdb event status&lt;br /&gt;
&lt;br /&gt;
# Show the time of the last failover the duration it took to recover&lt;br /&gt;
ctdb uptime&lt;br /&gt;
&lt;br /&gt;
# See various statistics and data&lt;br /&gt;
ctdb statistics&lt;br /&gt;
&lt;br /&gt;
# Use the onnode command to execute a command on all cluster nodes&lt;br /&gt;
onnode all ctdb status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Stop a ctdb cluster member&lt;br /&gt;
ctdb stop&lt;br /&gt;
&lt;br /&gt;
# Start a stopped ctdb cluster member&lt;br /&gt;
ctdb continue&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Firewalls ===&lt;br /&gt;
==== UFW ====&lt;br /&gt;
===== Checks =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show summary of UFW status&lt;br /&gt;
ufw status&lt;br /&gt;
&lt;br /&gt;
# Show verbose UFW status&lt;br /&gt;
ufw status verbose&lt;br /&gt;
&lt;br /&gt;
# Show UFW rules numbered&lt;br /&gt;
ufw status numbered&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Commands =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Allow access from a specific IP to a port and add a comment that show in the status&lt;br /&gt;
ufw allow from 10.0.0.253 to any port 22 proto tcp comment &#039;Allow SSH access from XYZ location&#039;&lt;br /&gt;
&lt;br /&gt;
# Delete numbered Firewall rule 56&lt;br /&gt;
ufw delete 56&lt;br /&gt;
&lt;br /&gt;
# Disable UFW logging (prevent syslog spam)&lt;br /&gt;
ufw logging off&lt;br /&gt;
&lt;br /&gt;
# Set UFW logging back to the default&lt;br /&gt;
ufw logging low&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Firewalld ====&lt;br /&gt;
===== SNMP access =====&lt;br /&gt;
* https://unix.stackexchange.com/questions/214388/how-to-let-the-firewall-of-rhel7-the-snmp-connection-passing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/firewalld/services/snmp.xml&lt;br /&gt;
&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;service&amp;gt;&lt;br /&gt;
  &amp;lt;short&amp;gt;SNMP&amp;lt;/short&amp;gt;&lt;br /&gt;
  &amp;lt;description&amp;gt;SNMP protocol&amp;lt;/description&amp;gt;&lt;br /&gt;
  &amp;lt;port protocol=&amp;quot;udp&amp;quot; port=&amp;quot;161&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/service&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
firewall-cmd --zone=public --add-service snmp --permanent&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Firewall-cmd =====&lt;br /&gt;
====== Checks ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all available commands&lt;br /&gt;
firewall-cmd -h&lt;br /&gt;
&lt;br /&gt;
# Check the configuration file of the firewall for errors&lt;br /&gt;
firewall-cmd --check-config&lt;br /&gt;
&lt;br /&gt;
# Display the current state of firewall-cmd (running/shutdown)&lt;br /&gt;
firewall-cmd --state&lt;br /&gt;
&lt;br /&gt;
# Display all available zones&lt;br /&gt;
firewall-cmd --get-zones&lt;br /&gt;
&lt;br /&gt;
# List all whitelisted services&lt;br /&gt;
firewall-cmd --list-services&lt;br /&gt;
&lt;br /&gt;
# List all services you can potentially enable&lt;br /&gt;
firewall-cmd --get-services&lt;br /&gt;
&lt;br /&gt;
# List all added or enabled services and ports in more detail&lt;br /&gt;
firewall-cmd --list-all&lt;br /&gt;
&lt;br /&gt;
# List verbose information for all zones&lt;br /&gt;
firewall-cmd --list-all-zones&lt;br /&gt;
&lt;br /&gt;
# List verbose information for the public zone&lt;br /&gt;
firewall-cmd --list-all --zone=public&lt;br /&gt;
&lt;br /&gt;
# See what port(s) are associated with the dns service&lt;br /&gt;
firewall-cmd --info-service dns&lt;br /&gt;
&lt;br /&gt;
# List all opened ports&lt;br /&gt;
firewall-cmd --list-ports&lt;br /&gt;
&lt;br /&gt;
# List kernel ruleset generated for nftables(?)&lt;br /&gt;
nft list ruleset&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Commands ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reload the firewall&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Whitelist the dns service, persistently even after reboot&lt;br /&gt;
firewall-cmd --add-service=dns ; sudo firewall-cmd --runtime-to-permanent; firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Whitelist the http service, persistently even after reboot&lt;br /&gt;
firewall-cmd --add-service=http ; sudo firewall-cmd --runtime-to-permanent; firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Remove the http service from the whitelist&lt;br /&gt;
firewall-cmd --remove-service=http&lt;br /&gt;
&lt;br /&gt;
# Add port 1234 (tcp) to the whitelist&lt;br /&gt;
firewall-cmd --add-port=1234/tcp&lt;br /&gt;
&lt;br /&gt;
# Remove port 1234 (tcp) from the whitelist&lt;br /&gt;
firewall-cmd --remove-port=1234/tcp&lt;br /&gt;
&lt;br /&gt;
# Add port 2345 (udp) to the whitelist in zone external&lt;br /&gt;
firewall-cmd --zone=external --add-port=2345/udp&lt;br /&gt;
&lt;br /&gt;
# Remove port 2345 (udp) from the whitelist for zone external&lt;br /&gt;
firewall-cmd --zone=external --add-port=2345/udp&lt;br /&gt;
&lt;br /&gt;
# Add current configuration to configuration permanently&lt;br /&gt;
firewall-cmd –runtime-to-permanent&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;DANGEROUS&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# SHUT IT DOWN DOC - DROP ALL PACKETS AND EXPIRE EXISTING CONNECTIONS&lt;br /&gt;
firewall-cmd --panic-on&lt;br /&gt;
&lt;br /&gt;
# ACCEPT PACKETS AGAIN&lt;br /&gt;
firewall-cmd --panic-off&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== CSF ====&lt;br /&gt;
ConfigServer Security and Firewall&lt;br /&gt;
&lt;br /&gt;
===== General =====&lt;br /&gt;
* Common configuration: /etc/csf/csf.conf &lt;br /&gt;
* Blacklist: /etc/csf/csf.deny &lt;br /&gt;
* Whitelist: /etc/csf/csf.allow &lt;br /&gt;
&lt;br /&gt;
===== Installation =====&lt;br /&gt;
From the official instructions: https://download.configserver.com/csf/install.txt&lt;br /&gt;
&lt;br /&gt;
====== Prerequisites ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Perl Modules&lt;br /&gt;
============&lt;br /&gt;
While most should be installed on a standard perl installation the following&lt;br /&gt;
may need to be installed manually:&lt;br /&gt;
&lt;br /&gt;
# On rpm based systems:&lt;br /&gt;
yum install perl-libwww-perl.noarch perl-LWP-Protocol-https.noarch perl-GDGraph&lt;br /&gt;
&lt;br /&gt;
# On APT based systems:&lt;br /&gt;
apt-get install libwww-perl liblwp-protocol-https-perl libgd-graph-perl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Install ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cd /usr/src&lt;br /&gt;
rm -fv csf.tgz&lt;br /&gt;
wget https://download.configserver.com/csf.tgz&lt;br /&gt;
tar -xzf csf.tgz&lt;br /&gt;
cd csf&lt;br /&gt;
sh install.sh&lt;br /&gt;
&lt;br /&gt;
# Next, test whether you have the required iptables modules:&lt;br /&gt;
perl /usr/local/csf/bin/csftest.pl&lt;br /&gt;
&lt;br /&gt;
# Don&#039;t worry if you cannot run all the features, so long as the script doesn&#039;t report any FATAL errors&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Checks =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check the running status of csf&lt;br /&gt;
csf status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Commands =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Commit config changes by restarting csf&lt;br /&gt;
csf -r&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== csf.conf =====&lt;br /&gt;
Some common changes within the configuration file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Set testing to 0 when your CSF configuration is &#039;production&#039; ready&lt;br /&gt;
TESTING = &amp;quot;0&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow access to any service you&#039;re hosting locally, for example https&lt;br /&gt;
TCP_IN = &amp;quot;443&amp;quot;&lt;br /&gt;
UDP_IN = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow all outwards HTTP/HTTPS traffic so you can yum/apt update&lt;br /&gt;
TCP_OUT = &amp;quot;80,443&amp;quot; &lt;br /&gt;
&lt;br /&gt;
# Allow outgoing traceroute&lt;br /&gt;
UDP_OUT = &amp;quot;33434:33523&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow your server to be pinged&lt;br /&gt;
ICMP_IN = &amp;quot;0&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Formatting =====&lt;br /&gt;
The varying styles of formatting used in allow.conf&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Allow anything relating to the following IPs/ranges&lt;br /&gt;
192.168.10.0/24 # Our application breaks without this range&lt;br /&gt;
192.168.1.1 # Our gateway or something&lt;br /&gt;
&lt;br /&gt;
# Detailed entries based on Transport protocol, direction, Application protocol and IP&lt;br /&gt;
tcp:in:d=22:s=7.7.7.7 # SSH access from our VPN&lt;br /&gt;
udp:in:d=161:s=10.11.12.100 # SNMP Access&lt;br /&gt;
tcp|in|d=22|s=fe80::1:/16 # IPV6 SSH access from our jumpgateway&lt;br /&gt;
udp|in|d=3389|s=10.1.0.0/24 # RDP Access from our entire office range&lt;br /&gt;
tcp|out|d=80,443|d=1.2.3.4/32 # Allow outgoing HTTP/HTTPS access via port 80 and 443&lt;br /&gt;
&lt;br /&gt;
# Allow sending Syslog messages to our Syslog server&lt;br /&gt;
udp|out|d=514|d=192.168.20.5 # UDP syslog server&lt;br /&gt;
tcp|out|d=10514|d=192.168.20.5 # UDP syslog server&lt;br /&gt;
&lt;br /&gt;
# Allow sending queries to some DNS servers&lt;br /&gt;
tcp|out|s=53|d=8.8.8.8&lt;br /&gt;
udp|out|s=53|d=1.1.1.1&lt;br /&gt;
udp|out|s=53|d=2606:4700:4700::1111 # Cloudflare IPv6 DNS Server&lt;br /&gt;
&lt;br /&gt;
# Include an external configuration file&lt;br /&gt;
Include /etc/csf/csf.custom-config&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rsyslog ===&lt;br /&gt;
&amp;lt;section begin=&amp;quot;linuxsyslog&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Legacy ====&lt;br /&gt;
* https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/6/html/deployment_guide/s2-templates&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/75-local-to-rsyslog-server.conf&lt;br /&gt;
# Send all logs to a rsyslog server&lt;br /&gt;
*.* @10.77.0.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#/etc/rsyslog.d/70-local-to-rsyslog-server.conf&lt;br /&gt;
# Define the hostname to send to the syslog server, include the priority number as first extra variable&lt;br /&gt;
$template SendHostname, &amp;quot;%PRI%1 %timestamp% myhost.mydomain.nl %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.warning @10.77.0.1;SendHostname&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/60-asd.conf&lt;br /&gt;
# Send messages to a syslog server, using a template aligned to IETF protocol 23, but specifying a custom hostname&lt;br /&gt;
$template custom_IETFprotocol_23,&amp;quot;%PRI%1 %TIMESTAMP:::date-rfc3339% prive.host.nl %APP-NAME% %PROCID% %MSGID% %STRUCTURED-DATA% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* @10.77.0.1;custom_IETFprotocol_23&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/60-asd.conf&lt;br /&gt;
# Log to the local server with a static hostname, using a custom structure&lt;br /&gt;
$template NewHostname, &amp;quot;%timestamp% tester.mydomain.nl %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* /var/log/wewuzerrors.txt;NewHostname&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
## /etc/rsyslog.d/65-customtemplate.conf&lt;br /&gt;
# https://stackoverflow.com/questions/57890176/extending-rsyslogs-default-logging-template&lt;br /&gt;
# An alternative to the contents above, specifying different/more fields&lt;br /&gt;
$template mynewtemplate,&amp;quot;%timegenerated% %HOSTNAME% %syslogfacility-text%.%syslogseverity-text% %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* /var/log/wazanda.txt;mynewtemplate&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rainerscript ====&lt;br /&gt;
Rainerscript: https://rsyslog.readthedocs.io/en/latest/rainerscript/control_structures.html&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/70-local-to-rsyslog-server.conf&lt;br /&gt;
# Define a template and specify a hostname to send as:&lt;br /&gt;
template(name=&amp;quot;SendHostname&amp;quot; type=&amp;quot;string&amp;quot;&lt;br /&gt;
string=&amp;quot;%timestamp% myhost.mydomain.nl %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
# Send logs to target syslog server and port&lt;br /&gt;
*.warning action(type=&amp;quot;omfwd&amp;quot; Target=&amp;quot;10.0.33.10&amp;quot; Template=&amp;quot;SendHostname&amp;quot; Port=&amp;quot;514&amp;quot; Protocol=&amp;quot;udp&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Testing ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use the logger tool to test syslog server reception&lt;br /&gt;
logger -p local0.error &#039;Hello World!&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section end=&amp;quot;linuxsyslog&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== named ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Perform a test load of all primary zones within named.conf, as the named user&lt;br /&gt;
sudo -u named named-checkconf -z&lt;br /&gt;
&lt;br /&gt;
# Check zone file 192.168.77.0 defined in the 77.168.192.in-addr.arpa zone&lt;br /&gt;
named-checkzone 77.168.192.in-addr.arpa 192.168.77.0&lt;br /&gt;
&lt;br /&gt;
# Check zone file brammerloo.nl defined in the brammerloo.nl zone&lt;br /&gt;
named-checkzone brammerloo.nl brammerloo.nl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Basic configuration for the options field in &#039;&#039;&#039;/etc/named.conf&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
options {&lt;br /&gt;
# Define on what IP to listen on, for port 53&lt;br /&gt;
        listen-on port 53 { 127.0.0.1; 192.168.0.1; 192.168.1.1; };&lt;br /&gt;
        directory       &amp;quot;/var/named&amp;quot;;&lt;br /&gt;
        dump-file       &amp;quot;/var/named/data/cache_dump.db&amp;quot;;&lt;br /&gt;
        statistics-file &amp;quot;/var/named/data/named_stats.txt&amp;quot;;&lt;br /&gt;
        memstatistics-file &amp;quot;/var/named/data/named_mem_stats.txt&amp;quot;;&lt;br /&gt;
        secroots-file   &amp;quot;/var/named/data/named.secroots&amp;quot;;&lt;br /&gt;
        recursing-file  &amp;quot;/var/named/data/named.recursing&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# Only allow DNS queries from specific local subnets&lt;br /&gt;
# To allow from anything use: allow query { any; };&lt;br /&gt;
        allow-query     { localhost; 127.0.0.1; 192.168.0.0/24; 192.168.1.0/24; };&lt;br /&gt;
&lt;br /&gt;
# If the server can&#039;t resolve an address locally, use the following DNS servers for help&lt;br /&gt;
        forwarders {&lt;br /&gt;
        8.8.8.8;&lt;br /&gt;
        1.1.1.1;&lt;br /&gt;
        };&lt;br /&gt;
&lt;br /&gt;
        recursion yes;&lt;br /&gt;
        dnssec-validation no;&lt;br /&gt;
&lt;br /&gt;
        managed-keys-directory &amp;quot;/var/named/dynamic&amp;quot;;&lt;br /&gt;
        geoip-directory &amp;quot;/usr/share/GeoIP&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
        pid-file &amp;quot;/run/named/named.pid&amp;quot;;&lt;br /&gt;
        session-keyfile &amp;quot;/run/named/session.key&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
        /* https://fedoraproject.org/wiki/Changes/CryptoPolicy */&lt;br /&gt;
        include &amp;quot;/etc/crypto-policies/back-ends/bind.config&amp;quot;;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone defnitions: &#039;&#039;&#039;/etc/named.rfc1912.zones&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Define zones to listen for&lt;br /&gt;
zone &amp;quot;brammerloo.nl&amp;quot; IN {&lt;br /&gt;
        type master;&lt;br /&gt;
        file &amp;quot;brammerloo.nl&amp;quot;;&lt;br /&gt;
        allow-update { none; };&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
zone &amp;quot;1.168.192.in-addr.arpa&amp;quot; IN {&lt;br /&gt;
        type master;&lt;br /&gt;
        file &amp;quot;192.168.1.0&amp;quot;;&lt;br /&gt;
        allow-update { none; };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone file for Reverse lookup: &#039;&#039;&#039;/var/named/192.168.1.0&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$TTL 300&lt;br /&gt;
@       IN SOA  ns1.brammerloo.nl. admin.brammerloo.nl. (&lt;br /&gt;
                                        2023101102 ; serial&lt;br /&gt;
                                        180     ; refresh&lt;br /&gt;
                                        60      ; retry&lt;br /&gt;
                                        108000  ; expire&lt;br /&gt;
                                        60 )    ; minimum&lt;br /&gt;
    IN      NS      ns1.brammerloo.nl.&lt;br /&gt;
; PTR Records&lt;br /&gt;
11    IN   PTR   node1.&lt;br /&gt;
21    IN   PTR   server1.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone file for domain: &#039;&#039;&#039;/var/named/brammerloo.nl&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$TTL 300&lt;br /&gt;
@       IN SOA  ns1.brammerloo.nl. admin.brammerloo.nl. (&lt;br /&gt;
                                        2023101306 ; serial&lt;br /&gt;
                                        180     ; refresh&lt;br /&gt;
                                        60      ; retry&lt;br /&gt;
                                        108000  ; expire&lt;br /&gt;
                                        60 )    ; minimum&lt;br /&gt;
    IN      NS      ns1.brammerloo.nl.&lt;br /&gt;
@                  IN      A     192.168.1.6   ; domain brammerloo.nl is me!&lt;br /&gt;
ns1.brammerloo.nl. IN      A     192.168.78.31 ; FQDN for my domain&lt;br /&gt;
node1              IN      A     192.168.78.31 ; Basic A-record&lt;br /&gt;
www                IN      CNAME node1         ; Point my website to my node1 A-record&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== dhcpd ===&lt;br /&gt;
==== dhclient ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Request an IPv4 adres from a DHCP server&lt;br /&gt;
dhclient -4&lt;br /&gt;
&lt;br /&gt;
# Show verbose information when requesting an IPv4 adres from a DHCP server&lt;br /&gt;
dhclient -4 -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Basic configuration options in the &#039;&#039;&#039;/etc/dhcp/dhcpd.conf&#039;&#039;&#039; file&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Set the domain clients should use when resolving hostnames (equivalent to search domain)&lt;br /&gt;
option domain-name &amp;quot;brammerloo.nl&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# Set the domain name servers for DHCP clients&lt;br /&gt;
option domain-name-servers ns1.brammerloo.nl, 8.8.8.8;&lt;br /&gt;
&lt;br /&gt;
default-lease-time 600;&lt;br /&gt;
max-lease-time 7200;&lt;br /&gt;
log-facility local7;&lt;br /&gt;
&lt;br /&gt;
# Best practice = define any connected subnets, but don&#039;t configure DHCP for them&lt;br /&gt;
subnet 192.168.1.0 netmask 255.255.255.0 {&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Basic DHCP for a subnet configuration&lt;br /&gt;
subnet 192.168.0.0 netmask 255.255.255.0 {&lt;br /&gt;
  range 192.168.0.100 192.168.0.150;&lt;br /&gt;
  option routers 192.168.0.1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== smbd / Samba / CIFS ===&lt;br /&gt;
https://linuxconfig.org/install-samba-on-redhat-8&lt;br /&gt;
&lt;br /&gt;
==== Basic configuration ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install and enable&lt;br /&gt;
dnf install samba samba-client&lt;br /&gt;
systemctl enable --now {smb,nmb}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a client-user to authenticate with&lt;br /&gt;
sudo useradd samba-user&lt;br /&gt;
&lt;br /&gt;
# Give the user a password to authenticate with&lt;br /&gt;
sudo smbpasswd -a samba-user&lt;br /&gt;
&lt;br /&gt;
# Create a group to associate with the samba share&lt;br /&gt;
sudo groupadd sambagroup&lt;br /&gt;
&lt;br /&gt;
# Add the user to the group we will be configuring for the share&lt;br /&gt;
sudo usermod -a -G sambagroup samba-user&lt;br /&gt;
&lt;br /&gt;
# Create the folder we will be sharing&lt;br /&gt;
sudo mkdir /var/shares/myshare&lt;br /&gt;
&lt;br /&gt;
# Apply proper permission&lt;br /&gt;
sudo chown -R samba-user:sambagroup /var/shares/myshare/&lt;br /&gt;
sudo chmod -R 0770 /var/shares/myshare/&lt;br /&gt;
&lt;br /&gt;
# Apply proper permission for SELinux&lt;br /&gt;
sudo chcon -t samba_share_t /var/shares/myshare/&lt;br /&gt;
&lt;br /&gt;
# Backup the default config&lt;br /&gt;
cp /etc/samba/smb.conf /etc/samba/smb.conf~&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/samba/smb.conf&lt;br /&gt;
[global]&lt;br /&gt;
 workgroup = &amp;lt;DOMAIN-OR-WORKGROUP&amp;gt;&lt;br /&gt;
 server string = Samba Server %v&lt;br /&gt;
 netbios name = &amp;lt;SERVER-HOSTNAME&amp;gt;&lt;br /&gt;
 security = user&lt;br /&gt;
 map to guest = bad user&lt;br /&gt;
 dns proxy = no&lt;br /&gt;
&lt;br /&gt;
#==================== Share Definitions ======================&lt;br /&gt;
[share001]&lt;br /&gt;
 path = /var/shares/myshare&lt;br /&gt;
 valid users = @sambagroup&lt;br /&gt;
 guest ok = no&lt;br /&gt;
 writable = yes&lt;br /&gt;
 browsable = yes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reload Samba services&lt;br /&gt;
systemctl reload {smb,nmb}&lt;br /&gt;
&lt;br /&gt;
# Mount in Windows&lt;br /&gt;
\\&amp;lt;SERVER-IP&amp;gt;\share001&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user: samba-user&lt;br /&gt;
pass: &amp;lt;Whatever password you filled in with smbpasswd -a&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Samba checks&lt;br /&gt;
smbstatus&lt;br /&gt;
smbstatus -S&lt;br /&gt;
smbstatus -b&lt;br /&gt;
&lt;br /&gt;
# Samba set debug mode&lt;br /&gt;
smbcontrol smbd debug 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Docker ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List Docker containers &lt;br /&gt;
docker ps&lt;br /&gt;
&lt;br /&gt;
# List all Docker container IDs&lt;br /&gt;
docker ps -aq&lt;br /&gt;
&lt;br /&gt;
# List logs for container 987sdh3qrasdhj&lt;br /&gt;
docker logs 987sdh3qrasdhj&lt;br /&gt;
&lt;br /&gt;
# List RAM/CPU usage for Docker container asdlkasd67k&lt;br /&gt;
docker stats asdlkasd67k&lt;br /&gt;
&lt;br /&gt;
# Show verbose container information such as commands run, network, ID, etc&lt;br /&gt;
docker inspect oiu2398sda87&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enter the shell inside a docker container&lt;br /&gt;
docker exec -ti a89sd98sa7d /bin/bash&lt;br /&gt;
&lt;br /&gt;
# Execute a command inside a container as a specific user, root in this case&lt;br /&gt;
docker exec -it -u root asd87289hasdadz tail /var/log/nginx/access.log&lt;br /&gt;
docker exec -u 0 -it as892asnj2as /bin/bash&lt;br /&gt;
&lt;br /&gt;
# Restart docker container yoga&lt;br /&gt;
docker restart yoga&lt;br /&gt;
&lt;br /&gt;
# Restart the 3 given containers&lt;br /&gt;
docker restart 79f71c7f4d91 bbb3d3f5c3b1 b0a3204d4098&lt;br /&gt;
&lt;br /&gt;
# Start this container&lt;br /&gt;
docker start as9823nzxc0&lt;br /&gt;
&lt;br /&gt;
# Stop this container&lt;br /&gt;
docker stop as9823nzxc0&lt;br /&gt;
&lt;br /&gt;
# Restart all unhealthy Docker containers&lt;br /&gt;
for i in $(docker ps | grep unhealthy | awk &#039;{print $1}&#039;); do docker restart &amp;quot;$i&amp;quot;; done;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PowerDNS ===&lt;br /&gt;
* https://doc.powerdns.com/authoritative/index.html&lt;br /&gt;
* https://doc.powerdns.com/authoritative/manpages/pdns_server.1.html&lt;br /&gt;
* https://doc.powerdns.com/authoritative/manpages/pdnsutil.1.html&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# List commands&lt;br /&gt;
pdns_server --help&lt;br /&gt;
&lt;br /&gt;
# Check config and parse for errors&lt;br /&gt;
pdns_server --config=check&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# List available commands &lt;br /&gt;
pdnsutil --help&lt;br /&gt;
&lt;br /&gt;
# Check config and parse for errors&lt;br /&gt;
pdnsutil --config=check&lt;br /&gt;
&lt;br /&gt;
# List all available zones&lt;br /&gt;
pdnsutil list-all-zones&lt;br /&gt;
&lt;br /&gt;
# List all domains in the primary zone&lt;br /&gt;
pdnsutil list-all-zones primary&lt;br /&gt;
&lt;br /&gt;
# See zone information for a specific domain&lt;br /&gt;
pdnsutil show-zone mydomain.com&lt;br /&gt;
pdnsutil show-zone 77.5.10.in-addr.arpa&lt;br /&gt;
&lt;br /&gt;
# Check zone for errors&lt;br /&gt;
pdnsutil check-zone mydomain.com&lt;br /&gt;
&lt;br /&gt;
# List all created TSIG keys&lt;br /&gt;
pdnsutil list-tsig-keys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# Activate TSIG key for domain &amp;quot;myexample.com&amp;quot; in the primary zone&lt;br /&gt;
pdnsutil &amp;quot; myexample.com transfer primary&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MAAS ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Logs in either place:&lt;br /&gt;
/var/log/maas/&lt;br /&gt;
/var/snap/maas/common/log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List status of MAAS services&lt;br /&gt;
maas status&lt;br /&gt;
&lt;br /&gt;
# List MAAS commands&lt;br /&gt;
maas --help&lt;br /&gt;
&lt;br /&gt;
# List available arguments for the init command&lt;br /&gt;
maas init --help&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section end=&amp;quot;linuxservices&amp;quot;/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Services&amp;diff=841</id>
		<title>Linux:Services</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Services&amp;diff=841"/>
		<updated>2025-10-01T11:12:16Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* Legacy */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet|Cheatsheets]]&lt;br /&gt;
&lt;br /&gt;
== Services ==&lt;br /&gt;
&amp;lt;section begin=&amp;quot;linuxservices&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Common ===&lt;br /&gt;
==== systemctl ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all services that are running or exited&lt;br /&gt;
systemctl&lt;br /&gt;
&lt;br /&gt;
# List all services, running or otherwise&lt;br /&gt;
systemctl --all&lt;br /&gt;
&lt;br /&gt;
# List all failed services&lt;br /&gt;
systemctl --state=failed&lt;br /&gt;
&lt;br /&gt;
# Reset the failed service &amp;quot;nginx&amp;quot;&lt;br /&gt;
systemctl reset-failed nginx&lt;br /&gt;
&lt;br /&gt;
# View the status of the &amp;quot;nfs-server&amp;quot; service&lt;br /&gt;
systemctl status nfs-server&lt;br /&gt;
&lt;br /&gt;
# Output the config file of &amp;quot;rsyslog&amp;quot; to the shell&lt;br /&gt;
systemctl cat rsyslog&lt;br /&gt;
&lt;br /&gt;
# Restart the &amp;quot;sshd&amp;quot; service, terminating established connections and re-parsing the configuration&lt;br /&gt;
systemctl restart sshd&lt;br /&gt;
&lt;br /&gt;
# Reload the &amp;quot;nginx&amp;quot; service so that it only re-parses the configuration&lt;br /&gt;
systemctl reload nginx&lt;br /&gt;
&lt;br /&gt;
# Stop the &amp;quot;nfs-ganesha&amp;quot; service so that it stops being run&lt;br /&gt;
systemctl stop nfs-ganesha&lt;br /&gt;
&lt;br /&gt;
# Start the &amp;quot;nfs-ganesha&amp;quot; service so that it starts being run again&lt;br /&gt;
systemctl start nfs-ganesha&lt;br /&gt;
&lt;br /&gt;
# Disable the &amp;quot;mariadb&amp;quot; service so that it doesn&#039;t start after the next boot&lt;br /&gt;
systemctl disable mariadb&lt;br /&gt;
&lt;br /&gt;
# Enable the &amp;quot;mariadb&amp;quot; service so that it starts after the next boot.&lt;br /&gt;
systemctl enable mariadb&lt;br /&gt;
&lt;br /&gt;
# Check the logs for all failed services&lt;br /&gt;
for i in $(systemctl --state=failed | head -n -4 | tail -n +2 | awk &#039;{print $1}&#039;); do systemctl --no-pager status &amp;quot;$i&amp;quot;; done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== NTP ===&lt;br /&gt;
==== Timedatectl ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show the current status of timedatectl&lt;br /&gt;
timedatectl&lt;br /&gt;
&lt;br /&gt;
# List available timezones&lt;br /&gt;
timedatectl list-timezones&lt;br /&gt;
&lt;br /&gt;
# Set the timezone to Amsterdam&lt;br /&gt;
timedatectl set-timezone Europe/Amsterdam&lt;br /&gt;
&lt;br /&gt;
# Show verbose sync information&lt;br /&gt;
timedatectl timesync-status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SNMP ===&lt;br /&gt;
==== V3 client installation ====&lt;br /&gt;
* https://kifarunix.com/quick-way-to-install-and-configure-snmp-on-ubuntu-20-04/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
apt install snmpd snmp libsnmp-dev&lt;br /&gt;
cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.bak&lt;br /&gt;
systemctl stop snmpd&lt;br /&gt;
net-snmp-create-v3-user -ro -X &amp;lt;CRYPTO-PASSWORD&amp;gt; -a SHA -X &amp;lt;PASSWORD&amp;gt; -x AES &amp;lt;USERNAME&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/snmp/snmpd.conf&lt;br /&gt;
sysLocation    NL;Zuid-Holland;Rotterdam, 78 MyStreet;2nd Floor;Server Room;Rack&lt;br /&gt;
sysContact     Me &amp;lt;me@example.org&amp;gt;&lt;br /&gt;
agentaddress   192.168.0.10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
systemctl start snmpd&lt;br /&gt;
systemctl enable snmpd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Test&lt;br /&gt;
snmpwalk -v3 -a SHA -A &amp;quot;AUTHENTICATION PASSWORD&amp;quot; -x AES -X &amp;quot;CRYPTO PASSWORD&amp;quot; -l authPriv -u &amp;quot;MYUSER&amp;quot; localhost | head&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CTDB  ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Verify CTDB cluster status&lt;br /&gt;
ctdb status&lt;br /&gt;
&lt;br /&gt;
# Show the allocated IP addresses and to which nodes they&#039;re bound&lt;br /&gt;
ctdb ip&lt;br /&gt;
&lt;br /&gt;
# See the status of all CTDB-scripts&lt;br /&gt;
ctdb scriptstatus&lt;br /&gt;
ctdb event status&lt;br /&gt;
&lt;br /&gt;
# Show the time of the last failover the duration it took to recover&lt;br /&gt;
ctdb uptime&lt;br /&gt;
&lt;br /&gt;
# See various statistics and data&lt;br /&gt;
ctdb statistics&lt;br /&gt;
&lt;br /&gt;
# Use the onnode command to execute a command on all cluster nodes&lt;br /&gt;
onnode all ctdb status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Stop a ctdb cluster member&lt;br /&gt;
ctdb stop&lt;br /&gt;
&lt;br /&gt;
# Start a stopped ctdb cluster member&lt;br /&gt;
ctdb continue&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Firewalls ===&lt;br /&gt;
==== UFW ====&lt;br /&gt;
===== Checks =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show summary of UFW status&lt;br /&gt;
ufw status&lt;br /&gt;
&lt;br /&gt;
# Show verbose UFW status&lt;br /&gt;
ufw status verbose&lt;br /&gt;
&lt;br /&gt;
# Show UFW rules numbered&lt;br /&gt;
ufw status numbered&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Commands =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Allow access from a specific IP to a port and add a comment that show in the status&lt;br /&gt;
ufw allow from 10.0.0.253 to any port 22 proto tcp comment &#039;Allow SSH access from XYZ location&#039;&lt;br /&gt;
&lt;br /&gt;
# Delete numbered Firewall rule 56&lt;br /&gt;
ufw delete 56&lt;br /&gt;
&lt;br /&gt;
# Disable UFW logging (prevent syslog spam)&lt;br /&gt;
ufw logging off&lt;br /&gt;
&lt;br /&gt;
# Set UFW logging back to the default&lt;br /&gt;
ufw logging low&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Firewalld ====&lt;br /&gt;
===== SNMP access =====&lt;br /&gt;
* https://unix.stackexchange.com/questions/214388/how-to-let-the-firewall-of-rhel7-the-snmp-connection-passing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/firewalld/services/snmp.xml&lt;br /&gt;
&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;service&amp;gt;&lt;br /&gt;
  &amp;lt;short&amp;gt;SNMP&amp;lt;/short&amp;gt;&lt;br /&gt;
  &amp;lt;description&amp;gt;SNMP protocol&amp;lt;/description&amp;gt;&lt;br /&gt;
  &amp;lt;port protocol=&amp;quot;udp&amp;quot; port=&amp;quot;161&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/service&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
firewall-cmd --zone=public --add-service snmp --permanent&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Firewall-cmd =====&lt;br /&gt;
====== Checks ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all available commands&lt;br /&gt;
firewall-cmd -h&lt;br /&gt;
&lt;br /&gt;
# Check the configuration file of the firewall for errors&lt;br /&gt;
firewall-cmd --check-config&lt;br /&gt;
&lt;br /&gt;
# Display the current state of firewall-cmd (running/shutdown)&lt;br /&gt;
firewall-cmd --state&lt;br /&gt;
&lt;br /&gt;
# Display all available zones&lt;br /&gt;
firewall-cmd --get-zones&lt;br /&gt;
&lt;br /&gt;
# List all whitelisted services&lt;br /&gt;
firewall-cmd --list-services&lt;br /&gt;
&lt;br /&gt;
# List all services you can potentially enable&lt;br /&gt;
firewall-cmd --get-services&lt;br /&gt;
&lt;br /&gt;
# List all added or enabled services and ports in more detail&lt;br /&gt;
firewall-cmd --list-all&lt;br /&gt;
&lt;br /&gt;
# List verbose information for all zones&lt;br /&gt;
firewall-cmd --list-all-zones&lt;br /&gt;
&lt;br /&gt;
# List verbose information for the public zone&lt;br /&gt;
firewall-cmd --list-all --zone=public&lt;br /&gt;
&lt;br /&gt;
# See what port(s) are associated with the dns service&lt;br /&gt;
firewall-cmd --info-service dns&lt;br /&gt;
&lt;br /&gt;
# List all opened ports&lt;br /&gt;
firewall-cmd --list-ports&lt;br /&gt;
&lt;br /&gt;
# List kernel ruleset generated for nftables(?)&lt;br /&gt;
nft list ruleset&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Commands ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reload the firewall&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Whitelist the dns service, persistently even after reboot&lt;br /&gt;
firewall-cmd --add-service=dns ; sudo firewall-cmd --runtime-to-permanent; firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Whitelist the http service, persistently even after reboot&lt;br /&gt;
firewall-cmd --add-service=http ; sudo firewall-cmd --runtime-to-permanent; firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Remove the http service from the whitelist&lt;br /&gt;
firewall-cmd --remove-service=http&lt;br /&gt;
&lt;br /&gt;
# Add port 1234 (tcp) to the whitelist&lt;br /&gt;
firewall-cmd --add-port=1234/tcp&lt;br /&gt;
&lt;br /&gt;
# Remove port 1234 (tcp) from the whitelist&lt;br /&gt;
firewall-cmd --remove-port=1234/tcp&lt;br /&gt;
&lt;br /&gt;
# Add port 2345 (udp) to the whitelist in zone external&lt;br /&gt;
firewall-cmd --zone=external --add-port=2345/udp&lt;br /&gt;
&lt;br /&gt;
# Remove port 2345 (udp) from the whitelist for zone external&lt;br /&gt;
firewall-cmd --zone=external --add-port=2345/udp&lt;br /&gt;
&lt;br /&gt;
# Add current configuration to configuration permanently&lt;br /&gt;
firewall-cmd –runtime-to-permanent&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;DANGEROUS&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# SHUT IT DOWN DOC - DROP ALL PACKETS AND EXPIRE EXISTING CONNECTIONS&lt;br /&gt;
firewall-cmd --panic-on&lt;br /&gt;
&lt;br /&gt;
# ACCEPT PACKETS AGAIN&lt;br /&gt;
firewall-cmd --panic-off&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== CSF ====&lt;br /&gt;
ConfigServer Security and Firewall&lt;br /&gt;
&lt;br /&gt;
===== General =====&lt;br /&gt;
* Common configuration: /etc/csf/csf.conf &lt;br /&gt;
* Blacklist: /etc/csf/csf.deny &lt;br /&gt;
* Whitelist: /etc/csf/csf.allow &lt;br /&gt;
&lt;br /&gt;
===== Installation =====&lt;br /&gt;
From the official instructions: https://download.configserver.com/csf/install.txt&lt;br /&gt;
&lt;br /&gt;
====== Prerequisites ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Perl Modules&lt;br /&gt;
============&lt;br /&gt;
While most should be installed on a standard perl installation the following&lt;br /&gt;
may need to be installed manually:&lt;br /&gt;
&lt;br /&gt;
# On rpm based systems:&lt;br /&gt;
yum install perl-libwww-perl.noarch perl-LWP-Protocol-https.noarch perl-GDGraph&lt;br /&gt;
&lt;br /&gt;
# On APT based systems:&lt;br /&gt;
apt-get install libwww-perl liblwp-protocol-https-perl libgd-graph-perl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Install ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cd /usr/src&lt;br /&gt;
rm -fv csf.tgz&lt;br /&gt;
wget https://download.configserver.com/csf.tgz&lt;br /&gt;
tar -xzf csf.tgz&lt;br /&gt;
cd csf&lt;br /&gt;
sh install.sh&lt;br /&gt;
&lt;br /&gt;
# Next, test whether you have the required iptables modules:&lt;br /&gt;
perl /usr/local/csf/bin/csftest.pl&lt;br /&gt;
&lt;br /&gt;
# Don&#039;t worry if you cannot run all the features, so long as the script doesn&#039;t report any FATAL errors&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Checks =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check the running status of csf&lt;br /&gt;
csf status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Commands =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Commit config changes by restarting csf&lt;br /&gt;
csf -r&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== csf.conf =====&lt;br /&gt;
Some common changes within the configuration file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Set testing to 0 when your CSF configuration is &#039;production&#039; ready&lt;br /&gt;
TESTING = &amp;quot;0&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow access to any service you&#039;re hosting locally, for example https&lt;br /&gt;
TCP_IN = &amp;quot;443&amp;quot;&lt;br /&gt;
UDP_IN = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow all outwards HTTP/HTTPS traffic so you can yum/apt update&lt;br /&gt;
TCP_OUT = &amp;quot;80,443&amp;quot; &lt;br /&gt;
&lt;br /&gt;
# Allow outgoing traceroute&lt;br /&gt;
UDP_OUT = &amp;quot;33434:33523&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow your server to be pinged&lt;br /&gt;
ICMP_IN = &amp;quot;0&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Formatting =====&lt;br /&gt;
The varying styles of formatting used in allow.conf&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Allow anything relating to the following IPs/ranges&lt;br /&gt;
192.168.10.0/24 # Our application breaks without this range&lt;br /&gt;
192.168.1.1 # Our gateway or something&lt;br /&gt;
&lt;br /&gt;
# Detailed entries based on Transport protocol, direction, Application protocol and IP&lt;br /&gt;
tcp:in:d=22:s=7.7.7.7 # SSH access from our VPN&lt;br /&gt;
udp:in:d=161:s=10.11.12.100 # SNMP Access&lt;br /&gt;
tcp|in|d=22|s=fe80::1:/16 # IPV6 SSH access from our jumpgateway&lt;br /&gt;
udp|in|d=3389|s=10.1.0.0/24 # RDP Access from our entire office range&lt;br /&gt;
tcp|out|d=80,443|d=1.2.3.4/32 # Allow outgoing HTTP/HTTPS access via port 80 and 443&lt;br /&gt;
&lt;br /&gt;
# Allow sending Syslog messages to our Syslog server&lt;br /&gt;
udp|out|d=514|d=192.168.20.5 # UDP syslog server&lt;br /&gt;
tcp|out|d=10514|d=192.168.20.5 # UDP syslog server&lt;br /&gt;
&lt;br /&gt;
# Allow sending queries to some DNS servers&lt;br /&gt;
tcp|out|s=53|d=8.8.8.8&lt;br /&gt;
udp|out|s=53|d=1.1.1.1&lt;br /&gt;
udp|out|s=53|d=2606:4700:4700::1111 # Cloudflare IPv6 DNS Server&lt;br /&gt;
&lt;br /&gt;
# Include an external configuration file&lt;br /&gt;
Include /etc/csf/csf.custom-config&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rsyslog ===&lt;br /&gt;
&amp;lt;section begin=&amp;quot;linuxsyslog&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Legacy ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#/etc/rsyslog.d/70-local-to-rsyslog-server.conf&lt;br /&gt;
# Define the hostname to send to the syslog server, include the priority number as first extra variable&lt;br /&gt;
$template SendHostname, &amp;quot;&amp;lt;%pri%&amp;gt; %timestamp% myhost.mydomain.nl %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.warning @10.77.0.1;SendHostname&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/60-asd.conf&lt;br /&gt;
# Log to the local server with a static hostname, same structure as regular syslog&lt;br /&gt;
$template NewHostname, &amp;quot;%timestamp% tester.mydomain.nl %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* /var/log/wewuzerrors.txt;NewHostname&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://stackoverflow.com/questions/57890176/extending-rsyslogs-default-logging-template&lt;br /&gt;
# An alternative to the contents above, specifying different/more fields&lt;br /&gt;
$template mynewtemplate,&amp;quot;%timegenerated% %HOSTNAME% %syslogfacility-text%.%syslogseverity-text% %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* /var/log/wazanda.txt;mynewtemplate&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rainerscript ====&lt;br /&gt;
Rainerscript: https://rsyslog.readthedocs.io/en/latest/rainerscript/control_structures.html&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/70-local-to-rsyslog-server.conf&lt;br /&gt;
# Define a template and specify a hostname to send as:&lt;br /&gt;
template(name=&amp;quot;SendHostname&amp;quot; type=&amp;quot;string&amp;quot;&lt;br /&gt;
string=&amp;quot;%timestamp% myhost.mydomain.nl %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
# Send logs to target syslog server and port&lt;br /&gt;
*.warning action(type=&amp;quot;omfwd&amp;quot; Target=&amp;quot;10.0.33.10&amp;quot; Template=&amp;quot;SendHostname&amp;quot; Port=&amp;quot;514&amp;quot; Protocol=&amp;quot;udp&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Testing ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use the logger tool to test syslog server reception&lt;br /&gt;
logger -p local0.error &#039;Hello World!&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section end=&amp;quot;linuxsyslog&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== named ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Perform a test load of all primary zones within named.conf, as the named user&lt;br /&gt;
sudo -u named named-checkconf -z&lt;br /&gt;
&lt;br /&gt;
# Check zone file 192.168.77.0 defined in the 77.168.192.in-addr.arpa zone&lt;br /&gt;
named-checkzone 77.168.192.in-addr.arpa 192.168.77.0&lt;br /&gt;
&lt;br /&gt;
# Check zone file brammerloo.nl defined in the brammerloo.nl zone&lt;br /&gt;
named-checkzone brammerloo.nl brammerloo.nl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Basic configuration for the options field in &#039;&#039;&#039;/etc/named.conf&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
options {&lt;br /&gt;
# Define on what IP to listen on, for port 53&lt;br /&gt;
        listen-on port 53 { 127.0.0.1; 192.168.0.1; 192.168.1.1; };&lt;br /&gt;
        directory       &amp;quot;/var/named&amp;quot;;&lt;br /&gt;
        dump-file       &amp;quot;/var/named/data/cache_dump.db&amp;quot;;&lt;br /&gt;
        statistics-file &amp;quot;/var/named/data/named_stats.txt&amp;quot;;&lt;br /&gt;
        memstatistics-file &amp;quot;/var/named/data/named_mem_stats.txt&amp;quot;;&lt;br /&gt;
        secroots-file   &amp;quot;/var/named/data/named.secroots&amp;quot;;&lt;br /&gt;
        recursing-file  &amp;quot;/var/named/data/named.recursing&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# Only allow DNS queries from specific local subnets&lt;br /&gt;
# To allow from anything use: allow query { any; };&lt;br /&gt;
        allow-query     { localhost; 127.0.0.1; 192.168.0.0/24; 192.168.1.0/24; };&lt;br /&gt;
&lt;br /&gt;
# If the server can&#039;t resolve an address locally, use the following DNS servers for help&lt;br /&gt;
        forwarders {&lt;br /&gt;
        8.8.8.8;&lt;br /&gt;
        1.1.1.1;&lt;br /&gt;
        };&lt;br /&gt;
&lt;br /&gt;
        recursion yes;&lt;br /&gt;
        dnssec-validation no;&lt;br /&gt;
&lt;br /&gt;
        managed-keys-directory &amp;quot;/var/named/dynamic&amp;quot;;&lt;br /&gt;
        geoip-directory &amp;quot;/usr/share/GeoIP&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
        pid-file &amp;quot;/run/named/named.pid&amp;quot;;&lt;br /&gt;
        session-keyfile &amp;quot;/run/named/session.key&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
        /* https://fedoraproject.org/wiki/Changes/CryptoPolicy */&lt;br /&gt;
        include &amp;quot;/etc/crypto-policies/back-ends/bind.config&amp;quot;;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone defnitions: &#039;&#039;&#039;/etc/named.rfc1912.zones&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Define zones to listen for&lt;br /&gt;
zone &amp;quot;brammerloo.nl&amp;quot; IN {&lt;br /&gt;
        type master;&lt;br /&gt;
        file &amp;quot;brammerloo.nl&amp;quot;;&lt;br /&gt;
        allow-update { none; };&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
zone &amp;quot;1.168.192.in-addr.arpa&amp;quot; IN {&lt;br /&gt;
        type master;&lt;br /&gt;
        file &amp;quot;192.168.1.0&amp;quot;;&lt;br /&gt;
        allow-update { none; };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone file for Reverse lookup: &#039;&#039;&#039;/var/named/192.168.1.0&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$TTL 300&lt;br /&gt;
@       IN SOA  ns1.brammerloo.nl. admin.brammerloo.nl. (&lt;br /&gt;
                                        2023101102 ; serial&lt;br /&gt;
                                        180     ; refresh&lt;br /&gt;
                                        60      ; retry&lt;br /&gt;
                                        108000  ; expire&lt;br /&gt;
                                        60 )    ; minimum&lt;br /&gt;
    IN      NS      ns1.brammerloo.nl.&lt;br /&gt;
; PTR Records&lt;br /&gt;
11    IN   PTR   node1.&lt;br /&gt;
21    IN   PTR   server1.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone file for domain: &#039;&#039;&#039;/var/named/brammerloo.nl&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$TTL 300&lt;br /&gt;
@       IN SOA  ns1.brammerloo.nl. admin.brammerloo.nl. (&lt;br /&gt;
                                        2023101306 ; serial&lt;br /&gt;
                                        180     ; refresh&lt;br /&gt;
                                        60      ; retry&lt;br /&gt;
                                        108000  ; expire&lt;br /&gt;
                                        60 )    ; minimum&lt;br /&gt;
    IN      NS      ns1.brammerloo.nl.&lt;br /&gt;
@                  IN      A     192.168.1.6   ; domain brammerloo.nl is me!&lt;br /&gt;
ns1.brammerloo.nl. IN      A     192.168.78.31 ; FQDN for my domain&lt;br /&gt;
node1              IN      A     192.168.78.31 ; Basic A-record&lt;br /&gt;
www                IN      CNAME node1         ; Point my website to my node1 A-record&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== dhcpd ===&lt;br /&gt;
==== dhclient ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Request an IPv4 adres from a DHCP server&lt;br /&gt;
dhclient -4&lt;br /&gt;
&lt;br /&gt;
# Show verbose information when requesting an IPv4 adres from a DHCP server&lt;br /&gt;
dhclient -4 -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Basic configuration options in the &#039;&#039;&#039;/etc/dhcp/dhcpd.conf&#039;&#039;&#039; file&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Set the domain clients should use when resolving hostnames (equivalent to search domain)&lt;br /&gt;
option domain-name &amp;quot;brammerloo.nl&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# Set the domain name servers for DHCP clients&lt;br /&gt;
option domain-name-servers ns1.brammerloo.nl, 8.8.8.8;&lt;br /&gt;
&lt;br /&gt;
default-lease-time 600;&lt;br /&gt;
max-lease-time 7200;&lt;br /&gt;
log-facility local7;&lt;br /&gt;
&lt;br /&gt;
# Best practice = define any connected subnets, but don&#039;t configure DHCP for them&lt;br /&gt;
subnet 192.168.1.0 netmask 255.255.255.0 {&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Basic DHCP for a subnet configuration&lt;br /&gt;
subnet 192.168.0.0 netmask 255.255.255.0 {&lt;br /&gt;
  range 192.168.0.100 192.168.0.150;&lt;br /&gt;
  option routers 192.168.0.1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== smbd / Samba / CIFS ===&lt;br /&gt;
https://linuxconfig.org/install-samba-on-redhat-8&lt;br /&gt;
&lt;br /&gt;
==== Basic configuration ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install and enable&lt;br /&gt;
dnf install samba samba-client&lt;br /&gt;
systemctl enable --now {smb,nmb}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a client-user to authenticate with&lt;br /&gt;
sudo useradd samba-user&lt;br /&gt;
&lt;br /&gt;
# Give the user a password to authenticate with&lt;br /&gt;
sudo smbpasswd -a samba-user&lt;br /&gt;
&lt;br /&gt;
# Create a group to associate with the samba share&lt;br /&gt;
sudo groupadd sambagroup&lt;br /&gt;
&lt;br /&gt;
# Add the user to the group we will be configuring for the share&lt;br /&gt;
sudo usermod -a -G sambagroup samba-user&lt;br /&gt;
&lt;br /&gt;
# Create the folder we will be sharing&lt;br /&gt;
sudo mkdir /var/shares/myshare&lt;br /&gt;
&lt;br /&gt;
# Apply proper permission&lt;br /&gt;
sudo chown -R samba-user:sambagroup /var/shares/myshare/&lt;br /&gt;
sudo chmod -R 0770 /var/shares/myshare/&lt;br /&gt;
&lt;br /&gt;
# Apply proper permission for SELinux&lt;br /&gt;
sudo chcon -t samba_share_t /var/shares/myshare/&lt;br /&gt;
&lt;br /&gt;
# Backup the default config&lt;br /&gt;
cp /etc/samba/smb.conf /etc/samba/smb.conf~&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/samba/smb.conf&lt;br /&gt;
[global]&lt;br /&gt;
 workgroup = &amp;lt;DOMAIN-OR-WORKGROUP&amp;gt;&lt;br /&gt;
 server string = Samba Server %v&lt;br /&gt;
 netbios name = &amp;lt;SERVER-HOSTNAME&amp;gt;&lt;br /&gt;
 security = user&lt;br /&gt;
 map to guest = bad user&lt;br /&gt;
 dns proxy = no&lt;br /&gt;
&lt;br /&gt;
#==================== Share Definitions ======================&lt;br /&gt;
[share001]&lt;br /&gt;
 path = /var/shares/myshare&lt;br /&gt;
 valid users = @sambagroup&lt;br /&gt;
 guest ok = no&lt;br /&gt;
 writable = yes&lt;br /&gt;
 browsable = yes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reload Samba services&lt;br /&gt;
systemctl reload {smb,nmb}&lt;br /&gt;
&lt;br /&gt;
# Mount in Windows&lt;br /&gt;
\\&amp;lt;SERVER-IP&amp;gt;\share001&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user: samba-user&lt;br /&gt;
pass: &amp;lt;Whatever password you filled in with smbpasswd -a&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Samba checks&lt;br /&gt;
smbstatus&lt;br /&gt;
smbstatus -S&lt;br /&gt;
smbstatus -b&lt;br /&gt;
&lt;br /&gt;
# Samba set debug mode&lt;br /&gt;
smbcontrol smbd debug 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Docker ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List Docker containers &lt;br /&gt;
docker ps&lt;br /&gt;
&lt;br /&gt;
# List all Docker container IDs&lt;br /&gt;
docker ps -aq&lt;br /&gt;
&lt;br /&gt;
# List logs for container 987sdh3qrasdhj&lt;br /&gt;
docker logs 987sdh3qrasdhj&lt;br /&gt;
&lt;br /&gt;
# List RAM/CPU usage for Docker container asdlkasd67k&lt;br /&gt;
docker stats asdlkasd67k&lt;br /&gt;
&lt;br /&gt;
# Show verbose container information such as commands run, network, ID, etc&lt;br /&gt;
docker inspect oiu2398sda87&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enter the shell inside a docker container&lt;br /&gt;
docker exec -ti a89sd98sa7d /bin/bash&lt;br /&gt;
&lt;br /&gt;
# Execute a command inside a container as a specific user, root in this case&lt;br /&gt;
docker exec -it -u root asd87289hasdadz tail /var/log/nginx/access.log&lt;br /&gt;
docker exec -u 0 -it as892asnj2as /bin/bash&lt;br /&gt;
&lt;br /&gt;
# Restart docker container yoga&lt;br /&gt;
docker restart yoga&lt;br /&gt;
&lt;br /&gt;
# Restart the 3 given containers&lt;br /&gt;
docker restart 79f71c7f4d91 bbb3d3f5c3b1 b0a3204d4098&lt;br /&gt;
&lt;br /&gt;
# Start this container&lt;br /&gt;
docker start as9823nzxc0&lt;br /&gt;
&lt;br /&gt;
# Stop this container&lt;br /&gt;
docker stop as9823nzxc0&lt;br /&gt;
&lt;br /&gt;
# Restart all unhealthy Docker containers&lt;br /&gt;
for i in $(docker ps | grep unhealthy | awk &#039;{print $1}&#039;); do docker restart &amp;quot;$i&amp;quot;; done;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PowerDNS ===&lt;br /&gt;
* https://doc.powerdns.com/authoritative/index.html&lt;br /&gt;
* https://doc.powerdns.com/authoritative/manpages/pdns_server.1.html&lt;br /&gt;
* https://doc.powerdns.com/authoritative/manpages/pdnsutil.1.html&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# List commands&lt;br /&gt;
pdns_server --help&lt;br /&gt;
&lt;br /&gt;
# Check config and parse for errors&lt;br /&gt;
pdns_server --config=check&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# List available commands &lt;br /&gt;
pdnsutil --help&lt;br /&gt;
&lt;br /&gt;
# Check config and parse for errors&lt;br /&gt;
pdnsutil --config=check&lt;br /&gt;
&lt;br /&gt;
# List all available zones&lt;br /&gt;
pdnsutil list-all-zones&lt;br /&gt;
&lt;br /&gt;
# List all domains in the primary zone&lt;br /&gt;
pdnsutil list-all-zones primary&lt;br /&gt;
&lt;br /&gt;
# See zone information for a specific domain&lt;br /&gt;
pdnsutil show-zone mydomain.com&lt;br /&gt;
pdnsutil show-zone 77.5.10.in-addr.arpa&lt;br /&gt;
&lt;br /&gt;
# Check zone for errors&lt;br /&gt;
pdnsutil check-zone mydomain.com&lt;br /&gt;
&lt;br /&gt;
# List all created TSIG keys&lt;br /&gt;
pdnsutil list-tsig-keys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# Activate TSIG key for domain &amp;quot;myexample.com&amp;quot; in the primary zone&lt;br /&gt;
pdnsutil &amp;quot; myexample.com transfer primary&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MAAS ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Logs in either place:&lt;br /&gt;
/var/log/maas/&lt;br /&gt;
/var/snap/maas/common/log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List status of MAAS services&lt;br /&gt;
maas status&lt;br /&gt;
&lt;br /&gt;
# List MAAS commands&lt;br /&gt;
maas --help&lt;br /&gt;
&lt;br /&gt;
# List available arguments for the init command&lt;br /&gt;
maas init --help&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section end=&amp;quot;linuxservices&amp;quot;/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Services&amp;diff=840</id>
		<title>Linux:Services</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Services&amp;diff=840"/>
		<updated>2025-10-01T11:05:19Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* Legacy */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet|Cheatsheets]]&lt;br /&gt;
&lt;br /&gt;
== Services ==&lt;br /&gt;
&amp;lt;section begin=&amp;quot;linuxservices&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Common ===&lt;br /&gt;
==== systemctl ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all services that are running or exited&lt;br /&gt;
systemctl&lt;br /&gt;
&lt;br /&gt;
# List all services, running or otherwise&lt;br /&gt;
systemctl --all&lt;br /&gt;
&lt;br /&gt;
# List all failed services&lt;br /&gt;
systemctl --state=failed&lt;br /&gt;
&lt;br /&gt;
# Reset the failed service &amp;quot;nginx&amp;quot;&lt;br /&gt;
systemctl reset-failed nginx&lt;br /&gt;
&lt;br /&gt;
# View the status of the &amp;quot;nfs-server&amp;quot; service&lt;br /&gt;
systemctl status nfs-server&lt;br /&gt;
&lt;br /&gt;
# Output the config file of &amp;quot;rsyslog&amp;quot; to the shell&lt;br /&gt;
systemctl cat rsyslog&lt;br /&gt;
&lt;br /&gt;
# Restart the &amp;quot;sshd&amp;quot; service, terminating established connections and re-parsing the configuration&lt;br /&gt;
systemctl restart sshd&lt;br /&gt;
&lt;br /&gt;
# Reload the &amp;quot;nginx&amp;quot; service so that it only re-parses the configuration&lt;br /&gt;
systemctl reload nginx&lt;br /&gt;
&lt;br /&gt;
# Stop the &amp;quot;nfs-ganesha&amp;quot; service so that it stops being run&lt;br /&gt;
systemctl stop nfs-ganesha&lt;br /&gt;
&lt;br /&gt;
# Start the &amp;quot;nfs-ganesha&amp;quot; service so that it starts being run again&lt;br /&gt;
systemctl start nfs-ganesha&lt;br /&gt;
&lt;br /&gt;
# Disable the &amp;quot;mariadb&amp;quot; service so that it doesn&#039;t start after the next boot&lt;br /&gt;
systemctl disable mariadb&lt;br /&gt;
&lt;br /&gt;
# Enable the &amp;quot;mariadb&amp;quot; service so that it starts after the next boot.&lt;br /&gt;
systemctl enable mariadb&lt;br /&gt;
&lt;br /&gt;
# Check the logs for all failed services&lt;br /&gt;
for i in $(systemctl --state=failed | head -n -4 | tail -n +2 | awk &#039;{print $1}&#039;); do systemctl --no-pager status &amp;quot;$i&amp;quot;; done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== NTP ===&lt;br /&gt;
==== Timedatectl ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show the current status of timedatectl&lt;br /&gt;
timedatectl&lt;br /&gt;
&lt;br /&gt;
# List available timezones&lt;br /&gt;
timedatectl list-timezones&lt;br /&gt;
&lt;br /&gt;
# Set the timezone to Amsterdam&lt;br /&gt;
timedatectl set-timezone Europe/Amsterdam&lt;br /&gt;
&lt;br /&gt;
# Show verbose sync information&lt;br /&gt;
timedatectl timesync-status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SNMP ===&lt;br /&gt;
==== V3 client installation ====&lt;br /&gt;
* https://kifarunix.com/quick-way-to-install-and-configure-snmp-on-ubuntu-20-04/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
apt install snmpd snmp libsnmp-dev&lt;br /&gt;
cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.bak&lt;br /&gt;
systemctl stop snmpd&lt;br /&gt;
net-snmp-create-v3-user -ro -X &amp;lt;CRYPTO-PASSWORD&amp;gt; -a SHA -X &amp;lt;PASSWORD&amp;gt; -x AES &amp;lt;USERNAME&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/snmp/snmpd.conf&lt;br /&gt;
sysLocation    NL;Zuid-Holland;Rotterdam, 78 MyStreet;2nd Floor;Server Room;Rack&lt;br /&gt;
sysContact     Me &amp;lt;me@example.org&amp;gt;&lt;br /&gt;
agentaddress   192.168.0.10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
systemctl start snmpd&lt;br /&gt;
systemctl enable snmpd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Test&lt;br /&gt;
snmpwalk -v3 -a SHA -A &amp;quot;AUTHENTICATION PASSWORD&amp;quot; -x AES -X &amp;quot;CRYPTO PASSWORD&amp;quot; -l authPriv -u &amp;quot;MYUSER&amp;quot; localhost | head&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CTDB  ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Verify CTDB cluster status&lt;br /&gt;
ctdb status&lt;br /&gt;
&lt;br /&gt;
# Show the allocated IP addresses and to which nodes they&#039;re bound&lt;br /&gt;
ctdb ip&lt;br /&gt;
&lt;br /&gt;
# See the status of all CTDB-scripts&lt;br /&gt;
ctdb scriptstatus&lt;br /&gt;
ctdb event status&lt;br /&gt;
&lt;br /&gt;
# Show the time of the last failover the duration it took to recover&lt;br /&gt;
ctdb uptime&lt;br /&gt;
&lt;br /&gt;
# See various statistics and data&lt;br /&gt;
ctdb statistics&lt;br /&gt;
&lt;br /&gt;
# Use the onnode command to execute a command on all cluster nodes&lt;br /&gt;
onnode all ctdb status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Stop a ctdb cluster member&lt;br /&gt;
ctdb stop&lt;br /&gt;
&lt;br /&gt;
# Start a stopped ctdb cluster member&lt;br /&gt;
ctdb continue&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Firewalls ===&lt;br /&gt;
==== UFW ====&lt;br /&gt;
===== Checks =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show summary of UFW status&lt;br /&gt;
ufw status&lt;br /&gt;
&lt;br /&gt;
# Show verbose UFW status&lt;br /&gt;
ufw status verbose&lt;br /&gt;
&lt;br /&gt;
# Show UFW rules numbered&lt;br /&gt;
ufw status numbered&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Commands =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Allow access from a specific IP to a port and add a comment that show in the status&lt;br /&gt;
ufw allow from 10.0.0.253 to any port 22 proto tcp comment &#039;Allow SSH access from XYZ location&#039;&lt;br /&gt;
&lt;br /&gt;
# Delete numbered Firewall rule 56&lt;br /&gt;
ufw delete 56&lt;br /&gt;
&lt;br /&gt;
# Disable UFW logging (prevent syslog spam)&lt;br /&gt;
ufw logging off&lt;br /&gt;
&lt;br /&gt;
# Set UFW logging back to the default&lt;br /&gt;
ufw logging low&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Firewalld ====&lt;br /&gt;
===== SNMP access =====&lt;br /&gt;
* https://unix.stackexchange.com/questions/214388/how-to-let-the-firewall-of-rhel7-the-snmp-connection-passing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/firewalld/services/snmp.xml&lt;br /&gt;
&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;service&amp;gt;&lt;br /&gt;
  &amp;lt;short&amp;gt;SNMP&amp;lt;/short&amp;gt;&lt;br /&gt;
  &amp;lt;description&amp;gt;SNMP protocol&amp;lt;/description&amp;gt;&lt;br /&gt;
  &amp;lt;port protocol=&amp;quot;udp&amp;quot; port=&amp;quot;161&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/service&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
firewall-cmd --zone=public --add-service snmp --permanent&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Firewall-cmd =====&lt;br /&gt;
====== Checks ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all available commands&lt;br /&gt;
firewall-cmd -h&lt;br /&gt;
&lt;br /&gt;
# Check the configuration file of the firewall for errors&lt;br /&gt;
firewall-cmd --check-config&lt;br /&gt;
&lt;br /&gt;
# Display the current state of firewall-cmd (running/shutdown)&lt;br /&gt;
firewall-cmd --state&lt;br /&gt;
&lt;br /&gt;
# Display all available zones&lt;br /&gt;
firewall-cmd --get-zones&lt;br /&gt;
&lt;br /&gt;
# List all whitelisted services&lt;br /&gt;
firewall-cmd --list-services&lt;br /&gt;
&lt;br /&gt;
# List all services you can potentially enable&lt;br /&gt;
firewall-cmd --get-services&lt;br /&gt;
&lt;br /&gt;
# List all added or enabled services and ports in more detail&lt;br /&gt;
firewall-cmd --list-all&lt;br /&gt;
&lt;br /&gt;
# List verbose information for all zones&lt;br /&gt;
firewall-cmd --list-all-zones&lt;br /&gt;
&lt;br /&gt;
# List verbose information for the public zone&lt;br /&gt;
firewall-cmd --list-all --zone=public&lt;br /&gt;
&lt;br /&gt;
# See what port(s) are associated with the dns service&lt;br /&gt;
firewall-cmd --info-service dns&lt;br /&gt;
&lt;br /&gt;
# List all opened ports&lt;br /&gt;
firewall-cmd --list-ports&lt;br /&gt;
&lt;br /&gt;
# List kernel ruleset generated for nftables(?)&lt;br /&gt;
nft list ruleset&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Commands ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reload the firewall&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Whitelist the dns service, persistently even after reboot&lt;br /&gt;
firewall-cmd --add-service=dns ; sudo firewall-cmd --runtime-to-permanent; firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Whitelist the http service, persistently even after reboot&lt;br /&gt;
firewall-cmd --add-service=http ; sudo firewall-cmd --runtime-to-permanent; firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Remove the http service from the whitelist&lt;br /&gt;
firewall-cmd --remove-service=http&lt;br /&gt;
&lt;br /&gt;
# Add port 1234 (tcp) to the whitelist&lt;br /&gt;
firewall-cmd --add-port=1234/tcp&lt;br /&gt;
&lt;br /&gt;
# Remove port 1234 (tcp) from the whitelist&lt;br /&gt;
firewall-cmd --remove-port=1234/tcp&lt;br /&gt;
&lt;br /&gt;
# Add port 2345 (udp) to the whitelist in zone external&lt;br /&gt;
firewall-cmd --zone=external --add-port=2345/udp&lt;br /&gt;
&lt;br /&gt;
# Remove port 2345 (udp) from the whitelist for zone external&lt;br /&gt;
firewall-cmd --zone=external --add-port=2345/udp&lt;br /&gt;
&lt;br /&gt;
# Add current configuration to configuration permanently&lt;br /&gt;
firewall-cmd –runtime-to-permanent&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;DANGEROUS&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# SHUT IT DOWN DOC - DROP ALL PACKETS AND EXPIRE EXISTING CONNECTIONS&lt;br /&gt;
firewall-cmd --panic-on&lt;br /&gt;
&lt;br /&gt;
# ACCEPT PACKETS AGAIN&lt;br /&gt;
firewall-cmd --panic-off&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== CSF ====&lt;br /&gt;
ConfigServer Security and Firewall&lt;br /&gt;
&lt;br /&gt;
===== General =====&lt;br /&gt;
* Common configuration: /etc/csf/csf.conf &lt;br /&gt;
* Blacklist: /etc/csf/csf.deny &lt;br /&gt;
* Whitelist: /etc/csf/csf.allow &lt;br /&gt;
&lt;br /&gt;
===== Installation =====&lt;br /&gt;
From the official instructions: https://download.configserver.com/csf/install.txt&lt;br /&gt;
&lt;br /&gt;
====== Prerequisites ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Perl Modules&lt;br /&gt;
============&lt;br /&gt;
While most should be installed on a standard perl installation the following&lt;br /&gt;
may need to be installed manually:&lt;br /&gt;
&lt;br /&gt;
# On rpm based systems:&lt;br /&gt;
yum install perl-libwww-perl.noarch perl-LWP-Protocol-https.noarch perl-GDGraph&lt;br /&gt;
&lt;br /&gt;
# On APT based systems:&lt;br /&gt;
apt-get install libwww-perl liblwp-protocol-https-perl libgd-graph-perl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Install ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cd /usr/src&lt;br /&gt;
rm -fv csf.tgz&lt;br /&gt;
wget https://download.configserver.com/csf.tgz&lt;br /&gt;
tar -xzf csf.tgz&lt;br /&gt;
cd csf&lt;br /&gt;
sh install.sh&lt;br /&gt;
&lt;br /&gt;
# Next, test whether you have the required iptables modules:&lt;br /&gt;
perl /usr/local/csf/bin/csftest.pl&lt;br /&gt;
&lt;br /&gt;
# Don&#039;t worry if you cannot run all the features, so long as the script doesn&#039;t report any FATAL errors&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Checks =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check the running status of csf&lt;br /&gt;
csf status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Commands =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Commit config changes by restarting csf&lt;br /&gt;
csf -r&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== csf.conf =====&lt;br /&gt;
Some common changes within the configuration file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Set testing to 0 when your CSF configuration is &#039;production&#039; ready&lt;br /&gt;
TESTING = &amp;quot;0&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow access to any service you&#039;re hosting locally, for example https&lt;br /&gt;
TCP_IN = &amp;quot;443&amp;quot;&lt;br /&gt;
UDP_IN = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow all outwards HTTP/HTTPS traffic so you can yum/apt update&lt;br /&gt;
TCP_OUT = &amp;quot;80,443&amp;quot; &lt;br /&gt;
&lt;br /&gt;
# Allow outgoing traceroute&lt;br /&gt;
UDP_OUT = &amp;quot;33434:33523&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow your server to be pinged&lt;br /&gt;
ICMP_IN = &amp;quot;0&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Formatting =====&lt;br /&gt;
The varying styles of formatting used in allow.conf&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Allow anything relating to the following IPs/ranges&lt;br /&gt;
192.168.10.0/24 # Our application breaks without this range&lt;br /&gt;
192.168.1.1 # Our gateway or something&lt;br /&gt;
&lt;br /&gt;
# Detailed entries based on Transport protocol, direction, Application protocol and IP&lt;br /&gt;
tcp:in:d=22:s=7.7.7.7 # SSH access from our VPN&lt;br /&gt;
udp:in:d=161:s=10.11.12.100 # SNMP Access&lt;br /&gt;
tcp|in|d=22|s=fe80::1:/16 # IPV6 SSH access from our jumpgateway&lt;br /&gt;
udp|in|d=3389|s=10.1.0.0/24 # RDP Access from our entire office range&lt;br /&gt;
tcp|out|d=80,443|d=1.2.3.4/32 # Allow outgoing HTTP/HTTPS access via port 80 and 443&lt;br /&gt;
&lt;br /&gt;
# Allow sending Syslog messages to our Syslog server&lt;br /&gt;
udp|out|d=514|d=192.168.20.5 # UDP syslog server&lt;br /&gt;
tcp|out|d=10514|d=192.168.20.5 # UDP syslog server&lt;br /&gt;
&lt;br /&gt;
# Allow sending queries to some DNS servers&lt;br /&gt;
tcp|out|s=53|d=8.8.8.8&lt;br /&gt;
udp|out|s=53|d=1.1.1.1&lt;br /&gt;
udp|out|s=53|d=2606:4700:4700::1111 # Cloudflare IPv6 DNS Server&lt;br /&gt;
&lt;br /&gt;
# Include an external configuration file&lt;br /&gt;
Include /etc/csf/csf.custom-config&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rsyslog ===&lt;br /&gt;
&amp;lt;section begin=&amp;quot;linuxsyslog&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Legacy ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#/etc/rsyslog.d/70-local-to-rsyslog-server.conf&lt;br /&gt;
# Define the hostname to send to the syslog server, include the priority number as first extra variable&lt;br /&gt;
$template SendHostname, &amp;quot;&amp;lt;%pri%&amp;gt; %timestamp% myhost.mydomain.nl %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.warning @10.77.0.1;SendHostname&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/60-asd.conf&lt;br /&gt;
# Log to the local server with a static hostname, same structure as regular syslog&lt;br /&gt;
$template NewHostname, &amp;quot;%timestamp% tester.mydomain.nl %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* /var/log/wewuzerrors.txt;NewHostname&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rainerscript ====&lt;br /&gt;
Rainerscript: https://rsyslog.readthedocs.io/en/latest/rainerscript/control_structures.html&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/70-local-to-rsyslog-server.conf&lt;br /&gt;
# Define a template and specify a hostname to send as:&lt;br /&gt;
template(name=&amp;quot;SendHostname&amp;quot; type=&amp;quot;string&amp;quot;&lt;br /&gt;
string=&amp;quot;%timestamp% myhost.mydomain.nl %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
# Send logs to target syslog server and port&lt;br /&gt;
*.warning action(type=&amp;quot;omfwd&amp;quot; Target=&amp;quot;10.0.33.10&amp;quot; Template=&amp;quot;SendHostname&amp;quot; Port=&amp;quot;514&amp;quot; Protocol=&amp;quot;udp&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Testing ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use the logger tool to test syslog server reception&lt;br /&gt;
logger -p local0.error &#039;Hello World!&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section end=&amp;quot;linuxsyslog&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== named ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Perform a test load of all primary zones within named.conf, as the named user&lt;br /&gt;
sudo -u named named-checkconf -z&lt;br /&gt;
&lt;br /&gt;
# Check zone file 192.168.77.0 defined in the 77.168.192.in-addr.arpa zone&lt;br /&gt;
named-checkzone 77.168.192.in-addr.arpa 192.168.77.0&lt;br /&gt;
&lt;br /&gt;
# Check zone file brammerloo.nl defined in the brammerloo.nl zone&lt;br /&gt;
named-checkzone brammerloo.nl brammerloo.nl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Basic configuration for the options field in &#039;&#039;&#039;/etc/named.conf&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
options {&lt;br /&gt;
# Define on what IP to listen on, for port 53&lt;br /&gt;
        listen-on port 53 { 127.0.0.1; 192.168.0.1; 192.168.1.1; };&lt;br /&gt;
        directory       &amp;quot;/var/named&amp;quot;;&lt;br /&gt;
        dump-file       &amp;quot;/var/named/data/cache_dump.db&amp;quot;;&lt;br /&gt;
        statistics-file &amp;quot;/var/named/data/named_stats.txt&amp;quot;;&lt;br /&gt;
        memstatistics-file &amp;quot;/var/named/data/named_mem_stats.txt&amp;quot;;&lt;br /&gt;
        secroots-file   &amp;quot;/var/named/data/named.secroots&amp;quot;;&lt;br /&gt;
        recursing-file  &amp;quot;/var/named/data/named.recursing&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# Only allow DNS queries from specific local subnets&lt;br /&gt;
# To allow from anything use: allow query { any; };&lt;br /&gt;
        allow-query     { localhost; 127.0.0.1; 192.168.0.0/24; 192.168.1.0/24; };&lt;br /&gt;
&lt;br /&gt;
# If the server can&#039;t resolve an address locally, use the following DNS servers for help&lt;br /&gt;
        forwarders {&lt;br /&gt;
        8.8.8.8;&lt;br /&gt;
        1.1.1.1;&lt;br /&gt;
        };&lt;br /&gt;
&lt;br /&gt;
        recursion yes;&lt;br /&gt;
        dnssec-validation no;&lt;br /&gt;
&lt;br /&gt;
        managed-keys-directory &amp;quot;/var/named/dynamic&amp;quot;;&lt;br /&gt;
        geoip-directory &amp;quot;/usr/share/GeoIP&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
        pid-file &amp;quot;/run/named/named.pid&amp;quot;;&lt;br /&gt;
        session-keyfile &amp;quot;/run/named/session.key&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
        /* https://fedoraproject.org/wiki/Changes/CryptoPolicy */&lt;br /&gt;
        include &amp;quot;/etc/crypto-policies/back-ends/bind.config&amp;quot;;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone defnitions: &#039;&#039;&#039;/etc/named.rfc1912.zones&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Define zones to listen for&lt;br /&gt;
zone &amp;quot;brammerloo.nl&amp;quot; IN {&lt;br /&gt;
        type master;&lt;br /&gt;
        file &amp;quot;brammerloo.nl&amp;quot;;&lt;br /&gt;
        allow-update { none; };&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
zone &amp;quot;1.168.192.in-addr.arpa&amp;quot; IN {&lt;br /&gt;
        type master;&lt;br /&gt;
        file &amp;quot;192.168.1.0&amp;quot;;&lt;br /&gt;
        allow-update { none; };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone file for Reverse lookup: &#039;&#039;&#039;/var/named/192.168.1.0&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$TTL 300&lt;br /&gt;
@       IN SOA  ns1.brammerloo.nl. admin.brammerloo.nl. (&lt;br /&gt;
                                        2023101102 ; serial&lt;br /&gt;
                                        180     ; refresh&lt;br /&gt;
                                        60      ; retry&lt;br /&gt;
                                        108000  ; expire&lt;br /&gt;
                                        60 )    ; minimum&lt;br /&gt;
    IN      NS      ns1.brammerloo.nl.&lt;br /&gt;
; PTR Records&lt;br /&gt;
11    IN   PTR   node1.&lt;br /&gt;
21    IN   PTR   server1.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone file for domain: &#039;&#039;&#039;/var/named/brammerloo.nl&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$TTL 300&lt;br /&gt;
@       IN SOA  ns1.brammerloo.nl. admin.brammerloo.nl. (&lt;br /&gt;
                                        2023101306 ; serial&lt;br /&gt;
                                        180     ; refresh&lt;br /&gt;
                                        60      ; retry&lt;br /&gt;
                                        108000  ; expire&lt;br /&gt;
                                        60 )    ; minimum&lt;br /&gt;
    IN      NS      ns1.brammerloo.nl.&lt;br /&gt;
@                  IN      A     192.168.1.6   ; domain brammerloo.nl is me!&lt;br /&gt;
ns1.brammerloo.nl. IN      A     192.168.78.31 ; FQDN for my domain&lt;br /&gt;
node1              IN      A     192.168.78.31 ; Basic A-record&lt;br /&gt;
www                IN      CNAME node1         ; Point my website to my node1 A-record&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== dhcpd ===&lt;br /&gt;
==== dhclient ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Request an IPv4 adres from a DHCP server&lt;br /&gt;
dhclient -4&lt;br /&gt;
&lt;br /&gt;
# Show verbose information when requesting an IPv4 adres from a DHCP server&lt;br /&gt;
dhclient -4 -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Basic configuration options in the &#039;&#039;&#039;/etc/dhcp/dhcpd.conf&#039;&#039;&#039; file&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Set the domain clients should use when resolving hostnames (equivalent to search domain)&lt;br /&gt;
option domain-name &amp;quot;brammerloo.nl&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# Set the domain name servers for DHCP clients&lt;br /&gt;
option domain-name-servers ns1.brammerloo.nl, 8.8.8.8;&lt;br /&gt;
&lt;br /&gt;
default-lease-time 600;&lt;br /&gt;
max-lease-time 7200;&lt;br /&gt;
log-facility local7;&lt;br /&gt;
&lt;br /&gt;
# Best practice = define any connected subnets, but don&#039;t configure DHCP for them&lt;br /&gt;
subnet 192.168.1.0 netmask 255.255.255.0 {&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Basic DHCP for a subnet configuration&lt;br /&gt;
subnet 192.168.0.0 netmask 255.255.255.0 {&lt;br /&gt;
  range 192.168.0.100 192.168.0.150;&lt;br /&gt;
  option routers 192.168.0.1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== smbd / Samba / CIFS ===&lt;br /&gt;
https://linuxconfig.org/install-samba-on-redhat-8&lt;br /&gt;
&lt;br /&gt;
==== Basic configuration ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install and enable&lt;br /&gt;
dnf install samba samba-client&lt;br /&gt;
systemctl enable --now {smb,nmb}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a client-user to authenticate with&lt;br /&gt;
sudo useradd samba-user&lt;br /&gt;
&lt;br /&gt;
# Give the user a password to authenticate with&lt;br /&gt;
sudo smbpasswd -a samba-user&lt;br /&gt;
&lt;br /&gt;
# Create a group to associate with the samba share&lt;br /&gt;
sudo groupadd sambagroup&lt;br /&gt;
&lt;br /&gt;
# Add the user to the group we will be configuring for the share&lt;br /&gt;
sudo usermod -a -G sambagroup samba-user&lt;br /&gt;
&lt;br /&gt;
# Create the folder we will be sharing&lt;br /&gt;
sudo mkdir /var/shares/myshare&lt;br /&gt;
&lt;br /&gt;
# Apply proper permission&lt;br /&gt;
sudo chown -R samba-user:sambagroup /var/shares/myshare/&lt;br /&gt;
sudo chmod -R 0770 /var/shares/myshare/&lt;br /&gt;
&lt;br /&gt;
# Apply proper permission for SELinux&lt;br /&gt;
sudo chcon -t samba_share_t /var/shares/myshare/&lt;br /&gt;
&lt;br /&gt;
# Backup the default config&lt;br /&gt;
cp /etc/samba/smb.conf /etc/samba/smb.conf~&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/samba/smb.conf&lt;br /&gt;
[global]&lt;br /&gt;
 workgroup = &amp;lt;DOMAIN-OR-WORKGROUP&amp;gt;&lt;br /&gt;
 server string = Samba Server %v&lt;br /&gt;
 netbios name = &amp;lt;SERVER-HOSTNAME&amp;gt;&lt;br /&gt;
 security = user&lt;br /&gt;
 map to guest = bad user&lt;br /&gt;
 dns proxy = no&lt;br /&gt;
&lt;br /&gt;
#==================== Share Definitions ======================&lt;br /&gt;
[share001]&lt;br /&gt;
 path = /var/shares/myshare&lt;br /&gt;
 valid users = @sambagroup&lt;br /&gt;
 guest ok = no&lt;br /&gt;
 writable = yes&lt;br /&gt;
 browsable = yes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reload Samba services&lt;br /&gt;
systemctl reload {smb,nmb}&lt;br /&gt;
&lt;br /&gt;
# Mount in Windows&lt;br /&gt;
\\&amp;lt;SERVER-IP&amp;gt;\share001&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user: samba-user&lt;br /&gt;
pass: &amp;lt;Whatever password you filled in with smbpasswd -a&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Samba checks&lt;br /&gt;
smbstatus&lt;br /&gt;
smbstatus -S&lt;br /&gt;
smbstatus -b&lt;br /&gt;
&lt;br /&gt;
# Samba set debug mode&lt;br /&gt;
smbcontrol smbd debug 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Docker ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List Docker containers &lt;br /&gt;
docker ps&lt;br /&gt;
&lt;br /&gt;
# List all Docker container IDs&lt;br /&gt;
docker ps -aq&lt;br /&gt;
&lt;br /&gt;
# List logs for container 987sdh3qrasdhj&lt;br /&gt;
docker logs 987sdh3qrasdhj&lt;br /&gt;
&lt;br /&gt;
# List RAM/CPU usage for Docker container asdlkasd67k&lt;br /&gt;
docker stats asdlkasd67k&lt;br /&gt;
&lt;br /&gt;
# Show verbose container information such as commands run, network, ID, etc&lt;br /&gt;
docker inspect oiu2398sda87&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enter the shell inside a docker container&lt;br /&gt;
docker exec -ti a89sd98sa7d /bin/bash&lt;br /&gt;
&lt;br /&gt;
# Execute a command inside a container as a specific user, root in this case&lt;br /&gt;
docker exec -it -u root asd87289hasdadz tail /var/log/nginx/access.log&lt;br /&gt;
docker exec -u 0 -it as892asnj2as /bin/bash&lt;br /&gt;
&lt;br /&gt;
# Restart docker container yoga&lt;br /&gt;
docker restart yoga&lt;br /&gt;
&lt;br /&gt;
# Restart the 3 given containers&lt;br /&gt;
docker restart 79f71c7f4d91 bbb3d3f5c3b1 b0a3204d4098&lt;br /&gt;
&lt;br /&gt;
# Start this container&lt;br /&gt;
docker start as9823nzxc0&lt;br /&gt;
&lt;br /&gt;
# Stop this container&lt;br /&gt;
docker stop as9823nzxc0&lt;br /&gt;
&lt;br /&gt;
# Restart all unhealthy Docker containers&lt;br /&gt;
for i in $(docker ps | grep unhealthy | awk &#039;{print $1}&#039;); do docker restart &amp;quot;$i&amp;quot;; done;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PowerDNS ===&lt;br /&gt;
* https://doc.powerdns.com/authoritative/index.html&lt;br /&gt;
* https://doc.powerdns.com/authoritative/manpages/pdns_server.1.html&lt;br /&gt;
* https://doc.powerdns.com/authoritative/manpages/pdnsutil.1.html&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# List commands&lt;br /&gt;
pdns_server --help&lt;br /&gt;
&lt;br /&gt;
# Check config and parse for errors&lt;br /&gt;
pdns_server --config=check&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# List available commands &lt;br /&gt;
pdnsutil --help&lt;br /&gt;
&lt;br /&gt;
# Check config and parse for errors&lt;br /&gt;
pdnsutil --config=check&lt;br /&gt;
&lt;br /&gt;
# List all available zones&lt;br /&gt;
pdnsutil list-all-zones&lt;br /&gt;
&lt;br /&gt;
# List all domains in the primary zone&lt;br /&gt;
pdnsutil list-all-zones primary&lt;br /&gt;
&lt;br /&gt;
# See zone information for a specific domain&lt;br /&gt;
pdnsutil show-zone mydomain.com&lt;br /&gt;
pdnsutil show-zone 77.5.10.in-addr.arpa&lt;br /&gt;
&lt;br /&gt;
# Check zone for errors&lt;br /&gt;
pdnsutil check-zone mydomain.com&lt;br /&gt;
&lt;br /&gt;
# List all created TSIG keys&lt;br /&gt;
pdnsutil list-tsig-keys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# Activate TSIG key for domain &amp;quot;myexample.com&amp;quot; in the primary zone&lt;br /&gt;
pdnsutil &amp;quot; myexample.com transfer primary&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MAAS ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Logs in either place:&lt;br /&gt;
/var/log/maas/&lt;br /&gt;
/var/snap/maas/common/log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List status of MAAS services&lt;br /&gt;
maas status&lt;br /&gt;
&lt;br /&gt;
# List MAAS commands&lt;br /&gt;
maas --help&lt;br /&gt;
&lt;br /&gt;
# List available arguments for the init command&lt;br /&gt;
maas init --help&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section end=&amp;quot;linuxservices&amp;quot;/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Services&amp;diff=839</id>
		<title>Linux:Services</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Services&amp;diff=839"/>
		<updated>2025-10-01T10:32:58Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* Legacy */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet|Cheatsheets]]&lt;br /&gt;
&lt;br /&gt;
== Services ==&lt;br /&gt;
&amp;lt;section begin=&amp;quot;linuxservices&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Common ===&lt;br /&gt;
==== systemctl ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all services that are running or exited&lt;br /&gt;
systemctl&lt;br /&gt;
&lt;br /&gt;
# List all services, running or otherwise&lt;br /&gt;
systemctl --all&lt;br /&gt;
&lt;br /&gt;
# List all failed services&lt;br /&gt;
systemctl --state=failed&lt;br /&gt;
&lt;br /&gt;
# Reset the failed service &amp;quot;nginx&amp;quot;&lt;br /&gt;
systemctl reset-failed nginx&lt;br /&gt;
&lt;br /&gt;
# View the status of the &amp;quot;nfs-server&amp;quot; service&lt;br /&gt;
systemctl status nfs-server&lt;br /&gt;
&lt;br /&gt;
# Output the config file of &amp;quot;rsyslog&amp;quot; to the shell&lt;br /&gt;
systemctl cat rsyslog&lt;br /&gt;
&lt;br /&gt;
# Restart the &amp;quot;sshd&amp;quot; service, terminating established connections and re-parsing the configuration&lt;br /&gt;
systemctl restart sshd&lt;br /&gt;
&lt;br /&gt;
# Reload the &amp;quot;nginx&amp;quot; service so that it only re-parses the configuration&lt;br /&gt;
systemctl reload nginx&lt;br /&gt;
&lt;br /&gt;
# Stop the &amp;quot;nfs-ganesha&amp;quot; service so that it stops being run&lt;br /&gt;
systemctl stop nfs-ganesha&lt;br /&gt;
&lt;br /&gt;
# Start the &amp;quot;nfs-ganesha&amp;quot; service so that it starts being run again&lt;br /&gt;
systemctl start nfs-ganesha&lt;br /&gt;
&lt;br /&gt;
# Disable the &amp;quot;mariadb&amp;quot; service so that it doesn&#039;t start after the next boot&lt;br /&gt;
systemctl disable mariadb&lt;br /&gt;
&lt;br /&gt;
# Enable the &amp;quot;mariadb&amp;quot; service so that it starts after the next boot.&lt;br /&gt;
systemctl enable mariadb&lt;br /&gt;
&lt;br /&gt;
# Check the logs for all failed services&lt;br /&gt;
for i in $(systemctl --state=failed | head -n -4 | tail -n +2 | awk &#039;{print $1}&#039;); do systemctl --no-pager status &amp;quot;$i&amp;quot;; done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== NTP ===&lt;br /&gt;
==== Timedatectl ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show the current status of timedatectl&lt;br /&gt;
timedatectl&lt;br /&gt;
&lt;br /&gt;
# List available timezones&lt;br /&gt;
timedatectl list-timezones&lt;br /&gt;
&lt;br /&gt;
# Set the timezone to Amsterdam&lt;br /&gt;
timedatectl set-timezone Europe/Amsterdam&lt;br /&gt;
&lt;br /&gt;
# Show verbose sync information&lt;br /&gt;
timedatectl timesync-status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SNMP ===&lt;br /&gt;
==== V3 client installation ====&lt;br /&gt;
* https://kifarunix.com/quick-way-to-install-and-configure-snmp-on-ubuntu-20-04/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
apt install snmpd snmp libsnmp-dev&lt;br /&gt;
cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.bak&lt;br /&gt;
systemctl stop snmpd&lt;br /&gt;
net-snmp-create-v3-user -ro -X &amp;lt;CRYPTO-PASSWORD&amp;gt; -a SHA -X &amp;lt;PASSWORD&amp;gt; -x AES &amp;lt;USERNAME&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/snmp/snmpd.conf&lt;br /&gt;
sysLocation    NL;Zuid-Holland;Rotterdam, 78 MyStreet;2nd Floor;Server Room;Rack&lt;br /&gt;
sysContact     Me &amp;lt;me@example.org&amp;gt;&lt;br /&gt;
agentaddress   192.168.0.10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
systemctl start snmpd&lt;br /&gt;
systemctl enable snmpd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Test&lt;br /&gt;
snmpwalk -v3 -a SHA -A &amp;quot;AUTHENTICATION PASSWORD&amp;quot; -x AES -X &amp;quot;CRYPTO PASSWORD&amp;quot; -l authPriv -u &amp;quot;MYUSER&amp;quot; localhost | head&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CTDB  ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Verify CTDB cluster status&lt;br /&gt;
ctdb status&lt;br /&gt;
&lt;br /&gt;
# Show the allocated IP addresses and to which nodes they&#039;re bound&lt;br /&gt;
ctdb ip&lt;br /&gt;
&lt;br /&gt;
# See the status of all CTDB-scripts&lt;br /&gt;
ctdb scriptstatus&lt;br /&gt;
ctdb event status&lt;br /&gt;
&lt;br /&gt;
# Show the time of the last failover the duration it took to recover&lt;br /&gt;
ctdb uptime&lt;br /&gt;
&lt;br /&gt;
# See various statistics and data&lt;br /&gt;
ctdb statistics&lt;br /&gt;
&lt;br /&gt;
# Use the onnode command to execute a command on all cluster nodes&lt;br /&gt;
onnode all ctdb status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Stop a ctdb cluster member&lt;br /&gt;
ctdb stop&lt;br /&gt;
&lt;br /&gt;
# Start a stopped ctdb cluster member&lt;br /&gt;
ctdb continue&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Firewalls ===&lt;br /&gt;
==== UFW ====&lt;br /&gt;
===== Checks =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show summary of UFW status&lt;br /&gt;
ufw status&lt;br /&gt;
&lt;br /&gt;
# Show verbose UFW status&lt;br /&gt;
ufw status verbose&lt;br /&gt;
&lt;br /&gt;
# Show UFW rules numbered&lt;br /&gt;
ufw status numbered&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Commands =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Allow access from a specific IP to a port and add a comment that show in the status&lt;br /&gt;
ufw allow from 10.0.0.253 to any port 22 proto tcp comment &#039;Allow SSH access from XYZ location&#039;&lt;br /&gt;
&lt;br /&gt;
# Delete numbered Firewall rule 56&lt;br /&gt;
ufw delete 56&lt;br /&gt;
&lt;br /&gt;
# Disable UFW logging (prevent syslog spam)&lt;br /&gt;
ufw logging off&lt;br /&gt;
&lt;br /&gt;
# Set UFW logging back to the default&lt;br /&gt;
ufw logging low&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Firewalld ====&lt;br /&gt;
===== SNMP access =====&lt;br /&gt;
* https://unix.stackexchange.com/questions/214388/how-to-let-the-firewall-of-rhel7-the-snmp-connection-passing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/firewalld/services/snmp.xml&lt;br /&gt;
&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;service&amp;gt;&lt;br /&gt;
  &amp;lt;short&amp;gt;SNMP&amp;lt;/short&amp;gt;&lt;br /&gt;
  &amp;lt;description&amp;gt;SNMP protocol&amp;lt;/description&amp;gt;&lt;br /&gt;
  &amp;lt;port protocol=&amp;quot;udp&amp;quot; port=&amp;quot;161&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/service&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
firewall-cmd --zone=public --add-service snmp --permanent&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Firewall-cmd =====&lt;br /&gt;
====== Checks ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all available commands&lt;br /&gt;
firewall-cmd -h&lt;br /&gt;
&lt;br /&gt;
# Check the configuration file of the firewall for errors&lt;br /&gt;
firewall-cmd --check-config&lt;br /&gt;
&lt;br /&gt;
# Display the current state of firewall-cmd (running/shutdown)&lt;br /&gt;
firewall-cmd --state&lt;br /&gt;
&lt;br /&gt;
# Display all available zones&lt;br /&gt;
firewall-cmd --get-zones&lt;br /&gt;
&lt;br /&gt;
# List all whitelisted services&lt;br /&gt;
firewall-cmd --list-services&lt;br /&gt;
&lt;br /&gt;
# List all services you can potentially enable&lt;br /&gt;
firewall-cmd --get-services&lt;br /&gt;
&lt;br /&gt;
# List all added or enabled services and ports in more detail&lt;br /&gt;
firewall-cmd --list-all&lt;br /&gt;
&lt;br /&gt;
# List verbose information for all zones&lt;br /&gt;
firewall-cmd --list-all-zones&lt;br /&gt;
&lt;br /&gt;
# List verbose information for the public zone&lt;br /&gt;
firewall-cmd --list-all --zone=public&lt;br /&gt;
&lt;br /&gt;
# See what port(s) are associated with the dns service&lt;br /&gt;
firewall-cmd --info-service dns&lt;br /&gt;
&lt;br /&gt;
# List all opened ports&lt;br /&gt;
firewall-cmd --list-ports&lt;br /&gt;
&lt;br /&gt;
# List kernel ruleset generated for nftables(?)&lt;br /&gt;
nft list ruleset&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Commands ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reload the firewall&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Whitelist the dns service, persistently even after reboot&lt;br /&gt;
firewall-cmd --add-service=dns ; sudo firewall-cmd --runtime-to-permanent; firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Whitelist the http service, persistently even after reboot&lt;br /&gt;
firewall-cmd --add-service=http ; sudo firewall-cmd --runtime-to-permanent; firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Remove the http service from the whitelist&lt;br /&gt;
firewall-cmd --remove-service=http&lt;br /&gt;
&lt;br /&gt;
# Add port 1234 (tcp) to the whitelist&lt;br /&gt;
firewall-cmd --add-port=1234/tcp&lt;br /&gt;
&lt;br /&gt;
# Remove port 1234 (tcp) from the whitelist&lt;br /&gt;
firewall-cmd --remove-port=1234/tcp&lt;br /&gt;
&lt;br /&gt;
# Add port 2345 (udp) to the whitelist in zone external&lt;br /&gt;
firewall-cmd --zone=external --add-port=2345/udp&lt;br /&gt;
&lt;br /&gt;
# Remove port 2345 (udp) from the whitelist for zone external&lt;br /&gt;
firewall-cmd --zone=external --add-port=2345/udp&lt;br /&gt;
&lt;br /&gt;
# Add current configuration to configuration permanently&lt;br /&gt;
firewall-cmd –runtime-to-permanent&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;DANGEROUS&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# SHUT IT DOWN DOC - DROP ALL PACKETS AND EXPIRE EXISTING CONNECTIONS&lt;br /&gt;
firewall-cmd --panic-on&lt;br /&gt;
&lt;br /&gt;
# ACCEPT PACKETS AGAIN&lt;br /&gt;
firewall-cmd --panic-off&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== CSF ====&lt;br /&gt;
ConfigServer Security and Firewall&lt;br /&gt;
&lt;br /&gt;
===== General =====&lt;br /&gt;
* Common configuration: /etc/csf/csf.conf &lt;br /&gt;
* Blacklist: /etc/csf/csf.deny &lt;br /&gt;
* Whitelist: /etc/csf/csf.allow &lt;br /&gt;
&lt;br /&gt;
===== Installation =====&lt;br /&gt;
From the official instructions: https://download.configserver.com/csf/install.txt&lt;br /&gt;
&lt;br /&gt;
====== Prerequisites ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Perl Modules&lt;br /&gt;
============&lt;br /&gt;
While most should be installed on a standard perl installation the following&lt;br /&gt;
may need to be installed manually:&lt;br /&gt;
&lt;br /&gt;
# On rpm based systems:&lt;br /&gt;
yum install perl-libwww-perl.noarch perl-LWP-Protocol-https.noarch perl-GDGraph&lt;br /&gt;
&lt;br /&gt;
# On APT based systems:&lt;br /&gt;
apt-get install libwww-perl liblwp-protocol-https-perl libgd-graph-perl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Install ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cd /usr/src&lt;br /&gt;
rm -fv csf.tgz&lt;br /&gt;
wget https://download.configserver.com/csf.tgz&lt;br /&gt;
tar -xzf csf.tgz&lt;br /&gt;
cd csf&lt;br /&gt;
sh install.sh&lt;br /&gt;
&lt;br /&gt;
# Next, test whether you have the required iptables modules:&lt;br /&gt;
perl /usr/local/csf/bin/csftest.pl&lt;br /&gt;
&lt;br /&gt;
# Don&#039;t worry if you cannot run all the features, so long as the script doesn&#039;t report any FATAL errors&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Checks =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check the running status of csf&lt;br /&gt;
csf status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Commands =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Commit config changes by restarting csf&lt;br /&gt;
csf -r&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== csf.conf =====&lt;br /&gt;
Some common changes within the configuration file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Set testing to 0 when your CSF configuration is &#039;production&#039; ready&lt;br /&gt;
TESTING = &amp;quot;0&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow access to any service you&#039;re hosting locally, for example https&lt;br /&gt;
TCP_IN = &amp;quot;443&amp;quot;&lt;br /&gt;
UDP_IN = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow all outwards HTTP/HTTPS traffic so you can yum/apt update&lt;br /&gt;
TCP_OUT = &amp;quot;80,443&amp;quot; &lt;br /&gt;
&lt;br /&gt;
# Allow outgoing traceroute&lt;br /&gt;
UDP_OUT = &amp;quot;33434:33523&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow your server to be pinged&lt;br /&gt;
ICMP_IN = &amp;quot;0&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Formatting =====&lt;br /&gt;
The varying styles of formatting used in allow.conf&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Allow anything relating to the following IPs/ranges&lt;br /&gt;
192.168.10.0/24 # Our application breaks without this range&lt;br /&gt;
192.168.1.1 # Our gateway or something&lt;br /&gt;
&lt;br /&gt;
# Detailed entries based on Transport protocol, direction, Application protocol and IP&lt;br /&gt;
tcp:in:d=22:s=7.7.7.7 # SSH access from our VPN&lt;br /&gt;
udp:in:d=161:s=10.11.12.100 # SNMP Access&lt;br /&gt;
tcp|in|d=22|s=fe80::1:/16 # IPV6 SSH access from our jumpgateway&lt;br /&gt;
udp|in|d=3389|s=10.1.0.0/24 # RDP Access from our entire office range&lt;br /&gt;
tcp|out|d=80,443|d=1.2.3.4/32 # Allow outgoing HTTP/HTTPS access via port 80 and 443&lt;br /&gt;
&lt;br /&gt;
# Allow sending Syslog messages to our Syslog server&lt;br /&gt;
udp|out|d=514|d=192.168.20.5 # UDP syslog server&lt;br /&gt;
tcp|out|d=10514|d=192.168.20.5 # UDP syslog server&lt;br /&gt;
&lt;br /&gt;
# Allow sending queries to some DNS servers&lt;br /&gt;
tcp|out|s=53|d=8.8.8.8&lt;br /&gt;
udp|out|s=53|d=1.1.1.1&lt;br /&gt;
udp|out|s=53|d=2606:4700:4700::1111 # Cloudflare IPv6 DNS Server&lt;br /&gt;
&lt;br /&gt;
# Include an external configuration file&lt;br /&gt;
Include /etc/csf/csf.custom-config&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rsyslog ===&lt;br /&gt;
&amp;lt;section begin=&amp;quot;linuxsyslog&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Legacy ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#/etc/rsyslog.d/70-local-to-rsyslog-server.conf&lt;br /&gt;
# Define the hostname to send to the syslog server, include the priority number as first extra variable&lt;br /&gt;
$template SendHostname, &amp;quot;&amp;lt;%pri%&amp;gt; %timestamp% myhost.mydomain.nl %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
$ActionForwardDefaultTemplate SendHostname&lt;br /&gt;
&lt;br /&gt;
*.warning @10.77.0.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/60-asd.conf&lt;br /&gt;
# Log to the local server with a static hostname, same structure as regular syslog&lt;br /&gt;
$template NewHostname, &amp;quot;%timestamp% tester.mydomain.nl %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*.* /var/log/wewuzerrors.txt;NewHostname&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rainerscript ====&lt;br /&gt;
Rainerscript: https://rsyslog.readthedocs.io/en/latest/rainerscript/control_structures.html&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/70-local-to-rsyslog-server.conf&lt;br /&gt;
# Define a template and specify a hostname to send as:&lt;br /&gt;
template(name=&amp;quot;SendHostname&amp;quot; type=&amp;quot;string&amp;quot;&lt;br /&gt;
string=&amp;quot;%timestamp% myhost.mydomain.nl %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
# Send logs to target syslog server and port&lt;br /&gt;
*.warning action(type=&amp;quot;omfwd&amp;quot; Target=&amp;quot;10.0.33.10&amp;quot; Template=&amp;quot;SendHostname&amp;quot; Port=&amp;quot;514&amp;quot; Protocol=&amp;quot;udp&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Testing ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use the logger tool to test syslog server reception&lt;br /&gt;
logger -p local0.error &#039;Hello World!&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section end=&amp;quot;linuxsyslog&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== named ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Perform a test load of all primary zones within named.conf, as the named user&lt;br /&gt;
sudo -u named named-checkconf -z&lt;br /&gt;
&lt;br /&gt;
# Check zone file 192.168.77.0 defined in the 77.168.192.in-addr.arpa zone&lt;br /&gt;
named-checkzone 77.168.192.in-addr.arpa 192.168.77.0&lt;br /&gt;
&lt;br /&gt;
# Check zone file brammerloo.nl defined in the brammerloo.nl zone&lt;br /&gt;
named-checkzone brammerloo.nl brammerloo.nl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Basic configuration for the options field in &#039;&#039;&#039;/etc/named.conf&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
options {&lt;br /&gt;
# Define on what IP to listen on, for port 53&lt;br /&gt;
        listen-on port 53 { 127.0.0.1; 192.168.0.1; 192.168.1.1; };&lt;br /&gt;
        directory       &amp;quot;/var/named&amp;quot;;&lt;br /&gt;
        dump-file       &amp;quot;/var/named/data/cache_dump.db&amp;quot;;&lt;br /&gt;
        statistics-file &amp;quot;/var/named/data/named_stats.txt&amp;quot;;&lt;br /&gt;
        memstatistics-file &amp;quot;/var/named/data/named_mem_stats.txt&amp;quot;;&lt;br /&gt;
        secroots-file   &amp;quot;/var/named/data/named.secroots&amp;quot;;&lt;br /&gt;
        recursing-file  &amp;quot;/var/named/data/named.recursing&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# Only allow DNS queries from specific local subnets&lt;br /&gt;
# To allow from anything use: allow query { any; };&lt;br /&gt;
        allow-query     { localhost; 127.0.0.1; 192.168.0.0/24; 192.168.1.0/24; };&lt;br /&gt;
&lt;br /&gt;
# If the server can&#039;t resolve an address locally, use the following DNS servers for help&lt;br /&gt;
        forwarders {&lt;br /&gt;
        8.8.8.8;&lt;br /&gt;
        1.1.1.1;&lt;br /&gt;
        };&lt;br /&gt;
&lt;br /&gt;
        recursion yes;&lt;br /&gt;
        dnssec-validation no;&lt;br /&gt;
&lt;br /&gt;
        managed-keys-directory &amp;quot;/var/named/dynamic&amp;quot;;&lt;br /&gt;
        geoip-directory &amp;quot;/usr/share/GeoIP&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
        pid-file &amp;quot;/run/named/named.pid&amp;quot;;&lt;br /&gt;
        session-keyfile &amp;quot;/run/named/session.key&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
        /* https://fedoraproject.org/wiki/Changes/CryptoPolicy */&lt;br /&gt;
        include &amp;quot;/etc/crypto-policies/back-ends/bind.config&amp;quot;;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone defnitions: &#039;&#039;&#039;/etc/named.rfc1912.zones&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Define zones to listen for&lt;br /&gt;
zone &amp;quot;brammerloo.nl&amp;quot; IN {&lt;br /&gt;
        type master;&lt;br /&gt;
        file &amp;quot;brammerloo.nl&amp;quot;;&lt;br /&gt;
        allow-update { none; };&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
zone &amp;quot;1.168.192.in-addr.arpa&amp;quot; IN {&lt;br /&gt;
        type master;&lt;br /&gt;
        file &amp;quot;192.168.1.0&amp;quot;;&lt;br /&gt;
        allow-update { none; };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone file for Reverse lookup: &#039;&#039;&#039;/var/named/192.168.1.0&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$TTL 300&lt;br /&gt;
@       IN SOA  ns1.brammerloo.nl. admin.brammerloo.nl. (&lt;br /&gt;
                                        2023101102 ; serial&lt;br /&gt;
                                        180     ; refresh&lt;br /&gt;
                                        60      ; retry&lt;br /&gt;
                                        108000  ; expire&lt;br /&gt;
                                        60 )    ; minimum&lt;br /&gt;
    IN      NS      ns1.brammerloo.nl.&lt;br /&gt;
; PTR Records&lt;br /&gt;
11    IN   PTR   node1.&lt;br /&gt;
21    IN   PTR   server1.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone file for domain: &#039;&#039;&#039;/var/named/brammerloo.nl&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$TTL 300&lt;br /&gt;
@       IN SOA  ns1.brammerloo.nl. admin.brammerloo.nl. (&lt;br /&gt;
                                        2023101306 ; serial&lt;br /&gt;
                                        180     ; refresh&lt;br /&gt;
                                        60      ; retry&lt;br /&gt;
                                        108000  ; expire&lt;br /&gt;
                                        60 )    ; minimum&lt;br /&gt;
    IN      NS      ns1.brammerloo.nl.&lt;br /&gt;
@                  IN      A     192.168.1.6   ; domain brammerloo.nl is me!&lt;br /&gt;
ns1.brammerloo.nl. IN      A     192.168.78.31 ; FQDN for my domain&lt;br /&gt;
node1              IN      A     192.168.78.31 ; Basic A-record&lt;br /&gt;
www                IN      CNAME node1         ; Point my website to my node1 A-record&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== dhcpd ===&lt;br /&gt;
==== dhclient ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Request an IPv4 adres from a DHCP server&lt;br /&gt;
dhclient -4&lt;br /&gt;
&lt;br /&gt;
# Show verbose information when requesting an IPv4 adres from a DHCP server&lt;br /&gt;
dhclient -4 -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Basic configuration options in the &#039;&#039;&#039;/etc/dhcp/dhcpd.conf&#039;&#039;&#039; file&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Set the domain clients should use when resolving hostnames (equivalent to search domain)&lt;br /&gt;
option domain-name &amp;quot;brammerloo.nl&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# Set the domain name servers for DHCP clients&lt;br /&gt;
option domain-name-servers ns1.brammerloo.nl, 8.8.8.8;&lt;br /&gt;
&lt;br /&gt;
default-lease-time 600;&lt;br /&gt;
max-lease-time 7200;&lt;br /&gt;
log-facility local7;&lt;br /&gt;
&lt;br /&gt;
# Best practice = define any connected subnets, but don&#039;t configure DHCP for them&lt;br /&gt;
subnet 192.168.1.0 netmask 255.255.255.0 {&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Basic DHCP for a subnet configuration&lt;br /&gt;
subnet 192.168.0.0 netmask 255.255.255.0 {&lt;br /&gt;
  range 192.168.0.100 192.168.0.150;&lt;br /&gt;
  option routers 192.168.0.1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== smbd / Samba / CIFS ===&lt;br /&gt;
https://linuxconfig.org/install-samba-on-redhat-8&lt;br /&gt;
&lt;br /&gt;
==== Basic configuration ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install and enable&lt;br /&gt;
dnf install samba samba-client&lt;br /&gt;
systemctl enable --now {smb,nmb}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a client-user to authenticate with&lt;br /&gt;
sudo useradd samba-user&lt;br /&gt;
&lt;br /&gt;
# Give the user a password to authenticate with&lt;br /&gt;
sudo smbpasswd -a samba-user&lt;br /&gt;
&lt;br /&gt;
# Create a group to associate with the samba share&lt;br /&gt;
sudo groupadd sambagroup&lt;br /&gt;
&lt;br /&gt;
# Add the user to the group we will be configuring for the share&lt;br /&gt;
sudo usermod -a -G sambagroup samba-user&lt;br /&gt;
&lt;br /&gt;
# Create the folder we will be sharing&lt;br /&gt;
sudo mkdir /var/shares/myshare&lt;br /&gt;
&lt;br /&gt;
# Apply proper permission&lt;br /&gt;
sudo chown -R samba-user:sambagroup /var/shares/myshare/&lt;br /&gt;
sudo chmod -R 0770 /var/shares/myshare/&lt;br /&gt;
&lt;br /&gt;
# Apply proper permission for SELinux&lt;br /&gt;
sudo chcon -t samba_share_t /var/shares/myshare/&lt;br /&gt;
&lt;br /&gt;
# Backup the default config&lt;br /&gt;
cp /etc/samba/smb.conf /etc/samba/smb.conf~&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/samba/smb.conf&lt;br /&gt;
[global]&lt;br /&gt;
 workgroup = &amp;lt;DOMAIN-OR-WORKGROUP&amp;gt;&lt;br /&gt;
 server string = Samba Server %v&lt;br /&gt;
 netbios name = &amp;lt;SERVER-HOSTNAME&amp;gt;&lt;br /&gt;
 security = user&lt;br /&gt;
 map to guest = bad user&lt;br /&gt;
 dns proxy = no&lt;br /&gt;
&lt;br /&gt;
#==================== Share Definitions ======================&lt;br /&gt;
[share001]&lt;br /&gt;
 path = /var/shares/myshare&lt;br /&gt;
 valid users = @sambagroup&lt;br /&gt;
 guest ok = no&lt;br /&gt;
 writable = yes&lt;br /&gt;
 browsable = yes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reload Samba services&lt;br /&gt;
systemctl reload {smb,nmb}&lt;br /&gt;
&lt;br /&gt;
# Mount in Windows&lt;br /&gt;
\\&amp;lt;SERVER-IP&amp;gt;\share001&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user: samba-user&lt;br /&gt;
pass: &amp;lt;Whatever password you filled in with smbpasswd -a&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Samba checks&lt;br /&gt;
smbstatus&lt;br /&gt;
smbstatus -S&lt;br /&gt;
smbstatus -b&lt;br /&gt;
&lt;br /&gt;
# Samba set debug mode&lt;br /&gt;
smbcontrol smbd debug 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Docker ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List Docker containers &lt;br /&gt;
docker ps&lt;br /&gt;
&lt;br /&gt;
# List all Docker container IDs&lt;br /&gt;
docker ps -aq&lt;br /&gt;
&lt;br /&gt;
# List logs for container 987sdh3qrasdhj&lt;br /&gt;
docker logs 987sdh3qrasdhj&lt;br /&gt;
&lt;br /&gt;
# List RAM/CPU usage for Docker container asdlkasd67k&lt;br /&gt;
docker stats asdlkasd67k&lt;br /&gt;
&lt;br /&gt;
# Show verbose container information such as commands run, network, ID, etc&lt;br /&gt;
docker inspect oiu2398sda87&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enter the shell inside a docker container&lt;br /&gt;
docker exec -ti a89sd98sa7d /bin/bash&lt;br /&gt;
&lt;br /&gt;
# Execute a command inside a container as a specific user, root in this case&lt;br /&gt;
docker exec -it -u root asd87289hasdadz tail /var/log/nginx/access.log&lt;br /&gt;
docker exec -u 0 -it as892asnj2as /bin/bash&lt;br /&gt;
&lt;br /&gt;
# Restart docker container yoga&lt;br /&gt;
docker restart yoga&lt;br /&gt;
&lt;br /&gt;
# Restart the 3 given containers&lt;br /&gt;
docker restart 79f71c7f4d91 bbb3d3f5c3b1 b0a3204d4098&lt;br /&gt;
&lt;br /&gt;
# Start this container&lt;br /&gt;
docker start as9823nzxc0&lt;br /&gt;
&lt;br /&gt;
# Stop this container&lt;br /&gt;
docker stop as9823nzxc0&lt;br /&gt;
&lt;br /&gt;
# Restart all unhealthy Docker containers&lt;br /&gt;
for i in $(docker ps | grep unhealthy | awk &#039;{print $1}&#039;); do docker restart &amp;quot;$i&amp;quot;; done;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PowerDNS ===&lt;br /&gt;
* https://doc.powerdns.com/authoritative/index.html&lt;br /&gt;
* https://doc.powerdns.com/authoritative/manpages/pdns_server.1.html&lt;br /&gt;
* https://doc.powerdns.com/authoritative/manpages/pdnsutil.1.html&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# List commands&lt;br /&gt;
pdns_server --help&lt;br /&gt;
&lt;br /&gt;
# Check config and parse for errors&lt;br /&gt;
pdns_server --config=check&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# List available commands &lt;br /&gt;
pdnsutil --help&lt;br /&gt;
&lt;br /&gt;
# Check config and parse for errors&lt;br /&gt;
pdnsutil --config=check&lt;br /&gt;
&lt;br /&gt;
# List all available zones&lt;br /&gt;
pdnsutil list-all-zones&lt;br /&gt;
&lt;br /&gt;
# List all domains in the primary zone&lt;br /&gt;
pdnsutil list-all-zones primary&lt;br /&gt;
&lt;br /&gt;
# See zone information for a specific domain&lt;br /&gt;
pdnsutil show-zone mydomain.com&lt;br /&gt;
pdnsutil show-zone 77.5.10.in-addr.arpa&lt;br /&gt;
&lt;br /&gt;
# Check zone for errors&lt;br /&gt;
pdnsutil check-zone mydomain.com&lt;br /&gt;
&lt;br /&gt;
# List all created TSIG keys&lt;br /&gt;
pdnsutil list-tsig-keys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# Activate TSIG key for domain &amp;quot;myexample.com&amp;quot; in the primary zone&lt;br /&gt;
pdnsutil &amp;quot; myexample.com transfer primary&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MAAS ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Logs in either place:&lt;br /&gt;
/var/log/maas/&lt;br /&gt;
/var/snap/maas/common/log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List status of MAAS services&lt;br /&gt;
maas status&lt;br /&gt;
&lt;br /&gt;
# List MAAS commands&lt;br /&gt;
maas --help&lt;br /&gt;
&lt;br /&gt;
# List available arguments for the init command&lt;br /&gt;
maas init --help&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section end=&amp;quot;linuxservices&amp;quot;/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Tools&amp;diff=838</id>
		<title>Linux:Tools</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Tools&amp;diff=838"/>
		<updated>2025-09-30T07:42:58Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* cron */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet]]&lt;br /&gt;
&lt;br /&gt;
== Commands ==&lt;br /&gt;
=== Quick access ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Scroll through a file with less&lt;br /&gt;
less -s myfile.txt&lt;br /&gt;
&lt;br /&gt;
# Select line 5 from the output&lt;br /&gt;
cat example.txt | sel -e &#039;5&#039;&lt;br /&gt;
&lt;br /&gt;
# Select lines from the output, starting from the top&lt;br /&gt;
cat example.txt | head -5&lt;br /&gt;
&lt;br /&gt;
# Select lines from the output, starting from the bottom&lt;br /&gt;
cat example.txt | tail -5&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Commands ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Display the full path of a file(assuming the syslog file is available in the current folder)&lt;br /&gt;
readlink -f syslog&lt;br /&gt;
&lt;br /&gt;
# Unzip a file&lt;br /&gt;
gunzip /var/log/messages.2.gz&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Uncommon commands ===&lt;br /&gt;
* https://ngelinux.com/what-is-proc-sysrq-trigger-in-linux-and-how-to-use-sysrq-kernel-feature/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CrASHing THIs SERVer, WiTH no SurVIvORS!&lt;br /&gt;
echo c &amp;gt; /proc/sysrq-trigger&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Network ==&lt;br /&gt;
=== ping ===&lt;br /&gt;
Troubleshooting MTU: https://access.redhat.com/solutions/2440411&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Ping with an interval of 5 seconds&lt;br /&gt;
ping -i 5 192.168.0.1&lt;br /&gt;
&lt;br /&gt;
# Ping 192.168.10.5 using a specific interface&lt;br /&gt;
ping -I bond0 192.168.10.5&lt;br /&gt;
&lt;br /&gt;
# Ping 8.8.8.8 for 20 times&lt;br /&gt;
ping -c 20 8.8.8.8&lt;br /&gt;
&lt;br /&gt;
# Ping google.com using IPv4&lt;br /&gt;
ping -4 google.com&lt;br /&gt;
&lt;br /&gt;
# Ping google.com using IPv6&lt;br /&gt;
ping -6 google.com&lt;br /&gt;
&lt;br /&gt;
# Ping using packets of size 264&lt;br /&gt;
ping -s 264 1.1.1.1&lt;br /&gt;
&lt;br /&gt;
# Test an MTU-size of 9000 by sending non-fragmented packages of size 8972 (28 bytes left for the headers)&lt;br /&gt;
ping -M do -s 8972 192.168.77.88&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== traceroute ===&lt;br /&gt;
Package &#039;&#039;&#039;mtr&#039;&#039;&#039; (My traceroute) is also very good&lt;br /&gt;
&lt;br /&gt;
* https://web.archive.org/web/20110101100046/https://www.exit109.com/~jeremy/news/providers/traceroute.html&lt;br /&gt;
* [https://en.wikipedia.org/wiki/Traceroute UDP ports 33434 to 33534 are used by traceroute by default.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show the traversed hops towards google.com using IPv4&lt;br /&gt;
traceroute -4 google.com&lt;br /&gt;
&lt;br /&gt;
# Show the traversed hops towards google.com using IPv6&lt;br /&gt;
traceroute -6 google.com&lt;br /&gt;
&lt;br /&gt;
# Does the same as &amp;quot;traceroute -6 google.com&amp;quot;&lt;br /&gt;
traceroute6 google.com&lt;br /&gt;
&lt;br /&gt;
# Use ICMP for checking hops&lt;br /&gt;
traceroute -4 -I brammerloo.nl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== route ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List configured routes&lt;br /&gt;
route&lt;br /&gt;
&lt;br /&gt;
# List routes but display IPs instead of hostnames&lt;br /&gt;
route -n&lt;br /&gt;
&lt;br /&gt;
# Delete default route &lt;br /&gt;
ip route del 0.0.0.0/0 via 192.168.10.1 dev ens3&lt;br /&gt;
&lt;br /&gt;
# Delete default route (explicit)&lt;br /&gt;
ip route del default via 192.168.0.1 dev eth0 proto static metric 100&lt;br /&gt;
&lt;br /&gt;
# Add a default route via a specific IP and interface&lt;br /&gt;
ip route add default via 192.168.0.1 dev eth0 proto static metric 90&lt;br /&gt;
&lt;br /&gt;
# Add route for a network via gateway on an interface&lt;br /&gt;
ip route add 10.0.100.0/24 via 10.0.100.254 dev ens5&lt;br /&gt;
&lt;br /&gt;
# Add default route met een specifieke metric&lt;br /&gt;
ip route add default via 10.0.180.1 dev ens7 proto static metric 90&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== netstat ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Display network connections and current states&lt;br /&gt;
netstat&lt;br /&gt;
&lt;br /&gt;
# Check listening ports, connected remote IPs, processes, states and more&lt;br /&gt;
netstat -taupen&lt;br /&gt;
&lt;br /&gt;
# Check listening ports and IPs of the local server&lt;br /&gt;
netstat -tulpn&lt;br /&gt;
&lt;br /&gt;
# List the routing table&lt;br /&gt;
netstat -r&lt;br /&gt;
&lt;br /&gt;
# List verbose common TCP and ICMP information&lt;br /&gt;
netstat -s&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ss ===&lt;br /&gt;
Replacement for netstat&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Check open ports, connected IPs, processes, states and more&lt;br /&gt;
ss -taupen&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== tcpdump ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Listen on interface eth0 for traffic coming from host  172.16.0.11&lt;br /&gt;
tcpdump -i eth0 host 172.16.0.11&lt;br /&gt;
&lt;br /&gt;
# Listen on interface eno2 for traffic coming from host  172.16.1.20, going to port 443&lt;br /&gt;
tcpdump -i en02 host 172.16.1.20 port 443&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== uuidgen ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate a unique UUID (for an interface)&lt;br /&gt;
uuidgen eth0&lt;br /&gt;
7bb91614-6ffe-4bdc-9b37-c6e9d37f6987&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ip ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show network information &lt;br /&gt;
ip address&lt;br /&gt;
ip a&lt;br /&gt;
&lt;br /&gt;
# Show all configured routes&lt;br /&gt;
ip r show&lt;br /&gt;
&lt;br /&gt;
# Display statistics for all interfaces&lt;br /&gt;
ip -s link&lt;br /&gt;
&lt;br /&gt;
# Display detailed statistics for all interfaces&lt;br /&gt;
ip -s -s link&lt;br /&gt;
&lt;br /&gt;
# Execute the ifconfig command within a specific router&lt;br /&gt;
ip netns exec qrouter-asdwe49-as8d7-asd2-ert0-cvb7klj2 &amp;quot;ifconfig&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== DNS | dig &amp;amp; nslookup ===&lt;br /&gt;
* https://intodns.com/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Lookup reverse DNS host information&lt;br /&gt;
dig -x 10.0.2.15&lt;br /&gt;
&lt;br /&gt;
# Lookup the nameservers of google.com, by asking nameserver 1.1.1.1&lt;br /&gt;
dig google.com  @1.1.1.1 NS&lt;br /&gt;
&lt;br /&gt;
# Lookup reverse DNS host information&lt;br /&gt;
host 10.0.2.15&lt;br /&gt;
&lt;br /&gt;
# Lookup DNS host information&lt;br /&gt;
nslookup 10.0.2.15&lt;br /&gt;
&lt;br /&gt;
# Lookup host information for google.com while using DNS-server 8.8.8.8&lt;br /&gt;
nslookup google.com 8.8.8.8&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Package managers ==&lt;br /&gt;
=== apt ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check for updates&lt;br /&gt;
apt update&lt;br /&gt;
&lt;br /&gt;
# List packages that can be upgraded&lt;br /&gt;
apt list --upgradable&lt;br /&gt;
&lt;br /&gt;
# Installed available updates&lt;br /&gt;
apt upgrade&lt;br /&gt;
&lt;br /&gt;
# List installed packages&lt;br /&gt;
apt list --installed&lt;br /&gt;
&lt;br /&gt;
# List package details and description&lt;br /&gt;
apt show net-tools&lt;br /&gt;
&lt;br /&gt;
# Search inside all package descriptions for your keyword&lt;br /&gt;
apt-cache search ssh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rpm ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all local RPM packages&lt;br /&gt;
rpm -qa&lt;br /&gt;
&lt;br /&gt;
# Query for a specific installed rpm package&lt;br /&gt;
rpm -qi nginx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== yum ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  Search for all available packages that include string &amp;quot;nginx&amp;quot;&lt;br /&gt;
yum search nginx&lt;br /&gt;
&lt;br /&gt;
# Install the package named Nginx&lt;br /&gt;
yum install nginx&lt;br /&gt;
&lt;br /&gt;
# List installed packages&lt;br /&gt;
yum list installed&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== dnf ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  Upgrade and install updates&lt;br /&gt;
dnf upgrade&lt;br /&gt;
&lt;br /&gt;
# Remove the podman package&lt;br /&gt;
dnf remove podman&lt;br /&gt;
&lt;br /&gt;
# Show information about the zlib package&lt;br /&gt;
dnf info zlib&lt;br /&gt;
&lt;br /&gt;
# Show mandatory/optional/default packages within the Networking Tools group&lt;br /&gt;
dnf group info &amp;quot;Networking Tools&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Filesystem ==&lt;br /&gt;
=== fdisk ===&lt;br /&gt;
&#039;&#039;&#039;cfdisk&#039;&#039;&#039; is also nice&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check your disks and partitions&lt;br /&gt;
fdisk -l&lt;br /&gt;
&lt;br /&gt;
# Enter fdisk interactive mode&lt;br /&gt;
fdisk /dev/nvme0n2p1&lt;br /&gt;
&lt;br /&gt;
# List available partition types&lt;br /&gt;
l&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Format /dev/vdb as BTRFS&lt;br /&gt;
echo -e &amp;quot;n\np\n1\n\n\nt\n8E\np\nw&amp;quot; | fdisk /dev/vdb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Other ==&lt;br /&gt;
=== man + mandb ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Open the manual for the man tool&lt;br /&gt;
man man&lt;br /&gt;
&lt;br /&gt;
# Open the manual for the ls tool&lt;br /&gt;
man ls&lt;br /&gt;
&lt;br /&gt;
# &#039;Update&#039; mandb by purging and or processing manuals&lt;br /&gt;
mandb&lt;br /&gt;
&lt;br /&gt;
# Purge everything and regenerate manuals&lt;br /&gt;
mandb --create&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ls ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List folders sorted by modified date&lt;br /&gt;
ls -trol&lt;br /&gt;
&lt;br /&gt;
# List folder contents recursively&lt;br /&gt;
ls -alsR myfolder/&lt;br /&gt;
&lt;br /&gt;
# List folder contents sorted by time, newest first and reverse order&lt;br /&gt;
ls -latr myfolder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== grep ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Search for any occurences of &amp;quot;inet_interface&amp;quot; in a file&lt;br /&gt;
grep inet_interface /etc/postfix/main.cf&lt;br /&gt;
&lt;br /&gt;
# Search for pattern &amp;quot;audit&amp;quot; in file /var/log/syslog&lt;br /&gt;
grep -e &amp;quot;audit&amp;quot; /var/log/syslog&lt;br /&gt;
&lt;br /&gt;
# Search for text &amp;quot;started&amp;quot; in everything in /var/log/, and list the filename for each occurence&lt;br /&gt;
grep -H &amp;quot;started&amp;quot; /var/log/*&lt;br /&gt;
&lt;br /&gt;
# Search for any mention of &amp;quot;md&amp;quot; within a file, by piping to grep&lt;br /&gt;
cat /var/log/messages | grep md&lt;br /&gt;
&lt;br /&gt;
# Search for any of text &amp;quot;test&amp;quot; within the /etc folder recursively, also shows filename by default&lt;br /&gt;
grep -r &amp;quot;test&amp;quot; /etc&lt;br /&gt;
&lt;br /&gt;
# Recursively search for any mention of &amp;quot;audit&amp;quot; in each file within the specified directory, display linenumber and ignore low/upper case&lt;br /&gt;
grep -rni audit /var/log/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== lsof ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List what has files opened on the directory/mount&lt;br /&gt;
lsof /data/mount/lustre-01&lt;br /&gt;
&lt;br /&gt;
# List processes listening on port 443&lt;br /&gt;
lsof -i :443&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== awk ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List the first column of the output generated by docker ps&lt;br /&gt;
docker ps | awk &#039;{print $1}&#039;&lt;br /&gt;
&lt;br /&gt;
# Print 9th column of folder contents&lt;br /&gt;
ll /mnt/btrfs/share1/ | awk &#039;{print $9}&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== tar ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Compress the destination directory and keep the source path within the zipped file&lt;br /&gt;
tar -czvf name-of-archive.tar.gz /path/to/directory-or-file&lt;br /&gt;
&lt;br /&gt;
# Compress the destination directory, but put the folder contents into the . within the zipped file&lt;br /&gt;
tar -czvf name-of-archive.tar.gz -C /path/to/directory-or-file .&lt;br /&gt;
&lt;br /&gt;
# Extract a tar.gz file to the current folder&lt;br /&gt;
tar -xzvf name-of-archive.tar.gz&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== find ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Basic find command&lt;br /&gt;
find / -name name-to-search-for&lt;br /&gt;
&lt;br /&gt;
# Search the current folder for all files&lt;br /&gt;
find . -name \* &lt;br /&gt;
&lt;br /&gt;
# Search the current folder for all files and count them&lt;br /&gt;
find . -name \* | wc -l&lt;br /&gt;
&lt;br /&gt;
# Find all files with the SUID bit set&lt;br /&gt;
find / -name &amp;quot;*&amp;quot; -perm /u+s&lt;br /&gt;
&lt;br /&gt;
# Find the current folder for files that were modified in the last 15 minutes&lt;br /&gt;
find . -mmin -15 -type f -name &amp;quot;*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Search for all modified files between 2023-01-01 and 2023-12-30&lt;br /&gt;
find /var/log/ -type f -name &amp;quot;*&amp;quot; -newermt 2023-01-01 ! -newermt 2023-12-30&lt;br /&gt;
&lt;br /&gt;
# Search for all modified folders between 2022-01-01 and 2022-02-10, limited to a single folders&#039; depth&lt;br /&gt;
find /data/research001/ -maxdepth 1 -type d -newermt 2022-01-01 ! -newermt 2022-02-10&lt;br /&gt;
&lt;br /&gt;
# Search the current folder for all .log files and search &amp;amp; output any line containing string &amp;quot;error&amp;quot;&lt;br /&gt;
find . -name \*.log -exec grep -H error {} \;&lt;br /&gt;
&lt;br /&gt;
# Screwing around&lt;br /&gt;
for i in $(find URL* -name &amp;quot;*.report&amp;quot; | sort); do echo &amp;quot;$i&amp;quot; &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE ; done&lt;br /&gt;
for i in $(find URL* -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; | sort &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE ; done&lt;br /&gt;
for i in $(find URL* -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; | sort &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE | awk &#039;{print $2}&#039;; done&lt;br /&gt;
for i in $(find URL* -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE | awk &#039;{print $2}&#039;; done&lt;br /&gt;
for i in $(find * -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE | awk &#039;{print $2}&#039;; done&lt;br /&gt;
ll URL* | awk &#039;{print $9}&#039; | grep &amp;quot;*.report&amp;quot; | sort | for i in $(find * -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE | awk &#039;{print $2}&#039;; done&lt;br /&gt;
ll URL* | awk &#039;{print $9}&#039; | grep .report | sort | for i in $(find * -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE&lt;br /&gt;
&lt;br /&gt;
find URL1 -name \*.report -exec grep -H TOTAL_SIZE {} \; | LC_ALL=C awk -M &#039;BEGIN{FS=OFS=&amp;quot;\t&amp;quot;} {printf(&amp;quot;%s\t%.02f\n&amp;quot;, $1, $2/(1024*1024*1024))}&#039; | sed -e &#039;s~^.*/~~&#039; -e &#039;s~\..*SIZE~~&#039; | sort&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== less ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
25     = Go to line 25&lt;br /&gt;
g      = Go to top of file&lt;br /&gt;
G      = Go to bottom of file&lt;br /&gt;
/      = Activate search mode&lt;br /&gt;
/Error = Search for &amp;quot;Error&amp;quot;&lt;br /&gt;
n      = Move to next search result&lt;br /&gt;
N      = Move to previous search result&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Don&#039;t wrap long lines to the current screen (move left or right to see non-truncated line)&lt;br /&gt;
less -S /var/log/syslog&lt;br /&gt;
&lt;br /&gt;
# Output a file&#039;s contents and read it with less&lt;br /&gt;
cat /etc/snmpd/snmp.conf | less -S&lt;br /&gt;
&lt;br /&gt;
# Number the lines when viewing&lt;br /&gt;
less -N /var/log/messages&lt;br /&gt;
&lt;br /&gt;
# Open less at the first search result for &amp;quot;error&amp;quot;. (Do not use space between the -p parameter and your search query)&lt;br /&gt;
less -p&amp;quot;Error&amp;quot; /var/log/messages&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ssh ===&lt;br /&gt;
* https://man.openbsd.org/ssh.1&lt;br /&gt;
* https://www.openssh.com/legacy.html&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Stolen from https://www.openssh.com/legacy.html&lt;br /&gt;
ssh -Q cipher       # List supported ciphers&lt;br /&gt;
ssh -Q mac          # List supported MACs&lt;br /&gt;
ssh -Q key          # List supported public key types&lt;br /&gt;
ssh -Q kex          # List supported key exchange algorithms&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Connect to a server using a specific user&lt;br /&gt;
ssh mirelurk@192.168.0.1&lt;br /&gt;
&lt;br /&gt;
# Connect to a server using a specific RSA private key&lt;br /&gt;
ssh 192.168.0.1 -i /home/john/.ssh/id_rsa_key-5&lt;br /&gt;
&lt;br /&gt;
# Connect to a server using a specific SSH port&lt;br /&gt;
ssh 192.168.0.1 -p 1111&lt;br /&gt;
&lt;br /&gt;
# Show verbose information when connecting to a server&lt;br /&gt;
ssh -v 192.168.0.1&lt;br /&gt;
&lt;br /&gt;
# Connect using an ancient algorithm and keytype&lt;br /&gt;
ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 -c aes128-cbc  admin@10.50.10.50&lt;br /&gt;
&lt;br /&gt;
# Execute &#039;ls&#039; on a remote server and output the result to your shell session&lt;br /&gt;
echo &#039;ls&#039; | ssh -T user@10.0.20.75&lt;br /&gt;
&lt;br /&gt;
# Execute a command on a remote server and output the result to a local file&lt;br /&gt;
echo &#039;ls&#039; | ssh -T user@10.0.20.75 &amp;gt; &amp;lt;filename&amp;gt;.log&lt;br /&gt;
&lt;br /&gt;
# Log in by providing a password in the CLI&lt;br /&gt;
sshpass &#039;MyPassword&#039; ssh -XY root@10.100.25.1&lt;br /&gt;
&lt;br /&gt;
# Copy a local file to another server&lt;br /&gt;
scp /home/root/myfiletocopy ubuntu@192.168.0.10:/home/ubuntu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== vim ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Esc   Switches between input/command mode&lt;br /&gt;
&lt;br /&gt;
o     Create a new line below the current cursor position and switch to input mode&lt;br /&gt;
:wq   Save (write) and quit the file&lt;br /&gt;
:q!   Quit immediately without applying any changes&lt;br /&gt;
&lt;br /&gt;
j     Move the cursor one line downwards&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enter the Vim tutorial&lt;br /&gt;
vimtutor&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rsync ===&lt;br /&gt;
Also see rclone for enterprise storage enviroments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Copy contents of source /mnt/science/data/ to target /home/garyon/backup/science/ recursively&lt;br /&gt;
rsync -a /mnt/science/data/ /home/garyon/backup/science/&lt;br /&gt;
&lt;br /&gt;
# Copy  everything: symlinks, hardlinks, extended attributes, modified times, files, folders, etc&lt;br /&gt;
rsync -avHXS --progress /mnt/science/data/ /home/mayra/backup/science/&lt;br /&gt;
&lt;br /&gt;
# Show progress during a transfer&lt;br /&gt;
rsync -avHXS --progress /mnt/science/data/ /home/stefanie/backup/science/&lt;br /&gt;
&lt;br /&gt;
# rsync is additive by default&lt;br /&gt;
# After an initial rsync, delete files in the target that were deleted in the source&lt;br /&gt;
rsync --delete -avHXS /mnt/science/data/ /home/bob/backup/science/&lt;br /&gt;
&lt;br /&gt;
# Sync using SSH&lt;br /&gt;
rsync -avrS --delete /data/cardio/ 192.168.0.15:/backup/cardio/&lt;br /&gt;
&lt;br /&gt;
# Sync using a specific SSH port&lt;br /&gt;
rsync -avrS --rsh=&#039;ssh -p2020&#039; --delete /data/science/ 192.168.0.20:/backup/science/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== cron ===&lt;br /&gt;
Run tasks at specific intervals.&lt;br /&gt;
&lt;br /&gt;
* https://crontab.guru/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List cron jobs for the current user&lt;br /&gt;
crontab -l&lt;br /&gt;
&lt;br /&gt;
# Modify cron jobs for the current user&lt;br /&gt;
crontab -eq&lt;br /&gt;
&lt;br /&gt;
# Run  the &amp;quot;ls&amp;quot; command every 5 minutes&lt;br /&gt;
*/5 * * * * ps aux&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== screen ===&lt;br /&gt;
Create virtual sessions on the server you&#039;re connected to.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all current sessions&lt;br /&gt;
screen -list&lt;br /&gt;
&lt;br /&gt;
# Create new session &amp;quot;mynewsession&amp;quot;&lt;br /&gt;
screen -S mynewsession&lt;br /&gt;
&lt;br /&gt;
# Detach current session&lt;br /&gt;
CTRL + A + D&lt;br /&gt;
&lt;br /&gt;
# Attach session &amp;quot;mynewssion&amp;quot;&lt;br /&gt;
screen -r mynewsession&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ldapsearch ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DC = Domain Component&lt;br /&gt;
The values that identify the domain in which the object is located, may contain subdomains too i.e. &amp;quot;DC=customer,DC=amazon,DC=com&amp;quot;&lt;br /&gt;
&lt;br /&gt;
OU =  Organization Unit&lt;br /&gt;
A container/folder in which objects or users are stored. Actively used in Microsoft Active Directory&#039;s i.e. &amp;quot;OU=janitors,DC=customer,DC=amazon,DC=com&amp;quot;&lt;br /&gt;
&lt;br /&gt;
CN = Canonical Name&lt;br /&gt;
The name of the group you&#039;re searching for or in i.e. &amp;quot;CN=fullprivilege,OU=janitors,DC=customer,DC=amazon,DC=com&amp;quot;&lt;br /&gt;
&lt;br /&gt;
UID = User Identifier&lt;br /&gt;
The unique identifier to find a user with, usually the username i.e. &amp;quot;uid=magicmike,CN=fullprivilege,OU=janitors,DC=customer,DC=amazon,DC=com&amp;quot;&lt;br /&gt;
&lt;br /&gt;
DN = Distinguished Name&lt;br /&gt;
The entire path to an object, consisting of a combination of above values, at least the DCs and a CN or UID, i.e. &amp;quot;uid=magicmike,CN=fullprivilege,OU=janitors,DC=customer,DC=amazon,DC=com&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following assumes domain &amp;quot;brammerloo.nl&amp;quot;, based on usage for FreeIPA&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Search and show attributes for user tonberry in group users in group accounts in domain brammerloo.nl, using the admin user to authenticatie&lt;br /&gt;
ldapsearch -W -b &amp;quot;uid=tonberry,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;  -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Do the same as above, but specify LDAP-server ipa01.brammerloo.nl to send the query to&lt;br /&gt;
ldapsearch -W -H ldap://ipa01.brammerloo.nl -b &amp;quot;uid=tonberry,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;  -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Do the same as above, but specify a specific port&lt;br /&gt;
ldapsearch -W -H ldap://ipa01.brammerloo.nl:389 -b &amp;quot;uid=tonberry,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;  -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Use the &amp;quot;elastic&amp;quot; user to query for attributes of the &amp;quot;elastic-users&amp;quot; group which itself is a member of the &amp;quot;groups&amp;quot; group&lt;br /&gt;
ldapsearch -W -b &amp;quot;cn=elastic-users,cn=groups,cn=accounts,dc=brammerloo,dc=nl&amp;quot;  -D &amp;quot;uid=elastic,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Do the same as above, but specify you only want the member attribute&lt;br /&gt;
ldapsearch -W -b &amp;quot;cn=elastic-users,cn=groups,cn=accounts,dc=brammerloo,dc=nl&amp;quot; -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot; member&lt;br /&gt;
&lt;br /&gt;
# Show all groups of which tonberry is a member of by searching for the memberOf attribute&lt;br /&gt;
ldapsearch -W -b &amp;quot;uid=tonberry,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;  -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot; memberOf&lt;br /&gt;
&lt;br /&gt;
# List attributes for all groups in the group &amp;quot;groups&amp;quot;&lt;br /&gt;
ldapsearch -W -b &amp;quot;cn=groups,cn=accounts,dc=brammerloo,dc=nl&amp;quot; -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== git ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List your current branch and situation&lt;br /&gt;
git status&lt;br /&gt;
&lt;br /&gt;
# List all branches and your current one&lt;br /&gt;
git branch --all&lt;br /&gt;
&lt;br /&gt;
# List all available tags&lt;br /&gt;
git tag&lt;br /&gt;
&lt;br /&gt;
# List the current selected tag&lt;br /&gt;
git describe&lt;br /&gt;
git describe --tags&lt;br /&gt;
&lt;br /&gt;
# Compare changes in the current working directory to the committed tree, and list what files have been changed&lt;br /&gt;
git diff-files&lt;br /&gt;
&lt;br /&gt;
# Compare changes in the current working directory to the committed tree, and list what has changed&lt;br /&gt;
git diff-files -p&lt;br /&gt;
&lt;br /&gt;
# Compare the committed tree to the current working directory, and list what has changed&lt;br /&gt;
git diff HEAD&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Common ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a folder and initialize it for use by git&lt;br /&gt;
mkdir gitrepo1; cd gitrepo1; git init&lt;br /&gt;
&lt;br /&gt;
# Switch to another branch&lt;br /&gt;
git checkout stable/zed&lt;br /&gt;
&lt;br /&gt;
# Switch to a specific tag&lt;br /&gt;
git checkout tags/14.11.0&lt;br /&gt;
&lt;br /&gt;
# Fetch data from the current upstream branch&lt;br /&gt;
git pull&lt;br /&gt;
&lt;br /&gt;
# Pull data from a specific branch&lt;br /&gt;
git pull origin unmaintained/yoga&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rclone ===&lt;br /&gt;
* https://rclone.org/&lt;br /&gt;
&lt;br /&gt;
==== Installation ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Install the latest version from the website&lt;br /&gt;
curl https://rclone.org/install.sh | sudo bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Example configuration based on OpenStack swift. Config should be in the homefolder of your user .config/rclone/rclone.conf:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
[swift-ssd]&lt;br /&gt;
type = swift&lt;br /&gt;
user = patrick&lt;br /&gt;
key = &amp;lt;PASSWORD&amp;gt;&lt;br /&gt;
auth = https://openstack.brammerloo.nl:5000/v3&lt;br /&gt;
region = Rotterdam&lt;br /&gt;
domain = Default&lt;br /&gt;
tenant = patrickproject&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# List all containers, buckets and or folders of container &amp;quot;swift-ssd&amp;quot;&lt;br /&gt;
rclone lsd &amp;quot;swift-ssd:&amp;quot;&lt;br /&gt;
          20 2025-02-10 09:46:00         2 ssd-container&lt;br /&gt;
           0 2025-02-10 09:46:00         1 swift-ssd&lt;br /&gt;
           0 2025-02-10 09:46:00         1 swift-ssd2&lt;br /&gt;
&lt;br /&gt;
rclone lsd &amp;quot;swift-ssd:ssd-container&amp;quot;&lt;br /&gt;
           0 2025-02-10 09:48:02        -1 mystorage&lt;br /&gt;
&lt;br /&gt;
# List contents, files, folders of bucket &amp;quot;ssd-container&amp;quot;, within container &amp;quot;swift-ssd&amp;quot;&lt;br /&gt;
rclone ls &amp;quot;swift-ssd:ssd-container&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# List the contents of file &amp;quot;asd&amp;quot;&lt;br /&gt;
rclone cat &amp;quot;swift-ssd:ssd-container/asd&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Mount an object storage to local folder /mnt/object-ssd/&lt;br /&gt;
rclone mount swift-ssd:ssd-container /mnt/object-ssd&lt;br /&gt;
&lt;br /&gt;
# Synchronize a local folder to a destination folder inside a bucket, in interactive mode&lt;br /&gt;
rclone sync -i /etc/rsyslog.d swift-ssd:ssd-container/mystorage/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== mdtest ===&lt;br /&gt;
This chapter was mostly written and contributed by Ivo Palli.&lt;br /&gt;
&lt;br /&gt;
==== General ====&lt;br /&gt;
mdtest is part of the ior performance test package.&lt;br /&gt;
&lt;br /&gt;
==== RHEL Installation ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
wget https://github.com/hpc/ior/releases/download/3.3.0/ior-3.3.0.tar.bz2&lt;br /&gt;
tar xjf ior-*.tar.bz2&lt;br /&gt;
cd ior-*/&lt;br /&gt;
&lt;br /&gt;
yum install openmpi-devel environment-modules&lt;br /&gt;
# Relog your shell so &#039;module&#039; is available&lt;br /&gt;
module load mpi&lt;br /&gt;
module list&lt;br /&gt;
./configure&lt;br /&gt;
make -j4&lt;br /&gt;
make install&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ubuntu Installation ====&lt;br /&gt;
* https://gist.github.com/hokiegeek2/3057f8bb3beb519ae9b556e41824be30&lt;br /&gt;
* https://ior.readthedocs.io/en/latest/userDoc/install.html&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
VERSION=4.0.0&lt;br /&gt;
wget https://github.com/hpc/ior/releases/download/$VERSION/ior-$VERSION.tar.gz&lt;br /&gt;
tar -xzvf ior-$VERSION.tar.gz&lt;br /&gt;
cd ior-$VERSION/&lt;br /&gt;
&lt;br /&gt;
apt install libopenmpi-dev environment-modules openmpi-bin openmpi-common libgtk2.0-dev -y&lt;br /&gt;
./configure&lt;br /&gt;
&lt;br /&gt;
make -j4&lt;br /&gt;
make install&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Usage =====&lt;br /&gt;
Note: Number of items should be a multiple of depth x branching factor&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
module load mpi&lt;br /&gt;
&lt;br /&gt;
# Run command &amp;quot;mdtest -n 2000 -z 5 -b 2 -d /mnt/ssd/&amp;quot; 10 times in a row&lt;br /&gt;
mpirun --oversubscribe --allow-run-as-root -n 10 mdtest -n 2000 -z 5 -b 2 -d /mnt/nfs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Links =====&lt;br /&gt;
* https://github.com/hpc/ior&lt;br /&gt;
* https://www.glennklockwood.com/benchmarks/mdtest.html Guide&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Tools&amp;diff=837</id>
		<title>Linux:Tools</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Tools&amp;diff=837"/>
		<updated>2025-09-30T07:41:41Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* ldapsearch */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet]]&lt;br /&gt;
&lt;br /&gt;
== Commands ==&lt;br /&gt;
=== Quick access ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Scroll through a file with less&lt;br /&gt;
less -s myfile.txt&lt;br /&gt;
&lt;br /&gt;
# Select line 5 from the output&lt;br /&gt;
cat example.txt | sel -e &#039;5&#039;&lt;br /&gt;
&lt;br /&gt;
# Select lines from the output, starting from the top&lt;br /&gt;
cat example.txt | head -5&lt;br /&gt;
&lt;br /&gt;
# Select lines from the output, starting from the bottom&lt;br /&gt;
cat example.txt | tail -5&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Commands ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Display the full path of a file(assuming the syslog file is available in the current folder)&lt;br /&gt;
readlink -f syslog&lt;br /&gt;
&lt;br /&gt;
# Unzip a file&lt;br /&gt;
gunzip /var/log/messages.2.gz&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Uncommon commands ===&lt;br /&gt;
* https://ngelinux.com/what-is-proc-sysrq-trigger-in-linux-and-how-to-use-sysrq-kernel-feature/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CrASHing THIs SERVer, WiTH no SurVIvORS!&lt;br /&gt;
echo c &amp;gt; /proc/sysrq-trigger&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Network ==&lt;br /&gt;
=== ping ===&lt;br /&gt;
Troubleshooting MTU: https://access.redhat.com/solutions/2440411&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Ping with an interval of 5 seconds&lt;br /&gt;
ping -i 5 192.168.0.1&lt;br /&gt;
&lt;br /&gt;
# Ping 192.168.10.5 using a specific interface&lt;br /&gt;
ping -I bond0 192.168.10.5&lt;br /&gt;
&lt;br /&gt;
# Ping 8.8.8.8 for 20 times&lt;br /&gt;
ping -c 20 8.8.8.8&lt;br /&gt;
&lt;br /&gt;
# Ping google.com using IPv4&lt;br /&gt;
ping -4 google.com&lt;br /&gt;
&lt;br /&gt;
# Ping google.com using IPv6&lt;br /&gt;
ping -6 google.com&lt;br /&gt;
&lt;br /&gt;
# Ping using packets of size 264&lt;br /&gt;
ping -s 264 1.1.1.1&lt;br /&gt;
&lt;br /&gt;
# Test an MTU-size of 9000 by sending non-fragmented packages of size 8972 (28 bytes left for the headers)&lt;br /&gt;
ping -M do -s 8972 192.168.77.88&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== traceroute ===&lt;br /&gt;
Package &#039;&#039;&#039;mtr&#039;&#039;&#039; (My traceroute) is also very good&lt;br /&gt;
&lt;br /&gt;
* https://web.archive.org/web/20110101100046/https://www.exit109.com/~jeremy/news/providers/traceroute.html&lt;br /&gt;
* [https://en.wikipedia.org/wiki/Traceroute UDP ports 33434 to 33534 are used by traceroute by default.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show the traversed hops towards google.com using IPv4&lt;br /&gt;
traceroute -4 google.com&lt;br /&gt;
&lt;br /&gt;
# Show the traversed hops towards google.com using IPv6&lt;br /&gt;
traceroute -6 google.com&lt;br /&gt;
&lt;br /&gt;
# Does the same as &amp;quot;traceroute -6 google.com&amp;quot;&lt;br /&gt;
traceroute6 google.com&lt;br /&gt;
&lt;br /&gt;
# Use ICMP for checking hops&lt;br /&gt;
traceroute -4 -I brammerloo.nl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== route ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List configured routes&lt;br /&gt;
route&lt;br /&gt;
&lt;br /&gt;
# List routes but display IPs instead of hostnames&lt;br /&gt;
route -n&lt;br /&gt;
&lt;br /&gt;
# Delete default route &lt;br /&gt;
ip route del 0.0.0.0/0 via 192.168.10.1 dev ens3&lt;br /&gt;
&lt;br /&gt;
# Delete default route (explicit)&lt;br /&gt;
ip route del default via 192.168.0.1 dev eth0 proto static metric 100&lt;br /&gt;
&lt;br /&gt;
# Add a default route via a specific IP and interface&lt;br /&gt;
ip route add default via 192.168.0.1 dev eth0 proto static metric 90&lt;br /&gt;
&lt;br /&gt;
# Add route for a network via gateway on an interface&lt;br /&gt;
ip route add 10.0.100.0/24 via 10.0.100.254 dev ens5&lt;br /&gt;
&lt;br /&gt;
# Add default route met een specifieke metric&lt;br /&gt;
ip route add default via 10.0.180.1 dev ens7 proto static metric 90&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== netstat ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Display network connections and current states&lt;br /&gt;
netstat&lt;br /&gt;
&lt;br /&gt;
# Check listening ports, connected remote IPs, processes, states and more&lt;br /&gt;
netstat -taupen&lt;br /&gt;
&lt;br /&gt;
# Check listening ports and IPs of the local server&lt;br /&gt;
netstat -tulpn&lt;br /&gt;
&lt;br /&gt;
# List the routing table&lt;br /&gt;
netstat -r&lt;br /&gt;
&lt;br /&gt;
# List verbose common TCP and ICMP information&lt;br /&gt;
netstat -s&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ss ===&lt;br /&gt;
Replacement for netstat&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Check open ports, connected IPs, processes, states and more&lt;br /&gt;
ss -taupen&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== tcpdump ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Listen on interface eth0 for traffic coming from host  172.16.0.11&lt;br /&gt;
tcpdump -i eth0 host 172.16.0.11&lt;br /&gt;
&lt;br /&gt;
# Listen on interface eno2 for traffic coming from host  172.16.1.20, going to port 443&lt;br /&gt;
tcpdump -i en02 host 172.16.1.20 port 443&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== uuidgen ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate a unique UUID (for an interface)&lt;br /&gt;
uuidgen eth0&lt;br /&gt;
7bb91614-6ffe-4bdc-9b37-c6e9d37f6987&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ip ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show network information &lt;br /&gt;
ip address&lt;br /&gt;
ip a&lt;br /&gt;
&lt;br /&gt;
# Show all configured routes&lt;br /&gt;
ip r show&lt;br /&gt;
&lt;br /&gt;
# Display statistics for all interfaces&lt;br /&gt;
ip -s link&lt;br /&gt;
&lt;br /&gt;
# Display detailed statistics for all interfaces&lt;br /&gt;
ip -s -s link&lt;br /&gt;
&lt;br /&gt;
# Execute the ifconfig command within a specific router&lt;br /&gt;
ip netns exec qrouter-asdwe49-as8d7-asd2-ert0-cvb7klj2 &amp;quot;ifconfig&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== DNS | dig &amp;amp; nslookup ===&lt;br /&gt;
* https://intodns.com/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Lookup reverse DNS host information&lt;br /&gt;
dig -x 10.0.2.15&lt;br /&gt;
&lt;br /&gt;
# Lookup the nameservers of google.com, by asking nameserver 1.1.1.1&lt;br /&gt;
dig google.com  @1.1.1.1 NS&lt;br /&gt;
&lt;br /&gt;
# Lookup reverse DNS host information&lt;br /&gt;
host 10.0.2.15&lt;br /&gt;
&lt;br /&gt;
# Lookup DNS host information&lt;br /&gt;
nslookup 10.0.2.15&lt;br /&gt;
&lt;br /&gt;
# Lookup host information for google.com while using DNS-server 8.8.8.8&lt;br /&gt;
nslookup google.com 8.8.8.8&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Package managers ==&lt;br /&gt;
=== apt ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check for updates&lt;br /&gt;
apt update&lt;br /&gt;
&lt;br /&gt;
# List packages that can be upgraded&lt;br /&gt;
apt list --upgradable&lt;br /&gt;
&lt;br /&gt;
# Installed available updates&lt;br /&gt;
apt upgrade&lt;br /&gt;
&lt;br /&gt;
# List installed packages&lt;br /&gt;
apt list --installed&lt;br /&gt;
&lt;br /&gt;
# List package details and description&lt;br /&gt;
apt show net-tools&lt;br /&gt;
&lt;br /&gt;
# Search inside all package descriptions for your keyword&lt;br /&gt;
apt-cache search ssh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rpm ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all local RPM packages&lt;br /&gt;
rpm -qa&lt;br /&gt;
&lt;br /&gt;
# Query for a specific installed rpm package&lt;br /&gt;
rpm -qi nginx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== yum ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  Search for all available packages that include string &amp;quot;nginx&amp;quot;&lt;br /&gt;
yum search nginx&lt;br /&gt;
&lt;br /&gt;
# Install the package named Nginx&lt;br /&gt;
yum install nginx&lt;br /&gt;
&lt;br /&gt;
# List installed packages&lt;br /&gt;
yum list installed&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== dnf ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  Upgrade and install updates&lt;br /&gt;
dnf upgrade&lt;br /&gt;
&lt;br /&gt;
# Remove the podman package&lt;br /&gt;
dnf remove podman&lt;br /&gt;
&lt;br /&gt;
# Show information about the zlib package&lt;br /&gt;
dnf info zlib&lt;br /&gt;
&lt;br /&gt;
# Show mandatory/optional/default packages within the Networking Tools group&lt;br /&gt;
dnf group info &amp;quot;Networking Tools&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Filesystem ==&lt;br /&gt;
=== fdisk ===&lt;br /&gt;
&#039;&#039;&#039;cfdisk&#039;&#039;&#039; is also nice&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check your disks and partitions&lt;br /&gt;
fdisk -l&lt;br /&gt;
&lt;br /&gt;
# Enter fdisk interactive mode&lt;br /&gt;
fdisk /dev/nvme0n2p1&lt;br /&gt;
&lt;br /&gt;
# List available partition types&lt;br /&gt;
l&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Format /dev/vdb as BTRFS&lt;br /&gt;
echo -e &amp;quot;n\np\n1\n\n\nt\n8E\np\nw&amp;quot; | fdisk /dev/vdb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Other ==&lt;br /&gt;
=== man + mandb ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Open the manual for the man tool&lt;br /&gt;
man man&lt;br /&gt;
&lt;br /&gt;
# Open the manual for the ls tool&lt;br /&gt;
man ls&lt;br /&gt;
&lt;br /&gt;
# &#039;Update&#039; mandb by purging and or processing manuals&lt;br /&gt;
mandb&lt;br /&gt;
&lt;br /&gt;
# Purge everything and regenerate manuals&lt;br /&gt;
mandb --create&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ls ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List folders sorted by modified date&lt;br /&gt;
ls -trol&lt;br /&gt;
&lt;br /&gt;
# List folder contents recursively&lt;br /&gt;
ls -alsR myfolder/&lt;br /&gt;
&lt;br /&gt;
# List folder contents sorted by time, newest first and reverse order&lt;br /&gt;
ls -latr myfolder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== grep ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Search for any occurences of &amp;quot;inet_interface&amp;quot; in a file&lt;br /&gt;
grep inet_interface /etc/postfix/main.cf&lt;br /&gt;
&lt;br /&gt;
# Search for pattern &amp;quot;audit&amp;quot; in file /var/log/syslog&lt;br /&gt;
grep -e &amp;quot;audit&amp;quot; /var/log/syslog&lt;br /&gt;
&lt;br /&gt;
# Search for text &amp;quot;started&amp;quot; in everything in /var/log/, and list the filename for each occurence&lt;br /&gt;
grep -H &amp;quot;started&amp;quot; /var/log/*&lt;br /&gt;
&lt;br /&gt;
# Search for any mention of &amp;quot;md&amp;quot; within a file, by piping to grep&lt;br /&gt;
cat /var/log/messages | grep md&lt;br /&gt;
&lt;br /&gt;
# Search for any of text &amp;quot;test&amp;quot; within the /etc folder recursively, also shows filename by default&lt;br /&gt;
grep -r &amp;quot;test&amp;quot; /etc&lt;br /&gt;
&lt;br /&gt;
# Recursively search for any mention of &amp;quot;audit&amp;quot; in each file within the specified directory, display linenumber and ignore low/upper case&lt;br /&gt;
grep -rni audit /var/log/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== lsof ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List what has files opened on the directory/mount&lt;br /&gt;
lsof /data/mount/lustre-01&lt;br /&gt;
&lt;br /&gt;
# List processes listening on port 443&lt;br /&gt;
lsof -i :443&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== awk ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List the first column of the output generated by docker ps&lt;br /&gt;
docker ps | awk &#039;{print $1}&#039;&lt;br /&gt;
&lt;br /&gt;
# Print 9th column of folder contents&lt;br /&gt;
ll /mnt/btrfs/share1/ | awk &#039;{print $9}&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== tar ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Compress the destination directory and keep the source path within the zipped file&lt;br /&gt;
tar -czvf name-of-archive.tar.gz /path/to/directory-or-file&lt;br /&gt;
&lt;br /&gt;
# Compress the destination directory, but put the folder contents into the . within the zipped file&lt;br /&gt;
tar -czvf name-of-archive.tar.gz -C /path/to/directory-or-file .&lt;br /&gt;
&lt;br /&gt;
# Extract a tar.gz file to the current folder&lt;br /&gt;
tar -xzvf name-of-archive.tar.gz&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== find ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Basic find command&lt;br /&gt;
find / -name name-to-search-for&lt;br /&gt;
&lt;br /&gt;
# Search the current folder for all files&lt;br /&gt;
find . -name \* &lt;br /&gt;
&lt;br /&gt;
# Search the current folder for all files and count them&lt;br /&gt;
find . -name \* | wc -l&lt;br /&gt;
&lt;br /&gt;
# Find all files with the SUID bit set&lt;br /&gt;
find / -name &amp;quot;*&amp;quot; -perm /u+s&lt;br /&gt;
&lt;br /&gt;
# Find the current folder for files that were modified in the last 15 minutes&lt;br /&gt;
find . -mmin -15 -type f -name &amp;quot;*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Search for all modified files between 2023-01-01 and 2023-12-30&lt;br /&gt;
find /var/log/ -type f -name &amp;quot;*&amp;quot; -newermt 2023-01-01 ! -newermt 2023-12-30&lt;br /&gt;
&lt;br /&gt;
# Search for all modified folders between 2022-01-01 and 2022-02-10, limited to a single folders&#039; depth&lt;br /&gt;
find /data/research001/ -maxdepth 1 -type d -newermt 2022-01-01 ! -newermt 2022-02-10&lt;br /&gt;
&lt;br /&gt;
# Search the current folder for all .log files and search &amp;amp; output any line containing string &amp;quot;error&amp;quot;&lt;br /&gt;
find . -name \*.log -exec grep -H error {} \;&lt;br /&gt;
&lt;br /&gt;
# Screwing around&lt;br /&gt;
for i in $(find URL* -name &amp;quot;*.report&amp;quot; | sort); do echo &amp;quot;$i&amp;quot; &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE ; done&lt;br /&gt;
for i in $(find URL* -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; | sort &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE ; done&lt;br /&gt;
for i in $(find URL* -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; | sort &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE | awk &#039;{print $2}&#039;; done&lt;br /&gt;
for i in $(find URL* -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE | awk &#039;{print $2}&#039;; done&lt;br /&gt;
for i in $(find * -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE | awk &#039;{print $2}&#039;; done&lt;br /&gt;
ll URL* | awk &#039;{print $9}&#039; | grep &amp;quot;*.report&amp;quot; | sort | for i in $(find * -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE | awk &#039;{print $2}&#039;; done&lt;br /&gt;
ll URL* | awk &#039;{print $9}&#039; | grep .report | sort | for i in $(find * -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE&lt;br /&gt;
&lt;br /&gt;
find URL1 -name \*.report -exec grep -H TOTAL_SIZE {} \; | LC_ALL=C awk -M &#039;BEGIN{FS=OFS=&amp;quot;\t&amp;quot;} {printf(&amp;quot;%s\t%.02f\n&amp;quot;, $1, $2/(1024*1024*1024))}&#039; | sed -e &#039;s~^.*/~~&#039; -e &#039;s~\..*SIZE~~&#039; | sort&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== less ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
25     = Go to line 25&lt;br /&gt;
g      = Go to top of file&lt;br /&gt;
G      = Go to bottom of file&lt;br /&gt;
/      = Activate search mode&lt;br /&gt;
/Error = Search for &amp;quot;Error&amp;quot;&lt;br /&gt;
n      = Move to next search result&lt;br /&gt;
N      = Move to previous search result&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Don&#039;t wrap long lines to the current screen (move left or right to see non-truncated line)&lt;br /&gt;
less -S /var/log/syslog&lt;br /&gt;
&lt;br /&gt;
# Output a file&#039;s contents and read it with less&lt;br /&gt;
cat /etc/snmpd/snmp.conf | less -S&lt;br /&gt;
&lt;br /&gt;
# Number the lines when viewing&lt;br /&gt;
less -N /var/log/messages&lt;br /&gt;
&lt;br /&gt;
# Open less at the first search result for &amp;quot;error&amp;quot;. (Do not use space between the -p parameter and your search query)&lt;br /&gt;
less -p&amp;quot;Error&amp;quot; /var/log/messages&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ssh ===&lt;br /&gt;
* https://man.openbsd.org/ssh.1&lt;br /&gt;
* https://www.openssh.com/legacy.html&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Stolen from https://www.openssh.com/legacy.html&lt;br /&gt;
ssh -Q cipher       # List supported ciphers&lt;br /&gt;
ssh -Q mac          # List supported MACs&lt;br /&gt;
ssh -Q key          # List supported public key types&lt;br /&gt;
ssh -Q kex          # List supported key exchange algorithms&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Connect to a server using a specific user&lt;br /&gt;
ssh mirelurk@192.168.0.1&lt;br /&gt;
&lt;br /&gt;
# Connect to a server using a specific RSA private key&lt;br /&gt;
ssh 192.168.0.1 -i /home/john/.ssh/id_rsa_key-5&lt;br /&gt;
&lt;br /&gt;
# Connect to a server using a specific SSH port&lt;br /&gt;
ssh 192.168.0.1 -p 1111&lt;br /&gt;
&lt;br /&gt;
# Show verbose information when connecting to a server&lt;br /&gt;
ssh -v 192.168.0.1&lt;br /&gt;
&lt;br /&gt;
# Connect using an ancient algorithm and keytype&lt;br /&gt;
ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 -c aes128-cbc  admin@10.50.10.50&lt;br /&gt;
&lt;br /&gt;
# Execute &#039;ls&#039; on a remote server and output the result to your shell session&lt;br /&gt;
echo &#039;ls&#039; | ssh -T user@10.0.20.75&lt;br /&gt;
&lt;br /&gt;
# Execute a command on a remote server and output the result to a local file&lt;br /&gt;
echo &#039;ls&#039; | ssh -T user@10.0.20.75 &amp;gt; &amp;lt;filename&amp;gt;.log&lt;br /&gt;
&lt;br /&gt;
# Log in by providing a password in the CLI&lt;br /&gt;
sshpass &#039;MyPassword&#039; ssh -XY root@10.100.25.1&lt;br /&gt;
&lt;br /&gt;
# Copy a local file to another server&lt;br /&gt;
scp /home/root/myfiletocopy ubuntu@192.168.0.10:/home/ubuntu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== vim ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Esc   Switches between input/command mode&lt;br /&gt;
&lt;br /&gt;
o     Create a new line below the current cursor position and switch to input mode&lt;br /&gt;
:wq   Save (write) and quit the file&lt;br /&gt;
:q!   Quit immediately without applying any changes&lt;br /&gt;
&lt;br /&gt;
j     Move the cursor one line downwards&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enter the Vim tutorial&lt;br /&gt;
vimtutor&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rsync ===&lt;br /&gt;
Also see rclone for enterprise storage enviroments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Copy contents of source /mnt/science/data/ to target /home/garyon/backup/science/ recursively&lt;br /&gt;
rsync -a /mnt/science/data/ /home/garyon/backup/science/&lt;br /&gt;
&lt;br /&gt;
# Copy  everything: symlinks, hardlinks, extended attributes, modified times, files, folders, etc&lt;br /&gt;
rsync -avHXS --progress /mnt/science/data/ /home/mayra/backup/science/&lt;br /&gt;
&lt;br /&gt;
# Show progress during a transfer&lt;br /&gt;
rsync -avHXS --progress /mnt/science/data/ /home/stefanie/backup/science/&lt;br /&gt;
&lt;br /&gt;
# rsync is additive by default&lt;br /&gt;
# After an initial rsync, delete files in the target that were deleted in the source&lt;br /&gt;
rsync --delete -avHXS /mnt/science/data/ /home/bob/backup/science/&lt;br /&gt;
&lt;br /&gt;
# Sync using SSH&lt;br /&gt;
rsync -avrS --delete /data/cardio/ 192.168.0.15:/backup/cardio/&lt;br /&gt;
&lt;br /&gt;
# Sync using a specific SSH port&lt;br /&gt;
rsync -avrS --rsh=&#039;ssh -p2020&#039; --delete /data/science/ 192.168.0.20:/backup/science/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== cron ===&lt;br /&gt;
* https://crontab.guru/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List cron jobs for the current user&lt;br /&gt;
crontab -l&lt;br /&gt;
&lt;br /&gt;
# Modify cron jobs for the current user&lt;br /&gt;
crontab -eq&lt;br /&gt;
&lt;br /&gt;
# Run  the &amp;quot;ls&amp;quot; command every 5 minutes&lt;br /&gt;
*/5 * * * * ps aux&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ldapsearch ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DC = Domain Component&lt;br /&gt;
The values that identify the domain in which the object is located, may contain subdomains too i.e. &amp;quot;DC=customer,DC=amazon,DC=com&amp;quot;&lt;br /&gt;
&lt;br /&gt;
OU =  Organization Unit&lt;br /&gt;
A container/folder in which objects or users are stored. Actively used in Microsoft Active Directory&#039;s i.e. &amp;quot;OU=janitors,DC=customer,DC=amazon,DC=com&amp;quot;&lt;br /&gt;
&lt;br /&gt;
CN = Canonical Name&lt;br /&gt;
The name of the group you&#039;re searching for or in i.e. &amp;quot;CN=fullprivilege,OU=janitors,DC=customer,DC=amazon,DC=com&amp;quot;&lt;br /&gt;
&lt;br /&gt;
UID = User Identifier&lt;br /&gt;
The unique identifier to find a user with, usually the username i.e. &amp;quot;uid=magicmike,CN=fullprivilege,OU=janitors,DC=customer,DC=amazon,DC=com&amp;quot;&lt;br /&gt;
&lt;br /&gt;
DN = Distinguished Name&lt;br /&gt;
The entire path to an object, consisting of a combination of above values, at least the DCs and a CN or UID, i.e. &amp;quot;uid=magicmike,CN=fullprivilege,OU=janitors,DC=customer,DC=amazon,DC=com&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following assumes domain &amp;quot;brammerloo.nl&amp;quot;, based on usage for FreeIPA&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Search and show attributes for user tonberry in group users in group accounts in domain brammerloo.nl, using the admin user to authenticatie&lt;br /&gt;
ldapsearch -W -b &amp;quot;uid=tonberry,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;  -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Do the same as above, but specify LDAP-server ipa01.brammerloo.nl to send the query to&lt;br /&gt;
ldapsearch -W -H ldap://ipa01.brammerloo.nl -b &amp;quot;uid=tonberry,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;  -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Do the same as above, but specify a specific port&lt;br /&gt;
ldapsearch -W -H ldap://ipa01.brammerloo.nl:389 -b &amp;quot;uid=tonberry,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;  -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Use the &amp;quot;elastic&amp;quot; user to query for attributes of the &amp;quot;elastic-users&amp;quot; group which itself is a member of the &amp;quot;groups&amp;quot; group&lt;br /&gt;
ldapsearch -W -b &amp;quot;cn=elastic-users,cn=groups,cn=accounts,dc=brammerloo,dc=nl&amp;quot;  -D &amp;quot;uid=elastic,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Do the same as above, but specify you only want the member attribute&lt;br /&gt;
ldapsearch -W -b &amp;quot;cn=elastic-users,cn=groups,cn=accounts,dc=brammerloo,dc=nl&amp;quot; -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot; member&lt;br /&gt;
&lt;br /&gt;
# Show all groups of which tonberry is a member of by searching for the memberOf attribute&lt;br /&gt;
ldapsearch -W -b &amp;quot;uid=tonberry,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;  -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot; memberOf&lt;br /&gt;
&lt;br /&gt;
# List attributes for all groups in the group &amp;quot;groups&amp;quot;&lt;br /&gt;
ldapsearch -W -b &amp;quot;cn=groups,cn=accounts,dc=brammerloo,dc=nl&amp;quot; -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== git ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List your current branch and situation&lt;br /&gt;
git status&lt;br /&gt;
&lt;br /&gt;
# List all branches and your current one&lt;br /&gt;
git branch --all&lt;br /&gt;
&lt;br /&gt;
# List all available tags&lt;br /&gt;
git tag&lt;br /&gt;
&lt;br /&gt;
# List the current selected tag&lt;br /&gt;
git describe&lt;br /&gt;
git describe --tags&lt;br /&gt;
&lt;br /&gt;
# Compare changes in the current working directory to the committed tree, and list what files have been changed&lt;br /&gt;
git diff-files&lt;br /&gt;
&lt;br /&gt;
# Compare changes in the current working directory to the committed tree, and list what has changed&lt;br /&gt;
git diff-files -p&lt;br /&gt;
&lt;br /&gt;
# Compare the committed tree to the current working directory, and list what has changed&lt;br /&gt;
git diff HEAD&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Common ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a folder and initialize it for use by git&lt;br /&gt;
mkdir gitrepo1; cd gitrepo1; git init&lt;br /&gt;
&lt;br /&gt;
# Switch to another branch&lt;br /&gt;
git checkout stable/zed&lt;br /&gt;
&lt;br /&gt;
# Switch to a specific tag&lt;br /&gt;
git checkout tags/14.11.0&lt;br /&gt;
&lt;br /&gt;
# Fetch data from the current upstream branch&lt;br /&gt;
git pull&lt;br /&gt;
&lt;br /&gt;
# Pull data from a specific branch&lt;br /&gt;
git pull origin unmaintained/yoga&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rclone ===&lt;br /&gt;
* https://rclone.org/&lt;br /&gt;
&lt;br /&gt;
==== Installation ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Install the latest version from the website&lt;br /&gt;
curl https://rclone.org/install.sh | sudo bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Example configuration based on OpenStack swift. Config should be in the homefolder of your user .config/rclone/rclone.conf:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
[swift-ssd]&lt;br /&gt;
type = swift&lt;br /&gt;
user = patrick&lt;br /&gt;
key = &amp;lt;PASSWORD&amp;gt;&lt;br /&gt;
auth = https://openstack.brammerloo.nl:5000/v3&lt;br /&gt;
region = Rotterdam&lt;br /&gt;
domain = Default&lt;br /&gt;
tenant = patrickproject&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# List all containers, buckets and or folders of container &amp;quot;swift-ssd&amp;quot;&lt;br /&gt;
rclone lsd &amp;quot;swift-ssd:&amp;quot;&lt;br /&gt;
          20 2025-02-10 09:46:00         2 ssd-container&lt;br /&gt;
           0 2025-02-10 09:46:00         1 swift-ssd&lt;br /&gt;
           0 2025-02-10 09:46:00         1 swift-ssd2&lt;br /&gt;
&lt;br /&gt;
rclone lsd &amp;quot;swift-ssd:ssd-container&amp;quot;&lt;br /&gt;
           0 2025-02-10 09:48:02        -1 mystorage&lt;br /&gt;
&lt;br /&gt;
# List contents, files, folders of bucket &amp;quot;ssd-container&amp;quot;, within container &amp;quot;swift-ssd&amp;quot;&lt;br /&gt;
rclone ls &amp;quot;swift-ssd:ssd-container&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# List the contents of file &amp;quot;asd&amp;quot;&lt;br /&gt;
rclone cat &amp;quot;swift-ssd:ssd-container/asd&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Mount an object storage to local folder /mnt/object-ssd/&lt;br /&gt;
rclone mount swift-ssd:ssd-container /mnt/object-ssd&lt;br /&gt;
&lt;br /&gt;
# Synchronize a local folder to a destination folder inside a bucket, in interactive mode&lt;br /&gt;
rclone sync -i /etc/rsyslog.d swift-ssd:ssd-container/mystorage/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== mdtest ===&lt;br /&gt;
This chapter was mostly written and contributed by Ivo Palli.&lt;br /&gt;
&lt;br /&gt;
==== General ====&lt;br /&gt;
mdtest is part of the ior performance test package.&lt;br /&gt;
&lt;br /&gt;
==== RHEL Installation ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
wget https://github.com/hpc/ior/releases/download/3.3.0/ior-3.3.0.tar.bz2&lt;br /&gt;
tar xjf ior-*.tar.bz2&lt;br /&gt;
cd ior-*/&lt;br /&gt;
&lt;br /&gt;
yum install openmpi-devel environment-modules&lt;br /&gt;
# Relog your shell so &#039;module&#039; is available&lt;br /&gt;
module load mpi&lt;br /&gt;
module list&lt;br /&gt;
./configure&lt;br /&gt;
make -j4&lt;br /&gt;
make install&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ubuntu Installation ====&lt;br /&gt;
* https://gist.github.com/hokiegeek2/3057f8bb3beb519ae9b556e41824be30&lt;br /&gt;
* https://ior.readthedocs.io/en/latest/userDoc/install.html&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
VERSION=4.0.0&lt;br /&gt;
wget https://github.com/hpc/ior/releases/download/$VERSION/ior-$VERSION.tar.gz&lt;br /&gt;
tar -xzvf ior-$VERSION.tar.gz&lt;br /&gt;
cd ior-$VERSION/&lt;br /&gt;
&lt;br /&gt;
apt install libopenmpi-dev environment-modules openmpi-bin openmpi-common libgtk2.0-dev -y&lt;br /&gt;
./configure&lt;br /&gt;
&lt;br /&gt;
make -j4&lt;br /&gt;
make install&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Usage =====&lt;br /&gt;
Note: Number of items should be a multiple of depth x branching factor&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
module load mpi&lt;br /&gt;
&lt;br /&gt;
# Run command &amp;quot;mdtest -n 2000 -z 5 -b 2 -d /mnt/ssd/&amp;quot; 10 times in a row&lt;br /&gt;
mpirun --oversubscribe --allow-run-as-root -n 10 mdtest -n 2000 -z 5 -b 2 -d /mnt/nfs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Links =====&lt;br /&gt;
* https://github.com/hpc/ior&lt;br /&gt;
* https://www.glennklockwood.com/benchmarks/mdtest.html Guide&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Network&amp;diff=836</id>
		<title>Linux:Network</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Network&amp;diff=836"/>
		<updated>2025-09-25T12:55:33Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* nmcli */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet]]&lt;br /&gt;
&lt;br /&gt;
* https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers&lt;br /&gt;
&lt;br /&gt;
== Checks ==&lt;br /&gt;
=== Common ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List route table&lt;br /&gt;
route -n&lt;br /&gt;
&lt;br /&gt;
# Display network connections and current states&lt;br /&gt;
netstat&lt;br /&gt;
&lt;br /&gt;
# Check listening ports, connected remote IPs, processes, states and more&lt;br /&gt;
netstat -taupen&lt;br /&gt;
&lt;br /&gt;
# Check listening ports and IPs of the local server&lt;br /&gt;
netstat -tulpn&lt;br /&gt;
&lt;br /&gt;
# List the routing table&lt;br /&gt;
netstat -r&lt;br /&gt;
&lt;br /&gt;
# List verbose common TCP and ICMP information&lt;br /&gt;
netstat -s&lt;br /&gt;
&lt;br /&gt;
# List iptable rules (Nftables)&lt;br /&gt;
iptables -nvL&lt;br /&gt;
&lt;br /&gt;
# List iptable rules (Legacy iptables)&lt;br /&gt;
iptables-legacy -nvL&lt;br /&gt;
&lt;br /&gt;
# Test specific IP and port combination for connectivity&lt;br /&gt;
telnet 172.16.2.1 22&lt;br /&gt;
&lt;br /&gt;
# Wireshark on a specific interface to a file, listening on a local port and for a remote IP&lt;br /&gt;
tshark -p -i bond0 -w file.pcap -f &amp;quot;port 443 and host 172.16.16.25&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# List available routers&lt;br /&gt;
ip netns&lt;br /&gt;
&lt;br /&gt;
# Show interfaces with an IPv4 address&lt;br /&gt;
ip -4 a&lt;br /&gt;
&lt;br /&gt;
# Show interfaces with an IPv6 address&lt;br /&gt;
ip -6 a&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Network ==&lt;br /&gt;
=== NetworkManager ===&lt;br /&gt;
&#039;&#039;&#039;nmtui&#039;&#039;&#039; is a GUI-tool for managing NetworkManager connections.&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Show all active network connections&lt;br /&gt;
nmcli connection show&lt;br /&gt;
&lt;br /&gt;
# Show connection information for interface ens5&lt;br /&gt;
nmcli connection show ens5&lt;br /&gt;
&lt;br /&gt;
# Show active and unactive network connections&lt;br /&gt;
nmcli dev status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== nmcli ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Bring logical interface ens6 up&lt;br /&gt;
nmcli device up ens6&lt;br /&gt;
&lt;br /&gt;
# Turn off DHCP&lt;br /&gt;
nmcli con mod ens6 ipv4.method manual&lt;br /&gt;
nmcli con mod ens6 connection.autoconnect yes&lt;br /&gt;
&lt;br /&gt;
# Add an IP-address to interface ens6&lt;br /&gt;
nmcli connection modify ens6 ipv4.address &amp;quot;192.168.0.10/24&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Add DNS-servers to interface ens6&lt;br /&gt;
nmcli connection modify ens6 ipv4.dns &amp;quot;8.8.8.8,1.1.1.1,196.168.0.1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Add a gateway to interface ens6&lt;br /&gt;
nmcli con mod ens6 ipv4.gateway &amp;quot;192.168.0.1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Add a default route to interface ens160&lt;br /&gt;
nmcli connection modify ens160 +ipv4.routes &amp;quot;0.0.0.0/0 192.168.3.100&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Remove an IP-address from interface ens6&lt;br /&gt;
nmcli con mod ens6 -ipv4.addresses 192.168.0.11/24&lt;br /&gt;
&lt;br /&gt;
# Apply changes to interface ens&lt;br /&gt;
nmcli device reapply ens6&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== RHEL ===&lt;br /&gt;
==== Generic Interface ====&lt;br /&gt;
&amp;lt;code&amp;gt; BOOTPROTO=static &amp;lt;/code&amp;gt; for static address &amp;lt;/br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; BOOTPROTO=dhcp &amp;lt;/code&amp;gt; for DHCP&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# /etc/sysconfig/network-scripts/ifcfg-ens128&lt;br /&gt;
DEVICE=ens128&lt;br /&gt;
NAME=ens128&lt;br /&gt;
HWADDR=ab:cd:ef:gh:ij:kl&lt;br /&gt;
UUID=0a8d3485-d512-46da-8225-19f4721813c1&lt;br /&gt;
BOOTPROTO=static&lt;br /&gt;
STARTMODE=auto&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
IPADDR=192.168.10.2&lt;br /&gt;
NETMASK=255.255.255.0&lt;br /&gt;
GATEWAY=192.168.10.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Generic VLAN Interface ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# /etc/sysconfig/network-scripts/ifcfg-eno2.100&lt;br /&gt;
VLAN=yes&lt;br /&gt;
TYPE=Vlan&lt;br /&gt;
PHYSDEV=eno2&lt;br /&gt;
VLAN_ID=100&lt;br /&gt;
NAME=eno2.100&lt;br /&gt;
BOOTPROTO=static&lt;br /&gt;
HWADDR=ab:cd:ef:gh:ij:kl&lt;br /&gt;
IPADDR=192.168.100.217&lt;br /&gt;
NETMASK=255.255.255.0&lt;br /&gt;
STARTMODE=auto&lt;br /&gt;
UUID=689cff6f-c750-4db7-936c-234fb80b6018&lt;br /&gt;
GATEWAY=192.168.100.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== VLAN Bond interface configuration ====&lt;br /&gt;
===== Virtual Bond Master =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
BONDING_OPTS=&amp;quot;mode=802.3ad miimon=100&amp;quot;&lt;br /&gt;
TYPE=Bond&lt;br /&gt;
BONDING_MASTER=yes&lt;br /&gt;
PROXY_METHOD=none&lt;br /&gt;
BROWSER_ONLY=no&lt;br /&gt;
IPV6INIT=no&lt;br /&gt;
NAME=bond0&lt;br /&gt;
UUID=7bb91614-6ffe-4bdc-9b37-c6e9d37f6987&lt;br /&gt;
DEVICE=bond0&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
AUTOCONNECT_PRIORITY=9&lt;br /&gt;
AUTOCONNECT_RETRIES=0&lt;br /&gt;
AUTOCONNECT_SLAVES=yes&lt;br /&gt;
MTU=1500&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Physical bond Slaves =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# /etc/sysconfig/network-scripts/ifcfg-ens1&lt;br /&gt;
TYPE=Ethernet&lt;br /&gt;
NAME=ens1&lt;br /&gt;
UUID=c6a4da43-b84a-44f4-b49f-4bdc717d4238&lt;br /&gt;
DEVICE=ens1&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
AUTOCONNECT_PRIORITY=9&lt;br /&gt;
AUTOCONNECT_RETRIES=0&lt;br /&gt;
MASTER_UUID=7bb91614-6ffe-4bdc-9b37-c6e9d37f6987&lt;br /&gt;
MASTER=bond0&lt;br /&gt;
SLAVE=yes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# /etc/sysconfig/network-scripts/ifcfg-ens2&lt;br /&gt;
TYPE=Ethernet&lt;br /&gt;
NAME=ens2&lt;br /&gt;
UUID=ca09a126-a082-4620-a920-be45269e5d8a&lt;br /&gt;
DEVICE=ens2&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
AUTOCONNECT_PRIORITY=9&lt;br /&gt;
AUTOCONNECT_RETRIES=0&lt;br /&gt;
MASTER_UUID=7bb91614-6ffe-4bdc-9b37-c6e9d37f6987&lt;br /&gt;
MASTER=bond0&lt;br /&gt;
SLAVE=yes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== VLAN 100 Interface =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# /etc/sysconfig/network-scripts/ifcfg-vlan-bond0.100&lt;br /&gt;
VLAN=yes&lt;br /&gt;
TYPE=Vlan&lt;br /&gt;
PHYSDEV=bond0&lt;br /&gt;
VLAN_ID=100&lt;br /&gt;
REORDER_HDR=yes&lt;br /&gt;
GVRP=no&lt;br /&gt;
MVRP=no&lt;br /&gt;
HWADDR=&lt;br /&gt;
PROXY_METHOD=none&lt;br /&gt;
BROWSER_ONLY=no&lt;br /&gt;
BOOTPROTO=none&lt;br /&gt;
IPADDR=192.168.100.10&lt;br /&gt;
PREFIX=24&lt;br /&gt;
DEFROUTE=yes&lt;br /&gt;
IPV4_FAILURE_FATAL=no&lt;br /&gt;
NAME=vlan-bond0.100&lt;br /&gt;
UUID=83b0e31c-9a9f-47da-9dc6-645796bc47aa&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
AUTOCONNECT_PRIORITY=9&lt;br /&gt;
AUTOCONNECT_RETRIES=0&lt;br /&gt;
GATEWAY=192.168.100.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Ubuntu/Debian ===&lt;br /&gt;
==== Netplan ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Apply the configuration, but if the dialogue is left unconfirmed, the configuration will be reverted.&lt;br /&gt;
netplan try&lt;br /&gt;
&lt;br /&gt;
# Apply the configuration&lt;br /&gt;
netplan apply&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Generic DCHP interface =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;yaml&#039;&amp;gt;&lt;br /&gt;
network:&lt;br /&gt;
    version: 2&lt;br /&gt;
    ethernets:&lt;br /&gt;
        ens4:&lt;br /&gt;
            # Some info about the Interface/why does it exist&lt;br /&gt;
            dhcp4: true&lt;br /&gt;
            match:&lt;br /&gt;
                macaddress: fa:16:3e:aa:bb:cc&lt;br /&gt;
            set-name: ens4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Generic DHCP Interfaces, but while ignoring the routes for an Interface and disabling DHCP on the other.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;yaml&#039;&amp;gt;&lt;br /&gt;
network:&lt;br /&gt;
    version: 2&lt;br /&gt;
    ethernets:&lt;br /&gt;
        ens4:&lt;br /&gt;
            # Some info about the Interface/why does it exist&lt;br /&gt;
            dhcp4: true&lt;br /&gt;
            dhcp4-overrides:&lt;br /&gt;
              use-routes: false&lt;br /&gt;
            match:&lt;br /&gt;
                macaddress: fa:16:3e:aa:bb:cc&lt;br /&gt;
            set-name: ens4&lt;br /&gt;
        ens5:&lt;br /&gt;
            # Some info about the Interface/why does it exist&lt;br /&gt;
            dhcp4: no&lt;br /&gt;
            match:&lt;br /&gt;
                macaddress: fa:16:cc:dd:ee&lt;br /&gt;
            set-name: ens5&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Generic static interface =====&lt;br /&gt;
You may have to disable automatic network-configuration:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;yaml&#039;&amp;gt;&lt;br /&gt;
sudo bash -c &#039;echo &amp;quot;network: {config: disabled}&amp;quot; &amp;gt; /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;yaml&#039;&amp;gt;&lt;br /&gt;
network:&lt;br /&gt;
    version: 2&lt;br /&gt;
    ethernets:&lt;br /&gt;
        ens7:&lt;br /&gt;
           addresses:&lt;br /&gt;
              - 192.168.0.23/24&lt;br /&gt;
           match:&lt;br /&gt;
               macaddress: ab:cd:ef:gh:ij:kl&lt;br /&gt;
           mtu: 1500&lt;br /&gt;
           set-name: ens7&lt;br /&gt;
           nameservers:&lt;br /&gt;
               addresses: [1.1.1.1, 8.8.8.8]&lt;br /&gt;
           routes:&lt;br /&gt;
              - to: default&lt;br /&gt;
                via: 192.168.0.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== VLAN Interface =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;yaml&#039;&amp;gt;&lt;br /&gt;
network:&lt;br /&gt;
    version: 2&lt;br /&gt;
    ethernets:&lt;br /&gt;
        eno1: {}&lt;br /&gt;
    vlans:&lt;br /&gt;
        eno1.10:&lt;br /&gt;
            id: 10&lt;br /&gt;
            link: eno1&lt;br /&gt;
            addresses: [192.168.1.1/24]&lt;br /&gt;
        eno1.20:&lt;br /&gt;
            id: 20&lt;br /&gt;
            link: eno1&lt;br /&gt;
            addresses: [192.168.2.1/24]&lt;br /&gt;
            nameservers:&lt;br /&gt;
              addresses:&lt;br /&gt;
                - 1.1.1.1&lt;br /&gt;
                - 8.8.8.8&lt;br /&gt;
              search: []&lt;br /&gt;
            routes:&lt;br /&gt;
              - to: default&lt;br /&gt;
                via: 192.168.2.1&lt;br /&gt;
        eno1.30:&lt;br /&gt;
            id: 30&lt;br /&gt;
            link: eno1&lt;br /&gt;
            addresses: [192.168.3.1/24]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Empty Interface =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;yaml&#039;&amp;gt;&lt;br /&gt;
network:&lt;br /&gt;
  version: 2&lt;br /&gt;
  ethernets:&lt;br /&gt;
    eno2:&lt;br /&gt;
      dhcp4: false&lt;br /&gt;
      dhcp6: false&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Interface files ====&lt;br /&gt;
Classic &amp;lt;code&amp;gt;/etc/network/interfaces.d&amp;lt;/code&amp;gt; files i.e. &amp;lt;code&amp;gt; /etc/network/interfaces.d/ens200.conf &amp;lt;/code&amp;gt;&lt;br /&gt;
Otherwise use &amp;lt;code&amp;gt;/etc/network/interfaces &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Generic IPv4 =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# /etc/network/interfaces.d/ens160.conf&lt;br /&gt;
auto ens160&lt;br /&gt;
iface ens160 inet static&lt;br /&gt;
    address 192.168.23.7&lt;br /&gt;
    netmask 255.255.255.0&lt;br /&gt;
    gateway 192.168.23.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Generic IPv6 =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# /etc/network/interfaces.d/ens3.conf&lt;br /&gt;
iface ens3 inet6 static&lt;br /&gt;
    address abcd:defg:0:1234:5123:abcd:abcd:1234&lt;br /&gt;
    netmask 48&lt;br /&gt;
    gateway abcd:defg::1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Bond =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
auto eno1&lt;br /&gt;
iface eno1 inet manual&lt;br /&gt;
&lt;br /&gt;
auto eno2&lt;br /&gt;
iface eno2 inet manual&lt;br /&gt;
&lt;br /&gt;
auto bond0&lt;br /&gt;
iface bond0 inet static&lt;br /&gt;
        address 192.168.39.245&lt;br /&gt;
        gateway 192.168.39.254&lt;br /&gt;
        network 255.255.255.0&lt;br /&gt;
        bond-slaves eno1 eno2&lt;br /&gt;
        bond-miimon 100&lt;br /&gt;
        bond-mode 802.3ad&lt;br /&gt;
        bond-xmit-hash-policy layer2+3&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Services&amp;diff=835</id>
		<title>Linux:Services</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Services&amp;diff=835"/>
		<updated>2025-09-25T12:28:32Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* Checks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet|Cheatsheets]]&lt;br /&gt;
&lt;br /&gt;
== Services ==&lt;br /&gt;
&amp;lt;section begin=&amp;quot;linuxservices&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Common ===&lt;br /&gt;
==== systemctl ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all services that are running or exited&lt;br /&gt;
systemctl&lt;br /&gt;
&lt;br /&gt;
# List all services, running or otherwise&lt;br /&gt;
systemctl --all&lt;br /&gt;
&lt;br /&gt;
# List all failed services&lt;br /&gt;
systemctl --state=failed&lt;br /&gt;
&lt;br /&gt;
# Reset the failed service &amp;quot;nginx&amp;quot;&lt;br /&gt;
systemctl reset-failed nginx&lt;br /&gt;
&lt;br /&gt;
# View the status of the &amp;quot;nfs-server&amp;quot; service&lt;br /&gt;
systemctl status nfs-server&lt;br /&gt;
&lt;br /&gt;
# Output the config file of &amp;quot;rsyslog&amp;quot; to the shell&lt;br /&gt;
systemctl cat rsyslog&lt;br /&gt;
&lt;br /&gt;
# Restart the &amp;quot;sshd&amp;quot; service, terminating established connections and re-parsing the configuration&lt;br /&gt;
systemctl restart sshd&lt;br /&gt;
&lt;br /&gt;
# Reload the &amp;quot;nginx&amp;quot; service so that it only re-parses the configuration&lt;br /&gt;
systemctl reload nginx&lt;br /&gt;
&lt;br /&gt;
# Stop the &amp;quot;nfs-ganesha&amp;quot; service so that it stops being run&lt;br /&gt;
systemctl stop nfs-ganesha&lt;br /&gt;
&lt;br /&gt;
# Start the &amp;quot;nfs-ganesha&amp;quot; service so that it starts being run again&lt;br /&gt;
systemctl start nfs-ganesha&lt;br /&gt;
&lt;br /&gt;
# Disable the &amp;quot;mariadb&amp;quot; service so that it doesn&#039;t start after the next boot&lt;br /&gt;
systemctl disable mariadb&lt;br /&gt;
&lt;br /&gt;
# Enable the &amp;quot;mariadb&amp;quot; service so that it starts after the next boot.&lt;br /&gt;
systemctl enable mariadb&lt;br /&gt;
&lt;br /&gt;
# Check the logs for all failed services&lt;br /&gt;
for i in $(systemctl --state=failed | head -n -4 | tail -n +2 | awk &#039;{print $1}&#039;); do systemctl --no-pager status &amp;quot;$i&amp;quot;; done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== NTP ===&lt;br /&gt;
==== Timedatectl ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show the current status of timedatectl&lt;br /&gt;
timedatectl&lt;br /&gt;
&lt;br /&gt;
# List available timezones&lt;br /&gt;
timedatectl list-timezones&lt;br /&gt;
&lt;br /&gt;
# Set the timezone to Amsterdam&lt;br /&gt;
timedatectl set-timezone Europe/Amsterdam&lt;br /&gt;
&lt;br /&gt;
# Show verbose sync information&lt;br /&gt;
timedatectl timesync-status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SNMP ===&lt;br /&gt;
==== V3 client installation ====&lt;br /&gt;
* https://kifarunix.com/quick-way-to-install-and-configure-snmp-on-ubuntu-20-04/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
apt install snmpd snmp libsnmp-dev&lt;br /&gt;
cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.bak&lt;br /&gt;
systemctl stop snmpd&lt;br /&gt;
net-snmp-create-v3-user -ro -X &amp;lt;CRYPTO-PASSWORD&amp;gt; -a SHA -X &amp;lt;PASSWORD&amp;gt; -x AES &amp;lt;USERNAME&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/snmp/snmpd.conf&lt;br /&gt;
sysLocation    NL;Zuid-Holland;Rotterdam, 78 MyStreet;2nd Floor;Server Room;Rack&lt;br /&gt;
sysContact     Me &amp;lt;me@example.org&amp;gt;&lt;br /&gt;
agentaddress   192.168.0.10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
systemctl start snmpd&lt;br /&gt;
systemctl enable snmpd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Test&lt;br /&gt;
snmpwalk -v3 -a SHA -A &amp;quot;AUTHENTICATION PASSWORD&amp;quot; -x AES -X &amp;quot;CRYPTO PASSWORD&amp;quot; -l authPriv -u &amp;quot;MYUSER&amp;quot; localhost | head&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CTDB  ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Verify CTDB cluster status&lt;br /&gt;
ctdb status&lt;br /&gt;
&lt;br /&gt;
# Show the allocated IP addresses and to which nodes they&#039;re bound&lt;br /&gt;
ctdb ip&lt;br /&gt;
&lt;br /&gt;
# See the status of all CTDB-scripts&lt;br /&gt;
ctdb scriptstatus&lt;br /&gt;
ctdb event status&lt;br /&gt;
&lt;br /&gt;
# Show the time of the last failover the duration it took to recover&lt;br /&gt;
ctdb uptime&lt;br /&gt;
&lt;br /&gt;
# See various statistics and data&lt;br /&gt;
ctdb statistics&lt;br /&gt;
&lt;br /&gt;
# Use the onnode command to execute a command on all cluster nodes&lt;br /&gt;
onnode all ctdb status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Stop a ctdb cluster member&lt;br /&gt;
ctdb stop&lt;br /&gt;
&lt;br /&gt;
# Start a stopped ctdb cluster member&lt;br /&gt;
ctdb continue&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Firewalls ===&lt;br /&gt;
==== UFW ====&lt;br /&gt;
===== Checks =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show summary of UFW status&lt;br /&gt;
ufw status&lt;br /&gt;
&lt;br /&gt;
# Show verbose UFW status&lt;br /&gt;
ufw status verbose&lt;br /&gt;
&lt;br /&gt;
# Show UFW rules numbered&lt;br /&gt;
ufw status numbered&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Commands =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Allow access from a specific IP to a port and add a comment that show in the status&lt;br /&gt;
ufw allow from 10.0.0.253 to any port 22 proto tcp comment &#039;Allow SSH access from XYZ location&#039;&lt;br /&gt;
&lt;br /&gt;
# Delete numbered Firewall rule 56&lt;br /&gt;
ufw delete 56&lt;br /&gt;
&lt;br /&gt;
# Disable UFW logging (prevent syslog spam)&lt;br /&gt;
ufw logging off&lt;br /&gt;
&lt;br /&gt;
# Set UFW logging back to the default&lt;br /&gt;
ufw logging low&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Firewalld ====&lt;br /&gt;
===== SNMP access =====&lt;br /&gt;
* https://unix.stackexchange.com/questions/214388/how-to-let-the-firewall-of-rhel7-the-snmp-connection-passing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/firewalld/services/snmp.xml&lt;br /&gt;
&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;service&amp;gt;&lt;br /&gt;
  &amp;lt;short&amp;gt;SNMP&amp;lt;/short&amp;gt;&lt;br /&gt;
  &amp;lt;description&amp;gt;SNMP protocol&amp;lt;/description&amp;gt;&lt;br /&gt;
  &amp;lt;port protocol=&amp;quot;udp&amp;quot; port=&amp;quot;161&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/service&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
firewall-cmd --zone=public --add-service snmp --permanent&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Firewall-cmd =====&lt;br /&gt;
====== Checks ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all available commands&lt;br /&gt;
firewall-cmd -h&lt;br /&gt;
&lt;br /&gt;
# Check the configuration file of the firewall for errors&lt;br /&gt;
firewall-cmd --check-config&lt;br /&gt;
&lt;br /&gt;
# Display the current state of firewall-cmd (running/shutdown)&lt;br /&gt;
firewall-cmd --state&lt;br /&gt;
&lt;br /&gt;
# Display all available zones&lt;br /&gt;
firewall-cmd --get-zones&lt;br /&gt;
&lt;br /&gt;
# List all whitelisted services&lt;br /&gt;
firewall-cmd --list-services&lt;br /&gt;
&lt;br /&gt;
# List all services you can potentially enable&lt;br /&gt;
firewall-cmd --get-services&lt;br /&gt;
&lt;br /&gt;
# List all added or enabled services and ports in more detail&lt;br /&gt;
firewall-cmd --list-all&lt;br /&gt;
&lt;br /&gt;
# List verbose information for all zones&lt;br /&gt;
firewall-cmd --list-all-zones&lt;br /&gt;
&lt;br /&gt;
# List verbose information for the public zone&lt;br /&gt;
firewall-cmd --list-all --zone=public&lt;br /&gt;
&lt;br /&gt;
# See what port(s) are associated with the dns service&lt;br /&gt;
firewall-cmd --info-service dns&lt;br /&gt;
&lt;br /&gt;
# List all opened ports&lt;br /&gt;
firewall-cmd --list-ports&lt;br /&gt;
&lt;br /&gt;
# List kernel ruleset generated for nftables(?)&lt;br /&gt;
nft list ruleset&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Commands ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reload the firewall&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Whitelist the dns service, persistently even after reboot&lt;br /&gt;
firewall-cmd --add-service=dns ; sudo firewall-cmd --runtime-to-permanent; firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Whitelist the http service, persistently even after reboot&lt;br /&gt;
firewall-cmd --add-service=http ; sudo firewall-cmd --runtime-to-permanent; firewall-cmd --reload&lt;br /&gt;
&lt;br /&gt;
# Remove the http service from the whitelist&lt;br /&gt;
firewall-cmd --remove-service=http&lt;br /&gt;
&lt;br /&gt;
# Add port 1234 (tcp) to the whitelist&lt;br /&gt;
firewall-cmd --add-port=1234/tcp&lt;br /&gt;
&lt;br /&gt;
# Remove port 1234 (tcp) from the whitelist&lt;br /&gt;
firewall-cmd --remove-port=1234/tcp&lt;br /&gt;
&lt;br /&gt;
# Add port 2345 (udp) to the whitelist in zone external&lt;br /&gt;
firewall-cmd --zone=external --add-port=2345/udp&lt;br /&gt;
&lt;br /&gt;
# Remove port 2345 (udp) from the whitelist for zone external&lt;br /&gt;
firewall-cmd --zone=external --add-port=2345/udp&lt;br /&gt;
&lt;br /&gt;
# Add current configuration to configuration permanently&lt;br /&gt;
firewall-cmd –runtime-to-permanent&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;DANGEROUS&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# SHUT IT DOWN DOC - DROP ALL PACKETS AND EXPIRE EXISTING CONNECTIONS&lt;br /&gt;
firewall-cmd --panic-on&lt;br /&gt;
&lt;br /&gt;
# ACCEPT PACKETS AGAIN&lt;br /&gt;
firewall-cmd --panic-off&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== CSF ====&lt;br /&gt;
ConfigServer Security and Firewall&lt;br /&gt;
&lt;br /&gt;
===== General =====&lt;br /&gt;
* Common configuration: /etc/csf/csf.conf &lt;br /&gt;
* Blacklist: /etc/csf/csf.deny &lt;br /&gt;
* Whitelist: /etc/csf/csf.allow &lt;br /&gt;
&lt;br /&gt;
===== Installation =====&lt;br /&gt;
From the official instructions: https://download.configserver.com/csf/install.txt&lt;br /&gt;
&lt;br /&gt;
====== Prerequisites ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Perl Modules&lt;br /&gt;
============&lt;br /&gt;
While most should be installed on a standard perl installation the following&lt;br /&gt;
may need to be installed manually:&lt;br /&gt;
&lt;br /&gt;
# On rpm based systems:&lt;br /&gt;
yum install perl-libwww-perl.noarch perl-LWP-Protocol-https.noarch perl-GDGraph&lt;br /&gt;
&lt;br /&gt;
# On APT based systems:&lt;br /&gt;
apt-get install libwww-perl liblwp-protocol-https-perl libgd-graph-perl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Install ======&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cd /usr/src&lt;br /&gt;
rm -fv csf.tgz&lt;br /&gt;
wget https://download.configserver.com/csf.tgz&lt;br /&gt;
tar -xzf csf.tgz&lt;br /&gt;
cd csf&lt;br /&gt;
sh install.sh&lt;br /&gt;
&lt;br /&gt;
# Next, test whether you have the required iptables modules:&lt;br /&gt;
perl /usr/local/csf/bin/csftest.pl&lt;br /&gt;
&lt;br /&gt;
# Don&#039;t worry if you cannot run all the features, so long as the script doesn&#039;t report any FATAL errors&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Checks =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check the running status of csf&lt;br /&gt;
csf status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Commands =====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Commit config changes by restarting csf&lt;br /&gt;
csf -r&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== csf.conf =====&lt;br /&gt;
Some common changes within the configuration file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Set testing to 0 when your CSF configuration is &#039;production&#039; ready&lt;br /&gt;
TESTING = &amp;quot;0&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow access to any service you&#039;re hosting locally, for example https&lt;br /&gt;
TCP_IN = &amp;quot;443&amp;quot;&lt;br /&gt;
UDP_IN = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow all outwards HTTP/HTTPS traffic so you can yum/apt update&lt;br /&gt;
TCP_OUT = &amp;quot;80,443&amp;quot; &lt;br /&gt;
&lt;br /&gt;
# Allow outgoing traceroute&lt;br /&gt;
UDP_OUT = &amp;quot;33434:33523&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Allow your server to be pinged&lt;br /&gt;
ICMP_IN = &amp;quot;0&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Formatting =====&lt;br /&gt;
The varying styles of formatting used in allow.conf&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Allow anything relating to the following IPs/ranges&lt;br /&gt;
192.168.10.0/24 # Our application breaks without this range&lt;br /&gt;
192.168.1.1 # Our gateway or something&lt;br /&gt;
&lt;br /&gt;
# Detailed entries based on Transport protocol, direction, Application protocol and IP&lt;br /&gt;
tcp:in:d=22:s=7.7.7.7 # SSH access from our VPN&lt;br /&gt;
udp:in:d=161:s=10.11.12.100 # SNMP Access&lt;br /&gt;
tcp|in|d=22|s=fe80::1:/16 # IPV6 SSH access from our jumpgateway&lt;br /&gt;
udp|in|d=3389|s=10.1.0.0/24 # RDP Access from our entire office range&lt;br /&gt;
tcp|out|d=80,443|d=1.2.3.4/32 # Allow outgoing HTTP/HTTPS access via port 80 and 443&lt;br /&gt;
&lt;br /&gt;
# Allow sending Syslog messages to our Syslog server&lt;br /&gt;
udp|out|d=514|d=192.168.20.5 # UDP syslog server&lt;br /&gt;
tcp|out|d=10514|d=192.168.20.5 # UDP syslog server&lt;br /&gt;
&lt;br /&gt;
# Allow sending queries to some DNS servers&lt;br /&gt;
tcp|out|s=53|d=8.8.8.8&lt;br /&gt;
udp|out|s=53|d=1.1.1.1&lt;br /&gt;
udp|out|s=53|d=2606:4700:4700::1111 # Cloudflare IPv6 DNS Server&lt;br /&gt;
&lt;br /&gt;
# Include an external configuration file&lt;br /&gt;
Include /etc/csf/csf.custom-config&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rsyslog ===&lt;br /&gt;
&amp;lt;section begin=&amp;quot;linuxsyslog&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Legacy ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#/etc/rsyslog.d/70-local-to-rsyslog-server.conf&lt;br /&gt;
# Define the hostname to send to the syslog server&lt;br /&gt;
$template SendHostname, &amp;quot;&amp;lt;%pri%&amp;gt; %timestamp% myhost.mydomain.nl %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
$ActionForwardDefaultTemplate SendHostname&lt;br /&gt;
&lt;br /&gt;
*.warning @10.77.0.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rainerscript ====&lt;br /&gt;
Rainerscript: https://rsyslog.readthedocs.io/en/latest/rainerscript/control_structures.html&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/rsyslog.d/70-local-to-rsyslog-server.conf&lt;br /&gt;
# Define a template and specify a hostname to send as:&lt;br /&gt;
template(name=&amp;quot;SendHostname&amp;quot; type=&amp;quot;string&amp;quot;&lt;br /&gt;
string=&amp;quot;%timestamp% myhost.mydomain.nl %syslogtag% %msg%\n&amp;quot;&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
# Send logs to target syslog server and port&lt;br /&gt;
*.warning action(type=&amp;quot;omfwd&amp;quot; Target=&amp;quot;10.0.33.10&amp;quot; Template=&amp;quot;SendHostname&amp;quot; Port=&amp;quot;514&amp;quot; Protocol=&amp;quot;udp&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Testing ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use the logger tool to test syslog server reception&lt;br /&gt;
logger -p local0.error &#039;Hello World!&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section end=&amp;quot;linuxsyslog&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== named ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Perform a test load of all primary zones within named.conf, as the named user&lt;br /&gt;
sudo -u named named-checkconf -z&lt;br /&gt;
&lt;br /&gt;
# Check zone file 192.168.77.0 defined in the 77.168.192.in-addr.arpa zone&lt;br /&gt;
named-checkzone 77.168.192.in-addr.arpa 192.168.77.0&lt;br /&gt;
&lt;br /&gt;
# Check zone file brammerloo.nl defined in the brammerloo.nl zone&lt;br /&gt;
named-checkzone brammerloo.nl brammerloo.nl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Basic configuration for the options field in &#039;&#039;&#039;/etc/named.conf&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
options {&lt;br /&gt;
# Define on what IP to listen on, for port 53&lt;br /&gt;
        listen-on port 53 { 127.0.0.1; 192.168.0.1; 192.168.1.1; };&lt;br /&gt;
        directory       &amp;quot;/var/named&amp;quot;;&lt;br /&gt;
        dump-file       &amp;quot;/var/named/data/cache_dump.db&amp;quot;;&lt;br /&gt;
        statistics-file &amp;quot;/var/named/data/named_stats.txt&amp;quot;;&lt;br /&gt;
        memstatistics-file &amp;quot;/var/named/data/named_mem_stats.txt&amp;quot;;&lt;br /&gt;
        secroots-file   &amp;quot;/var/named/data/named.secroots&amp;quot;;&lt;br /&gt;
        recursing-file  &amp;quot;/var/named/data/named.recursing&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# Only allow DNS queries from specific local subnets&lt;br /&gt;
# To allow from anything use: allow query { any; };&lt;br /&gt;
        allow-query     { localhost; 127.0.0.1; 192.168.0.0/24; 192.168.1.0/24; };&lt;br /&gt;
&lt;br /&gt;
# If the server can&#039;t resolve an address locally, use the following DNS servers for help&lt;br /&gt;
        forwarders {&lt;br /&gt;
        8.8.8.8;&lt;br /&gt;
        1.1.1.1;&lt;br /&gt;
        };&lt;br /&gt;
&lt;br /&gt;
        recursion yes;&lt;br /&gt;
        dnssec-validation no;&lt;br /&gt;
&lt;br /&gt;
        managed-keys-directory &amp;quot;/var/named/dynamic&amp;quot;;&lt;br /&gt;
        geoip-directory &amp;quot;/usr/share/GeoIP&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
        pid-file &amp;quot;/run/named/named.pid&amp;quot;;&lt;br /&gt;
        session-keyfile &amp;quot;/run/named/session.key&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
        /* https://fedoraproject.org/wiki/Changes/CryptoPolicy */&lt;br /&gt;
        include &amp;quot;/etc/crypto-policies/back-ends/bind.config&amp;quot;;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone defnitions: &#039;&#039;&#039;/etc/named.rfc1912.zones&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Define zones to listen for&lt;br /&gt;
zone &amp;quot;brammerloo.nl&amp;quot; IN {&lt;br /&gt;
        type master;&lt;br /&gt;
        file &amp;quot;brammerloo.nl&amp;quot;;&lt;br /&gt;
        allow-update { none; };&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
zone &amp;quot;1.168.192.in-addr.arpa&amp;quot; IN {&lt;br /&gt;
        type master;&lt;br /&gt;
        file &amp;quot;192.168.1.0&amp;quot;;&lt;br /&gt;
        allow-update { none; };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone file for Reverse lookup: &#039;&#039;&#039;/var/named/192.168.1.0&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$TTL 300&lt;br /&gt;
@       IN SOA  ns1.brammerloo.nl. admin.brammerloo.nl. (&lt;br /&gt;
                                        2023101102 ; serial&lt;br /&gt;
                                        180     ; refresh&lt;br /&gt;
                                        60      ; retry&lt;br /&gt;
                                        108000  ; expire&lt;br /&gt;
                                        60 )    ; minimum&lt;br /&gt;
    IN      NS      ns1.brammerloo.nl.&lt;br /&gt;
; PTR Records&lt;br /&gt;
11    IN   PTR   node1.&lt;br /&gt;
21    IN   PTR   server1.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zone file for domain: &#039;&#039;&#039;/var/named/brammerloo.nl&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$TTL 300&lt;br /&gt;
@       IN SOA  ns1.brammerloo.nl. admin.brammerloo.nl. (&lt;br /&gt;
                                        2023101306 ; serial&lt;br /&gt;
                                        180     ; refresh&lt;br /&gt;
                                        60      ; retry&lt;br /&gt;
                                        108000  ; expire&lt;br /&gt;
                                        60 )    ; minimum&lt;br /&gt;
    IN      NS      ns1.brammerloo.nl.&lt;br /&gt;
@                  IN      A     192.168.1.6   ; domain brammerloo.nl is me!&lt;br /&gt;
ns1.brammerloo.nl. IN      A     192.168.78.31 ; FQDN for my domain&lt;br /&gt;
node1              IN      A     192.168.78.31 ; Basic A-record&lt;br /&gt;
www                IN      CNAME node1         ; Point my website to my node1 A-record&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== dhcpd ===&lt;br /&gt;
==== dhclient ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Request an IPv4 adres from a DHCP server&lt;br /&gt;
dhclient -4&lt;br /&gt;
&lt;br /&gt;
# Show verbose information when requesting an IPv4 adres from a DHCP server&lt;br /&gt;
dhclient -4 -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Basic configuration options in the &#039;&#039;&#039;/etc/dhcp/dhcpd.conf&#039;&#039;&#039; file&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Set the domain clients should use when resolving hostnames (equivalent to search domain)&lt;br /&gt;
option domain-name &amp;quot;brammerloo.nl&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# Set the domain name servers for DHCP clients&lt;br /&gt;
option domain-name-servers ns1.brammerloo.nl, 8.8.8.8;&lt;br /&gt;
&lt;br /&gt;
default-lease-time 600;&lt;br /&gt;
max-lease-time 7200;&lt;br /&gt;
log-facility local7;&lt;br /&gt;
&lt;br /&gt;
# Best practice = define any connected subnets, but don&#039;t configure DHCP for them&lt;br /&gt;
subnet 192.168.1.0 netmask 255.255.255.0 {&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Basic DHCP for a subnet configuration&lt;br /&gt;
subnet 192.168.0.0 netmask 255.255.255.0 {&lt;br /&gt;
  range 192.168.0.100 192.168.0.150;&lt;br /&gt;
  option routers 192.168.0.1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== smbd / Samba / CIFS ===&lt;br /&gt;
https://linuxconfig.org/install-samba-on-redhat-8&lt;br /&gt;
&lt;br /&gt;
==== Basic configuration ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install and enable&lt;br /&gt;
dnf install samba samba-client&lt;br /&gt;
systemctl enable --now {smb,nmb}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a client-user to authenticate with&lt;br /&gt;
sudo useradd samba-user&lt;br /&gt;
&lt;br /&gt;
# Give the user a password to authenticate with&lt;br /&gt;
sudo smbpasswd -a samba-user&lt;br /&gt;
&lt;br /&gt;
# Create a group to associate with the samba share&lt;br /&gt;
sudo groupadd sambagroup&lt;br /&gt;
&lt;br /&gt;
# Add the user to the group we will be configuring for the share&lt;br /&gt;
sudo usermod -a -G sambagroup samba-user&lt;br /&gt;
&lt;br /&gt;
# Create the folder we will be sharing&lt;br /&gt;
sudo mkdir /var/shares/myshare&lt;br /&gt;
&lt;br /&gt;
# Apply proper permission&lt;br /&gt;
sudo chown -R samba-user:sambagroup /var/shares/myshare/&lt;br /&gt;
sudo chmod -R 0770 /var/shares/myshare/&lt;br /&gt;
&lt;br /&gt;
# Apply proper permission for SELinux&lt;br /&gt;
sudo chcon -t samba_share_t /var/shares/myshare/&lt;br /&gt;
&lt;br /&gt;
# Backup the default config&lt;br /&gt;
cp /etc/samba/smb.conf /etc/samba/smb.conf~&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# /etc/samba/smb.conf&lt;br /&gt;
[global]&lt;br /&gt;
 workgroup = &amp;lt;DOMAIN-OR-WORKGROUP&amp;gt;&lt;br /&gt;
 server string = Samba Server %v&lt;br /&gt;
 netbios name = &amp;lt;SERVER-HOSTNAME&amp;gt;&lt;br /&gt;
 security = user&lt;br /&gt;
 map to guest = bad user&lt;br /&gt;
 dns proxy = no&lt;br /&gt;
&lt;br /&gt;
#==================== Share Definitions ======================&lt;br /&gt;
[share001]&lt;br /&gt;
 path = /var/shares/myshare&lt;br /&gt;
 valid users = @sambagroup&lt;br /&gt;
 guest ok = no&lt;br /&gt;
 writable = yes&lt;br /&gt;
 browsable = yes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reload Samba services&lt;br /&gt;
systemctl reload {smb,nmb}&lt;br /&gt;
&lt;br /&gt;
# Mount in Windows&lt;br /&gt;
\\&amp;lt;SERVER-IP&amp;gt;\share001&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user: samba-user&lt;br /&gt;
pass: &amp;lt;Whatever password you filled in with smbpasswd -a&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Samba checks&lt;br /&gt;
smbstatus&lt;br /&gt;
smbstatus -S&lt;br /&gt;
smbstatus -b&lt;br /&gt;
&lt;br /&gt;
# Samba set debug mode&lt;br /&gt;
smbcontrol smbd debug 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Docker ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List Docker containers &lt;br /&gt;
docker ps&lt;br /&gt;
&lt;br /&gt;
# List all Docker container IDs&lt;br /&gt;
docker ps -aq&lt;br /&gt;
&lt;br /&gt;
# List logs for container 987sdh3qrasdhj&lt;br /&gt;
docker logs 987sdh3qrasdhj&lt;br /&gt;
&lt;br /&gt;
# List RAM/CPU usage for Docker container asdlkasd67k&lt;br /&gt;
docker stats asdlkasd67k&lt;br /&gt;
&lt;br /&gt;
# Show verbose container information such as commands run, network, ID, etc&lt;br /&gt;
docker inspect oiu2398sda87&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enter the shell inside a docker container&lt;br /&gt;
docker exec -ti a89sd98sa7d /bin/bash&lt;br /&gt;
&lt;br /&gt;
# Execute a command inside a container as a specific user, root in this case&lt;br /&gt;
docker exec -it -u root asd87289hasdadz tail /var/log/nginx/access.log&lt;br /&gt;
docker exec -u 0 -it as892asnj2as /bin/bash&lt;br /&gt;
&lt;br /&gt;
# Restart docker container yoga&lt;br /&gt;
docker restart yoga&lt;br /&gt;
&lt;br /&gt;
# Restart the 3 given containers&lt;br /&gt;
docker restart 79f71c7f4d91 bbb3d3f5c3b1 b0a3204d4098&lt;br /&gt;
&lt;br /&gt;
# Start this container&lt;br /&gt;
docker start as9823nzxc0&lt;br /&gt;
&lt;br /&gt;
# Stop this container&lt;br /&gt;
docker stop as9823nzxc0&lt;br /&gt;
&lt;br /&gt;
# Restart all unhealthy Docker containers&lt;br /&gt;
for i in $(docker ps | grep unhealthy | awk &#039;{print $1}&#039;); do docker restart &amp;quot;$i&amp;quot;; done;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PowerDNS ===&lt;br /&gt;
* https://doc.powerdns.com/authoritative/index.html&lt;br /&gt;
* https://doc.powerdns.com/authoritative/manpages/pdns_server.1.html&lt;br /&gt;
* https://doc.powerdns.com/authoritative/manpages/pdnsutil.1.html&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# List commands&lt;br /&gt;
pdns_server --help&lt;br /&gt;
&lt;br /&gt;
# Check config and parse for errors&lt;br /&gt;
pdns_server --config=check&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# List available commands &lt;br /&gt;
pdnsutil --help&lt;br /&gt;
&lt;br /&gt;
# Check config and parse for errors&lt;br /&gt;
pdnsutil --config=check&lt;br /&gt;
&lt;br /&gt;
# List all available zones&lt;br /&gt;
pdnsutil list-all-zones&lt;br /&gt;
&lt;br /&gt;
# List all domains in the primary zone&lt;br /&gt;
pdnsutil list-all-zones primary&lt;br /&gt;
&lt;br /&gt;
# See zone information for a specific domain&lt;br /&gt;
pdnsutil show-zone mydomain.com&lt;br /&gt;
pdnsutil show-zone 77.5.10.in-addr.arpa&lt;br /&gt;
&lt;br /&gt;
# Check zone for errors&lt;br /&gt;
pdnsutil check-zone mydomain.com&lt;br /&gt;
&lt;br /&gt;
# List all created TSIG keys&lt;br /&gt;
pdnsutil list-tsig-keys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# Activate TSIG key for domain &amp;quot;myexample.com&amp;quot; in the primary zone&lt;br /&gt;
pdnsutil &amp;quot; myexample.com transfer primary&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MAAS ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Logs in either place:&lt;br /&gt;
/var/log/maas/&lt;br /&gt;
/var/snap/maas/common/log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List status of MAAS services&lt;br /&gt;
maas status&lt;br /&gt;
&lt;br /&gt;
# List MAAS commands&lt;br /&gt;
maas --help&lt;br /&gt;
&lt;br /&gt;
# List available arguments for the init command&lt;br /&gt;
maas init --help&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section end=&amp;quot;linuxservices&amp;quot;/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Tools&amp;diff=834</id>
		<title>Linux:Tools</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Tools&amp;diff=834"/>
		<updated>2025-09-23T13:01:50Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* rclone */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet]]&lt;br /&gt;
&lt;br /&gt;
== Commands ==&lt;br /&gt;
=== Quick access ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Scroll through a file with less&lt;br /&gt;
less -s myfile.txt&lt;br /&gt;
&lt;br /&gt;
# Select line 5 from the output&lt;br /&gt;
cat example.txt | sel -e &#039;5&#039;&lt;br /&gt;
&lt;br /&gt;
# Select lines from the output, starting from the top&lt;br /&gt;
cat example.txt | head -5&lt;br /&gt;
&lt;br /&gt;
# Select lines from the output, starting from the bottom&lt;br /&gt;
cat example.txt | tail -5&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Commands ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Display the full path of a file(assuming the syslog file is available in the current folder)&lt;br /&gt;
readlink -f syslog&lt;br /&gt;
&lt;br /&gt;
# Unzip a file&lt;br /&gt;
gunzip /var/log/messages.2.gz&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Uncommon commands ===&lt;br /&gt;
* https://ngelinux.com/what-is-proc-sysrq-trigger-in-linux-and-how-to-use-sysrq-kernel-feature/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CrASHing THIs SERVer, WiTH no SurVIvORS!&lt;br /&gt;
echo c &amp;gt; /proc/sysrq-trigger&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Network ==&lt;br /&gt;
=== ping ===&lt;br /&gt;
Troubleshooting MTU: https://access.redhat.com/solutions/2440411&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Ping with an interval of 5 seconds&lt;br /&gt;
ping -i 5 192.168.0.1&lt;br /&gt;
&lt;br /&gt;
# Ping 192.168.10.5 using a specific interface&lt;br /&gt;
ping -I bond0 192.168.10.5&lt;br /&gt;
&lt;br /&gt;
# Ping 8.8.8.8 for 20 times&lt;br /&gt;
ping -c 20 8.8.8.8&lt;br /&gt;
&lt;br /&gt;
# Ping google.com using IPv4&lt;br /&gt;
ping -4 google.com&lt;br /&gt;
&lt;br /&gt;
# Ping google.com using IPv6&lt;br /&gt;
ping -6 google.com&lt;br /&gt;
&lt;br /&gt;
# Ping using packets of size 264&lt;br /&gt;
ping -s 264 1.1.1.1&lt;br /&gt;
&lt;br /&gt;
# Test an MTU-size of 9000 by sending non-fragmented packages of size 8972 (28 bytes left for the headers)&lt;br /&gt;
ping -M do -s 8972 192.168.77.88&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== traceroute ===&lt;br /&gt;
Package &#039;&#039;&#039;mtr&#039;&#039;&#039; (My traceroute) is also very good&lt;br /&gt;
&lt;br /&gt;
* https://web.archive.org/web/20110101100046/https://www.exit109.com/~jeremy/news/providers/traceroute.html&lt;br /&gt;
* [https://en.wikipedia.org/wiki/Traceroute UDP ports 33434 to 33534 are used by traceroute by default.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show the traversed hops towards google.com using IPv4&lt;br /&gt;
traceroute -4 google.com&lt;br /&gt;
&lt;br /&gt;
# Show the traversed hops towards google.com using IPv6&lt;br /&gt;
traceroute -6 google.com&lt;br /&gt;
&lt;br /&gt;
# Does the same as &amp;quot;traceroute -6 google.com&amp;quot;&lt;br /&gt;
traceroute6 google.com&lt;br /&gt;
&lt;br /&gt;
# Use ICMP for checking hops&lt;br /&gt;
traceroute -4 -I brammerloo.nl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== route ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List configured routes&lt;br /&gt;
route&lt;br /&gt;
&lt;br /&gt;
# List routes but display IPs instead of hostnames&lt;br /&gt;
route -n&lt;br /&gt;
&lt;br /&gt;
# Delete default route &lt;br /&gt;
ip route del 0.0.0.0/0 via 192.168.10.1 dev ens3&lt;br /&gt;
&lt;br /&gt;
# Delete default route (explicit)&lt;br /&gt;
ip route del default via 192.168.0.1 dev eth0 proto static metric 100&lt;br /&gt;
&lt;br /&gt;
# Add a default route via a specific IP and interface&lt;br /&gt;
ip route add default via 192.168.0.1 dev eth0 proto static metric 90&lt;br /&gt;
&lt;br /&gt;
# Add route for a network via gateway on an interface&lt;br /&gt;
ip route add 10.0.100.0/24 via 10.0.100.254 dev ens5&lt;br /&gt;
&lt;br /&gt;
# Add default route met een specifieke metric&lt;br /&gt;
ip route add default via 10.0.180.1 dev ens7 proto static metric 90&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== netstat ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Display network connections and current states&lt;br /&gt;
netstat&lt;br /&gt;
&lt;br /&gt;
# Check listening ports, connected remote IPs, processes, states and more&lt;br /&gt;
netstat -taupen&lt;br /&gt;
&lt;br /&gt;
# Check listening ports and IPs of the local server&lt;br /&gt;
netstat -tulpn&lt;br /&gt;
&lt;br /&gt;
# List the routing table&lt;br /&gt;
netstat -r&lt;br /&gt;
&lt;br /&gt;
# List verbose common TCP and ICMP information&lt;br /&gt;
netstat -s&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ss ===&lt;br /&gt;
Replacement for netstat&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Check open ports, connected IPs, processes, states and more&lt;br /&gt;
ss -taupen&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== tcpdump ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Listen on interface eth0 for traffic coming from host  172.16.0.11&lt;br /&gt;
tcpdump -i eth0 host 172.16.0.11&lt;br /&gt;
&lt;br /&gt;
# Listen on interface eno2 for traffic coming from host  172.16.1.20, going to port 443&lt;br /&gt;
tcpdump -i en02 host 172.16.1.20 port 443&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== uuidgen ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate a unique UUID (for an interface)&lt;br /&gt;
uuidgen eth0&lt;br /&gt;
7bb91614-6ffe-4bdc-9b37-c6e9d37f6987&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ip ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show network information &lt;br /&gt;
ip address&lt;br /&gt;
ip a&lt;br /&gt;
&lt;br /&gt;
# Show all configured routes&lt;br /&gt;
ip r show&lt;br /&gt;
&lt;br /&gt;
# Display statistics for all interfaces&lt;br /&gt;
ip -s link&lt;br /&gt;
&lt;br /&gt;
# Display detailed statistics for all interfaces&lt;br /&gt;
ip -s -s link&lt;br /&gt;
&lt;br /&gt;
# Execute the ifconfig command within a specific router&lt;br /&gt;
ip netns exec qrouter-asdwe49-as8d7-asd2-ert0-cvb7klj2 &amp;quot;ifconfig&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== DNS | dig &amp;amp; nslookup ===&lt;br /&gt;
* https://intodns.com/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Lookup reverse DNS host information&lt;br /&gt;
dig -x 10.0.2.15&lt;br /&gt;
&lt;br /&gt;
# Lookup the nameservers of google.com, by asking nameserver 1.1.1.1&lt;br /&gt;
dig google.com  @1.1.1.1 NS&lt;br /&gt;
&lt;br /&gt;
# Lookup reverse DNS host information&lt;br /&gt;
host 10.0.2.15&lt;br /&gt;
&lt;br /&gt;
# Lookup DNS host information&lt;br /&gt;
nslookup 10.0.2.15&lt;br /&gt;
&lt;br /&gt;
# Lookup host information for google.com while using DNS-server 8.8.8.8&lt;br /&gt;
nslookup google.com 8.8.8.8&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Package managers ==&lt;br /&gt;
=== apt ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check for updates&lt;br /&gt;
apt update&lt;br /&gt;
&lt;br /&gt;
# List packages that can be upgraded&lt;br /&gt;
apt list --upgradable&lt;br /&gt;
&lt;br /&gt;
# Installed available updates&lt;br /&gt;
apt upgrade&lt;br /&gt;
&lt;br /&gt;
# List installed packages&lt;br /&gt;
apt list --installed&lt;br /&gt;
&lt;br /&gt;
# List package details and description&lt;br /&gt;
apt show net-tools&lt;br /&gt;
&lt;br /&gt;
# Search inside all package descriptions for your keyword&lt;br /&gt;
apt-cache search ssh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rpm ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all local RPM packages&lt;br /&gt;
rpm -qa&lt;br /&gt;
&lt;br /&gt;
# Query for a specific installed rpm package&lt;br /&gt;
rpm -qi nginx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== yum ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  Search for all available packages that include string &amp;quot;nginx&amp;quot;&lt;br /&gt;
yum search nginx&lt;br /&gt;
&lt;br /&gt;
# Install the package named Nginx&lt;br /&gt;
yum install nginx&lt;br /&gt;
&lt;br /&gt;
# List installed packages&lt;br /&gt;
yum list installed&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== dnf ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  Upgrade and install updates&lt;br /&gt;
dnf upgrade&lt;br /&gt;
&lt;br /&gt;
# Remove the podman package&lt;br /&gt;
dnf remove podman&lt;br /&gt;
&lt;br /&gt;
# Show information about the zlib package&lt;br /&gt;
dnf info zlib&lt;br /&gt;
&lt;br /&gt;
# Show mandatory/optional/default packages within the Networking Tools group&lt;br /&gt;
dnf group info &amp;quot;Networking Tools&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Filesystem ==&lt;br /&gt;
=== fdisk ===&lt;br /&gt;
&#039;&#039;&#039;cfdisk&#039;&#039;&#039; is also nice&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check your disks and partitions&lt;br /&gt;
fdisk -l&lt;br /&gt;
&lt;br /&gt;
# Enter fdisk interactive mode&lt;br /&gt;
fdisk /dev/nvme0n2p1&lt;br /&gt;
&lt;br /&gt;
# List available partition types&lt;br /&gt;
l&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Format /dev/vdb as BTRFS&lt;br /&gt;
echo -e &amp;quot;n\np\n1\n\n\nt\n8E\np\nw&amp;quot; | fdisk /dev/vdb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Other ==&lt;br /&gt;
=== man + mandb ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Open the manual for the man tool&lt;br /&gt;
man man&lt;br /&gt;
&lt;br /&gt;
# Open the manual for the ls tool&lt;br /&gt;
man ls&lt;br /&gt;
&lt;br /&gt;
# &#039;Update&#039; mandb by purging and or processing manuals&lt;br /&gt;
mandb&lt;br /&gt;
&lt;br /&gt;
# Purge everything and regenerate manuals&lt;br /&gt;
mandb --create&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ls ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List folders sorted by modified date&lt;br /&gt;
ls -trol&lt;br /&gt;
&lt;br /&gt;
# List folder contents recursively&lt;br /&gt;
ls -alsR myfolder/&lt;br /&gt;
&lt;br /&gt;
# List folder contents sorted by time, newest first and reverse order&lt;br /&gt;
ls -latr myfolder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== grep ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Search for any occurences of &amp;quot;inet_interface&amp;quot; in a file&lt;br /&gt;
grep inet_interface /etc/postfix/main.cf&lt;br /&gt;
&lt;br /&gt;
# Search for pattern &amp;quot;audit&amp;quot; in file /var/log/syslog&lt;br /&gt;
grep -e &amp;quot;audit&amp;quot; /var/log/syslog&lt;br /&gt;
&lt;br /&gt;
# Search for text &amp;quot;started&amp;quot; in everything in /var/log/, and list the filename for each occurence&lt;br /&gt;
grep -H &amp;quot;started&amp;quot; /var/log/*&lt;br /&gt;
&lt;br /&gt;
# Search for any mention of &amp;quot;md&amp;quot; within a file, by piping to grep&lt;br /&gt;
cat /var/log/messages | grep md&lt;br /&gt;
&lt;br /&gt;
# Search for any of text &amp;quot;test&amp;quot; within the /etc folder recursively, also shows filename by default&lt;br /&gt;
grep -r &amp;quot;test&amp;quot; /etc&lt;br /&gt;
&lt;br /&gt;
# Recursively search for any mention of &amp;quot;audit&amp;quot; in each file within the specified directory, display linenumber and ignore low/upper case&lt;br /&gt;
grep -rni audit /var/log/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== lsof ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List what has files opened on the directory/mount&lt;br /&gt;
lsof /data/mount/lustre-01&lt;br /&gt;
&lt;br /&gt;
# List processes listening on port 443&lt;br /&gt;
lsof -i :443&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== awk ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List the first column of the output generated by docker ps&lt;br /&gt;
docker ps | awk &#039;{print $1}&#039;&lt;br /&gt;
&lt;br /&gt;
# Print 9th column of folder contents&lt;br /&gt;
ll /mnt/btrfs/share1/ | awk &#039;{print $9}&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== tar ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Compress the destination directory and keep the source path within the zipped file&lt;br /&gt;
tar -czvf name-of-archive.tar.gz /path/to/directory-or-file&lt;br /&gt;
&lt;br /&gt;
# Compress the destination directory, but put the folder contents into the . within the zipped file&lt;br /&gt;
tar -czvf name-of-archive.tar.gz -C /path/to/directory-or-file .&lt;br /&gt;
&lt;br /&gt;
# Extract a tar.gz file to the current folder&lt;br /&gt;
tar -xzvf name-of-archive.tar.gz&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== find ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Basic find command&lt;br /&gt;
find / -name name-to-search-for&lt;br /&gt;
&lt;br /&gt;
# Search the current folder for all files&lt;br /&gt;
find . -name \* &lt;br /&gt;
&lt;br /&gt;
# Search the current folder for all files and count them&lt;br /&gt;
find . -name \* | wc -l&lt;br /&gt;
&lt;br /&gt;
# Find all files with the SUID bit set&lt;br /&gt;
find / -name &amp;quot;*&amp;quot; -perm /u+s&lt;br /&gt;
&lt;br /&gt;
# Find the current folder for files that were modified in the last 15 minutes&lt;br /&gt;
find . -mmin -15 -type f -name &amp;quot;*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Search for all modified files between 2023-01-01 and 2023-12-30&lt;br /&gt;
find /var/log/ -type f -name &amp;quot;*&amp;quot; -newermt 2023-01-01 ! -newermt 2023-12-30&lt;br /&gt;
&lt;br /&gt;
# Search for all modified folders between 2022-01-01 and 2022-02-10, limited to a single folders&#039; depth&lt;br /&gt;
find /data/research001/ -maxdepth 1 -type d -newermt 2022-01-01 ! -newermt 2022-02-10&lt;br /&gt;
&lt;br /&gt;
# Search the current folder for all .log files and search &amp;amp; output any line containing string &amp;quot;error&amp;quot;&lt;br /&gt;
find . -name \*.log -exec grep -H error {} \;&lt;br /&gt;
&lt;br /&gt;
# Screwing around&lt;br /&gt;
for i in $(find URL* -name &amp;quot;*.report&amp;quot; | sort); do echo &amp;quot;$i&amp;quot; &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE ; done&lt;br /&gt;
for i in $(find URL* -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; | sort &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE ; done&lt;br /&gt;
for i in $(find URL* -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; | sort &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE | awk &#039;{print $2}&#039;; done&lt;br /&gt;
for i in $(find URL* -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE | awk &#039;{print $2}&#039;; done&lt;br /&gt;
for i in $(find * -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE | awk &#039;{print $2}&#039;; done&lt;br /&gt;
ll URL* | awk &#039;{print $9}&#039; | grep &amp;quot;*.report&amp;quot; | sort | for i in $(find * -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE | awk &#039;{print $2}&#039;; done&lt;br /&gt;
ll URL* | awk &#039;{print $9}&#039; | grep .report | sort | for i in $(find * -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE&lt;br /&gt;
&lt;br /&gt;
find URL1 -name \*.report -exec grep -H TOTAL_SIZE {} \; | LC_ALL=C awk -M &#039;BEGIN{FS=OFS=&amp;quot;\t&amp;quot;} {printf(&amp;quot;%s\t%.02f\n&amp;quot;, $1, $2/(1024*1024*1024))}&#039; | sed -e &#039;s~^.*/~~&#039; -e &#039;s~\..*SIZE~~&#039; | sort&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== less ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
25     = Go to line 25&lt;br /&gt;
g      = Go to top of file&lt;br /&gt;
G      = Go to bottom of file&lt;br /&gt;
/      = Activate search mode&lt;br /&gt;
/Error = Search for &amp;quot;Error&amp;quot;&lt;br /&gt;
n      = Move to next search result&lt;br /&gt;
N      = Move to previous search result&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Don&#039;t wrap long lines to the current screen (move left or right to see non-truncated line)&lt;br /&gt;
less -S /var/log/syslog&lt;br /&gt;
&lt;br /&gt;
# Output a file&#039;s contents and read it with less&lt;br /&gt;
cat /etc/snmpd/snmp.conf | less -S&lt;br /&gt;
&lt;br /&gt;
# Number the lines when viewing&lt;br /&gt;
less -N /var/log/messages&lt;br /&gt;
&lt;br /&gt;
# Open less at the first search result for &amp;quot;error&amp;quot;. (Do not use space between the -p parameter and your search query)&lt;br /&gt;
less -p&amp;quot;Error&amp;quot; /var/log/messages&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ssh ===&lt;br /&gt;
* https://man.openbsd.org/ssh.1&lt;br /&gt;
* https://www.openssh.com/legacy.html&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Stolen from https://www.openssh.com/legacy.html&lt;br /&gt;
ssh -Q cipher       # List supported ciphers&lt;br /&gt;
ssh -Q mac          # List supported MACs&lt;br /&gt;
ssh -Q key          # List supported public key types&lt;br /&gt;
ssh -Q kex          # List supported key exchange algorithms&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Connect to a server using a specific user&lt;br /&gt;
ssh mirelurk@192.168.0.1&lt;br /&gt;
&lt;br /&gt;
# Connect to a server using a specific RSA private key&lt;br /&gt;
ssh 192.168.0.1 -i /home/john/.ssh/id_rsa_key-5&lt;br /&gt;
&lt;br /&gt;
# Connect to a server using a specific SSH port&lt;br /&gt;
ssh 192.168.0.1 -p 1111&lt;br /&gt;
&lt;br /&gt;
# Show verbose information when connecting to a server&lt;br /&gt;
ssh -v 192.168.0.1&lt;br /&gt;
&lt;br /&gt;
# Connect using an ancient algorithm and keytype&lt;br /&gt;
ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 -c aes128-cbc  admin@10.50.10.50&lt;br /&gt;
&lt;br /&gt;
# Execute &#039;ls&#039; on a remote server and output the result to your shell session&lt;br /&gt;
echo &#039;ls&#039; | ssh -T user@10.0.20.75&lt;br /&gt;
&lt;br /&gt;
# Execute a command on a remote server and output the result to a local file&lt;br /&gt;
echo &#039;ls&#039; | ssh -T user@10.0.20.75 &amp;gt; &amp;lt;filename&amp;gt;.log&lt;br /&gt;
&lt;br /&gt;
# Log in by providing a password in the CLI&lt;br /&gt;
sshpass &#039;MyPassword&#039; ssh -XY root@10.100.25.1&lt;br /&gt;
&lt;br /&gt;
# Copy a local file to another server&lt;br /&gt;
scp /home/root/myfiletocopy ubuntu@192.168.0.10:/home/ubuntu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== vim ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Esc   Switches between input/command mode&lt;br /&gt;
&lt;br /&gt;
o     Create a new line below the current cursor position and switch to input mode&lt;br /&gt;
:wq   Save (write) and quit the file&lt;br /&gt;
:q!   Quit immediately without applying any changes&lt;br /&gt;
&lt;br /&gt;
j     Move the cursor one line downwards&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enter the Vim tutorial&lt;br /&gt;
vimtutor&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rsync ===&lt;br /&gt;
Also see rclone for enterprise storage enviroments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Copy contents of source /mnt/science/data/ to target /home/garyon/backup/science/ recursively&lt;br /&gt;
rsync -a /mnt/science/data/ /home/garyon/backup/science/&lt;br /&gt;
&lt;br /&gt;
# Copy  everything: symlinks, hardlinks, extended attributes, modified times, files, folders, etc&lt;br /&gt;
rsync -avHXS --progress /mnt/science/data/ /home/mayra/backup/science/&lt;br /&gt;
&lt;br /&gt;
# Show progress during a transfer&lt;br /&gt;
rsync -avHXS --progress /mnt/science/data/ /home/stefanie/backup/science/&lt;br /&gt;
&lt;br /&gt;
# rsync is additive by default&lt;br /&gt;
# After an initial rsync, delete files in the target that were deleted in the source&lt;br /&gt;
rsync --delete -avHXS /mnt/science/data/ /home/bob/backup/science/&lt;br /&gt;
&lt;br /&gt;
# Sync using SSH&lt;br /&gt;
rsync -avrS --delete /data/cardio/ 192.168.0.15:/backup/cardio/&lt;br /&gt;
&lt;br /&gt;
# Sync using a specific SSH port&lt;br /&gt;
rsync -avrS --rsh=&#039;ssh -p2020&#039; --delete /data/science/ 192.168.0.20:/backup/science/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== cron ===&lt;br /&gt;
* https://crontab.guru/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List cron jobs for the current user&lt;br /&gt;
crontab -l&lt;br /&gt;
&lt;br /&gt;
# Modify cron jobs for the current user&lt;br /&gt;
crontab -eq&lt;br /&gt;
&lt;br /&gt;
# Run  the &amp;quot;ls&amp;quot; command every 5 minutes&lt;br /&gt;
*/5 * * * * ps aux&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ldapsearch ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DC = Domain Component&lt;br /&gt;
The values that identify the domain in which the object is located, may contain subdomains too i.e. &amp;quot;DC=customer,DC=amazon,DC=com&amp;quot;&lt;br /&gt;
&lt;br /&gt;
OU =  Organization Unit&lt;br /&gt;
A container/folder in which objects or users are stored. Actively used in Microsoft Active Directory&#039;s i.e. &amp;quot;OU=janitors,DC=customer,DC=amazon,DC=com&amp;quot;&lt;br /&gt;
&lt;br /&gt;
CN = Canonical Name&lt;br /&gt;
The name of the group you&#039;re searching for or in i.e. &amp;quot;CN=fullprivilege,OU=janitors,DC=customer,DC=amazon,DC=com&amp;quot;&lt;br /&gt;
&lt;br /&gt;
UID = User Identifier&lt;br /&gt;
The unique identifier to find a user with, usually the username i.e. &amp;quot;uid=magicmike,CN=fullprivilege,OU=janitors,DC=customer,DC=amazon,DC=com&amp;quot;&lt;br /&gt;
&lt;br /&gt;
DN = Distinguished Name&lt;br /&gt;
The entire path to an object, consisting of a combination of above values, at least the DCs and a CN or UID, i.e. &amp;quot;uid=magicmike,CN=fullprivilege,OU=janitors,DC=customer,DC=amazon,DC=com&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following assumes domain &amp;quot;brammerloo.nl&amp;quot;, based on usage for FreeIPA&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Search and show attributes for user tonberry in group users in group accounts in domain brammerloo.nl, using the admin user to authenticatie&lt;br /&gt;
ldapsearch -W -b &amp;quot;uid=tonberry,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;  -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Do the same as above, but specify LDAP-server ipa01.brammerloo.nl to send the query to&lt;br /&gt;
ldapsearch -W -H ldap://ipa01.brammerloo.nl -b &amp;quot;uid=tonberry,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;  -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Do the same as above, but specify a specific port&lt;br /&gt;
ldapsearch -W -H ldap://ipa01.brammerloo.nl:389 -b &amp;quot;uid=tonberry,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;  -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Use the &amp;quot;elastic&amp;quot; user to query for attributes of the &amp;quot;elastic-users&amp;quot; group which itself is a member of the &amp;quot;groups&amp;quot; group&lt;br /&gt;
ldapsearch -W -b &amp;quot;cn=elastic-users,cn=groups,cn=accounts,dc=brammerloo,dc=nl&amp;quot;  -D &amp;quot;uid=elastic,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Do the same as above, but this this specify you only want the member attribute&lt;br /&gt;
ldapsearch -W -b &amp;quot;cn=elastic-users,cn=groups,cn=accounts,dc=brammerloo,dc=nl&amp;quot; -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot; member&lt;br /&gt;
&lt;br /&gt;
# Show all groups of which tonberry is a member of by searching for the memberOf attribute&lt;br /&gt;
ldapsearch -W -b &amp;quot;uid=tonberry,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;  -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot; memberOf&lt;br /&gt;
&lt;br /&gt;
# List attributes for all groups in the group &amp;quot;groups&amp;quot;&lt;br /&gt;
ldapsearch -W -b &amp;quot;cn=groups,cn=accounts,dc=brammerloo,dc=nl&amp;quot; -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== git ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List your current branch and situation&lt;br /&gt;
git status&lt;br /&gt;
&lt;br /&gt;
# List all branches and your current one&lt;br /&gt;
git branch --all&lt;br /&gt;
&lt;br /&gt;
# List all available tags&lt;br /&gt;
git tag&lt;br /&gt;
&lt;br /&gt;
# List the current selected tag&lt;br /&gt;
git describe&lt;br /&gt;
git describe --tags&lt;br /&gt;
&lt;br /&gt;
# Compare changes in the current working directory to the committed tree, and list what files have been changed&lt;br /&gt;
git diff-files&lt;br /&gt;
&lt;br /&gt;
# Compare changes in the current working directory to the committed tree, and list what has changed&lt;br /&gt;
git diff-files -p&lt;br /&gt;
&lt;br /&gt;
# Compare the committed tree to the current working directory, and list what has changed&lt;br /&gt;
git diff HEAD&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Common ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a folder and initialize it for use by git&lt;br /&gt;
mkdir gitrepo1; cd gitrepo1; git init&lt;br /&gt;
&lt;br /&gt;
# Switch to another branch&lt;br /&gt;
git checkout stable/zed&lt;br /&gt;
&lt;br /&gt;
# Switch to a specific tag&lt;br /&gt;
git checkout tags/14.11.0&lt;br /&gt;
&lt;br /&gt;
# Fetch data from the current upstream branch&lt;br /&gt;
git pull&lt;br /&gt;
&lt;br /&gt;
# Pull data from a specific branch&lt;br /&gt;
git pull origin unmaintained/yoga&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rclone ===&lt;br /&gt;
* https://rclone.org/&lt;br /&gt;
&lt;br /&gt;
==== Installation ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Install the latest version from the website&lt;br /&gt;
curl https://rclone.org/install.sh | sudo bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Example configuration based on OpenStack swift. Config should be in the homefolder of your user .config/rclone/rclone.conf:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
[swift-ssd]&lt;br /&gt;
type = swift&lt;br /&gt;
user = patrick&lt;br /&gt;
key = &amp;lt;PASSWORD&amp;gt;&lt;br /&gt;
auth = https://openstack.brammerloo.nl:5000/v3&lt;br /&gt;
region = Rotterdam&lt;br /&gt;
domain = Default&lt;br /&gt;
tenant = patrickproject&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# List all containers, buckets and or folders of container &amp;quot;swift-ssd&amp;quot;&lt;br /&gt;
rclone lsd &amp;quot;swift-ssd:&amp;quot;&lt;br /&gt;
          20 2025-02-10 09:46:00         2 ssd-container&lt;br /&gt;
           0 2025-02-10 09:46:00         1 swift-ssd&lt;br /&gt;
           0 2025-02-10 09:46:00         1 swift-ssd2&lt;br /&gt;
&lt;br /&gt;
rclone lsd &amp;quot;swift-ssd:ssd-container&amp;quot;&lt;br /&gt;
           0 2025-02-10 09:48:02        -1 mystorage&lt;br /&gt;
&lt;br /&gt;
# List contents, files, folders of bucket &amp;quot;ssd-container&amp;quot;, within container &amp;quot;swift-ssd&amp;quot;&lt;br /&gt;
rclone ls &amp;quot;swift-ssd:ssd-container&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# List the contents of file &amp;quot;asd&amp;quot;&lt;br /&gt;
rclone cat &amp;quot;swift-ssd:ssd-container/asd&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Mount an object storage to local folder /mnt/object-ssd/&lt;br /&gt;
rclone mount swift-ssd:ssd-container /mnt/object-ssd&lt;br /&gt;
&lt;br /&gt;
# Synchronize a local folder to a destination folder inside a bucket, in interactive mode&lt;br /&gt;
rclone sync -i /etc/rsyslog.d swift-ssd:ssd-container/mystorage/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== mdtest ===&lt;br /&gt;
This chapter was mostly written and contributed by Ivo Palli.&lt;br /&gt;
&lt;br /&gt;
==== General ====&lt;br /&gt;
mdtest is part of the ior performance test package.&lt;br /&gt;
&lt;br /&gt;
==== RHEL Installation ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
wget https://github.com/hpc/ior/releases/download/3.3.0/ior-3.3.0.tar.bz2&lt;br /&gt;
tar xjf ior-*.tar.bz2&lt;br /&gt;
cd ior-*/&lt;br /&gt;
&lt;br /&gt;
yum install openmpi-devel environment-modules&lt;br /&gt;
# Relog your shell so &#039;module&#039; is available&lt;br /&gt;
module load mpi&lt;br /&gt;
module list&lt;br /&gt;
./configure&lt;br /&gt;
make -j4&lt;br /&gt;
make install&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ubuntu Installation ====&lt;br /&gt;
* https://gist.github.com/hokiegeek2/3057f8bb3beb519ae9b556e41824be30&lt;br /&gt;
* https://ior.readthedocs.io/en/latest/userDoc/install.html&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
VERSION=4.0.0&lt;br /&gt;
wget https://github.com/hpc/ior/releases/download/$VERSION/ior-$VERSION.tar.gz&lt;br /&gt;
tar -xzvf ior-$VERSION.tar.gz&lt;br /&gt;
cd ior-$VERSION/&lt;br /&gt;
&lt;br /&gt;
apt install libopenmpi-dev environment-modules openmpi-bin openmpi-common libgtk2.0-dev -y&lt;br /&gt;
./configure&lt;br /&gt;
&lt;br /&gt;
make -j4&lt;br /&gt;
make install&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Usage =====&lt;br /&gt;
Note: Number of items should be a multiple of depth x branching factor&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
module load mpi&lt;br /&gt;
&lt;br /&gt;
# Run command &amp;quot;mdtest -n 2000 -z 5 -b 2 -d /mnt/ssd/&amp;quot; 10 times in a row&lt;br /&gt;
mpirun --oversubscribe --allow-run-as-root -n 10 mdtest -n 2000 -z 5 -b 2 -d /mnt/nfs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Links =====&lt;br /&gt;
* https://github.com/hpc/ior&lt;br /&gt;
* https://www.glennklockwood.com/benchmarks/mdtest.html Guide&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
	<entry>
		<id>https://wiki.brammerloo.nl/index.php?title=Linux:Tools&amp;diff=833</id>
		<title>Linux:Tools</title>
		<link rel="alternate" type="text/html" href="https://wiki.brammerloo.nl/index.php?title=Linux:Tools&amp;diff=833"/>
		<updated>2025-09-23T13:00:22Z</updated>

		<summary type="html">&lt;p&gt;Patrick: /* Ubuntu Installation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Cheatsheet]]&lt;br /&gt;
&lt;br /&gt;
== Commands ==&lt;br /&gt;
=== Quick access ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Scroll through a file with less&lt;br /&gt;
less -s myfile.txt&lt;br /&gt;
&lt;br /&gt;
# Select line 5 from the output&lt;br /&gt;
cat example.txt | sel -e &#039;5&#039;&lt;br /&gt;
&lt;br /&gt;
# Select lines from the output, starting from the top&lt;br /&gt;
cat example.txt | head -5&lt;br /&gt;
&lt;br /&gt;
# Select lines from the output, starting from the bottom&lt;br /&gt;
cat example.txt | tail -5&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Commands ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Display the full path of a file(assuming the syslog file is available in the current folder)&lt;br /&gt;
readlink -f syslog&lt;br /&gt;
&lt;br /&gt;
# Unzip a file&lt;br /&gt;
gunzip /var/log/messages.2.gz&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Uncommon commands ===&lt;br /&gt;
* https://ngelinux.com/what-is-proc-sysrq-trigger-in-linux-and-how-to-use-sysrq-kernel-feature/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CrASHing THIs SERVer, WiTH no SurVIvORS!&lt;br /&gt;
echo c &amp;gt; /proc/sysrq-trigger&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Network ==&lt;br /&gt;
=== ping ===&lt;br /&gt;
Troubleshooting MTU: https://access.redhat.com/solutions/2440411&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Ping with an interval of 5 seconds&lt;br /&gt;
ping -i 5 192.168.0.1&lt;br /&gt;
&lt;br /&gt;
# Ping 192.168.10.5 using a specific interface&lt;br /&gt;
ping -I bond0 192.168.10.5&lt;br /&gt;
&lt;br /&gt;
# Ping 8.8.8.8 for 20 times&lt;br /&gt;
ping -c 20 8.8.8.8&lt;br /&gt;
&lt;br /&gt;
# Ping google.com using IPv4&lt;br /&gt;
ping -4 google.com&lt;br /&gt;
&lt;br /&gt;
# Ping google.com using IPv6&lt;br /&gt;
ping -6 google.com&lt;br /&gt;
&lt;br /&gt;
# Ping using packets of size 264&lt;br /&gt;
ping -s 264 1.1.1.1&lt;br /&gt;
&lt;br /&gt;
# Test an MTU-size of 9000 by sending non-fragmented packages of size 8972 (28 bytes left for the headers)&lt;br /&gt;
ping -M do -s 8972 192.168.77.88&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== traceroute ===&lt;br /&gt;
Package &#039;&#039;&#039;mtr&#039;&#039;&#039; (My traceroute) is also very good&lt;br /&gt;
&lt;br /&gt;
* https://web.archive.org/web/20110101100046/https://www.exit109.com/~jeremy/news/providers/traceroute.html&lt;br /&gt;
* [https://en.wikipedia.org/wiki/Traceroute UDP ports 33434 to 33534 are used by traceroute by default.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show the traversed hops towards google.com using IPv4&lt;br /&gt;
traceroute -4 google.com&lt;br /&gt;
&lt;br /&gt;
# Show the traversed hops towards google.com using IPv6&lt;br /&gt;
traceroute -6 google.com&lt;br /&gt;
&lt;br /&gt;
# Does the same as &amp;quot;traceroute -6 google.com&amp;quot;&lt;br /&gt;
traceroute6 google.com&lt;br /&gt;
&lt;br /&gt;
# Use ICMP for checking hops&lt;br /&gt;
traceroute -4 -I brammerloo.nl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== route ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List configured routes&lt;br /&gt;
route&lt;br /&gt;
&lt;br /&gt;
# List routes but display IPs instead of hostnames&lt;br /&gt;
route -n&lt;br /&gt;
&lt;br /&gt;
# Delete default route &lt;br /&gt;
ip route del 0.0.0.0/0 via 192.168.10.1 dev ens3&lt;br /&gt;
&lt;br /&gt;
# Delete default route (explicit)&lt;br /&gt;
ip route del default via 192.168.0.1 dev eth0 proto static metric 100&lt;br /&gt;
&lt;br /&gt;
# Add a default route via a specific IP and interface&lt;br /&gt;
ip route add default via 192.168.0.1 dev eth0 proto static metric 90&lt;br /&gt;
&lt;br /&gt;
# Add route for a network via gateway on an interface&lt;br /&gt;
ip route add 10.0.100.0/24 via 10.0.100.254 dev ens5&lt;br /&gt;
&lt;br /&gt;
# Add default route met een specifieke metric&lt;br /&gt;
ip route add default via 10.0.180.1 dev ens7 proto static metric 90&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== netstat ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Display network connections and current states&lt;br /&gt;
netstat&lt;br /&gt;
&lt;br /&gt;
# Check listening ports, connected remote IPs, processes, states and more&lt;br /&gt;
netstat -taupen&lt;br /&gt;
&lt;br /&gt;
# Check listening ports and IPs of the local server&lt;br /&gt;
netstat -tulpn&lt;br /&gt;
&lt;br /&gt;
# List the routing table&lt;br /&gt;
netstat -r&lt;br /&gt;
&lt;br /&gt;
# List verbose common TCP and ICMP information&lt;br /&gt;
netstat -s&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ss ===&lt;br /&gt;
Replacement for netstat&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Check open ports, connected IPs, processes, states and more&lt;br /&gt;
ss -taupen&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== tcpdump ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# Listen on interface eth0 for traffic coming from host  172.16.0.11&lt;br /&gt;
tcpdump -i eth0 host 172.16.0.11&lt;br /&gt;
&lt;br /&gt;
# Listen on interface eno2 for traffic coming from host  172.16.1.20, going to port 443&lt;br /&gt;
tcpdump -i en02 host 172.16.1.20 port 443&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== uuidgen ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate a unique UUID (for an interface)&lt;br /&gt;
uuidgen eth0&lt;br /&gt;
7bb91614-6ffe-4bdc-9b37-c6e9d37f6987&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ip ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show network information &lt;br /&gt;
ip address&lt;br /&gt;
ip a&lt;br /&gt;
&lt;br /&gt;
# Show all configured routes&lt;br /&gt;
ip r show&lt;br /&gt;
&lt;br /&gt;
# Display statistics for all interfaces&lt;br /&gt;
ip -s link&lt;br /&gt;
&lt;br /&gt;
# Display detailed statistics for all interfaces&lt;br /&gt;
ip -s -s link&lt;br /&gt;
&lt;br /&gt;
# Execute the ifconfig command within a specific router&lt;br /&gt;
ip netns exec qrouter-asdwe49-as8d7-asd2-ert0-cvb7klj2 &amp;quot;ifconfig&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== DNS | dig &amp;amp; nslookup ===&lt;br /&gt;
* https://intodns.com/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Lookup reverse DNS host information&lt;br /&gt;
dig -x 10.0.2.15&lt;br /&gt;
&lt;br /&gt;
# Lookup the nameservers of google.com, by asking nameserver 1.1.1.1&lt;br /&gt;
dig google.com  @1.1.1.1 NS&lt;br /&gt;
&lt;br /&gt;
# Lookup reverse DNS host information&lt;br /&gt;
host 10.0.2.15&lt;br /&gt;
&lt;br /&gt;
# Lookup DNS host information&lt;br /&gt;
nslookup 10.0.2.15&lt;br /&gt;
&lt;br /&gt;
# Lookup host information for google.com while using DNS-server 8.8.8.8&lt;br /&gt;
nslookup google.com 8.8.8.8&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Package managers ==&lt;br /&gt;
=== apt ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check for updates&lt;br /&gt;
apt update&lt;br /&gt;
&lt;br /&gt;
# List packages that can be upgraded&lt;br /&gt;
apt list --upgradable&lt;br /&gt;
&lt;br /&gt;
# Installed available updates&lt;br /&gt;
apt upgrade&lt;br /&gt;
&lt;br /&gt;
# List installed packages&lt;br /&gt;
apt list --installed&lt;br /&gt;
&lt;br /&gt;
# List package details and description&lt;br /&gt;
apt show net-tools&lt;br /&gt;
&lt;br /&gt;
# Search inside all package descriptions for your keyword&lt;br /&gt;
apt-cache search ssh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rpm ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List all local RPM packages&lt;br /&gt;
rpm -qa&lt;br /&gt;
&lt;br /&gt;
# Query for a specific installed rpm package&lt;br /&gt;
rpm -qi nginx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== yum ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  Search for all available packages that include string &amp;quot;nginx&amp;quot;&lt;br /&gt;
yum search nginx&lt;br /&gt;
&lt;br /&gt;
# Install the package named Nginx&lt;br /&gt;
yum install nginx&lt;br /&gt;
&lt;br /&gt;
# List installed packages&lt;br /&gt;
yum list installed&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== dnf ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  Upgrade and install updates&lt;br /&gt;
dnf upgrade&lt;br /&gt;
&lt;br /&gt;
# Remove the podman package&lt;br /&gt;
dnf remove podman&lt;br /&gt;
&lt;br /&gt;
# Show information about the zlib package&lt;br /&gt;
dnf info zlib&lt;br /&gt;
&lt;br /&gt;
# Show mandatory/optional/default packages within the Networking Tools group&lt;br /&gt;
dnf group info &amp;quot;Networking Tools&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Filesystem ==&lt;br /&gt;
=== fdisk ===&lt;br /&gt;
&#039;&#039;&#039;cfdisk&#039;&#039;&#039; is also nice&lt;br /&gt;
&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check your disks and partitions&lt;br /&gt;
fdisk -l&lt;br /&gt;
&lt;br /&gt;
# Enter fdisk interactive mode&lt;br /&gt;
fdisk /dev/nvme0n2p1&lt;br /&gt;
&lt;br /&gt;
# List available partition types&lt;br /&gt;
l&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Format /dev/vdb as BTRFS&lt;br /&gt;
echo -e &amp;quot;n\np\n1\n\n\nt\n8E\np\nw&amp;quot; | fdisk /dev/vdb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Other ==&lt;br /&gt;
=== man + mandb ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Open the manual for the man tool&lt;br /&gt;
man man&lt;br /&gt;
&lt;br /&gt;
# Open the manual for the ls tool&lt;br /&gt;
man ls&lt;br /&gt;
&lt;br /&gt;
# &#039;Update&#039; mandb by purging and or processing manuals&lt;br /&gt;
mandb&lt;br /&gt;
&lt;br /&gt;
# Purge everything and regenerate manuals&lt;br /&gt;
mandb --create&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ls ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List folders sorted by modified date&lt;br /&gt;
ls -trol&lt;br /&gt;
&lt;br /&gt;
# List folder contents recursively&lt;br /&gt;
ls -alsR myfolder/&lt;br /&gt;
&lt;br /&gt;
# List folder contents sorted by time, newest first and reverse order&lt;br /&gt;
ls -latr myfolder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== grep ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Search for any occurences of &amp;quot;inet_interface&amp;quot; in a file&lt;br /&gt;
grep inet_interface /etc/postfix/main.cf&lt;br /&gt;
&lt;br /&gt;
# Search for pattern &amp;quot;audit&amp;quot; in file /var/log/syslog&lt;br /&gt;
grep -e &amp;quot;audit&amp;quot; /var/log/syslog&lt;br /&gt;
&lt;br /&gt;
# Search for text &amp;quot;started&amp;quot; in everything in /var/log/, and list the filename for each occurence&lt;br /&gt;
grep -H &amp;quot;started&amp;quot; /var/log/*&lt;br /&gt;
&lt;br /&gt;
# Search for any mention of &amp;quot;md&amp;quot; within a file, by piping to grep&lt;br /&gt;
cat /var/log/messages | grep md&lt;br /&gt;
&lt;br /&gt;
# Search for any of text &amp;quot;test&amp;quot; within the /etc folder recursively, also shows filename by default&lt;br /&gt;
grep -r &amp;quot;test&amp;quot; /etc&lt;br /&gt;
&lt;br /&gt;
# Recursively search for any mention of &amp;quot;audit&amp;quot; in each file within the specified directory, display linenumber and ignore low/upper case&lt;br /&gt;
grep -rni audit /var/log/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== lsof ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List what has files opened on the directory/mount&lt;br /&gt;
lsof /data/mount/lustre-01&lt;br /&gt;
&lt;br /&gt;
# List processes listening on port 443&lt;br /&gt;
lsof -i :443&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== awk ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List the first column of the output generated by docker ps&lt;br /&gt;
docker ps | awk &#039;{print $1}&#039;&lt;br /&gt;
&lt;br /&gt;
# Print 9th column of folder contents&lt;br /&gt;
ll /mnt/btrfs/share1/ | awk &#039;{print $9}&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== tar ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Compress the destination directory and keep the source path within the zipped file&lt;br /&gt;
tar -czvf name-of-archive.tar.gz /path/to/directory-or-file&lt;br /&gt;
&lt;br /&gt;
# Compress the destination directory, but put the folder contents into the . within the zipped file&lt;br /&gt;
tar -czvf name-of-archive.tar.gz -C /path/to/directory-or-file .&lt;br /&gt;
&lt;br /&gt;
# Extract a tar.gz file to the current folder&lt;br /&gt;
tar -xzvf name-of-archive.tar.gz&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== find ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Basic find command&lt;br /&gt;
find / -name name-to-search-for&lt;br /&gt;
&lt;br /&gt;
# Search the current folder for all files&lt;br /&gt;
find . -name \* &lt;br /&gt;
&lt;br /&gt;
# Search the current folder for all files and count them&lt;br /&gt;
find . -name \* | wc -l&lt;br /&gt;
&lt;br /&gt;
# Find all files with the SUID bit set&lt;br /&gt;
find / -name &amp;quot;*&amp;quot; -perm /u+s&lt;br /&gt;
&lt;br /&gt;
# Find the current folder for files that were modified in the last 15 minutes&lt;br /&gt;
find . -mmin -15 -type f -name &amp;quot;*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Search for all modified files between 2023-01-01 and 2023-12-30&lt;br /&gt;
find /var/log/ -type f -name &amp;quot;*&amp;quot; -newermt 2023-01-01 ! -newermt 2023-12-30&lt;br /&gt;
&lt;br /&gt;
# Search for all modified folders between 2022-01-01 and 2022-02-10, limited to a single folders&#039; depth&lt;br /&gt;
find /data/research001/ -maxdepth 1 -type d -newermt 2022-01-01 ! -newermt 2022-02-10&lt;br /&gt;
&lt;br /&gt;
# Search the current folder for all .log files and search &amp;amp; output any line containing string &amp;quot;error&amp;quot;&lt;br /&gt;
find . -name \*.log -exec grep -H error {} \;&lt;br /&gt;
&lt;br /&gt;
# Screwing around&lt;br /&gt;
for i in $(find URL* -name &amp;quot;*.report&amp;quot; | sort); do echo &amp;quot;$i&amp;quot; &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE ; done&lt;br /&gt;
for i in $(find URL* -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; | sort &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE ; done&lt;br /&gt;
for i in $(find URL* -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; | sort &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE | awk &#039;{print $2}&#039;; done&lt;br /&gt;
for i in $(find URL* -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE | awk &#039;{print $2}&#039;; done&lt;br /&gt;
for i in $(find * -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE | awk &#039;{print $2}&#039;; done&lt;br /&gt;
ll URL* | awk &#039;{print $9}&#039; | grep &amp;quot;*.report&amp;quot; | sort | for i in $(find * -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE | awk &#039;{print $2}&#039;; done&lt;br /&gt;
ll URL* | awk &#039;{print $9}&#039; | grep .report | sort | for i in $(find * -name &amp;quot;*.report&amp;quot;); do basename &amp;quot;$i&amp;quot; &amp;amp;&amp;amp; cat &amp;quot;$i&amp;quot; | grep TOTAL_SIZE&lt;br /&gt;
&lt;br /&gt;
find URL1 -name \*.report -exec grep -H TOTAL_SIZE {} \; | LC_ALL=C awk -M &#039;BEGIN{FS=OFS=&amp;quot;\t&amp;quot;} {printf(&amp;quot;%s\t%.02f\n&amp;quot;, $1, $2/(1024*1024*1024))}&#039; | sed -e &#039;s~^.*/~~&#039; -e &#039;s~\..*SIZE~~&#039; | sort&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== less ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
25     = Go to line 25&lt;br /&gt;
g      = Go to top of file&lt;br /&gt;
G      = Go to bottom of file&lt;br /&gt;
/      = Activate search mode&lt;br /&gt;
/Error = Search for &amp;quot;Error&amp;quot;&lt;br /&gt;
n      = Move to next search result&lt;br /&gt;
N      = Move to previous search result&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Don&#039;t wrap long lines to the current screen (move left or right to see non-truncated line)&lt;br /&gt;
less -S /var/log/syslog&lt;br /&gt;
&lt;br /&gt;
# Output a file&#039;s contents and read it with less&lt;br /&gt;
cat /etc/snmpd/snmp.conf | less -S&lt;br /&gt;
&lt;br /&gt;
# Number the lines when viewing&lt;br /&gt;
less -N /var/log/messages&lt;br /&gt;
&lt;br /&gt;
# Open less at the first search result for &amp;quot;error&amp;quot;. (Do not use space between the -p parameter and your search query)&lt;br /&gt;
less -p&amp;quot;Error&amp;quot; /var/log/messages&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ssh ===&lt;br /&gt;
* https://man.openbsd.org/ssh.1&lt;br /&gt;
* https://www.openssh.com/legacy.html&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Stolen from https://www.openssh.com/legacy.html&lt;br /&gt;
ssh -Q cipher       # List supported ciphers&lt;br /&gt;
ssh -Q mac          # List supported MACs&lt;br /&gt;
ssh -Q key          # List supported public key types&lt;br /&gt;
ssh -Q kex          # List supported key exchange algorithms&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Connect to a server using a specific user&lt;br /&gt;
ssh mirelurk@192.168.0.1&lt;br /&gt;
&lt;br /&gt;
# Connect to a server using a specific RSA private key&lt;br /&gt;
ssh 192.168.0.1 -i /home/john/.ssh/id_rsa_key-5&lt;br /&gt;
&lt;br /&gt;
# Connect to a server using a specific SSH port&lt;br /&gt;
ssh 192.168.0.1 -p 1111&lt;br /&gt;
&lt;br /&gt;
# Show verbose information when connecting to a server&lt;br /&gt;
ssh -v 192.168.0.1&lt;br /&gt;
&lt;br /&gt;
# Connect using an ancient algorithm and keytype&lt;br /&gt;
ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 -c aes128-cbc  admin@10.50.10.50&lt;br /&gt;
&lt;br /&gt;
# Execute &#039;ls&#039; on a remote server and output the result to your shell session&lt;br /&gt;
echo &#039;ls&#039; | ssh -T user@10.0.20.75&lt;br /&gt;
&lt;br /&gt;
# Execute a command on a remote server and output the result to a local file&lt;br /&gt;
echo &#039;ls&#039; | ssh -T user@10.0.20.75 &amp;gt; &amp;lt;filename&amp;gt;.log&lt;br /&gt;
&lt;br /&gt;
# Log in by providing a password in the CLI&lt;br /&gt;
sshpass &#039;MyPassword&#039; ssh -XY root@10.100.25.1&lt;br /&gt;
&lt;br /&gt;
# Copy a local file to another server&lt;br /&gt;
scp /home/root/myfiletocopy ubuntu@192.168.0.10:/home/ubuntu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== vim ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Esc   Switches between input/command mode&lt;br /&gt;
&lt;br /&gt;
o     Create a new line below the current cursor position and switch to input mode&lt;br /&gt;
:wq   Save (write) and quit the file&lt;br /&gt;
:q!   Quit immediately without applying any changes&lt;br /&gt;
&lt;br /&gt;
j     Move the cursor one line downwards&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enter the Vim tutorial&lt;br /&gt;
vimtutor&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rsync ===&lt;br /&gt;
Also see rclone for enterprise storage enviroments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Copy contents of source /mnt/science/data/ to target /home/garyon/backup/science/ recursively&lt;br /&gt;
rsync -a /mnt/science/data/ /home/garyon/backup/science/&lt;br /&gt;
&lt;br /&gt;
# Copy  everything: symlinks, hardlinks, extended attributes, modified times, files, folders, etc&lt;br /&gt;
rsync -avHXS --progress /mnt/science/data/ /home/mayra/backup/science/&lt;br /&gt;
&lt;br /&gt;
# Show progress during a transfer&lt;br /&gt;
rsync -avHXS --progress /mnt/science/data/ /home/stefanie/backup/science/&lt;br /&gt;
&lt;br /&gt;
# rsync is additive by default&lt;br /&gt;
# After an initial rsync, delete files in the target that were deleted in the source&lt;br /&gt;
rsync --delete -avHXS /mnt/science/data/ /home/bob/backup/science/&lt;br /&gt;
&lt;br /&gt;
# Sync using SSH&lt;br /&gt;
rsync -avrS --delete /data/cardio/ 192.168.0.15:/backup/cardio/&lt;br /&gt;
&lt;br /&gt;
# Sync using a specific SSH port&lt;br /&gt;
rsync -avrS --rsh=&#039;ssh -p2020&#039; --delete /data/science/ 192.168.0.20:/backup/science/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== cron ===&lt;br /&gt;
* https://crontab.guru/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List cron jobs for the current user&lt;br /&gt;
crontab -l&lt;br /&gt;
&lt;br /&gt;
# Modify cron jobs for the current user&lt;br /&gt;
crontab -eq&lt;br /&gt;
&lt;br /&gt;
# Run  the &amp;quot;ls&amp;quot; command every 5 minutes&lt;br /&gt;
*/5 * * * * ps aux&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ldapsearch ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DC = Domain Component&lt;br /&gt;
The values that identify the domain in which the object is located, may contain subdomains too i.e. &amp;quot;DC=customer,DC=amazon,DC=com&amp;quot;&lt;br /&gt;
&lt;br /&gt;
OU =  Organization Unit&lt;br /&gt;
A container/folder in which objects or users are stored. Actively used in Microsoft Active Directory&#039;s i.e. &amp;quot;OU=janitors,DC=customer,DC=amazon,DC=com&amp;quot;&lt;br /&gt;
&lt;br /&gt;
CN = Canonical Name&lt;br /&gt;
The name of the group you&#039;re searching for or in i.e. &amp;quot;CN=fullprivilege,OU=janitors,DC=customer,DC=amazon,DC=com&amp;quot;&lt;br /&gt;
&lt;br /&gt;
UID = User Identifier&lt;br /&gt;
The unique identifier to find a user with, usually the username i.e. &amp;quot;uid=magicmike,CN=fullprivilege,OU=janitors,DC=customer,DC=amazon,DC=com&amp;quot;&lt;br /&gt;
&lt;br /&gt;
DN = Distinguished Name&lt;br /&gt;
The entire path to an object, consisting of a combination of above values, at least the DCs and a CN or UID, i.e. &amp;quot;uid=magicmike,CN=fullprivilege,OU=janitors,DC=customer,DC=amazon,DC=com&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following assumes domain &amp;quot;brammerloo.nl&amp;quot;, based on usage for FreeIPA&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Search and show attributes for user tonberry in group users in group accounts in domain brammerloo.nl, using the admin user to authenticatie&lt;br /&gt;
ldapsearch -W -b &amp;quot;uid=tonberry,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;  -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Do the same as above, but specify LDAP-server ipa01.brammerloo.nl to send the query to&lt;br /&gt;
ldapsearch -W -H ldap://ipa01.brammerloo.nl -b &amp;quot;uid=tonberry,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;  -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Do the same as above, but specify a specific port&lt;br /&gt;
ldapsearch -W -H ldap://ipa01.brammerloo.nl:389 -b &amp;quot;uid=tonberry,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;  -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Use the &amp;quot;elastic&amp;quot; user to query for attributes of the &amp;quot;elastic-users&amp;quot; group which itself is a member of the &amp;quot;groups&amp;quot; group&lt;br /&gt;
ldapsearch -W -b &amp;quot;cn=elastic-users,cn=groups,cn=accounts,dc=brammerloo,dc=nl&amp;quot;  -D &amp;quot;uid=elastic,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Do the same as above, but this this specify you only want the member attribute&lt;br /&gt;
ldapsearch -W -b &amp;quot;cn=elastic-users,cn=groups,cn=accounts,dc=brammerloo,dc=nl&amp;quot; -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot; member&lt;br /&gt;
&lt;br /&gt;
# Show all groups of which tonberry is a member of by searching for the memberOf attribute&lt;br /&gt;
ldapsearch -W -b &amp;quot;uid=tonberry,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;  -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot; memberOf&lt;br /&gt;
&lt;br /&gt;
# List attributes for all groups in the group &amp;quot;groups&amp;quot;&lt;br /&gt;
ldapsearch -W -b &amp;quot;cn=groups,cn=accounts,dc=brammerloo,dc=nl&amp;quot; -D &amp;quot;uid=admin,cn=users,cn=accounts,dc=brammerloo,dc=nl&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== git ===&lt;br /&gt;
==== Checks ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# List your current branch and situation&lt;br /&gt;
git status&lt;br /&gt;
&lt;br /&gt;
# List all branches and your current one&lt;br /&gt;
git branch --all&lt;br /&gt;
&lt;br /&gt;
# List all available tags&lt;br /&gt;
git tag&lt;br /&gt;
&lt;br /&gt;
# List the current selected tag&lt;br /&gt;
git describe&lt;br /&gt;
git describe --tags&lt;br /&gt;
&lt;br /&gt;
# Compare changes in the current working directory to the committed tree, and list what files have been changed&lt;br /&gt;
git diff-files&lt;br /&gt;
&lt;br /&gt;
# Compare changes in the current working directory to the committed tree, and list what has changed&lt;br /&gt;
git diff-files -p&lt;br /&gt;
&lt;br /&gt;
# Compare the committed tree to the current working directory, and list what has changed&lt;br /&gt;
git diff HEAD&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Common ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a folder and initialize it for use by git&lt;br /&gt;
mkdir gitrepo1; cd gitrepo1; git init&lt;br /&gt;
&lt;br /&gt;
# Switch to another branch&lt;br /&gt;
git checkout stable/zed&lt;br /&gt;
&lt;br /&gt;
# Switch to a specific tag&lt;br /&gt;
git checkout tags/14.11.0&lt;br /&gt;
&lt;br /&gt;
# Fetch data from the current upstream branch&lt;br /&gt;
git pull&lt;br /&gt;
&lt;br /&gt;
# Pull data from a specific branch&lt;br /&gt;
git pull origin unmaintained/yoga&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rclone ===&lt;br /&gt;
* https://rclone.org/&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
Example configuration based on OpenStack swift. Config should be in the homefolder of your user .config/rclone/rclone.conf:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
[swift-ssd]&lt;br /&gt;
type = swift&lt;br /&gt;
user = patrick&lt;br /&gt;
key = &amp;lt;PASSWORD&amp;gt;&lt;br /&gt;
auth = https://openstack.brammerloo.nl:5000/v3&lt;br /&gt;
region = Rotterdam&lt;br /&gt;
domain = Default&lt;br /&gt;
tenant = patrickproject&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Commands ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
# List all containers, buckets and or folders of container &amp;quot;swift-ssd&amp;quot;&lt;br /&gt;
rclone lsd &amp;quot;swift-ssd:&amp;quot;&lt;br /&gt;
          20 2025-02-10 09:46:00         2 ssd-container&lt;br /&gt;
           0 2025-02-10 09:46:00         1 swift-ssd&lt;br /&gt;
           0 2025-02-10 09:46:00         1 swift-ssd2&lt;br /&gt;
&lt;br /&gt;
rclone lsd &amp;quot;swift-ssd:ssd-container&amp;quot;&lt;br /&gt;
           0 2025-02-10 09:48:02        -1 mystorage&lt;br /&gt;
&lt;br /&gt;
# List contents, files, folders of bucket &amp;quot;ssd-container&amp;quot;, within container &amp;quot;swift-ssd&amp;quot;&lt;br /&gt;
rclone ls &amp;quot;swift-ssd:ssd-container&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# List the contents of file &amp;quot;asd&amp;quot;&lt;br /&gt;
rclone cat &amp;quot;swift-ssd:ssd-container/asd&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Mount an object storage to local folder /mnt/object-ssd/&lt;br /&gt;
rclone mount swift-ssd:ssd-container /mnt/object-ssd&lt;br /&gt;
&lt;br /&gt;
# Synchronize a local folder to a destination folder inside a bucket, in interactive mode&lt;br /&gt;
rclone sync -i /etc/rsyslog.d swift-ssd:ssd-container/mystorage/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== mdtest ===&lt;br /&gt;
This chapter was mostly written and contributed by Ivo Palli.&lt;br /&gt;
&lt;br /&gt;
==== General ====&lt;br /&gt;
mdtest is part of the ior performance test package.&lt;br /&gt;
&lt;br /&gt;
==== RHEL Installation ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
wget https://github.com/hpc/ior/releases/download/3.3.0/ior-3.3.0.tar.bz2&lt;br /&gt;
tar xjf ior-*.tar.bz2&lt;br /&gt;
cd ior-*/&lt;br /&gt;
&lt;br /&gt;
yum install openmpi-devel environment-modules&lt;br /&gt;
# Relog your shell so &#039;module&#039; is available&lt;br /&gt;
module load mpi&lt;br /&gt;
module list&lt;br /&gt;
./configure&lt;br /&gt;
make -j4&lt;br /&gt;
make install&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ubuntu Installation ====&lt;br /&gt;
* https://gist.github.com/hokiegeek2/3057f8bb3beb519ae9b556e41824be30&lt;br /&gt;
* https://ior.readthedocs.io/en/latest/userDoc/install.html&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
VERSION=4.0.0&lt;br /&gt;
wget https://github.com/hpc/ior/releases/download/$VERSION/ior-$VERSION.tar.gz&lt;br /&gt;
tar -xzvf ior-$VERSION.tar.gz&lt;br /&gt;
cd ior-$VERSION/&lt;br /&gt;
&lt;br /&gt;
apt install libopenmpi-dev environment-modules openmpi-bin openmpi-common libgtk2.0-dev -y&lt;br /&gt;
./configure&lt;br /&gt;
&lt;br /&gt;
make -j4&lt;br /&gt;
make install&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Usage =====&lt;br /&gt;
Note: Number of items should be a multiple of depth x branching factor&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&#039;bash&#039;&amp;gt;&lt;br /&gt;
module load mpi&lt;br /&gt;
&lt;br /&gt;
# Run command &amp;quot;mdtest -n 2000 -z 5 -b 2 -d /mnt/ssd/&amp;quot; 10 times in a row&lt;br /&gt;
mpirun --oversubscribe --allow-run-as-root -n 10 mdtest -n 2000 -z 5 -b 2 -d /mnt/nfs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Links =====&lt;br /&gt;
* https://github.com/hpc/ior&lt;br /&gt;
* https://www.glennklockwood.com/benchmarks/mdtest.html Guide&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
	</entry>
</feed>