LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-15-2018, 12:28 PM   #1
schnappi
Member
 
Registered: Apr 2017
Posts: 52

Rep: Reputation: 3
iptables question


Hello,

Running below (with "x" changed to the wanted ports) works fine.

Code:
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport X -j REDIRECT --to-port X
However if put:

Code:
-t nat -A PREROUTING -i eth0 -p tcp --dport X -j REDIRECT --to-port X
into iptables-persistent rules.v4 file (/etc/iptables/rules.v4 on Debian) the command fails with an error pointing to the line where the above code is. How can one make the above command persistent with the iptables-persistent package?
 
Old 01-15-2018, 02:27 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,740

Rep: Reputation: 5922Reputation: 5922Reputation: 5922Reputation: 5922Reputation: 5922Reputation: 5922Reputation: 5922Reputation: 5922Reputation: 5922Reputation: 5922Reputation: 5922
The correct syntax for the posted rule is:
Code:
-A PREROUTING -i eth0 -p tcp -m tcp --dport X -j REDIRECT --to-ports Y
Instead of editing the file directly I would use the iptables-save utility. It parses the tables that creates the iptables-persistent rules.v4 file which is then read by the iptables-restore utility.
 
Old 01-15-2018, 06:48 PM   #3
schnappi
Member
 
Registered: Apr 2017
Posts: 52

Original Poster
Rep: Reputation: 3
Thanks. Still get a "line X failed" message after adding below to rules.v4 (with ports filled in).

Code:
-A PREROUTING -i eth0 -p tcp -m tcp --dport X -j REDIRECT --to-ports Y
Adding current iptables rules is a no go because it will add fail2ban rules into rules.v4 and always forget to stop fail2ban prior to doing. Also it is not relevant anyways because adding current iptables rules will not add prerouting rules (iptables -S will not show prerouting rules either). Only can see prerouting rules with;

Code:
iptables -t nat -L -n -v
Am starting to think that original syntax (as well as @michaelk) suggestion are both correct but that iptables prerouting rules need to be added somewhere besides rules.v4. Thoughts?

On another somewhat separate note will the below limit both UDP and TCP packets (basically if -p tcp or -p UDP is not specified will a rule default to applying to both TCP and UDP)?

Code:
iptables -A OUTPUT -m limit --limit 100/s -j ACCEPT

Last edited by schnappi; 01-15-2018 at 06:59 PM.
 
  


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
iptables question nickajeglin Linux - Security 9 04-08-2015 04:19 AM
A Question about iptables hezoka92 Linux - Newbie 1 05-18-2014 11:18 AM
iptables question lsu420luv General 2 03-23-2006 10:38 AM
IPTABLES question berserker_b2k Linux - Networking 0 02-04-2004 04:08 PM
iptables question Texicle Slackware 7 01-19-2003 12:48 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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