Welcome to Linux Forums! With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.
Find the answer to your Linux question:
New to Linux Forums? Register here for free!
    Linux Forums > Your Distro > Redhat / Fedora Linux Help > IPtables

Forgot Password?
 Redhat / Fedora Linux Help   Help and discussion related to Redhat and Fedora Linux.

Site Navigation
Linux Articles
Linux Forums
Linux Downloads
Linux Hosting
Free Magazines
Job Board
IRC Chat
RSS Feeds


Linux Forum Topics
Linux Forums
Your Distro
Linux Resources
GNU Linux Zone
The Community
Reply
 
Thread Tools Display Modes
Old 2 Weeks Ago   #1 (permalink)
Just Joined!
 
Join Date: Oct 2007
Posts: 19
IPtables

I am using the following iptables config on a fedora 11 server that is behind a Cisco firewall. I am having issues getting both an ftp client as well as command line to list the directory contents.

As soon as I take off iptables, I can connect and list using a passive FTP client, but still not with a command line active ftp list.

If I take out the Cisco firewall (connect from the LAN) I can get both to work with the iptables settings I have.

Can someone please help me to figure this out?

iptables config:
Code:
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

-A INPUT -p tcp -s 0/0 --sport 1024:65535  --dport 21 -m state --state NEW,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -s 0/0 --sport 1024:65535  --dport 20 -m state --state ESTABLISHED -j ACCEPT
-A OUTPUT -p tcp  --sport 21 -d 0/0 --dport 1024:65535 -m state --state ESTABLISHED -j ACCEPT
-A INPUT -p tcp -s 0/0 --sport 1024:65535 --dport 1024:65535 -m state --state ESTABLISHED,RELATED -j ACCEPT
-A OUTPUT -p tcp --sport 1024:65535 -d 0/0 --dport 1024:65535 -m state --state ESTABLISHED -j ACCEPT
-A OUTPUT -p tcp --sport 20 -d 0/0 --dport 1024:65535 -m state --state ESTABLISHED,RELATED -j ACCEPT

-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
Cisco:
Code:
access-list all_in extended permit tcp any host 98.76.54.32 eq 4422
access-list all_in extended permit tcp any host 98.76.54.32 eq 2121
static (inside,outside) tcp 98.76.54.32 citrix-ica 192.168.5.103 citrix-ica netmask 255.255.255.255
static (inside,outside) tcp 98.76.54.32 3389 192.168.5.103 3389 netmask 255.255.255.255
static (inside,outside) tcp 98.76.54.32 smtp 192.168.5.83 smtp netmask 255.255.255.255
static (inside,outside) tcp 98.76.54.32 www 123.45.67.89 www netmask 255.255.255.255
static (inside,outside) tcp 98.76.54.32 4422 123.45.67.89 ssh netmask 255.255.255.255
static (inside,outside) tcp 98.76.54.32 2121 123.45.67.89 ftp netmask 255.255.255.255
One other note. If I add the NEW state to the input as shown below, it will also work for the FTP client passive connection from the WAN. Still no luck on the active though.
Code:
-A INPUT -p tcp -s 0/0 --sport 1024:65535 --dport 1024:65535 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
FawnOfFeist is offline  


Reply With Quote
Old 2 Weeks Ago   #2 (permalink)
Linux Engineer
 
Lazydog's Avatar
 
Join Date: Jun 2004
Location: The Key Stone State
Posts: 1,187
Quote:
Originally Posted by FawnOfFeist View Post
I am using the following iptables config on a fedora 11 server that is behind a Cisco firewall. I am having issues getting both an ftp client as well as command line to list the directory contents.

As soon as I take off iptables, I can connect and list using a passive FTP client, but still not with a command line active ftp list.

If I take out the Cisco firewall (connect from the LAN) I can get both to work with the iptables settings I have.

Can someone please help me to figure this out?
I'll try.

Quote:
iptables config:
Code:
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

