6 Ekim 2025 Pazartesi

ipfwadm - Eski Firewall Kullanmayın

Giriş
Açıklaması şöyle. Yani ipfwadm ve ipchains eski şeyler
Initially, Linux introduced a tool called ipfwadm into the kernel to support a firewall. But it had significant limitations 

- Only basic packet filtering capabilities
- No support for stateful inspection; if outbound traffic was allowed, there was no automatic way to allow the related inbound response. For example, if you pinged, you wouldn't automatically receive the reply unless you manually configured it.

Things got a little better somewhat with the introduction of ipchains. It offered certain advantages over ipfwadm, such as 

- More flexible rule matching 
- Basic support for connection tracking.

However, it still fell short. The connection tracking wasn't fully stateful, there was no support for IPv6, and the design wasn't scalable — meaning rule sets became slower and harder to manage as they grew.

3 Aralık 2023 Pazar

tmpfs

Giriş
tmpfs'i yüklemek için iki seçenek var
1. /etc/fstab
2. mount komutu

1. /etc/fstab Dosyası - 
Kalıcıdır

Örnek
Şöyle yaparız.
$ sudo vim /etc/fstab

...
# tmpfs in RAM
tmpfs         /tmp         tmpfs         defaults,noatime,mode=1777      0 0
...
Şöyle yaparız.
$ sudo mount /tmp
$ mount | grep tmp # Check /tmp is in RAM
tmpfs on /tmp type tmpfs (rw,noatime)
Örnek
/etc/fstab dosyasına şöyle yaparız. Bir dahaki tekrar başlatmada bu dizin otomatik yüklenir.
tmpfs /mnt/dbtemp/PG_13_202007201/936082 tmpfs \ 
  rw,nodev,nosuid,noatime,nodiratime,size=1G 0 0
Ama bir dahaki başlatmayı beklememek için dizini RAM'e yükleriz
mount /mnt/dbtemp/PG_13_202007201/936082

2. mount komutu
Geçicidir

Örnek
Şöyle yaparız
# mount tmpfs /path/to/your/mountpoint -t tmpfs 

27 Kasım 2023 Pazartesi

mtr komutu

Giriş
Açıklaması şöyle
The Linux mtr tool, preinstalled with Fedora distributions, runs a complex traceroute combined with ping over the given target, giving us complete information about what path the network infrastructure takes to the target, along with how responsive the nodes in the path are. We can see the typical output in the screenshot above. We have all the hosts on the path from our system to linux.org, and we also have the ping result for each one.

23 Kasım 2023 Perşembe

Network File System - NFS

Giriş
Açıklaması şöyle
Native file sharing in Linux systems is done with NFS (Network File System). Its purpose? Simple and unique: share files in the network. Its implementation? Single purpose: sharing only. It only allows a shared folder across the network to be mounted as a local file system on a different computer. From there, the local Linux will manage shares like any other file: it’s just another file system, and in the nineties this sufficed.
Açıklaması şöyle
I have a file on my server that you need, so I configure NFS to publish it and you would use the mount command to load it on your end. Everything looks easy, even trivial.
Meta information
Açıklaması şöyle
But files you see carry with them important meta information like owner and permissions. How do I tell my file on my server that is configured to answer to a set of users, that it should also work with another set of users found on the computer its shared with? Normally you don’t. When you share files, you also share the users it will work with. Not so with NFS. For NFS, the single purpose was to allow a computer to mount files from a different computer. Users are somebody else’s problem.
NFS bunu umursamıyor. Açıklaması şöyle
And so my file travelled to your computer with the exact same permissions found on mine. The owner of the file is user 1000? On your computer it would be the same. Is the owner 1000 on my computer radu? Well, what is owner 1000 on yours? I don’t know. And NFS didn’t care either. It was not its responsibility. In practice this meant I could create my own user 1000, mount shares from a different computer and act on those files like they were mine. This is a major security vulnerability, one trivial to exploit and critical in its implications, allowing me to take over foreign files like they were mine.


2 Ekim 2023 Pazartesi

groupadd komutu

Giriş

--system seçeneği
Sistem grubu yaratır. Açıklaması şöyle
System groups are groups that are used by the system itself, such as the audio group for sound devices or the disk group for disk devices.

System groups have a number of special properties:

