WalzoneInterview Prep
📞 Interviewing soon? Practice with a realistic AI mock phone interview — it calls you, then scores you. First 15 min FREE →

Linux · Advanced · question 53 of 100

What is the role of the iptables command in Linux, and how is it used for configuring firewall rules?

📕 Buy this interview preparation book: 100 Linux questions & answers — PDF + EPUB for $5

In Linux, the iptables command is used for configuring firewall rules. It is a command-line tool that is used to set up, maintain, and inspect the firewall rules on a Linux system. The firewall rules are defined in a set of tables, which contain chains of rules that are applied to network traffic as it passes through the firewall.

The iptables command uses a series of rules to filter and manipulate network traffic. Each rule defines a set of conditions that incoming or outgoing traffic must meet in order to be allowed or denied. Rules are organized into chains, which define a sequence of rules to be applied to traffic.

The three built-in chains in iptables are INPUT, OUTPUT, and FORWARD. The INPUT chain is used to filter incoming traffic, the OUTPUT chain is used to filter outgoing traffic, and the FORWARD chain is used to filter traffic that is being forwarded through the system.

In addition to these built-in chains, iptables also allows for the creation of custom chains, which can be used to organize and apply more complex sets of rules.

Here are some examples of iptables commands and their uses:

iptables -A INPUT -s 192.168.1.0/24 -j DROP: This command appends a rule to the INPUT chain that drops any incoming traffic from the IP address range 192.168.1.0/24.

iptables -A OUTPUT -d 8.8.8.8 -p tcp –dport 53 -j ACCEPT: This command appends a rule to the OUTPUT chain that allows outgoing TCP traffic to destination port 53 (DNS) at IP address 8.8.8.8.

iptables -A FORWARD -i eth0 -o eth1 -j ACCEPT: This command appends a rule to the FORWARD chain that allows traffic to be forwarded from the eth0 interface to the eth1 interface.

iptables -L: This command lists all the rules in all chains.

iptables -F: This command flushes (deletes) all rules in all chains.

iptables-save: This command saves the current set of rules to a file, so that they can be restored later using the iptables-restore command.

iptables-restore < file: This command restores a previously saved set of rules from a file.

Overall, iptables provides a powerful and flexible way to configure firewall rules on a Linux system, allowing administrators to fine-tune network access and protect their systems from unwanted traffic.

Reading is step one. Saying it out loud is the interview. Our AI interviewer calls your phone and runs a realistic Linux interview — then scores it.
📞 Practice Linux — free 15 min
📕 Buy this interview preparation book: 100 Linux questions & answers — PDF + EPUB for $5

All 100 Linux questions · All topics