-A INPUT -p tcp -s 0/0 --sport 1024:65535  --dport 21 -m state --state NEW,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -s 0/0 --sport 1024:65535  --dport 20 -m state --state ESTABLISHED -j ACCEPT
-A OUTPUT -p tcp  --sport 21 -d 0/0 --dport 1024:65535 -m state --state ESTABLISHED -j ACCEPT
-A INPUT -p tcp -s 0/0 --sport 1024:65535 --dport 1024:65535 -m state --state ESTABLISHED,RELATED -j ACCEPT
-A OUTPUT -p tcp --sport 1024:65535 -d 0/0 --dport 1024:65535 -m state --state ESTABLISHED -j ACCEPT
-A OUTPUT -p tcp --sport 20 -d 0/0 --dport 1024:65535 -m state --state ESTABLISHED,RELATED -j ACCEPT

-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
Try this firewall it is a lot cleaner.
Code:
*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT DROP [0:0]
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -p tcp --dport 21 -m state --state NEW -j ACCEPT
-A INPUT -p tcp --dport 22 -m state --state NEW -j ACCEPT
-A INPUT -p tcp --dport 80 -m state --state NEW -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A OUTPUT -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
You don't need all the rubbish you have in your rules as it really doesn't help anything and is more confusing then anything.

Quote:
Cisco:
Code:
access-list all_in extended permit tcp any host 98.76.54.32 eq 4422
access-list all_in extended permit tcp any host 98.76.54.32 eq 2121
static (inside,outside) tcp 98.76.54.32 citrix-ica 192.168.5.103 citrix-ica netmask 255.255.255.255
static (inside,outside) tcp 98.76.54.32 3389 192.168.5.103 3389 netmask 255.255.255.255
static (inside,outside) tcp 98.76.54.32 smtp 192.168.5.83 smtp netmask 255.255.255.255
static (inside,outside) tcp 98.76.54.32 www 123.45.67.89 www netmask 255.255.255.255
static (inside,outside) tcp 98.76.54.32 4422 123.45.67.89 ssh netmask 255.255.255.255
static (inside,outside) tcp 98.76.54.32 2121 123.45.67.89 ftp netmask 255.255.255.255
OK, what is 4422 and 2121 used for? are these the ports that you want to connect ssh and ftp through? If so then you need to change your rules in iptables to use the same ports or you are going to have to REDIRECT them on the system to the correct ports.

One more thing you should do is activate ftp tracking to track Active and Passive connections. This can be done by editing iptables-config and change
Code:
IPTABLES_MODULES=""
to include
Code:
IPTABLES_MODULES="ip_conntrack_ftp"
Or placing the following is a script that you run
Code:
/sbin/modprobe ip_conntrack_ftp
Here is a TUTORIAL for IPTABLES you can read
__________________

Regards
Robert

Linux
The adventure of a life time.

Linux User #296285
Get Counted
Lazydog is offline   Reply With Quote
Old 2 Weeks Ago   #3 (permalink)
Just Joined!
 
Join Date: Oct 2007
Posts: 19
Thanks for the reply!

Tried the new iptables. Much cleaner for sure. Still though it does not connect externally without this one line. It is working now without the NEW state though, which is one thing I was looking for. I'm sure that it might be able to be cleaner
Code:
-A INPUT -p tcp -s 0/0 --sport 1024:65535 --dport 1024:65535 -m state --state ESTABLISHED,RELATED -j ACCEPT
Yes, we are using 4422 that has a PAT to port 22 on the inside of the Cisco. Same with 2121 PAT to port 21 on the inside.

Do I need to change the iptables entry if the Cisco router does the port address trans?

I also added the iptables-config entry
Code:
IPTABLES_MODULES="ip_conntrack_ftp"
FawnOfFeist is offline   Reply With Quote
Old 2 Weeks Ago   #4 (permalink)
Just Joined!
 
