IPtables - new vs new, established, related











up vote
6
down vote

favorite












I'm «pretty» new to IPtables, or I have used IPtables a few years, but never with advanced features. I understand the concept of stateful IPtables rules, but recently I discovered that some people only use NEW as state, not NEW,ESTABLISHED,RELATED as I would do, and has always done.



Let's take an example, let's assume that I would allow only outgoing HTTP[S] traffic to pass through the firewall. I know I would also need to allow outgoing DNS traffic in a real world scenario, but this is just an example. I would have written the iptable rules like this:



:INPUT DROP
:FORWARD DROP
:OUTPUT DROP

-A INPUT -p tcp -m multiport --sports 80,443 -m state --state ESTABLISHED,RELATED -j ACCEPT
-A OUTPUT -p tcp -m multiport --dports 80,443 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT


Is this correct? I wonder because I have seen people who have written the same firewall rules like this:



:INPUT DROP
:FORWARD DROP
:OUTPUT DROP

-A INPUT -p tcp -m multiport --sports 80,443 -m state --state ESTABLISHED,RELATED -j ACCEPT
-A OUTPUT -p tcp -m multiport --dports 80,443 -m state --state NEW -j ACCEPT


What is the difference between NEW and NEW,ESTABLISHED,RELATED for an outgoing rule? Is it enough just to write NEW and let the firewall do some mysterious magic? Or is it necessary to write NEW,ESTABLISHED,RELATED?










share|improve this question















migrated from security.stackexchange.com Jul 13 '15 at 19:05


This question came from our site for information security professionals.















  • As a note, the line is most commonly written this way: -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT. This change essentially turns iptables into a stateful firewall. Instead of having to define each TCP connection properly, this line essentially allows all traffic that has already been processed (and allowed) by iptables.
    – prateek61
    Jun 28 '16 at 2:44















up vote
6
down vote

favorite












I'm «pretty» new to IPtables, or I have used IPtables a few years, but never with advanced features. I understand the concept of stateful IPtables rules, but recently I discovered that some people only use NEW as state, not NEW,ESTABLISHED,RELATED as I would do, and has always done.



Let's take an example, let's assume that I would allow only outgoing HTTP[S] traffic to pass through the firewall. I know I would also need to allow outgoing DNS traffic in a real world scenario, but this is just an example. I would have written the iptable rules like this:



:INPUT DROP
:FORWARD DROP
:OUTPUT DROP

-A INPUT -p tcp -m multiport --sports 80,443 -m state --state ESTABLISHED,RELATED -j ACCEPT
-A OUTPUT -p tcp -m multiport --dports 80,443 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT


Is this correct? I wonder because I have seen people who have written the same firewall rules like this:



:INPUT DROP
:FORWARD DROP
:OUTPUT DROP

-A INPUT -p tcp -m multiport --sports 80,443 -m state --state ESTABLISHED,RELATED -j ACCEPT
-A OUTPUT -p tcp -m multiport --dports 80,443 -m state --state NEW -j ACCEPT


What is the difference between NEW and NEW,ESTABLISHED,RELATED for an outgoing rule? Is it enough just to write NEW and let the firewall do some mysterious magic? Or is it necessary to write NEW,ESTABLISHED,RELATED?










share|improve this question















migrated from security.stackexchange.com Jul 13 '15 at 19:05


This question came from our site for information security professionals.















  • As a note, the line is most commonly written this way: -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT. This change essentially turns iptables into a stateful firewall. Instead of having to define each TCP connection properly, this line essentially allows all traffic that has already been processed (and allowed) by iptables.
    – prateek61
    Jun 28 '16 at 2:44













up vote
6
down vote

favorite









up vote
6
down vote

favorite











I'm «pretty» new to IPtables, or I have used IPtables a few years, but never with advanced features. I understand the concept of stateful IPtables rules, but recently I discovered that some people only use NEW as state, not NEW,ESTABLISHED,RELATED as I would do, and has always done.



Let's take an example, let's assume that I would allow only outgoing HTTP[S] traffic to pass through the firewall. I know I would also need to allow outgoing DNS traffic in a real world scenario, but this is just an example. I would have written the iptable rules like this:



:INPUT DROP
:FORWARD DROP
:OUTPUT DROP

