A Firewall is used to restrict network access. In it's simplest form it will block TCP and UDP ports based on number or protocol, but many modern firewalls include complex algorithms to block unusual traffic, detect possible network attacks and monitor or block traffic based on many other factors.
Wikipedia
In computing, a firewall is a network security system that monitors and controls incoming and outgoing network traffic based on predetermined security rules. A firewall typically establishes a barrier between a trusted network and an untrusted network, such as the Internet.