LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 07-15-2013, 02:33 PM   #1
psycroptic
Member
 
Registered: Aug 2011
Location: USA
Distribution: ArchLinux - 3.0 kernel
Posts: 349

Rep: Reputation: Disabled
making a simple iptables firewall for internal server, just looking for tips (and allowing ftp)


i've got a mail server behind a router with ports 25,465,587 & 993 open externally. i've decided to make a simple firewall that closes off everything, then opens up these ports plus 22 for ssh and ping from the local network.

/etc/iptables/iptables.rules
Code:
*filter
:INPUT DROP [0:0]
-A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -s 172.16.0.0/16 -j ACCEPT
-A INPUT -p tcp --dport 22 -j ACCEPT
-A INPUT -p tcp --dport 25 -j ACCEPT
-A INPUT -p tcp --dport 465 -j ACCEPT
-A INPUT -p tcp --dport 587 -j ACCEPT
-A INPUT -p tcp --dport 993 -j ACCEPT
COMMIT
anything else that might be pertinent to add? not sure if FORWARD needs anything added there

Last edited by psycroptic; 07-16-2013 at 02:32 PM.
 
Old 07-15-2013, 03:09 PM   #2
mosiac
Member
 
Registered: Jan 2013
Distribution: RHEL
Posts: 54
Blog Entries: 1

Rep: Reputation: 4
I'm not too familiar with iptables but you can group all the ports if you like, but I think it looks cleaner the way you have it.
 
Old 07-15-2013, 06:37 PM   #3
dkm999
Member
 
Registered: Nov 2006
Location: Seattle, WA
Distribution: Fedora
Posts: 407

Rep: Reputation: 35
If the mail server is the only service running on this machine, you probably have all you need, except possibly a rule to prevent forwarding
Code:
:FORWARD DROP [0:0]
Other common services that you might want to have universally accessible are DNS (UDP port 53), and maybe HTTPD (port 80 and maybe 443 [SSL]).
 
1 members found this post helpful.
Old 07-15-2013, 08:51 PM   #4
psycroptic
Member
 
Registered: Aug 2011
Location: USA
Distribution: ArchLinux - 3.0 kernel
Posts: 349

Original Poster
Rep: Reputation: Disabled
good stuff. i've been trying to work out getting active FTP through iptables as the next thing.
 
Old 07-15-2013, 09:53 PM   #5
dkm999
Member
 
Registered: Nov 2006
Location: Seattle, WA
Distribution: Fedora
Posts: 407

Rep: Reputation: 35
It looks like this is a common problem: you only need to add these rules:
Code:
-A INPUT -p TCP -dport 21 -j ACCEPT
-A INPUT -p TCP -m helper --helper ftp -j ACCEPT
The phrase -m helper --helper ftp takes care of the fact that FTP uses two destination ports (21 & 20), and lets both through your firewall.
 
Old 07-15-2013, 10:20 PM   #6
psycroptic
Member
 
Registered: Aug 2011
Location: USA
Distribution: ArchLinux - 3.0 kernel
Posts: 349

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by dkm999 View Post
It looks like this is a common problem: you only need to add these rules:
Code:
-A INPUT -p TCP -dport 21 -j ACCEPT
-A INPUT -p TCP -m helper --helper ftp -j ACCEPT
The phrase -m helper --helper ftp takes care of the fact that FTP uses two destination ports (21 & 20), and lets both through your firewall.
yeah i added those, i still can't access the FTP server. even worse, Proftpd (the server i'm using) logs a successful login/chdir from my own machine, even though i definitely CANNOT access ftp with iptables running....
 
Old 07-15-2013, 10:27 PM   #7
dkm999
Member
 
Registered: Nov 2006
Location: Seattle, WA
Distribution: Fedora
Posts: 407

Rep: Reputation: 35
If Proftpd logs the connection and chdir, then the problem is not with the first iptables rule, at least (port 21). Those operations all occur over port 21, the control port. The problem may be elsewhere. Are you getting any packets counted on the second rule (-m helper --helper ftp)? You can see how many packets matched this rule using the command
Code:
iptables -nvL
.
 
Old 07-15-2013, 10:31 PM   #8
psycroptic
Member
 
Registered: Aug 2011
Location: USA
Distribution: ArchLinux - 3.0 kernel
Posts: 349

Original Poster
Rep: Reputation: Disabled
Actually, I hadn't loaded the "ip_conntrack_ftp" kernel module, which (apparently) is both necessary and not always loaded. Doing that enabled access.

Thanks for the help.
 
1 members found this post helpful.
  


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
iptables simple firewall rng Linux - Networking 11 08-13-2011 02:23 AM
[SOLVED] Need Help on Simple IPTables Router/Firewall dmlinton Linux - Networking 2 09-11-2010 10:00 AM
Problem with iptables firewall - can't ping machines on internal network ukstu Linux - Networking 2 11-26-2007 06:36 AM
Working IPTABLES STRONG firewall for TWO internal networks kennedy01 Linux - Wireless Networking 3 08-24-2004 11:10 PM
Simple IPTables... Want to pass all data from one external IP to an internal IP AdamRankin Linux - Networking 3 04-01-2003 03:24 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 10:59 PM.

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