Linux/CentOS to open the firewall

  
        

Use the following command:

#/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT

#/sbin/iptables -I INPUT -p tcp -- Dport 22 -j ACCEPT

#/etc/rc.d/init.d/iptables save

After restarting the computer, the firewall has opened ports 80 and 22 by default.

Temporarily turn off the firewall completely, you can not restart the machine:

#/etc/init.d/iptables status ##View Firewall Status

#/etc/init .d/iptable stop ## Turn off the firewall this time

#/etc/init.d/iptable restart ## Restart the firewall

Permanently turn off the firewall:

#chkconfig --level 35 iptables off (note that there are two British short lines in the middle; reboot)

Attachment:

The method for setting the firewall open port is as follows:

vi /Etc/sysconfig/iptables

Note that it is best to leave the management ports of VNC and SSH when modifying the firewall.

Here is an example of an iptables:

# Firewall configuration written by system-config-securitylevel

# Manual customization of this file is not recommended.*filter

:INPUT ACCEPT [0:0]

:FORWARD ACCEPT [0:0]

:OUTPUT ACCEPT [0:0]

:RH-Firewall- 1-INPUT - [0:0]

-A INPUT -j RH-Firewall-1-INPUT

-A FORWARD -j RH-Firewall-1-INPUT

-A RH-Firewall-1-INPUT -i lo -j ACCEPT

-A RH-Firewall-1-INPUT -p icmp –icmp-type any -j ACCEPT

- A RH-Firewall-1-INPUT -p 50 -j ACCEPT

-A RH-Firewall-1-INPUT -p 51 -j ACCEPT

-A RH-Firewall-1-INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT

-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 53 -j ACCEPT

-A RH-Firewall-1-INPUT -m state –state NEW -m udp -p udp –dport 53 -j ACCEPT

-A RH-Firewall-1-INPUT -m State –state NEW -m tcp -p tcp –dport 22 -j ACCEPT

-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 25 -j ACCEPT

-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT

-A RH-Firewall- 1-INPUT -m state –state NEW -m tcp -p tcp –dport 443 -j ACCEPT

-A RH-Firewall-1-INPUT -j REJECT –reject-with icmp-host- Prohibited

COMMIT

To modify this file according to your needs, for example, if you do not want to open port 80 to provide web services, you should delete this line accordingly:

-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT

Restart iptables after all modifications:

service iptables restart

You can verify that the rules are in effect: iptables -L

This completes the CentOS firewall settings modification.

Copyright © Windows knowledge All Rights Reserved