LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 12-02-2007, 07:44 AM   #1
spyxx7us
LQ Newbie
 
Registered: Jan 2006
Posts: 7

Rep: Reputation: 0
Help me with Iptables (simple)


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

Help me please!
Thanks very much!
 
Old 12-02-2007, 09:01 AM   #2
rupertwh
Member
 
Registered: Sep 2006
Location: Munich, Germany
Distribution: Debian / Ubuntu
Posts: 297

Rep: Reputation: 49
Hi,

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
 
Old 12-02-2007, 10:32 AM   #3
spyxx7us
LQ Newbie
 
Registered: Jan 2006
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by rupertwh View Post
Hi,

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?
 
Old 12-02-2007, 10:49 AM   #4
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
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
 
Old 12-02-2007, 06:53 PM   #5
ComputerHermit
LQ Newbie
 
Registered: Sep 2002
Location: ???
Distribution: RedHat7.2 Mandrake 8.0 Ubuntu 7.10 Mint 4.0
Posts: 10

Rep: Reputation: 0
I run iptables like this

http://computerwilltravel.webs.com/

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.
 
Old 12-03-2007, 02:10 AM   #6
spyxx7us
LQ Newbie
 
Registered: Jan 2006
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by win32sux View Post
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 also add this rule:

modprobe ip_conntrack_ftp

But it still doesn't work?
 
Old 12-03-2007, 02:19 AM   #7
rupertwh
Member
 
Registered: Sep 2006
Location: Munich, Germany
Distribution: Debian / Ubuntu
Posts: 297

Rep: Reputation: 49
Time to have a look at the rejected packages in your syslog...
 
Old 12-04-2007, 08:26 AM   #8
spyxx7us
LQ Newbie
 
Registered: Jan 2006
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by rupertwh View Post
Time to have a look at the rejected packages in your syslog...
I don't know how to write iptables to syslog
Rupertwh, please show me the way!
Thanks!
 
Old 12-04-2007, 08:26 AM   #9
spyxx7us
LQ Newbie
 
Registered: Jan 2006
Posts: 7

Original Poster
Rep: Reputation: 0
I use ProFTPD Version 1.3.0a

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

!!!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple iptables quesiton cbidwell Linux - Security 4 02-18-2007 04:24 AM
(Un)simple iptables question branden_burger Linux - Security 3 11-19-2006 03:25 PM
Simple iptables question deleted/ Linux - Security 4 05-11-2006 11:31 AM
Simple IPTABLES problem zahoo Linux - Networking 2 03-09-2005 09:43 PM
simple Iptables line enrique_arong Linux - Networking 1 06-09-2004 07:14 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 11:27 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration