logo

    Exploring Firewall-cmd: How to View and Analyze Your List of Firewall Rules

    skycentral.co.uk | Exploring Firewall-cmd: How to View and Analyze Your List of Firewall Rules

    Exploring Firewall-cmd: How to View and Analyze Your List of Firewall Rules

    Firewall rules are an essential part of securing your system and network. They act as a barrier between your computer and potential threats, controlling incoming and outgoing network traffic. In a Linux system, the firewall rules can be managed using firewall-cmd, a command-line tool. This article will guide you through the process of viewing and analyzing your list of firewall rules using firewall-cmd.

    Understanding Firewall-cmd

    Firewall-cmd is a command-line utility that provides a convenient interface for managing your firewall rules in a Linux system using the firewalld service. Firewalld is a dynamically managed firewall solution that enables administrators to dynamically adjust firewall rules without disrupting the connections. The firewall-cmd utility interacts with firewalld to modify the firewall settings, including adding, removing, and updating firewall rules.

    Viewing the List of Firewall Zones

    Firewalld organizes firewall rules into different zones, where each zone has a unique set of rules. Before analyzing the individual firewall rules, it is necessary to understand the different zones and their rules. To view the list of available zones in your system, you can use the following command:

    firewall-cmd --get-zones

    This command will display a list of zones available in your system, which can include default zones like ‘public’, ‘internal’, ‘external’, etc. Each zone has its own set of predefined rules and defaults.

    Listing the Active Zones

    Now that you know the available zones in your system, you can view the active zones using the following command:

    firewall-cmd --get-active-zones

    This command will display the active zones on various network interfaces along with their respective firewall rules. The output will include information such as the interface name, corresponding zone, and associated services.

    Enumerating All Firewall Rules

    To get a detailed list of all the firewall rules across all zones, you can use the command:

    firewall-cmd --list-all

    This command provides a comprehensive view of the firewall rules, including rules specific to each zone. The output will include information about the configured services, ports, sources, and target actions for each rule.

    Examining Zone-Specific Firewall Rules

    If you want to focus on the rules of a specific zone, you can use the --zone option along with the desired zone name. For example, to list the rules of the ‘public’ zone, use the command:

    firewall-cmd --zone=public --list-all

    This will display only the rules corresponding to the ‘public’ zone. This can be particularly useful when analyzing specific areas of your firewall configuration.

    Filtering Firewall Rules

    Firewall-cmd also provides options to filter the displayed rules based on specific criteria. This can be useful when dealing with a large number of rules and when searching for specific conditions. You can use the following options to filter the output:

    • --service : Filter the rules based on the associated service.
    • --port : Filter the rules based on the associated port.
    • --source : Filter the rules based on the source IP address or network.
    • --destination : Filter the rules based on the destination IP address or network.
    • --protocol : Filter the rules based on the protocol.

    For example, to list only the rules that allow SSH connections, you can use the command:

    firewall-cmd --zone=public --list-all --service=ssh

    This will display only the rules from the ‘public’ zone that allow SSH access.

    Analyzing Firewall Rules with Extended Information

    By default, the --list-all command provides a summarized view of the firewall rules. However, if you need more detailed information, firewall-cmd also provides options to display extended details.

    To view the rules with extended information, use the following command:

    firewall-cmd --zone=public --list-all --verbose

    This command will include additional details such as the associated zones, interfaces, services, and forwarding options. It can help you understand the full context of your firewall configuration.

    Understanding Rule Directives

    Each firewall rule consists of multiple directives that define its behavior. Understanding these directives is essential for examining and modifying firewall rules.

    Some commonly used directives include:

    • --add-service : Add a service to the zone.
    • --remove-service : Remove a service from the zone.
    • --add-port : Add a port to the zone.
    • --remove-port : Remove a port from the zone.
    • --add-source : Add a source IP address or network.
    • --remove-source : Remove a source IP address or network.

    These directives allow you to modify firewall rules according to your requirements.

    Modifying Firewall Rules

    Firewall-cmd also enables you to modify firewall rules dynamically. For example, to add a new service to a specific zone, you can use the following command:

    firewall-cmd --zone=public --add-service=http

    This command adds the HTTP service to the ‘public’ zone, allowing incoming connections on port 80.

    Similarly, you can use the directives mentioned earlier to add or remove ports, services, or sources.

    Conclusion

    In this article, you’ve explored how to view and analyze your list of firewall rules using firewall-cmd. Understanding the different zones, filtering options, and rule directives provided by firewall-cmd can help you effectively manage and secure your system and network. By utilizing these techniques, you can have better control over your firewall configuration and ensure the safety of your system and data.