LinuxQuestions.org
Review your favorite Linux distribution.
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 07-07-2018, 11:15 AM   #1
pedropt
Member
 
Registered: Aug 2014
Distribution: Devuan
Posts: 345

Rep: Reputation: Disabled
IP tables , allow specific ip list to access only 1 port .


Hi , i am struggling to find a way to this complicate set of rules in iptables .

Imagine this list of ips :
Quote:
1.1.1.1
4.5.6.7
9.3.4.5
What i need :

- I need that these ips can access only port 8080 on server no matter what port they are coming .

- All other ips not on this list can not access port 8080 but can access the current open ports on server .

How to do this with iptables ?

UPDATED

I have been trying here to figure out a solution .
What i need is a prerouting rule with ip source and a set of rules to allow that specific ip to allow port 8080 but close all others .

One thing to startup is to set in my prerouting table this rule :

Test for only 1 ip
Quote:

# Basically i was expecting to preroute this ip to port 8080
-A PREROUTING -p tcp -s 1.1.1.1 -j REDIRECT --to-ports 8080
and in the iptables input rules these instructions :
Quote:
#these set of rules allow port 8080 to that ip but block all others
-A INPUT -p all -m all -s 1.1.1.1 --dport 8080 -j ACCEPT

#Here drop all ports from 1 to 8079 to this ip
-A INPUT -s 1.1.1.1 --dport 1:8079 -j DROP

#Here drop all ports from 8081 to 65535 to this
-A INPUT -s 1.1.1.1 --dport 8081:65535 -j DROP

# Here i close the port 8080 for all other ips that are not in list
-A INPUT -p tcp -m tcp --dport 8080 -j DROP
However , it is not working

Last edited by pedropt; 07-07-2018 at 03:14 PM.
 
Old 07-07-2018, 03:25 PM   #2
pedropt
Member
 
Registered: Aug 2014
Distribution: Devuan
Posts: 345

Original Poster
Rep: Reputation: Disabled
I Figured out a solution .

In the PREROUTING table
Quote:
-A PREROUTING -p tcp -s 1.1.1.1 -j REDIRECT --to-ports 8080
In the Input Table

Quote:
-A INPUT -p tcp -m tcp -s 1.1.1.1 --dport 8080 -j ACCEPT
-A INPUT -p tcp -m tcp -s 1.1.1.1 --dport 1:8079 -j DROP
-A INPUT -p tcp -m tcp -s 1.1.1.1 --dport 8081:65535 -j DROP
-A INPUT -p tcp -m tcp --dport 8080 -j DROP

Last edited by pedropt; 07-08-2018 at 08:36 AM.
 
  


Reply

Tags
iptables



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
restrict specific port access only to root user gibigibi Linux - Server 3 05-15-2015 08:54 AM
ip6tables - allow specific port number v6 traffic to specific machine psycroptic Linux - Networking 0 03-17-2015 08:45 AM
list all connections to a specific port drhart4000 Linux - Networking 2 05-23-2012 04:39 AM
List IP Adresses connected to specific Port militiaware Linux - Networking 1 10-25-2011 05:13 AM
Restricting access to a specific port by MAC address caps_phisto Linux - Networking 3 10-23-2006 01:55 PM

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

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