LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 08-23-2016, 01:03 AM   #1
gly
LQ Newbie
 
Registered: Mar 2016
Posts: 24

Rep: Reputation: Disabled
iptables allow ftp only from a specific IP


hello,
hosting a server where all connections are permitted and only ftp(active,passive, file transfer) and ping(icmp) is permitted from a specific host. Kindly suggest the commands for configuration of the required iptables policy.
 
Old 08-23-2016, 03:01 AM   #2
sunnysthakur
Member
 
Registered: Aug 2012
Posts: 92

Rep: Reputation: Disabled
Try the below rule. It should work.

iptables -A INPUT -p tcp --dport 21 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 20 -j ACCEPT
-A INPUT -s 0.0.0.0/0 -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT
-A INPUT -s 0.0.0.0/0 -p tcp -m state --state NEW -m tcp --dport 20 -j ACCEPT
 
Old 08-23-2016, 08:15 AM   #3
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
I would suggest you take a closer look at your rules and tighten them down to only allow what is really needed instead of allowing everything.

As you have not posted any of your rules this might not work 100% as it relies on having a stateful firewall.
If you have a stateless firewall then you might want to go with sunnysthakur's reply.

Basically this is what you are looking for when using a stateful firewall.
You will want to place these before any drop statement:

Code:
-A INPUT -s x.x.x.x -p icmp --icmp-typs 8 -j ACCEPT
-A INPUT -s x.x.x.x -p tcp -m conntrack --ctstate NEW -m tcp --dport 21 -j ACCEPT
Make sure you load [i]"ip_conntrack_ftp"[i] to ensure that FTP is allowed to use port 20 for data transfer.
 
Old 08-24-2016, 04:38 AM   #4
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 2,150

Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
Try this:

Quote:
iptables -A INPUT -s 192.168.1.100 -p tcp --dport 21 -j ACCEPT
iptables -A INPUT -s 192.168.1.100 -p tcp --dport 20 -j ACCEPT
Quote:
FirewallD
# firewall-cmd --direct --add-rule ipv4 filter INPUT 1 -m tcp --source 192.168.1.100 -p tcp --dport 21 -j ACCEPT
# firewall-cmd --direct --add-rule ipv4 filter INPUT 1 -m tcp --source 192.168.1.100 -p tcp --dport 20 -j ACCEPT
 
Old 08-24-2016, 08:12 AM   #5
gly
LQ Newbie
 
Registered: Mar 2016
Posts: 24

Original Poster
Rep: Reputation: Disabled
rephrasing question

@all
thanks for the replies
But question is not complete. Let me rephrase.
1) The servers inbound policy is DROP. So no process can connect to server.
2) The server needs to exchange data with 2 client s say, 192.168.4.5 and 192.168.4.9 with ftp only, nothing else.
So what should be the iptables command on the server?
 
Old 08-24-2016, 12:45 PM   #6
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
See my post and adopt as needed.
 
Old 08-24-2016, 12:55 PM   #7
gly
LQ Newbie
 
Registered: Mar 2016
Posts: 24

Original Poster
Rep: Reputation: Disabled
@lazydog
I have tried something like
iptables -A INPUT -s 192.168.4.5 -p TCP --dport ftp -j accept
but it allows to login using ftp but doesn't allow for data transfer.
 
Old 08-24-2016, 01:38 PM   #8
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
Are you using a STATEFUL firewall or a STATELESS?

If you are using a STATEFUL firewall then my rules should work if you follow them 100%. This includes loading the FTP module also as I have stated.

If you are using STATELESS then you should follow JJJCR's comment as that is the setup for that type of firewall deployment.

Would it be possible for you to post your firewall rules?
 
Old 08-24-2016, 01:49 PM   #9
gly
LQ Newbie
 
Registered: Mar 2016
Posts: 24

Original Poster
Rep: Reputation: Disabled
@lazydog
the requirement is simple. The firewall will pull files using ftp from an IP and post files to another two IPs.These are done via scripts(automating it via crond). Along with these ftp get and put policy, the server may take telnet to another 2-3 locations. That's it . no other inbound and outbound policies allowed. Can u kindly suggests the complete command list for achieving this?
 
Old 08-24-2016, 02:35 PM   #10
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
Really.... REALLY??

You are leaving out a good part of the DETAILS that we would require to give you EXACTLY the commands you need to run. While your requirements are simple we gave you simply ways to complete what you are trying to do as we did not get the details we would require.

Now the time has come for you to step up to the plate and hit a home run for the team. We have given you everything we can without knowing the simple details we need to know. You need to look at your system and decide which set of instruction will work best for your setup and deploy them.

Without knowing what type of firewall you have deployed we have no idea which set of instruction will work best for you.
 
  


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
How do I allow only a specific ip with a specific mac on lan with iptables? tkmbe Linux - Networking 2 07-10-2012 05:20 PM
IPTABLES rerouting only specific ips to a specific internal pc paulspinsmash Linux - Networking 3 01-06-2011 09:59 PM
Anonymous FTP for all, user FTP logins only for specific IP ranges Sjorrit Slackware 15 04-24-2009 02:32 PM
iptables accept ftp port only to specific subnet GUIPenguin Linux - Security 2 09-29-2005 10:24 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 04:39 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