Dasar-dasar nftables

Nftables adalah firewall pengganti iptables dari netfilter framework.

https://wiki.debian.org/nftables

https://netfilter.org/projects/nftables/

https://wiki.nftables.org/wiki-nftables/index.php/Moving_from_iptables_to_nftables


nftables is a netfilter project that aims to replace the existing {ip,ip6,arp,eb}tables framework. It provides a new packet filtering framework, a new user-space utility (nft), and a compatibility layer for {ip,ip6}tables. It uses the existing hooks, connection tracking system, user-space queueing component, and logging subsystem of netfilter. https://wiki.archlinux.org/title/nftables


Diagram untuk memahami konsep nftables:


https://wiki.nftables.org/wiki-nftables/index.php/Netfilter_hooks


Bisa diperhatikan misalnya: ada paket masuk ke dalam router/server dicek dulu apakah interface port nya bridge atau tidak jika tidak kemudian jenis filter protocol apa yang ingin dipakai, misalnya protokol IP maka fokus saja ke background hijau didiagram di atas. Ini sesuai dengan kebutuhan misalnya mau packet filtering di layer 2 atau layer 3.

Untuk DNAT/SNAT bisa gunakan Prerouting/PostRouting Hook

Sebelum melakukan konfigurasi firewall perlu diperhatikan juga apakah akan diterapkan di Server atau Router, jika di Server maka yang sering dimainkan adalah chain INPUT, kemudian kalau di Router bisa di chain INPUT dan FORWARD (karena router akan men forward packet ke tujuan, pastikan juga kernel routing nya sudah aktif).  Untuk chain OUPUT bisa digunakan juga baik di Server maupun Router ini akan memfilter paket yang keluar dari dalam Server maupun Router. Namun untuk di nftables ini berbeda dengan iptables yang punya builtin chain, di nftables kita bisa bebas define chain sendiri. Didalam chain natinya akan berisi rule seperti source ip address dan port yang akan di accept,drop,dll.

The purpose of chains is to hold #Rules.

Rules are either constructed from expressions or statements and are contained within chains.

Okey langsung saja ke bagian contoh konfigurasi:

Cara instalasi:

apt-get install nftables


Case:

• Incoming packets should be dropped by default.

• Configure a list named “trusted” which contains DEV VM and use it in the firewall rules.

• Allow SSH and ICMP traffic from member of the “trusted” list to the SERVER host.


Untuk cara konfigurasi bisa via command line atau meletakkan nya di /etc/nftables.conf

Untuk saat ini akan mencoba via command line


Incoming packets should be dropped by default


nft add table inet filter

nft add chain inet filter input { type filter hook input priority 0 \; policy drop \; }


Create trusted list


nft add set inet filter trusted { type ipv4_addr \; }

nft add element inet filter trusted { 10.0.0.1 }

nft add element inet filter trusted { 10.0.0.2 }


Allow incoming SSH

nft add rule inet filter input tcp dport 22 ct state new,established set dnat to ip daddr @trusted accept


Allow incoming ICMP

nft add rule inet filter input icmp type echo-request set dnat to ip daddr @trusted accept


Okey cukup sekian dulu selanjutnya bisa dikembangkan untuk menyimpan di file konfigurasi dan supaya tidak hilang ketika misalnya server nya reboot.
Thank you.
Happy learning.






Komentar

Postingan populer dari blog ini

Pembahasan IT Network Systems Administration Module A DNS (Forward Zone, Reverse Zone, CNAME, MX, Split View)

Cara memahami dan menghafal model OSI dengan analogi

Table of Contents