- They are assigned a unique group ID (GID) from a reserved range of GIDs.
- They cannot be deleted by regular users.
- They can only be modified by the system administrator.
Örnek
Şöyle yaparız
# Create a system group for Prometheus
sudo groupadd --system prometheus

# Create a system user for Prometheus with /sbin/nologin shell
sudo useradd -s /sbin/nologin --system -g prometheus prometheus


nproc komutu - İşlemci Sayısını Döner

Örnek ver

15 Ağustos 2023 Salı

rsyslog Servisi

Örnek
Şöyle yaparız
# Install
> apt list -a rsyslog

# start and enable the rsyslog service
> sudo systemctl enable --now rsyslog
Konfigürasyon Dosyası
Konfigürasyon için /etc/rsyslog.conf dosyası veya /etc/rsyslog.d/ dizininde bir dosya kullanılır

Örnek
Şöyle yaparız. Kafka'daki your_topic_name_here isimli topic'i okur
# Load the Kafka output module
module(load="omkafka")

# Forward logs to Kafka broker(s)
action(type="omkafka" topic="your_topic_name_here" broker="kafka_broker_host:port")


11 Ağustos 2023 Cuma

io_uring

Giriş
Açıklaması şöyle
You might have heard about io_uring: a new addition to the kernel which specifically targets providing a uniform asynchronous API for all kinds of I/O operations, including, first and foremost, operations on local files. 
Project Loom ve io_uring
Açıklaması şöyle. Yani JDK 21 kullanıyorsak worker thread sayısını hem JVM'de hem de işletim sisteminde ayarlamak gerekir
It can, and it probably will (probably only for local files, as io_uring's performance gains over epoll aren't consistent, and the implementation itself frequently has security vulnerabilities). However, this only shifts the problem instead of fully solving it.

From the application’s perspective, we get a non-blocking, asynchronous API for file access. But if we look at what happens under the covers in io_uring, we'll discover that it manages a thread pool for blocking operations, such as these on local files. Hence instead of running compensating threads in the JVM, we'll get threads run and managed by io_uring.

This has some configuration implications. If you’d like to set an upper bound on the number of kernel threads used by your application, you’ll now have to configure both the JVM with its carrier thread pool, as well as io_uring, to cap the maximum number of threads it starts. Luckily, there's a great article describing how to do precisely that.

29 Mayıs 2023 Pazartesi

ssh Reverse Port Forwarding - Firewall Arkasındaki Sunucuya Erişmek İçindir

Giriş
Not : Açıklaması şöyle
For Remote Port forwarding the ssh server config /etc/ssh/sshd_config should have a property GatewayPorts yes
Açıklaması şöyle
Keep in mind that the ssh -R command requires SSH access to the remote server and proper authentication credentials. Additionally, the SSH server configuration on the remote host must allow port forwarding for this command to work.
ssh tunnel açmak için kullanılır. A <- Firewall <- B  olsun. B'den A'ya erişim var. Ancak B Firewall arkasında olduğu için A'nın B'ye erişimi yok.

Söz dizimi şöyle
ssh -R remote_port:local_address:local_port username@sshserver
Örnek
Şöyle yaparız
ssh -R 8888:localhost:8080 user@remote_host
Açıklaması şöyle
This command binds port 8888 on the remote server and forwards any incoming traffic to the web server running on localhost:8080 on your local machine. Now, you can access the web server on the local machine by connecting to http://remote_host:8888 from the remote server.

Örnek
A'dan B'ye erişmek için B'de şöyle yaparız.
$ ssh -f -N -R 1234:localhost:22 user@A_ip
A makinesinde şöyle yaparız.
$ ssh -p 1234 user@localhost
Örnek
Server <- Firewall <- Raspberry  olsun. Raspberry tarafında şöyle yaparız
rpi$ ssh -R 2222:localhost:22 username-on-server@server-ip-address
Sunucu makinede şöyle  yaparız
laptop$ ssh -p 2222 username-on-pi@server-ip-address

15 Mayıs 2023 Pazartesi

cron İş Dosyaları

crontab Dosyasında PATH Ortam Değişkeni
Açıklaması şöyle. crontab dosyasında PATH ortam değişkenini kullanmamak daha iyi.
cron scripts have a limited path, that doesn't include iptables, so it's not found.
if you do something like echo $PATH >> /root/test.log you will see that cron has a path with just /usr/bin and /bin
crontab Dosyasında SHELL Ortam Değişkeni
Açıklaması şöylee
cron needs to know which shell to start, there can only be one. The SHELL variable in crontab doesn’t specify possible shells, it specifies the shell to use. cron reads the value in SHELL, if any, and uses that as the command to run; it doesn’t interpret : or any other symbol.

