UNIX Question and Answer – Firewall Configuration
UNIX MCQ – Multiple Choice Questions for exam, interview, and Entrance Test
1. Which iptables command is used to block all incoming HTTP (port 80) traffic?
a) iptables -A INPUT -p tcp –dport 80 -j REJECT
b) iptables -A INPUT -p tcp –dport 80 -j DROP
c) iptables -A INPUT -p http -j REJECT
d) iptables -A INPUT -p http -j DROP
Answer: b) iptables -A INPUT -p tcp –dport 80 -j DROP
Explanation: This rule blocks all incoming HTTP traffic by dropping packets.
2. What is the purpose of the INPUT 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: a) To filter packets destined for the local system
Explanation: The INPUT chain in iptables is used to filter packets that are destined for the local system.
3. Which iptables rule is used to specify the source port range?
a) –sport-range
b) –source-port-range
c) –src-port-range
d) –sportrange
Answer: c) –src-port-range
Explanation: The `–src-port-range` option in iptables rules is used to specify the source port range.
4. 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.
5. Which iptables command is used to append a rule to the beginning of a specific chain?
a) iptables -I <chain>
b) iptables -P <chain>
c) iptables -B <chain>
d) iptables -N <chain>
Answer: a) iptables -I <chain>
Explanation: The `iptables -I <chain>` command is used to append a rule to the beginning of a specific chain in iptables.
6. 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.
7. Which iptables rule is used to specify the destination port range?
a) –dport-range
b) –destination-port-range
c) –dst-port-range
d) –dportrange
Answer: c) –dst-port-range
Explanation: The `–dst-port-range` option in iptables rules is used to specify the destination port range.
8. 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.
9. 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.
10. 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.
11. Which iptables rule is used to specify the source IP address?
a) –src
b) –source
c) –saddr
d) –src-address
Answer: c) –saddr
Explanation: The `–saddr` option in iptables rules is used to specify the source IP address.
12. 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.
13. 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.
14. 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.
15. 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.
16. 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.
17. Which iptables rule is used to specify the source IP address?
a) –src
b) –source
c) –saddr
d) –src-address
Answer: c) –saddr
Explanation: The `–saddr` option in iptables rules is used to specify the source IP address.
18. 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.
19. 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.
20. 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.
21. 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.
22. 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.
23. 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.
24. 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.
25. 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.
26. Which iptables command is used to block all incoming ICMP (ping) traffic?
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 ping -j REJECT
d) iptables -A INPUT -p ping -j DROP
Answer: b) iptables -A INPUT -p icmp –icmp-type echo-request -j DROP
Explanation: This rule blocks all incoming ICMP (ping) traffic by dropping packets.
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 destination port range?
a) –dport-range
b) –destination-port-range
c) –dst-port-range
d) –dportrange
Answer: c) –dst-port-range
Explanation: The `–dst-port-range` option in iptables rules is used to specify the destination port range.
29. 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.
30. Which iptables command is used to append a rule to the beginning of a specific chain?
a) iptables -I <chain>
b) iptables -P <chain>
c) iptables -B <chain>
d) iptables -N <chain>
Answer: a) iptables -I <chain>
Explanation: The `iptables -I <chain>` command is used to append a rule to the beginning of a specific chain in iptables.
31. 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.
32. Which iptables rule is used to specify the destination IP address?
a) –dst
b) –destination
c) –dstaddr
d) –daddr
Answer: b) –destination
Explanation: The `–destination` option in iptables rules is used to specify the destination IP address.
33. 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.
34. 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.
35. 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.
36. 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.
37. 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.
38. Which iptables rule is used to specify the source IP address?
a) –source
b) –src
c) –saddr
d) –src-address
Answer: c) –saddr
Explanation: The `–saddr` option in iptables rules is used to specify the source IP address.
39. 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.
40. 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.
41. 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.
42. 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.
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 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.
47. Which iptables command is used to block all incoming SSH (port 22) traffic?
a) iptables -A INPUT -p tcp –dport 22 -j REJECT
b) iptables -A INPUT -p tcp –dport 22 -j DROP
c) iptables -A INPUT -p ssh -j REJECT
d) iptables -A INPUT -p ssh -j DROP
Answer: b) iptables -A INPUT -p tcp –dport 22 -j DROP
Explanation: This rule blocks all incoming SSH traffic by dropping packets.
48. 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.
49. Which iptables rule is used to specify the source port?
a) –source-port
b) –src-port
c) –sport
d) –srcport
Answer: c) –sport
Explanation: The `–sport` option in iptables rules is used to specify the source port.
50. What is the purpose of the INPUT 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: a) To filter packets destined for the local system
Explanation: The INPUT chain in iptables is used to filter packets that are destined for the local system.