UNIX Question and Answer – Firewall Configuration
UNIX MCQ – Multiple Choice Questions for exam, interview, and Entrance Test
1. What is the purpose of iptables in UNIX?
a) To manage network interfaces
b) To configure firewall rules
c) To manage user permissions
d) To monitor system logs
Answer: b) To configure firewall rules
Explanation: iptables is a command-line utility used to configure packet filtering rules in the Linux kernel’s netfilter framework, effectively acting as a firewall.
2. Which command is used to list the current iptables rules in UNIX?
a) iptables-list
b) iptables-show
c) iptables-list-rules
d) iptables -L
Answer: d) iptables -L
Explanation: The iptables -L command lists all currently configured iptables rules in UNIX.
3. What is the default policy of the INPUT chain in iptables if no specific rules are defined?
a) ACCEPT
b) DROP
c) REJECT
d) ALLOW
Answer: b) DROP
Explanation: By default, if no specific rules are defined, the iptables INPUT chain policy is set to DROP, meaning all incoming packets are dropped unless explicitly allowed.
4. Which iptables chain is responsible for filtering incoming packets destined for the local system?
a) INPUT
b) OUTPUT
c) FORWARD
d) LOCAL
Answer: a) INPUT
Explanation: The INPUT chain in iptables is responsible for filtering incoming packets destined for the local system.
5. In iptables, what rule would you use to allow incoming SSH connections (on port 22)?
a) -A INPUT -p tcp –dport 22 -j ACCEPT
b) -A INPUT -s ssh -j ACCEPT
c) -A INPUT -p udp –dport 22 -j ALLOW
d) -A INPUT -i eth0 -p tcp –dport 22 -j ALLOW
Answer: a) -A INPUT -p tcp –dport 22 -j ACCEPT
Explanation: This rule allows incoming TCP connections on port 22 (SSH) in the INPUT chain.
6. What is the purpose of the -j option in iptables rules?
a) To specify the source IP address
b) To specify the destination port
c) To jump to the specified target if the rule matches
d) To log matching packets
Answer: c) To jump to the specified target if the rule matches
Explanation: The -j option in iptables rules is used to specify the target action to take if the rule matches.
7. Which iptables command is used to append a rule to the end of a chain?
a) iptables-append
b) iptables-add
c) iptables-insert
d) iptables -A
Answer: d) iptables -A
Explanation: The iptables -A command is used to append a rule to the end of a chain in iptables.
8. What does the DROP target do in iptables?
a) It silently discards the packet
b) It rejects the packet with an ICMP error message
c) It accepts the packet
d) It logs the packet and then drops it
Answer: a) It silently discards the packet
Explanation: The DROP target in iptables silently discards the packet without sending any response.
9. Which iptables rule is used to specify source IP addresses?
a) –source
b) –src
c) –from
d) –saddr
Answer: b) –src
Explanation: The –src option in iptables rules is used to specify the source IP addresses.
10. What is the purpose of the -m option in iptables rules?
a) To match packets based on a specified module
b) To specify the destination port
c) To jump to the specified target if the rule matches
d) To log matching packets
Answer: a) To match packets based on a specified module
Explanation: The -m option in iptables rules is used to specify a matching module to use for packet filtering.
11. Which command is used to save iptables rules to a file in UNIX?
a) iptables-save
b) iptables-export
c) iptables-backup
d) iptables-write
Answer: a) iptables-save
Explanation: The iptables-save command is used to save the current iptables rules to a file, typically for persistence across reboots.
12. What is the purpose of the FORWARD chain in iptables?
a) To filter packets destined for the local system
b) To filter packets originating from the local system
c) To filter packets forwarded through the local system
d) To filter packets based on their source IP address
Answer: c) To filter packets forwarded through the local system
Explanation: The FORWARD chain in iptables is used to filter packets that are forwarded through the local system.
13. Which iptables rule is used to specify the destination port?
a) –dest
b) –destination
c) –dst
d) –dport
Answer: d) –dport
Explanation: The –dport option in iptables rules is used to specify the destination port.
14. What is the purpose of the REJECT target in iptables?
a) It silently discards the packet
b) It rejects the packet with an ICMP error message
c) It accepts the packet
d) It logs the packet and then drops it
Answer: b) It rejects the packet with an ICMP error message
Explanation: The REJECT target in iptables rejects the packet and sends an ICMP error message back to the sender.
15. Which command is used to delete iptables rules in UNIX?
a) iptables-delete
b) iptables-remove
c) iptables-delete-rule
d) iptables -D
Answer: d) iptables -D
Explanation: The iptables -D command is used to delete iptables rules in UNIX.
16. What is the purpose of the -i option in iptables rules?
a) To specify the source IP address
b) To specify the destination port
c) To specify the input network interface
d) To specify the output network interface
Answer: c) To specify the input network interface
Explanation: The -i option in iptables rules is used to specify the input network interface.
17. Which command is used to flush all iptables rules in UNIX?
a) iptables-clear
b) iptables-flush
c) iptables-reset
d) iptables -F
Answer: d) iptables -F
Explanation: The iptables -F command is used to flush all iptables rules in UNIX, effectively deleting them.
18. What is the purpose of the ACCEPT target in iptables?
a) It silently discards the packet
b) It rejects the packet with an ICMP error message
c) It accepts the packet
d) It logs the packet and then drops it
Answer: c) It accepts the packet
Explanation: The ACCEPT target in iptables accepts the packet and allows it to pass through the firewall.
19. Which command is used to block all incoming traffic on a specific port in iptables?
a) iptables-block
b) iptables-reject
c) iptables -A INPUT -p tcp –dport <port> -j REJECT
d) iptables -A INPUT -p tcp –dport <port> -j DROP
Answer: d) iptables -A INPUT -p tcp –dport <port> -j DROP
Explanation: This rule blocks all incoming TCP traffic on the specified port by dropping packets.
20. What is the purpose of the OUTPUT chain in iptables?
a) To filter packets destined for the local system
b) To filter packets originating from the local system
c) To filter packets forwarded through the local system
d) To filter packets based on their source IP address
Answer: b) To filter packets originating from the local system
Explanation: The OUTPUT chain in iptables is used to filter packets that are generated by the local system.
21. Which iptables command is used to insert a rule at a specific position in a chain?
a) iptables-insert
b) iptables-add
c) iptables -I
d) iptables -I INPUT
Answer: c) iptables -I
Explanation: The iptables -I command is used to insert a rule at a specific position in a chain in iptables.
22. What is the purpose of the PREROUTING chain in iptables?
a) To filter packets before routing decisions are made
b) To filter packets after routing decisions are made
c) To filter packets before they are forwarded
d) To filter packets before they reach the local system
Answer: a) To filter packets before routing decisions are made
Explanation: The PREROUTING chain in iptables is used to filter packets before routing decisions are made, typically for NAT or port forwarding.
23. Which command is used to restore iptables rules from a file in UNIX?
a) iptables-restore
b) iptables-import
c) iptables-apply
d) iptables -R
Answer: a) iptables-restore
Explanation: The iptables-restore command is used to restore iptables rules from a file in UNIX.
24. What is the purpose of the NAT table in iptables?
a) To filter packets before routing decisions are made
b) To perform Network Address Translation
c) To filter packets before they are forwarded
d) To filter packets based on their source IP address
Answer: b) To perform Network Address Translation
Explanation: The NAT table in iptables is used to perform Network Address Translation, such as source or destination address translation.
25. Which iptables rule is used to specify the protocol (TCP, UDP, ICMP, etc.)?
a) –proto
b) –protocol
c) –tcp
d) –udp
Answer: b) –protocol
Explanation: The –protocol option in iptables rules is used to specify the protocol (TCP, UDP, ICMP, etc.) to match.
26. Which iptables command is used to delete a specific rule by its rule number?
a) iptables -D
b) iptables-delete
c) iptables-remove
d) iptables -R
Answer: a) iptables -D
Explanation: The iptables -D command is used to delete a specific rule by its rule number in iptables.
27. What is the purpose of the OUTPUT chain in iptables?
a) To filter packets destined for the local system
b) To filter packets originating from the local system
c) To filter packets forwarded through the local system
d) To filter packets based on their destination IP address
Answer: b) To filter packets originating from the local system
Explanation: The OUTPUT chain in iptables is used to filter packets that are generated by the local system.
28. Which iptables rule is used to specify the source port?
a) –sport
b) –source-port
c) –src-port
d) –sourceport
Answer: a) –sport
Explanation: The –sport option in iptables rules is used to specify the source port.
29. What is the purpose of the FORWARD chain in iptables?
a) To filter packets destined for the local system
b) To filter packets originating from the local system
c) To filter packets forwarded through the local system
d) To filter packets based on their source IP address
Answer: c) To filter packets forwarded through the local system
Explanation: The FORWARD chain in iptables is used to filter packets that are forwarded through the local system.
30. Which command is used to block all incoming ICMP traffic (ping) in iptables?
a) iptables -A INPUT -p icmp –icmp-type echo-request -j REJECT
b) iptables -A INPUT -p icmp –icmp-type echo-request -j DROP
c) iptables -A INPUT -p icmp –icmp-type echo-reply -j REJECT
d) iptables -A INPUT -p icmp –icmp-type echo-reply -j DROP
Answer: b) iptables -A INPUT -p icmp –icmp-type echo-request -j DROP
Explanation: This rule blocks all incoming ICMP echo request (ping) packets by dropping them.
31. What is the purpose of the nat table in iptables?
a) To filter packets before routing decisions are made
b) To perform Network Address Translation
c) To filter packets before they are forwarded
d) To filter packets based on their source IP address
Answer: b) To perform Network Address Translation
Explanation: The nat table in iptables is used to perform Network Address Translation, such as source or destination address translation.
32. Which command is used to list the current iptables rules in a specific chain in UNIX?
a) iptables-list-chain
b) iptables-show-chain
c) iptables -L <chain>
d) iptables -S <chain>
Answer: c) iptables -L <chain>
Explanation: The iptables -L <chain> command is used to list the current iptables rules in a specific chain in UNIX.
33. What is the purpose of the POSTROUTING chain in iptables?
a) To filter packets before routing decisions are made
b) To filter packets after routing decisions are made
c) To filter packets before they are forwarded
d) To filter packets after they are forwarded
Answer: d) To filter packets after they are forwarded
Explanation: The POSTROUTING chain in iptables is used to filter packets after they are forwarded.
34. Which iptables command is used to append a rule to the end of a specific chain?
a) iptables-append
b) iptables-add
c) iptables -A <chain>
d) iptables -E <chain>
Answer: c) iptables -A <chain>
Explanation: The iptables -A <chain> command is used to append a rule to the end of a specific chain in iptables.
35. What is the purpose of the PREROUTING chain in iptables?
a) To filter packets before routing decisions are made
b) To filter packets after routing decisions are made
c) To filter packets before they are forwarded
d) To filter packets before they reach the local system
Answer: a) To filter packets before routing decisions are made
Explanation: The PREROUTING chain in iptables is used to filter packets before routing decisions are made, typically for NAT or port forwarding.
36. Which iptables rule is used to specify the destination IP address?
a) –dest
b) –destination
c) –dst
d) –daddr
Answer: b) –destination
Explanation: The –destination option in iptables rules is used to specify the destination IP address.
37. What is the purpose of the MASQUERADE target in iptables?
a) To perform Network Address Translation
b) To silently discard packets
c) To reject packets with an ICMP error message
d) To log packets and then drop them
Answer: a) To perform Network Address Translation
Explanation: The MASQUERADE target in iptables is used to perform source address translation for outgoing packets.
38. Which iptables command is used to delete all rules in a specific chain?
a) iptables-flush
b) iptables-delete-chain
c) iptables-clear
d) iptables -F <chain>
Answer: d) iptables -F <chain>
Explanation: The iptables -F <chain> command is used to delete all rules in a specific chain in iptables.
39. What is the purpose of the LOG target in iptables?
a) To silently discard packets
b) To reject packets with an ICMP error message
c) To log packets
d) To log packets and then drop them
Answer: c) To log packets
Explanation: The LOG target in iptables is used to log matching packets to the system log.
40. Which command is used to enable IPv4 forwarding in UNIX?
a) sysctl -w net.ipv4.ip_forward=1
b) echo 1 > /proc/sys/net/ipv4/ip_forward
c) ip_forwarding=1
d) enable_ipv4_forwarding
Answer: a) sysctl -w net.ipv4.ip_forward=1
Explanation: The sysctl -w net.ipv4.ip_forward=1 command is used to enable IPv4 forwarding in UNIX.
41. What is the purpose of the SNAT target in iptables?
a) To perform Network Address Translation
b) To silently discard packets
c) To reject packets with an ICMP error message
d) To log packets and then drop them
Answer: a) To perform Network Address Translation
Explanation: The SNAT (Source NAT) target in iptables is used to perform source address translation for outgoing packets.
42. Which iptables rule is used to specify the protocol (TCP, UDP, ICMP, etc.)?
a) –proto
b) –protocol
c) –tcp
d) –udp
Answer: b) –protocol
Explanation: The –protocol option in iptables rules is used to specify the protocol (TCP, UDP, ICMP, etc.) to match.
43. What is the purpose of the state module in iptables?
a) To match packets based on their state
b) To match packets based on their source IP address
c) To match packets based on their destination IP address
d) To match packets based on their port numbers
Answer: a) To match packets based on their state
Explanation: The state module in iptables is used to match packets based on their connection state, such as NEW, ESTABLISHED, RELATED, or INVALID.
44. Which iptables command is used to save the current iptables rules to a file in UNIX?
a) iptables-save
b) iptables-export
c) iptables-backup
d) iptables -S
Answer: a) iptables-save
Explanation: The iptables-save command is used to save the current iptables rules to a file in UNIX.
45. What is the purpose of the DNAT target in iptables?
a) To perform Network Address Translation
b) To silently discard packets
c) To reject packets with an ICMP error message
d) To log packets and then drop them
Answer: a) To perform Network Address Translation
Explanation: The DNAT (Destination NAT) target in iptables is used to perform destination address translation for incoming packets.
46. Which iptables rule is used to specify the source IP address?
a) –source
b) –src
c) –saddr
d) –src-address
Answer: b) –src
Explanation: The –src option in iptables rules is used to specify the source IP address.
47. What is the purpose of the REDIRECT target in iptables?
a) To perform port redirection
b) To silently discard packets
c) To reject packets with an ICMP error message
d) To log packets and then drop them
Answer: a) To perform port redirection
Explanation: The REDIRECT target in iptables is used to redirect packets to a different port on the local system.
48. Which iptables command is used to delete all user-defined chains?
a) iptables-delete-chains
b) iptables -X
c) iptables -Z
d) iptables-clear-chains
Answer: b) iptables -X
Explanation: The iptables -X command is used to delete all user-defined chains in iptables.
49. What is the purpose of the –limit option in iptables rules?
a) To limit the number of packets matched per second
b) To limit the number of packets matched per minute
c) To limit the number of packets matched per hour
d) To limit the number of packets matched per day
Answer: a) To limit the number of packets matched per second
Explanation: The –limit option in iptables rules is used to limit the rate at which packets are matched.
50. Which command is used to display the current status of IPv4 packet forwarding in UNIX?
a) sysctl net.ipv4.ip_forward
b) cat /proc/sys/net/ipv4/ip_forward
c) ip_forward_status
d) show_ipv4_forwarding
Answer: b) cat /proc/sys/net/ipv4/ip_forward
Explanation: The cat /proc/sys/net/ipv4/ip_forward command is used to display the current status of IPv4 packet forwarding in UNIX.