• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

nft Command Examples in Linux

by Deepika

“nft” is a tool for configuring the Linux kernel firewall in a user-friendly way. It is designed to replace the older “iptables” firewall configuration tool. The “nftables” firewall framework provides more advanced functionality and improved performance compared to “iptables”.

“nft” allows system administrators to manage tables, chains, and rules in the Linux kernel firewall. A table in the firewall represents a specific domain of rules, such as the IPv4 or IPv6 domains. Chains are sequences of rules within a table, and rules define the actions to be taken for specific packets. The rules can include actions such as accepting, rejecting, or logging incoming packets.

“nft” provides a flexible and powerful interface for configuring the Linux kernel firewall, making it easier for system administrators to set up and manage firewall rules. The tool allows rules to be specified using a simple and intuitive syntax, and it provides a wide range of features for fine-tuning the firewall configuration.

nft Command Examples

1. View current configuration:

# sudo nft list ruleset

2. Add a new table with family “inet” and table “filter”:

# sudo nft add table inet filter

3. Add a new chain to accept all inbound traffic:

# sudo nft add chain inet filter input \{ type filter hook input priority 0 \; policy accept \}

4. Add a new rule to accept several TCP ports:

# sudo nft add rule inet filter input tcp dport \{ telnet, ssh, http, https \} accept

5. Add a NAT rule to translate all traffic from the `192.168.0.0/24` subnet to the host’s public IP:

# sudo nft add rule nat postrouting ip saddr 192.168.0.0/24 masquerade

6. Show rule handles:

# sudo nft --handle --numeric list chain family table chain

7. Delete a rule:

# sudo nft delete rule inet filter input handle 3

8. Save current configuration:

# sudo nft list ruleset > /etc/nftables.conf

Filed Under: Linux

Some more articles you might also be interested in …

  1. numactl Command Examples in Linux
  2. bzegrep: Find extended regular expression patterns in bzip2 compressed files using egrep
  3. Linux filesystem is filling, despite no large files or directories
  4. How to increase swap space on Linux
  5. git gc: Optimise the local repository by cleaning unnecessary files
  6. “git add” Command Examples
  7. kube-fzf: Shell commands for command-line fuzzy searching of Kubernetes Pods
  8. comby: Tool for structural code search and replace that supports many languages
  9. How to disable a specific command for a specific user in Linux
  10. ldapsearch Command Examples

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright