Some Insight into Effective Firewall Scripting

I would like a brief technical description of what firewall is. How was this software developed? How does this software function to ward off imminent attack? Could you also elaborate on how to write firewall scripts to enhance my system security? How do I get started and what protocols do I need to follow?
