The nft command is the user-space utility for the nftables framework, which is the modern replacement for iptables, ip6tables, arptables, and ebtables in Linux. Introduced in Linux kernel 3.13, nftables provides a more consistent and flexible syntax, improved performance, and a unified approach to packet filtering and classification.
Unlike its predecessor iptables, which used separate tools for different protocol families, nftables uses a single tool (nft) and a unified syntax for all protocol families. This simplification, along with other architectural improvements, makes nftables more powerful and easier to use for network administrators and security professionals.
Sets allow efficient matching against multiple values:
# Create a setnft add set ip filter blocked_ips { type ipv4_addr \; }# Add elements to the setnft add element ip filter blocked_ips { 192.168.1.1, 192.168.1.2 }# Use the set in a rulenft add rule ip filter input ip saddr @blocked_ips drop
# Create a mapnft add map ip filter port_map { type inet_service : verdict \; }# Add elements to the mapnft add element ip filter port_map { 22 : accept, 80 : accept, 443 : accept }# Use the map in a rulenft add rule ip filter input tcp dport vmap @port_map
nftables, through the nft command, provides a powerful and flexible framework for packet filtering, classification, and manipulation in Linux. Its unified approach, improved performance, and consistent syntax make it a superior alternative to the legacy iptables framework.
While the transition from iptables to nftables may require learning a new syntax and concepts, the benefits in terms of flexibility, performance, and maintainability make it well worth the effort. As Linux distributions continue to adopt nftables as the default firewall solution, mastering the nft command becomes increasingly important for system administrators and security professionals.
Test Your Knowledge
Take a quiz to reinforce what you've learned
Exam Preparation
Access short and long answer questions for written exams