I want iptables to filter only one interface, eth0, which is facing WAN. How can this be done? And I want to keep ftp and ssh ports open on eth0.
I want iptables to filter only one interface, eth0, which is facing WAN. How can this be done? And I want to keep ftp and ssh ports open on eth0.
So for all interfaces but one you want to accept all traffic, and on eth0 you want to drop all incoming traffic except ftp and ssh.
First, we could set a policy of accepting all traffic by default.
Then, we could reset your firewall rules.
Now we could say that we want to allow incoming traffic on eth0 that is a part of a connection we already allowed.
Also that we want to allow incoming ssh connections on eth0.
But that anything else incoming on eth0 should be dropped.
For slightly more depth see this CentOS wiki entry.
FTP is a trickier than ssh since it can use a random port, so see this previous question.
Something like this should do the job:
It is very simple when you make an
iptables
rule then you have to specify the interface. The option to specify the LAN card on whichiptables
should work is-i
Following rules can give you a good example
Last rule is to reject any other packet which does not match the first 2 rules. All rules in
iptables
are executed in the given order, so the rule to reject packets is always the last.The option to specify an interface in your iptables rule is
-i
, e.g.:-i eth0
.