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 12-24-2007, 06:46 AM   #1
Santoshkb
Member
 
Registered: Sep 2007
Posts: 56

Rep: Reputation: 15
Iptable-can we Set priority for rules in chain?


Hi all,
Requirement is all packets , on g/k is be redirected to 8080 portal port ,
at any Instance this rule excludes the mac specified,by adding iprule to accept packets from specified mac,

Ex:
1 . /sbin/iptables -A INPUT -p tcp --dport 22 -j ACCEPT

2 . /sbin/iptables -t nat -A PREROUTING -p tcp -j REDIRECT --to 8080

3 . /sbin/iptables -t nat -A PREROUTING -p tcp -m mac --mac-source 00:19:5B:6C:12:21 -j ACCEPT

iptables -t nat -L --lists

Chain PREROUTING (policy ACCEPT)
target prot opt source destination
REDIRECT tcp -- anywhere anywhere redir ports 8080
ACCEPT tcp -- anywhere anywhere MAC 00:19:5B:6C:12:21

Problem is it always considers the first rule: and redirects, how can we make the redirection rule low priority, and any ACCEPTS to be checked at beginning.

saw usage of -j MARK --setmark #priorityno .. could this be adapted here?


Lastly for allowing ssh from remote machine, used the below command
/sbin/iptables -A INPUT -p tcp --dport 22 -j ACCEPT


looking for your suggestions.Thanks in advance

Last edited by Santoshkb; 12-24-2007 at 06:48 AM. Reason: h
 
Old 12-24-2007, 08:21 AM   #2
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
You can put the statements in the reverse sequence, that is, first the ACCEPT, then the REDIRECT.

IPTables executes the rules in the order they are given. As soon as a rule is matched, the packet is processed according to the rule, and then the target is terminating (ACCEPT, REDIRECT) it is over and done.

jlinkels
 
Old 12-24-2007, 08:44 AM   #3
Santoshkb
Member
 
Registered: Sep 2007
Posts: 56

Original Poster
Rep: Reputation: 15
later

thanks, Initially is to be redirected . thing is its decided at later stage after authentication to allow user(with macid xx..xx). to acess without redirection,
any ways to make the current rule appear first or
make the former rule appear last(low priority)

did execute , but the first rule appears to take priority

1./sbin/iptables -t nat -A PREROUTING -p tcp -j REDIRECT --to 8080

2. /sbin/iptables -t nat -A PREROUTING -p tcp -m mac --mac-source 00:19:5B:6C:12:21 -j ACCEPT


/sbin/iptables -t nat -L

Chain PREROUTING (policy ACCEPT)
target prot opt source destination
REDIRECT tcp -- anywhere anywhere redir ports 8080
ACCEPT tcp -- anywhere anywhere MAC 00:19:5B:6C:12:21
 
Old 12-24-2007, 04:40 PM   #4
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
So this what you want:


Code:
1. /sbin/iptables -t nat -A PREROUTING -p tcp -m mac --mac-source 00:19:5B:6C:12:21 -j ACCEPT
2. /sbin/iptables -t nat -A PREROUTING -p tcp -j REDIRECT --to 8080
Use -I instead of -A, so the rule is not Appended but Inserted (at the head of the chain)

When the max address is not matched, the next rule is evaluated, then the next etc. and the very last rule is REDIRECT to 8080

Is that what you mean?

jlinkels
 
Old 12-25-2007, 05:48 AM   #5
Santoshkb
Member
 
Registered: Sep 2007
Posts: 56

Original Poster
Rep: Reputation: 15
Thanks

thanku jlinkels ,for correcting -A to -I and yes thats what i precisely mean.
 
Old 12-26-2007, 12:51 AM   #6
Santoshkb
Member
 
Registered: Sep 2007
Posts: 56

Original Poster
Rep: Reputation: 15
where should accept --dport 22 mentioned in filter/nat table?

m refering nat table for redirecting packets,

* Except to packets destined for port 22(ssh)

whether this iprule to accept port 22 is to be inserted in filter
or nat table? please do know hw its gng to affect by inserting rule in filter table(1) or nat table(2)
1. /sbin/iptables -A INPUT -p tcp --dport 22 -j ACCEPT
Or
2. /sbin/iptables -t nat -I PREROUTING -p tcp --dport 22 -j ACCEPT


One Last ..
i look to reject all packets (other than port 22/80, ) hence appended at last.. this rule is showing invalid.. whats wrong in rule below

/sbin/iptables -t nat -A PREROUTING -p tcp -j REJECT

thanks all

Last edited by Santoshkb; 12-26-2007 at 03:52 AM. Reason: h
 
  


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
IPTable rules RecoilUK Linux - Security 1 05-27-2005 07:25 PM
Snort rules> priority linuxtommy Linux - Security 1 09-12-2004 09:35 PM
Process order of iptables chain rules. mrpc_cambodia Linux - Networking 1 07-14-2004 12:21 AM
Help with IPtable Rules aqoliveira Linux - Security 3 12-10-2003 10:00 AM
Iptables rules priority exalik Linux - Networking 1 04-18-2003 11:50 PM

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

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