Long iptables rules efficiency & performance
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO9GURib1T8z7lCwjOGLQaGtrueEthgQ8LO42ZX8cOfTqDK4jvDDpKkLFwf2J49kYCMNW7d4ABih_XCb_2UXdq5fPJDkoyg7-8g_YfRUot-XnaXkNYycsNp7lA5_TW9td0FFpLQ2APzKcZ/s1600/1.jpg)
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYQ0N5W1qAOxLP7t7iOM6O6AzbZnkXUy16s7P_CWfOb5UbTQY_aDsc727chyphenhyphen5W4IppVNernMMQeaUFTB_rFzAd95_CDt-tnwN-nBx6JyUp2duGjPaL5-VgNO41AVsA_vu30EJcipdDG409/s400/Clash+Royale+CLAN+TAG%2523URR8PPP.png)
up vote
0
down vote
favorite
When building a long iptables rules, which one is more efficient, to use one long script per line or to use the tables? What about the performance, does it have effect to packets loss and untracked packets?
Example:
one script per line
iptables -A INPUT -i wlan0 -p tcp --sport 80 -j ACCEPT
using the tables
iptables -N table1
iptables -A INPUT -i wlan0 -j tbl1
iptables -A table1 -p tcp --sport 80 -j ACCEPT
iptables
add a comment |Â
up vote
0
down vote
favorite
When building a long iptables rules, which one is more efficient, to use one long script per line or to use the tables? What about the performance, does it have effect to packets loss and untracked packets?
Example:
one script per line
iptables -A INPUT -i wlan0 -p tcp --sport 80 -j ACCEPT
using the tables
iptables -N table1
iptables -A INPUT -i wlan0 -j tbl1
iptables -A table1 -p tcp --sport 80 -j ACCEPT
iptables
To performance test see people.netfilter.org/kadlec/nftest.pdf and strongarm.io/blog/linux-firewall-performance-testing
â Panther
Mar 28 at 14:38
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
When building a long iptables rules, which one is more efficient, to use one long script per line or to use the tables? What about the performance, does it have effect to packets loss and untracked packets?
Example:
one script per line
iptables -A INPUT -i wlan0 -p tcp --sport 80 -j ACCEPT
using the tables
iptables -N table1
iptables -A INPUT -i wlan0 -j tbl1
iptables -A table1 -p tcp --sport 80 -j ACCEPT
iptables
When building a long iptables rules, which one is more efficient, to use one long script per line or to use the tables? What about the performance, does it have effect to packets loss and untracked packets?
Example:
one script per line
iptables -A INPUT -i wlan0 -p tcp --sport 80 -j ACCEPT
using the tables
iptables -N table1
iptables -A INPUT -i wlan0 -j tbl1
iptables -A table1 -p tcp --sport 80 -j ACCEPT
iptables
iptables
edited Mar 29 at 2:58
muru
130k19273463
130k19273463
asked Mar 28 at 8:52
smnlss689
113
113
To performance test see people.netfilter.org/kadlec/nftest.pdf and strongarm.io/blog/linux-firewall-performance-testing
â Panther
Mar 28 at 14:38
add a comment |Â
To performance test see people.netfilter.org/kadlec/nftest.pdf and strongarm.io/blog/linux-firewall-performance-testing
â Panther
Mar 28 at 14:38
To performance test see people.netfilter.org/kadlec/nftest.pdf and strongarm.io/blog/linux-firewall-performance-testing
â Panther
Mar 28 at 14:38
To performance test see people.netfilter.org/kadlec/nftest.pdf and strongarm.io/blog/linux-firewall-performance-testing
â Panther
Mar 28 at 14:38
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
In your second example, you define a new chain called table1, and route incoming packets to the new chain in order to perform matching on the chain.
This can be a good strategy if, for example, the processing you do on that chain is somewhat heavy and you don't want to subject all incoming packets to it.
But in your example,
- ALL incoming traffic on the wlan0 interface is sent to the new chain (this even includes packets that are part of established connections!)
- The processing on that chain is trivial - just matching by source and destination port.
So in this simple example the extra complexity of defining a new chain and routing everything to it is unnecessary and redundant, and were you able to measure a performance difference, would probably result in the lower performance.
Performance really won't affect you unless you have a lot more rules or much heavier processing.
It is true, from my experience (just tested it) more chains will make it more heavier. I'm using a metered data connection, It consumes more bandwith when I use more chains, and using more REJECT. It also consumes more bandwith if I use DROP insted of REJECT. But I think more chains is more secure than simply write many rules at one with less chains. I'm just wondered how windows do it, it consumes less bandwith downloading using IDM software (tested it years ago) from the internet than any linux.
â smnlss689
Apr 10 at 2:54
If efficiency is a priority at all, you should accept any related or established packets as early as possible. You may already be doing this in rules that weren't part of your example, but I mention it just in case.
â thomasrutter
Apr 10 at 3:37
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
In your second example, you define a new chain called table1, and route incoming packets to the new chain in order to perform matching on the chain.
This can be a good strategy if, for example, the processing you do on that chain is somewhat heavy and you don't want to subject all incoming packets to it.
But in your example,
- ALL incoming traffic on the wlan0 interface is sent to the new chain (this even includes packets that are part of established connections!)
- The processing on that chain is trivial - just matching by source and destination port.
So in this simple example the extra complexity of defining a new chain and routing everything to it is unnecessary and redundant, and were you able to measure a performance difference, would probably result in the lower performance.
Performance really won't affect you unless you have a lot more rules or much heavier processing.
It is true, from my experience (just tested it) more chains will make it more heavier. I'm using a metered data connection, It consumes more bandwith when I use more chains, and using more REJECT. It also consumes more bandwith if I use DROP insted of REJECT. But I think more chains is more secure than simply write many rules at one with less chains. I'm just wondered how windows do it, it consumes less bandwith downloading using IDM software (tested it years ago) from the internet than any linux.
â smnlss689
Apr 10 at 2:54
If efficiency is a priority at all, you should accept any related or established packets as early as possible. You may already be doing this in rules that weren't part of your example, but I mention it just in case.
â thomasrutter
Apr 10 at 3:37
add a comment |Â
up vote
0
down vote
In your second example, you define a new chain called table1, and route incoming packets to the new chain in order to perform matching on the chain.
This can be a good strategy if, for example, the processing you do on that chain is somewhat heavy and you don't want to subject all incoming packets to it.
But in your example,
- ALL incoming traffic on the wlan0 interface is sent to the new chain (this even includes packets that are part of established connections!)
- The processing on that chain is trivial - just matching by source and destination port.
So in this simple example the extra complexity of defining a new chain and routing everything to it is unnecessary and redundant, and were you able to measure a performance difference, would probably result in the lower performance.
Performance really won't affect you unless you have a lot more rules or much heavier processing.
It is true, from my experience (just tested it) more chains will make it more heavier. I'm using a metered data connection, It consumes more bandwith when I use more chains, and using more REJECT. It also consumes more bandwith if I use DROP insted of REJECT. But I think more chains is more secure than simply write many rules at one with less chains. I'm just wondered how windows do it, it consumes less bandwith downloading using IDM software (tested it years ago) from the internet than any linux.
â smnlss689
Apr 10 at 2:54
If efficiency is a priority at all, you should accept any related or established packets as early as possible. You may already be doing this in rules that weren't part of your example, but I mention it just in case.
â thomasrutter
Apr 10 at 3:37
add a comment |Â
up vote
0
down vote
up vote
0
down vote
In your second example, you define a new chain called table1, and route incoming packets to the new chain in order to perform matching on the chain.
This can be a good strategy if, for example, the processing you do on that chain is somewhat heavy and you don't want to subject all incoming packets to it.
But in your example,
- ALL incoming traffic on the wlan0 interface is sent to the new chain (this even includes packets that are part of established connections!)
- The processing on that chain is trivial - just matching by source and destination port.
So in this simple example the extra complexity of defining a new chain and routing everything to it is unnecessary and redundant, and were you able to measure a performance difference, would probably result in the lower performance.
Performance really won't affect you unless you have a lot more rules or much heavier processing.
In your second example, you define a new chain called table1, and route incoming packets to the new chain in order to perform matching on the chain.
This can be a good strategy if, for example, the processing you do on that chain is somewhat heavy and you don't want to subject all incoming packets to it.
But in your example,
- ALL incoming traffic on the wlan0 interface is sent to the new chain (this even includes packets that are part of established connections!)
- The processing on that chain is trivial - just matching by source and destination port.
So in this simple example the extra complexity of defining a new chain and routing everything to it is unnecessary and redundant, and were you able to measure a performance difference, would probably result in the lower performance.
Performance really won't affect you unless you have a lot more rules or much heavier processing.
answered Mar 29 at 0:07
thomasrutter
25.4k46086
25.4k46086
It is true, from my experience (just tested it) more chains will make it more heavier. I'm using a metered data connection, It consumes more bandwith when I use more chains, and using more REJECT. It also consumes more bandwith if I use DROP insted of REJECT. But I think more chains is more secure than simply write many rules at one with less chains. I'm just wondered how windows do it, it consumes less bandwith downloading using IDM software (tested it years ago) from the internet than any linux.
â smnlss689
Apr 10 at 2:54
If efficiency is a priority at all, you should accept any related or established packets as early as possible. You may already be doing this in rules that weren't part of your example, but I mention it just in case.
â thomasrutter
Apr 10 at 3:37
add a comment |Â
It is true, from my experience (just tested it) more chains will make it more heavier. I'm using a metered data connection, It consumes more bandwith when I use more chains, and using more REJECT. It also consumes more bandwith if I use DROP insted of REJECT. But I think more chains is more secure than simply write many rules at one with less chains. I'm just wondered how windows do it, it consumes less bandwith downloading using IDM software (tested it years ago) from the internet than any linux.
â smnlss689
Apr 10 at 2:54
If efficiency is a priority at all, you should accept any related or established packets as early as possible. You may already be doing this in rules that weren't part of your example, but I mention it just in case.
â thomasrutter
Apr 10 at 3:37
It is true, from my experience (just tested it) more chains will make it more heavier. I'm using a metered data connection, It consumes more bandwith when I use more chains, and using more REJECT. It also consumes more bandwith if I use DROP insted of REJECT. But I think more chains is more secure than simply write many rules at one with less chains. I'm just wondered how windows do it, it consumes less bandwith downloading using IDM software (tested it years ago) from the internet than any linux.
â smnlss689
Apr 10 at 2:54
It is true, from my experience (just tested it) more chains will make it more heavier. I'm using a metered data connection, It consumes more bandwith when I use more chains, and using more REJECT. It also consumes more bandwith if I use DROP insted of REJECT. But I think more chains is more secure than simply write many rules at one with less chains. I'm just wondered how windows do it, it consumes less bandwith downloading using IDM software (tested it years ago) from the internet than any linux.
â smnlss689
Apr 10 at 2:54
If efficiency is a priority at all, you should accept any related or established packets as early as possible. You may already be doing this in rules that weren't part of your example, but I mention it just in case.
â thomasrutter
Apr 10 at 3:37
If efficiency is a priority at all, you should accept any related or established packets as early as possible. You may already be doing this in rules that weren't part of your example, but I mention it just in case.
â thomasrutter
Apr 10 at 3:37
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1019893%2flong-iptables-rules-efficiency-performance%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
To performance test see people.netfilter.org/kadlec/nftest.pdf and strongarm.io/blog/linux-firewall-performance-testing
â Panther
Mar 28 at 14:38