Iptables Tutorial
Iptables Tutorial
In this iptables tutorial, we are going to work with one of the default
tables, called filter. It consists of three chains:
• INPUT – controls incoming packets to the server.
• OUTPUT – filter packets that are going out from your server.
1. Install Iptables
Iptables comes pre-installed in most Linux distributions. However,
if you don’t have it in Ubuntu/Debian system by default, follow the
steps below:
1. Connect to your server via SSH. If you don’t know, you can
read our SSH tutorial.
sudo iptables -L -v
Here, the -L option is used to list all the rules, and -v is for
showing the info in a more detailed format. Below is the
example output:
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
You will now have the Linux iptables firewall installed. At this point,
you can notice that all chains are set to ACCEPT and have no
rules. This is not secure since any packet can come through without
filtering.
Don’t worry. We’ll tell you how to define rules on the next step of
our iptables tutorial.
Filtering Packets Based on Source
Iptables allows you to filter packets based on an IP address or a
range of IP addresses. You need to specify it after the -s option.
For example, to accept packets from 192.168.1.3, the command
would be:
sudo iptables -A INPUT -s 192.168.1.3 -j ACCEPT
Alternatively, if you need to filter only the incoming traffic, you can
use Hostinger VPS Firewall. Select your VPS and navigate to
the Firewall section: