1. Use the setup command
[1] Open a terminal window and enter the setup command
[[email protected] ~]# setup
[2] Select firewall configuration and run tool to go to the firewall configuration page.
[3] select Enabled to enable the firewall. If this option is not selected, enable it. Select customize for custom configuration.
[4] select the service port to be opened. In this example, select FTP and WWW (HTTP ). By default, the SSH service port is enabled for SSH remote login. If you configure a Linux server remotely, you must keep the SSH service port open and do not disconnect the path.
[5] After the configuration is completed, you can forward it to the end and save it. If there are other ports to be opened, there will also be a custom page in the middle. At the end of the page, select YES to overwrite the original settings and save the settings.
2. Command Line
[1] edit the firewall configuration. Port 21 and port 80 are the added FTP service and port 80.
[[email protected] ~]# vi /etc/sysconfig/iptables# Firewall configuration written by system-config-firewall# Manual customization of this file is not recommended.*filter:INPUT ACCEPT [0:0]:FORWARD ACCEPT [0:0]:OUTPUT ACCEPT [0:0]-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT-A INPUT -p icmp -j ACCEPT-A INPUT -i lo -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT-A INPUT -j REJECT --reject-with icmp-host-prohibited-A FORWARD -j REJECT --reject-with icmp-host-prohibitedCOMMIT
[2] disable the Firewall Service (temporarily disable the Firewall Service. The Service will be automatically enabled after restart)
[[email protected] ~]# service iptables stopiptables: Flushing firewall rules: [ OK ]iptables: Setting chains to policy ACCEPT: filter [ OK ]iptables: Unloading modules: [ OK ]
[3] configuring the Firewall Service does not start up by default (if the server does not need a firewall)
[[email protected] ~]# chkconfig iptables off
Centos Firewall Configuration