İşlerin Saklandığı Dosyalar
Şu dizinlerde saklanırlar.
/etc/cron.hourly 
/etc/cron.daily 
/etc/cron.weekly 
Örneğin cron.daily dizinine bakarsak çıktı olarak şunun gibi bir şey alırız.
-rwxr-xr-x   1 root root   539 Tue Apr 02 2019 22:13:44 apache2
-rwxr-xr-x   1 root root  1478 Tue May 28 2019 15:40:29 apt-compat
-rwxr-xr-x   1 root root   314 Wed Feb 13 2019 17:40:39 aptitude
-rwxr-xr-x   1 root root    77 Sat Feb 16 2019 11:10:23 apt-show-versions
-rwxr-xr-x   1 root root   355 Fri Dec 29 2017 09:02:08 bsdmainutils
-rwxr-xr-x   1 root root  1187 Fri Apr 19 2019 03:14:13 dpkg
-rwxr-xr-x   1 root root  4128 Sat Jul 20 2019 12:35:58 exim4-base
-rwxr-xr-x   1 root root   377 Tue Aug 28 2018 23:21:11 logrotate
-rwxr-xr-x   1 root root  1123 Sun Feb 10 2019 12:11:20 man-db
-rwxr-xr-x   1 root root  1403 Thu Mar 21 2019 22:42:36 ntp
-rwxr-xr-x   1 root root   249 Wed Sep 27 2017 17:45:23 passwd
-rw-r--r--   1 root root   102 Sun Jun 23 2019 18:49:01 .placeholder
-rwxr-xr-x   1 root root   383 Sat Mar 30 2019 17:10:38 samba
-rwxr-xr-x   1 root root   441 Sat Apr 06 2019 08:18:26 sysstat
% karakteri
Eğer komut içinde % karakteri varsa, \ karakteri ile escape etmek gerekir.

Örnek
Şöyle yaparız. Sabah 03:03 AM'de çalışır
3 3 * * * mongodump --out /var/backups/mongobackups/`date +"\%m-\%d-\%y"`
Birden fazla dosya çalıştırma
En kolay seçenek tüm dosyaları çalıştıracak ana bir shell dosyası oluşturmak
Örnek
Şöyle yaparız
for script in /home/user/scripts/enabled/*; do $script &>/dev/null; done
Full Path
Açıklaması şöyle
You should use in cron ALWAYS the full path to the executables. It is run in quite different environment and a lot of executables are not "reachable"

Bazı Örnekler
Dakika, saat ... şeklinde gider. Her X anlamında kullanmak istersek */X şeklinde kullanırız.

Örnek
Şöyle yaparız
0 8,12,16,20 * * * /opt/tools/var/log/zhrdct.log 2>&1
Örnek
Her gün saat 21:30'da çalışmasını istediğimiz iş için şöyle yaparız.
30 21 * * *  cp /home/user/folder_name -r  /home/user/public
Örnek
Her 15 dakikada bir çalışmasını istediğimiz iş için şöyle yaparız.
*/15 * * * * wget ...
Örnek - @reboot
Bilgisayar açılırken çalışan bir script için şöyle yaparız
@reboot sleep 15; /path/to/your/script >> /path/to/your/iofile.txt 2>&1
Örnek - @reboot
Şöyle yaparız
@reboot root /usr/bin/rtcwake -m no -l -t "$(/usr/bin/date -d 'today 16:00:00' '+%s')"

14 Mart 2023 Salı

auditctl komutu

Giriş
Açıklaması şöyle
The Linux kernel audit subsystem provides a mechanism for collecting and logging security events like access to sensitive files or system calls. It can help you troubleshoot unexpected behavior or collect forensic evidence in the event of a security breach. The audit subsystem is on by default on Amazon Linux 2, but it is not configured to log syscalls.
Security events'i toplan şey auditd sistemi. auditd ile ilgili bir soru burada

-a seçeneği
Örnek
Şöyle yaparız. Tüm audit toplamayı engeller
auditctl -a never,task

9 Mart 2023 Perşembe

