Home  >  Article  >  Computer Tutorials  >  Detailed tutorial on Linux firewall configuration (iptables and firewalld).

Detailed tutorial on Linux firewall configuration (iptables and firewalld).

WBOY
WBOYforward
2024-02-19 12:36:02668browse

Linux 防火墙配置(iptables和firewalld)详细教程。

The following is a brief Linux firewall configuration tutorial, covering two commonly used firewall tools: iptables and firewalld.

iptables is one of the most commonly used firewall tools on Linux, and firewalld is the default firewall management tool used in CentOS 7 and its derivatives.

iptables firewall configuration:

  1. View current firewall rules:

    iptables -L -n
  2. Clear the current firewall rules:

    iptables -F
  3. Allow inbound connections on specific ports:

    iptables -A INPUT -p <协议> --dport <端口号> -j ACCEPT

    For example, allow port 80 of TCP protocol:

    iptables -A INPUT -p tcp --dport 80 -j ACCEPT
  4. Allow inbound connections for specific IP address ranges:

    iptables -A INPUT -s <IP地址/子网掩码> -j ACCEPT

    For example, to allow connections from the 192.168.0.0/24 subnet:

    iptables -A INPUT -s 192.168.0.0/24 -j ACCEPT
  5. Block all inbound connections:

    iptables -P INPUT DROP
  6. Save configuration:

    service iptables save

firewalld firewall configuration:

  1. View current firewall rules:

    firewall-cmd --list-all
  2. Allow inbound connections on specific ports:

    firewall-cmd --zone=public --add-port=<端口号>/tcp --permanent

    For example, allow port 80 of TCP protocol:

    firewall-cmd --zone=public --add-port=80/tcp --permanent
  3. Allow inbound connections for specific IP address ranges:

    firewall-cmd --zone=public --add-source=<IP地址/子网掩码> --permanent

    For example, to allow connections from the 192.168.0.0/24 subnet:

    firewall-cmd --zone=public --add-source=192.168.0.0/24 --permanent
  4. Block all inbound connections:

    firewall-cmd --zone=public --set-default=drop
  5. Reload firewall configuration:

    firewall-cmd --reload

The above are just some common iptables and firewalld command examples, you can modify and extend them according to your own needs. Please note that you must be careful when configuring your firewall to ensure it is not blocking the legitimate traffic you need, and be sure to save and load the configuration for it to take effect. In addition, it is recommended to back up existing firewall rules before configuring the firewall to prevent unexpected situations.

The above is the detailed content of Detailed tutorial on Linux firewall configuration (iptables and firewalld).. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:mryunwei.com. If there is any infringement, please contact admin@php.cn delete
Previous article:How to open ExplorerNext article:How to open Explorer