Home > Common Problem > body text

How to set up linux firewall

小老鼠
Release: 2024-01-23 16:20:27
Original
1220 people have browsed it

Setting steps: 1. Open the firewall: First, make sure the firewall is turned on; 2. Add rules: Use the iptables command to add rules; 3. Save rules: After adding the rules, you need to save the rules , so that it will still take effect after the system is restarted; 4. Test the rules: After saving the rules, you can test whether the rules take effect; 5. Restart the firewall.

How to set up linux firewall

#In Linux systems, firewall settings usually involve the iptables tool. The following are some common firewall setting steps:

1. Turn on the firewall: First, you need to ensure that the firewall is turned on. You can use the following command to enable the firewall:

bash

sudo systemctl enable firewalld  
sudo systemctl start firewalld
Copy after login

2. Add rules: Use the iptables command to add rules. Here are some common rule examples:

Allow incoming TCP connections:

bash`sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT`
Copy after login

Allow incoming UDP connections:

bash`sudo iptables -A INPUT -p udp --dport 53 -j ACCEPT`
Copy after login

Deny all incoming connections:

bash`sudo iptables -A INPUT -j DROP`
Copy after login

Please note that the rules in the above examples are only examples and need to be modified according to specific needs when used in practice. Before adding rules, it is recommended to back up the current iptables configuration. You can use the following command to back up:

bash

sudo iptables-save > /path/to/backup.conf
Copy after login

3. Save the rules: After adding the rules, you need to save the rules so that they will still take effect after the system is restarted. You can use the following command to save the rules:

bash

sudo service iptables save
Copy after login

4. Test the rules: After saving the rules, you can test whether the rules are effective. You can use the following command to test:

bash

sudo iptables -L -n -v
Copy after login

This command will display the current iptables rule list, including added rules and related statistics. By checking the output, you can confirm that the rules were added correctly and took effect.

5. Restart the firewall: If you need to restart the firewall, you can use the following command:

bash

sudo systemctl restart firewalld
Copy after login

This will restart the firewall and load the new rule configuration. Please note that restarting the firewall will interrupt all current connections, so proceed with caution.

The above is the detailed content of How to set up linux firewall. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!