This is where IP tables come in handy. Iptables is a Linux command line firewall that allows administrators to manage incoming and outgoing traffic via a set of configurable table rules.
Iptables uses a set of tables which have chains that contain set of built-in or user-defined rules
IP tables is a command-line firewall utility that uses policy chains to allow or block traffic. When a connection tries to establish itself on your system, IP tables looks for a rule in its list to match it to. If it doesn’t find one, it resorts to the default action.