TMP Ortam Değişkeni

Giriş
Geçici dosyaların nerede hangi dizinde yaratılacağını belirtir.

27 Şubat 2023 Pazartesi

ssh-agent komutu

Giriş
Şifre ile korunana dosyaları bellekte tutar ve şifresiz erişim sağlar

Örnek
Şöyle yaparız
>> ssh-keygen -t rsa    #Press enter for all values

>> ls ~/.ssh/

demo-key      # private key
demo-key.pub  # public key

>> eval `ssh-agent -s`
>> ssh-add ~/.ssh/demo-key


awk komutu - printf

Örnek
Şöyle yaparız
$ awk '{printf("%06.2f\n", $1)}' <<< 99.111111
099.11

13 Şubat 2023 Pazartesi

tr komutu - Standart Input'u Değiştirir ve Standart Output'a Gönderir

Giriş
Açıklaması şöyle
Translate, squeeze, and/or delete characters from standard input, writing to standard output.
Söz dizimi şöyle
tr [options] string1 [string2]
Replace
Birinci string aranacak karakter, ikinci string değiştirilecek karakterdir

Örnek
Şöyle yaparız
>> echo "Hello World" | tr 'H' 'h'
hello World

>> echo "Hello World" | tr 'Ho' 'KK'
KellK WKrld
-d seçeneği - Delete characters
-c seçeneği -d ile belirtilen şeyin tersini yapar
Örnek
Şöyle yaparız. İkinci örnekte -d ile "Hd" karakterlerinin silinmesi isteniyor. Ancak -c ile bunlar silinmiyor ve geri kalan her şey siliniyor
>> echo "Hello World" | tr -d 'Ho'  
ell Wrld

# complement the delete
>> echo "Hello World" | tr -cd 'Hd\n' 
Hd

>> echo "Hello World 12345 " | tr -cd [:digit:]
12345

>> echo "Hello World 12345 " | tr -cd [:alpha:]
HelloWorld
-s seçeneği - Squeeze characters
Örnek
Şöyle yaparız
>> echo "HHHHHHHHello Worrrrrrrrrldddddddddddddddddd" | tr -s 'Hord' 
Hello World

>> echo "Hello World" | tr -s [:lower:] [:upper:]
HELO WORLD

9 Aralık 2022 Cuma

openssl req aracı İle CSR'yi İmzalamak Yani CSR'den Sertifika Üretmek

Giriş
CA : Certificate Authority belirtilir. Bu bir self signed certificate olabilir.
CAkey : Certificate Authority'nin private key dosyasıdır
out : Sertifika dosyasının ismidir

Örnek
CSR'den sertifika üretmek için şöyle yaparız. Burada minikube'a ait certificate authorities ve private key kullanılıyor.
openssl x509 -req rohan.csr 
  -CA ../minikube/ca.crt \ 
  -CAkey ../minikube/ca.key 
  -CAcreateserial \
  -out rohan.crt \
  -days 365
Örnek
Şöyle yaparız
openssl x509 \
    -req \
    -in host.csr \
    -CA self_signed.pem \
    -CAkey self_signed.key \
    -CAcreateserial \
    -out host.pem \
    -days 30 \
    -sha256


openssl req aracı İle Certificate Signing Requests (CSR) Üretmek

Giriş
Certificate Signing Requests (CSR) yaratmak içindir. CSR tiplerinden bazıları şöyle.
- PKCS #10 : Public-Key Cryptography Standards #10 CSR, RSA's CSR format.
- SPKAC : Signed Public Key and Challenge (SPKAC), Netscape's CSR format.
Bu araç PKCS#10 tipinden CSR üretir. Açıklaması şöyle.
PKCS#10 certificate request and certificate generating utility.
1. Önce elimizde bir private key olmalı
2. Bu private key "openssl req ..." ile CSR haline dönüştürülür

Seçenekler
key : private key dosyası belirtilir.
newkey
 :seçeneği ile kullanılacak algoritma belirtilir. Genellikle rsa:1024 , rsa:2048 , rsa:4096 seçilir.
nodes : Açıklaması şöyle. Private key dosyasının şifrelenmemesini sağlar.
The option -nodes is not the English word "nodes", but rather is "no DES". When given as an argument, it means OpenSSL will not encrypt the private key in a PKCS#12 file.
keyout :seçeneği ile private key dosyası belirtilir.
out : seçeneği ile CSR dosyası belirtilir.

