A properly configured firewall will protect against attacks by intruders and by robots. The principle firewall for all Linux machines is "Netfilter" and the principle tool used for configuring that firewall is "iptables".
These documents describe the use of Iptables for configuring Netfiler.