Join Date: Oct 2007
Posts: 19
Well, as stated above this is now working without the NEW state for the 1024 and up ports.

Active apparently is not going to function properly unless we have a 1-1 NAT, so I am really not too concerned about it.

If anyone else has any other suggestions they are welcome.
FawnOfFeist is offline   Reply With Quote
Old 2 Weeks Ago   #5 (permalink)
Linux Engineer
 
Lazydog's Avatar
 
Join Date: Jun 2004
Location: The Key Stone State
Posts: 1,187
Quote:
Originally Posted by FawnOfFeist View Post
Thanks for the reply!

Tried the new iptables. Much cleaner for sure. Still though it does not connect externally without this one line. It is working now without the NEW state though, which is one thing I was looking for. I'm sure that it might be able to be cleaner
Code:
-A INPUT -p tcp -s 0/0 --sport 1024:65535 --dport 1024:65535 -m state --state ESTABLISHED,RELATED -j ACCEPT
What is not working and what port are you connecting to on the server?

Quote:
Yes, we are using 4422 that has a PAT to port 22 on the inside of the Cisco. Same with 2121 PAT to port 21 on the inside.

Do I need to change the iptables entry if the Cisco router does the port address trans?
No, you should not have to.

Quote:
I also added the iptables-config entry
Code:
IPTABLES_MODULES="ip_conntrack_ftp"
OK, don't forget to modprobe it as it needs to get loaded. The above will only load ity when iptables is restarted.
__________________

Regards
Robert

Linux
The adventure of a life time.

Linux User #296285
Get Counted
Lazydog is offline   Reply With Quote
Old 2 Weeks Ago   #6 (permalink)
Just Joined!
 
Join Date: Oct 2007
Posts: 19
Quote:
Originally Posted by Lazydog View Post
What is not working and what port are you connecting to on the server?
It works to connect to port 2121 for ftp, and it logs in fine. When I try to do a list in passive mode, it hangs and then fails. With the line below in, it works.
Code:
-A INPUT -p tcp -s 0/0 --sport 1024:65535 --dport 1024:65535 -m state --state ESTABLISHED,RELATED -j ACCEPT
Quote:
Originally Posted by Lazydog View Post
No, you should not have to.
Indeed.
Quote:
Originally Posted by Lazydog View Post
OK, don't forget to modprobe it as it needs to get loaded. The above will only load ity when iptables is restarted.
I have restarted it a lot trying to get this to work properly.
FawnOfFeist is offline   Reply With Quote
Old 2 Weeks Ago   #7 (permalink)
Linux Engineer
 
Lazydog's Avatar
 
Join Date: Jun 2004
Location: The Key Stone State
Posts: 1,187
Quote:
Originally Posted by FawnOfFeist View Post
It works to connect to port 2121 for ftp, and it logs in fine. When I try to do a list in passive mode, it hangs and then fails. With the line below in, it works.
Code:
-A INPUT -p tcp -s 0/0 --sport 1024:65535 --dport 1024:65535 -m state --state ESTABLISHED,RELATED -j ACCEPT
Not understanding why you need this one. This line applies to already built connections and the line this line should work;
Code:
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
Your line looks at protocol and ports where mine doesn't care. If yours is working then my line should be working also.

There is something else here from your end that is not being told.
__________________

Regards
Robert

Linux
The adventure of a life time.

Linux User #296285
Get Counted
Lazydog is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Free Magazines
Run Your Own Web Server Using Linux & Apache - Free 191 Page Preview
Learn about everything you'll need to build and maintain your Linux servers, and to deploy Web applications to them.
subscribe
Open Source Security Myths Dispelled
Dispel the five major myths surrounding Open Source Security and gain the tools necessary to make a truly informed decision for your IT organization
subscribe
InformationWeek
InformationWeek is the only newsweekly you'll need to stay on top of the latest developments in information technology.
subscribe



All times are GMT. The time now is 05:50 PM.






© 2000 - 2009 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.3.0 RC2