-A INPUT -p tcp -m multiport --sports 80,443 -m state --state ESTABLISHED,RELATED -j ACCEPT
-A OUTPUT -p tcp -m multiport --dports 80,443 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT


Is this correct? I wonder because I have seen people who have written the same firewall rules like this:



:INPUT DROP
:FORWARD DROP
:OUTPUT DROP

-A INPUT -p tcp -m multiport --sports 80,443 -m state --state ESTABLISHED,RELATED -j ACCEPT
-A OUTPUT -p tcp -m multiport --dports 80,443 -m state --state NEW -j ACCEPT


What is the difference between NEW and NEW,ESTABLISHED,RELATED for an outgoing rule? Is it enough just to write NEW and let the firewall do some mysterious magic? Or is it necessary to write NEW,ESTABLISHED,RELATED?










share|improve this question















I'm «pretty» new to IPtables, or I have used IPtables a few years, but never with advanced features. I understand the concept of stateful IPtables rules, but recently I discovered that some people only use NEW as state, not NEW,ESTABLISHED,RELATED as I would do, and has always done.



Let's take an example, let's assume that I would allow only outgoing HTTP[S] traffic to pass through the firewall. I know I would also need to allow outgoing DNS traffic in a real world scenario, but this is just an example. I would have written the iptable rules like this:



:INPUT DROP
:FORWARD DROP
:OUTPUT DROP

-A INPUT -p tcp -m multiport --sports 80,443 -m state --state ESTABLISHED,RELATED -j ACCEPT
-A OUTPUT -p tcp -m multiport --dports 80,443 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT


Is this correct? I wonder because I have seen people who have written the same firewall rules like this:



:INPUT DROP
:FORWARD DROP
:OUTPUT DROP

-A INPUT -p tcp -m multiport --sports 80,443 -m state --state ESTABLISHED,RELATED -j ACCEPT
-A OUTPUT -p tcp -m multiport --dports 80,443 -m state --state NEW -j ACCEPT


What is the difference between NEW and NEW,ESTABLISHED,RELATED for an outgoing rule? Is it enough just to write NEW and let the firewall do some mysterious magic? Or is it necessary to write NEW,ESTABLISHED,RELATED?







http iptables






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 20 '15 at 1:53









Thomas Dickey

51.4k594164




51.4k594164










asked Jul 12 '15 at 14:48









BufferOverflow

213211




213211




migrated from security.stackexchange.com Jul 13 '15 at 19:05


This question came from our site for information security professionals.






migrated from security.stackexchange.com Jul 13 '15 at 19:05


This question came from our site for information security professionals.














  • As a note, the line is most commonly written this way: -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT. This change essentially turns iptables into a stateful firewall. Instead of having to define each TCP connection properly, this line essentially allows all traffic that has already been processed (and allowed) by iptables.
    – prateek61
    Jun 28 '16 at 2:44


















  • As a note, the line is most commonly written this way: -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT. This change essentially turns iptables into a stateful firewall. Instead of having to define each TCP connection properly, this line essentially allows all traffic that has already been processed (and allowed) by iptables.
    – prateek61
    Jun 28 '16 at 2:44
















As a note, the line is most commonly written this way: -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT. This change essentially turns iptables into a stateful firewall. Instead of having to define each TCP connection properly, this line essentially allows all traffic that has already been processed (and allowed) by iptables.
– prateek61
Jun 28 '16 at 2:44




As a note, the line is most commonly written this way: -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT. This change essentially turns iptables into a stateful firewall. Instead of having to define each TCP connection properly, this line essentially allows all traffic that has already been processed (and allowed) by iptables.
– prateek61
Jun 28 '16 at 2:44










1 Answer
1






active

oldest

votes

















up vote
3
down vote



accepted










The second configuration will not work (try it!).
Since your default policy is DROP on the OUTPUT chain, the third packet of the TCP three-way-handshake will be blocked by the firewall, as that one does not fall under NEW, so the connection will never be established.



It would work if your default OUTPUT policy would be ACCEPT, or you had some other OUTPUT rule afterwards which would allow ESTABLISHED and RELATED state.



In conclusion, the first ruleset is the correct one, if you want to have DROP as your default policy.






