#1, set the default target for the INPUT,FORWARD,OUTPUT chain DROP, or external cannot communicate with the server.
#2, set when the connection is RELATED and when ESTABLISHED, allowing data access server.
#3, set up an external client connects to the server port 80,22,21,873.
#4, allowing internal data through the back.
#5, allow external ping servers.
#6, set the status as RELATED and ESTABLISHED data sent from the server to the external.
#7, allowing the use external DNS servers to resolve domain names.
#8, set the server to connect to an external server on port 80.
#9, allow the server to send mail.
#10, allowed from outside the server ping

This disables all ports except SSH, http, and FTP, outer, of course we could use other ports for management, for example, we used PureFTPd in lnmp to manage FTP, so the first thing we need to edit the following/etc/proftpd.conf, configure the following:

PassivePorts 25000-26000 # (port number may choose)

And then also need to add a line in the code above:

$ TCP dport – 25,000:26,000 – ACCEPT # the 25000-26000 and the port number must be added for you

While some people may be using a VNC, then continue to add line:

$ TCP-dport 5901-ACCEPT#5901 into your VNC port

After all of the ports are configured, save the script as iptables.sh, uploaded to the VPS, Executive sh iptables.sh can automatically configure the firewall.

In this way, we find laws, other port you can choose according to their needs and open and then re-execute the script ~