Private Key Dosyası Zaten Varsa
Bu durumda -key ile private key dosyası belirtilir.

Örnek
Önce bir Private key yaratırız. Şöyle yaparız
$ openssl genrsa -out rohan.key 2048
Daha sonra CSR yaratmak için şöyle yaparız
$ openssl req -new -key rohan.key -out rohan.csr -sub "/CN=rohan/0=marketingweb"

$ ll
... rohan.csr
... rohan.key
Örnek
Şöyle yaparız
openssl req -new -key <private-key-file.key> -out <CSR-file.csr>
Örnek
Şöyle yaparız
openssl req -new -key <pem_file>.pem -out <out-csr-file>.pem 
  -subj "/CN=admin/O=prod/O=dev/O=uat"
Açıklaması şöyle
This would create a CSR (Certificate Signing Request) for the username admin, belonging to three groups: prod, dev and uat
Private Key Dosyası Yoksa
-key belirtilmez ve private key dosyası da üretilir.

Örnek
Şöyle yaparız
openssl req -new \
    -newkey rsa:4096 \
    -nodes \
    -keyout host.key \
    -out host.csr \
    -subj '/CN=TestHost/C=US/ST=CA/L=SF/O=Test'

8 Aralık 2022 Perşembe

ssh Local Port Forwarding - Kendi Bilgisayarımdan Bir Başka Sunucuya Erişmek İçindir

Giriş
Local Port Forwarding için ssh komutunun -L ve -N seçenekleri birlikte kullanılır. 
Söz dizimi şöyle
ssh -L <local-port>:localhost:<remote-address:remote-port> <username>@<firewall-ip>
Daha kısa söz dizimi şöyle. Burada localhost yazmaya gerek yok
ssh -L local_port:remote_address:remote_port username@sshserver
-L seçeneği
ssh tunnel açmak için kullanılır. Açıklaması şöyle
The OpenSSH client has a command line option for port forwarding, used like this:

ssh -L localport:server:serverport user@host

which will connect to host as user, and at the same time redirecting localport on the client to serverport on server
-N seçeneği
Açıklaması şöyle.
-N    Do not execute a remote command.  This is useful for just forwarding ports.
Açıklaması şöyle.
Normally, the ssh program runs a command on a remote system. For example, ssh user@server ls -l /tmp lists the content of the /tmp directory on server. When you leave the command out, as in ssh user@server, the user's shell is executed.

One of the features of OpenSSH is the creation of tunnels. The -D, -L and -R options use various techniques that allow the forwarding of network ports, also known as tunneling. By default, a tunnel created with ssh exists as long as the command executed by ssh runs on the remote server.

Often though, you are not interested in running a remote command; all you want is the tunnel. This is what the -N option is for.
Örnek
Şöyle yaparız
ssh -L 8888:destination:5432 user@remote_host
Açıklaması şöyle
This command binds port 8888 on your local machine and forwards any incoming traffic to the database server running on destination:5432 on the remote server. Now, you can access the database server on the remote machine by connecting to localhost:8888 from your local machine.

Örnek
A -> Firewall -> B  olsun. A'dan Firewall'a erişim var.

A'dan B'ye erişmek için A'da şöyle yaparız. -N seçeneğinin kullanılma sebebi sadece tunnel görevi görmek, başka bir "remote command" çalıştırmamak.
ssh -N -L 33642:remotemachine:5900 user@firewall
A makinesinde şöyle yaparız.
$ telnet localhost 33642
Örnek
Şöyle yaparız. Burada firewall adresi 172.168.65.117. Erişmek istediğimiz sunucu da firewall'un arkasında ve ismi postgres.123456789012.us-east-1.rds.amazonaws.com.
ssh -L 5432:postgres.123456789012.us-east-1.rds.amazonaws.com:5432 ec2-user@172.168.65.117
Eğer sunucu da firewall üzerinde çalışsaydı şöyle yapardık
ssh -L 6379:localhost:6379 ec2-user@172.168.65.117
Örnek
Privileged port olan 80'i 3000 portuna yönlendirmek için şöyle yaparız.  -N seçeneğinin kullanılma sebebi sadece tunnel görevi görmek, başka bir "remote command" çalıştırmamak.
sudo ssh $USERNAME@localhost -L 80:localhost:3000 -N