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.
#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
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`
Allow incoming UDP connections:
bash`sudo iptables -A INPUT -p udp --dport 53 -j ACCEPT`
Deny all incoming connections:
bash`sudo iptables -A INPUT -j DROP`
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
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
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
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
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!