share|improve this answer























  • Thanks for the answer. That was what I thought, but i got a little bit confused when I saw someone write it with only NEW. I thought maybe IPtables creates some sort of records of established connection, and it was then unecessary to use ESTABLISHED.
    – BufferOverflow
    Jul 14 '15 at 13:59











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f215757%2fiptables-new-vs-new-established-related%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
3
down vote



accepted










The second configuration will not work (try it!).
Since your default policy is DROP on the OUTPUT chain, the third packet of the TCP three-way-handshake will be blocked by the firewall, as that one does not fall under NEW, so the connection will never be established.



It would work if your default OUTPUT policy would be ACCEPT, or you had some other OUTPUT rule afterwards which would allow ESTABLISHED and RELATED state.



In conclusion, the first ruleset is the correct one, if you want to have DROP as your default policy.






share|improve this answer























  • Thanks for the answer. That was what I thought, but i got a little bit confused when I saw someone write it with only NEW. I thought maybe IPtables creates some sort of records of established connection, and it was then unecessary to use ESTABLISHED.
    – BufferOverflow
    Jul 14 '15 at 13:59















up vote
3
down vote



accepted










The second configuration will not work (try it!).
Since your default policy is DROP on the OUTPUT chain, the third packet of the TCP three-way-handshake will be blocked by the firewall, as that one does not fall under NEW, so the connection will never be established.



It would work if your default OUTPUT policy would be ACCEPT, or you had some other OUTPUT rule afterwards which would allow ESTABLISHED and RELATED state.



In conclusion, the first ruleset is the correct one, if you want to have DROP as your default policy.






share|improve this answer























  • Thanks for the answer. That was what I thought, but i got a little bit confused when I saw someone write it with only NEW. I thought maybe IPtables creates some sort of records of established connection, and it was then unecessary to use ESTABLISHED.
    – BufferOverflow
    Jul 14 '15 at 13:59













up vote
3
down vote



accepted







up vote
3
down vote



accepted






The second configuration will not work (try it!).
Since your default policy is DROP on the OUTPUT chain, the third packet of the TCP three-way-handshake will be blocked by the firewall, as that one does not fall under NEW, so the connection will never be established.



It would work if your default OUTPUT policy would be ACCEPT, or you had some other OUTPUT rule afterwards which would allow ESTABLISHED and RELATED state.



In conclusion, the first ruleset is the correct one, if you want to have DROP as your default policy.






share|improve this answer














The second configuration will not work (try it!).
Since your default policy is DROP on the OUTPUT chain, the third packet of the TCP three-way-handshake will be blocked by the firewall, as that one does not fall under NEW, so the connection will never be established.



It would work if your default OUTPUT policy would be ACCEPT, or you had some other OUTPUT rule afterwards which would allow ESTABLISHED and RELATED state.



In conclusion, the first ruleset is the correct one, if you want to have DROP as your default policy.







share|improve this answer














share|improve this answer



share|improve this answer








edited Jul 14 '15 at 9:08

























answered Jul 14 '15 at 9:02









katti

55949




55949












  • Thanks for the answer. That was what I thought, but i got a little bit confused when I saw someone write it with only NEW. I thought maybe IPtables creates some sort of records of established connection, and it was then unecessary to use ESTABLISHED.
    – BufferOverflow
    Jul 14 '15 at 13:59


















  • Thanks for the answer. That was what I thought, but i got a little bit confused when I saw someone write it with only NEW. I thought maybe IPtables creates some sort of records of established connection, and it was then unecessary to use ESTABLISHED.
    – BufferOverflow
    Jul 14 '15 at 13:59
















Thanks for the answer. That was what I thought, but i got a little bit confused when I saw someone write it with only NEW. I thought maybe IPtables creates some sort of records of established connection, and it was then unecessary to use ESTABLISHED.
– BufferOverflow
Jul 14 '15 at 13:59




Thanks for the answer. That was what I thought, but i got a little bit confused when I saw someone write it with only NEW. I thought maybe IPtables creates some sort of records of established connection, and it was then unecessary to use ESTABLISHED.
– BufferOverflow
Jul 14 '15 at 13:59


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f215757%2fiptables-new-vs-new-established-related%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

サソリ

広島県道265号伴広島線

Accessing regular linux commands in Huawei's Dopra Linux