Linux - SecurityThis forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have problem with iptables
My PC installed Linux AS4, allow service SSH and FTP through both Eth0 and Eth1 nics
But I want "Allow access FTP only through Eth1 Nic, not allow with Eth0"
I have this config of iptables:
#iptables -A INPUT -i lo -j ACCEPT
#iptables -A INPUT -p tcp --dport 22 -j ACCEPT
#iptables -A INPUT -i eth1 -p tcp --dport 21 -j ACCEPT
#iptables -A INPUT -i eth0 -p tcp --dport 21 -j DROP
#iptables -A INPUT -j DROP
(Before run these commands, i excuted #iptables -F, to delete all old rules)
But after run these commands, i can not access FTP through both Eth0 and Eth1
first thing you probably want to do is add a LOG rule right before the DROP, so you don't have to fly blind:
Code:
iptables -A INPUT -j LOG --log-prefix "Connection attempt: "
Now to your problem: You need a rule to allow ESTABLISHED and RELATED traffic. This will do several good things:
1. Most likely solve your ftp problem (ftp uses separate data/control ports).
2. Allow responses to and thus enable outgoing traffic.
3. Allow relevant and needed ICMP traffic.
Code:
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
Also, in order to be a nice citizen (and make your own troubleshooting easier) you should allow to be pinged:
Code:
iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
Putting it all together gives you a solid base for your incoming firewall:
Code:
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -i eth1 -p tcp --dport 21 -j ACCEPT
# don't need this, will be dropped anyway:
# iptables -A INPUT -i eth0 -p tcp --dport 21 -j DROP
iptables -A INPUT -j LOG --log-prefix "Connection attempt: "
iptables -A INPUT -j DROP
first thing you probably want to do is add a LOG rule right before the DROP, so you don't have to fly blind:
Code:
iptables -A INPUT -j LOG --log-prefix "Connection attempt: "
Now to your problem: You need a rule to allow ESTABLISHED and RELATED traffic. This will do several good things:
1. Most likely solve your ftp problem (ftp uses separate data/control ports).
2. Allow responses to and thus enable outgoing traffic.
3. Allow relevant and needed ICMP traffic.
Code:
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
Also, in order to be a nice citizen (and make your own troubleshooting easier) you should allow to be pinged:
Code:
iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
Putting it all together gives you a solid base for your incoming firewall:
Code:
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -i eth1 -p tcp --dport 21 -j ACCEPT
# don't need this, will be dropped anyway:
# iptables -A INPUT -i eth0 -p tcp --dport 21 -j DROP
iptables -A INPUT -j LOG --log-prefix "Connection attempt: "
iptables -A INPUT -j DROP
I run "iptables -F" then I excuted your code, but FTP still not works !
(if I stop iptables with "iptables -F", FTP works well)
What should i do?
With rules for port 21 and for RELATED,ESTABLISHED packets, the only thing I can think of that could be wrong is that you are missing the FTP conntrack helper module. See if loadiing it fixes your problem:
I will remove the link if ya like that is my sight I'm thinking of paying for the domain name the sight is not done!Comments and suggestions are welcome Hope it helps
Last edited by ComputerHermit; 12-02-2007 at 07:01 PM.
With rules for port 21 and for RELATED,ESTABLISHED packets, the only thing I can think of that could be wrong is that you are missing the FTP conntrack helper module. See if loadiing it fixes your problem:
Code:
modprobe ip_conntrack_ftp
I tried with following rules, but problem is still, can't access FTP on both Eth0 and Eth1:
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -i eth1 -p tcp --dport 21 -j ACCEPT
iptables -A INPUT -j LOG --log-prefix "Connection attempt: "
iptables -A INPUT -j DROP
I open more port 20
And i try 2 type of iptable config, but in the result, both types are not OK:
First type, allow FTP on eth0, Deny on eth1, but in the result, i still access FPT in both 2 NIC
/sbin/iptables -A INPUT -i lo -j ACCEPT
/sbin/iptables -A INPUT -p tcp --dport 22 -j ACCEPT
/sbin/iptables -A INPUT -i eth0 -p tcp --dport 21 -j ACCEPT
/sbin/iptables -A INPUT -i eth0 -p tcp --dport 20 -j ACCEPT
/sbin/iptables -A INPUT -i eth1 -p tcp --dport 21 -j DROP
/sbin/iptables -A INPUT -i eth1 -p tcp --dport 20 -j DROP
/sbin/iptables -A INPUT -j DROP
Second type, allow FTP on eth1, Deny on eth0, but in the result, i can NOT access FPT in both 2 NIC:
/sbin/iptables -A INPUT -i lo -j ACCEPT
/sbin/iptables -A INPUT -p tcp --dport 22 -j ACCEPT
/sbin/iptables -A INPUT -i eth0 -p tcp --dport 21 -j DROP
/sbin/iptables -A INPUT -i eth0 -p tcp --dport 20 -j DROP
/sbin/iptables -A INPUT -i eth1 -p tcp --dport 21 -j ACCEPT
/sbin/iptables -A INPUT -i eth1 -p tcp --dport 20 -j ACCEPT
/sbin/iptables -A INPUT -j DROP
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.