Why does my NAT setup only work properly from time to time?












1















Homework assignment...



There are 3 computers in a local network: 192.168.0.185 (the 'client'), 192.168.0.129 (the 'gateway') and 192.168.0.81 (the 'server'). The 'server' is running a HTTP server, so typing 192.168.0.81 in a browser's address bar from any of the other two computers displays a webpage.



The assignment is to set up NAT in the so-called 'gateway' in such a way that typing its IP address (192.168.0.129) in the 'client's browser will display the webpage served by the 'server'. This is my solution attempt:



echo 1 > /proc/sys/net/ipv4/ip_forward

iptables -t nat -A PREROUTING -p tcp -d 192.168.0.129 --dport 80 -j DNAT --to 192.168.0.81:80
iptables -t nat -A POSTROUTING -p tcp -d 192.168.0.81 --dport 80 -j SNAT --to 192.168.0.129:80


This (I hoped) would make the 'gateway' redirect requests made to it to the 'server' (DNAT) while substituting source address of the request to its own so that the 'server' will correctly send the response through the 'gateway' and not straightly to the 'client' (SNAT).



I typed the 'gateway's IP in the 'client's browser's address bar. Hooray! I saw the webpage! I thought I was done!



Except I wasn't. I then reloaded the page on the 'client'. And I got timeout error. I reloaded the page once again. Timeout again. I waited a teeny tiny bit and reloaded once again. This page the webpage was served correctly. So I reloaded for the final time and... timeout.



This confuses me. It seems that once a page is served things stop working for a while. Why is that happening? Where is my mistake?



I should note that typing the 'server's address in the 'client's browser (as opposed to typing the 'gateway's address) does not cause such problems.










share|improve this question

























  • could be a problem with the web server

    – jsotola
    25 mins ago











  • @jsotola I don't think so; please see the edited question.

    – gaazkam
    21 mins ago











  • @jsotola Because the assignment says I have to configure the 'gateway' in such a way to make this possible.

    – gaazkam
    17 mins ago
















1















Homework assignment...



There are 3 computers in a local network: 192.168.0.185 (the 'client'), 192.168.0.129 (the 'gateway') and 192.168.0.81 (the 'server'). The 'server' is running a HTTP server, so typing 192.168.0.81 in a browser's address bar from any of the other two computers displays a webpage.



The assignment is to set up NAT in the so-called 'gateway' in such a way that typing its IP address (192.168.0.129) in the 'client's browser will display the webpage served by the 'server'. This is my solution attempt:



echo 1 > /proc/sys/net/ipv4/ip_forward

iptables -t nat -A PREROUTING -p tcp -d 192.168.0.129 --dport 80 -j DNAT --to 192.168.0.81:80
iptables -t nat -A POSTROUTING -p tcp -d 192.168.0.81 --dport 80 -j SNAT --to 192.168.0.129:80


This (I hoped) would make the 'gateway' redirect requests made to it to the 'server' (DNAT) while substituting source address of the request to its own so that the 'server' will correctly send the response through the 'gateway' and not straightly to the 'client' (SNAT).



I typed the 'gateway's IP in the 'client's browser's address bar. Hooray! I saw the webpage! I thought I was done!



Except I wasn't. I then reloaded the page on the 'client'. And I got timeout error. I reloaded the page once again. Timeout again. I waited a teeny tiny bit and reloaded once again. This page the webpage was served correctly. So I reloaded for the final time and... timeout.



This confuses me. It seems that once a page is served things stop working for a while. Why is that happening? Where is my mistake?



I should note that typing the 'server's address in the 'client's browser (as opposed to typing the 'gateway's address) does not cause such problems.










share|improve this question

























  • could be a problem with the web server

    – jsotola
    25 mins ago











  • @jsotola I don't think so; please see the edited question.

    – gaazkam
    21 mins ago











  • @jsotola Because the assignment says I have to configure the 'gateway' in such a way to make this possible.

    – gaazkam
    17 mins ago














1












1








1








Homework assignment...



There are 3 computers in a local network: 192.168.0.185 (the 'client'), 192.168.0.129 (the 'gateway') and 192.168.0.81 (the 'server'). The 'server' is running a HTTP server, so typing 192.168.0.81 in a browser's address bar from any of the other two computers displays a webpage.



The assignment is to set up NAT in the so-called 'gateway' in such a way that typing its IP address (192.168.0.129) in the 'client's browser will display the webpage served by the 'server'. This is my solution attempt:



echo 1 > /proc/sys/net/ipv4/ip_forward

iptables -t nat -A PREROUTING -p tcp -d 192.168.0.129 --dport 80 -j DNAT --to 192.168.0.81:80
iptables -t nat -A POSTROUTING -p tcp -d 192.168.0.81 --dport 80 -j SNAT --to 192.168.0.129:80


This (I hoped) would make the 'gateway' redirect requests made to it to the 'server' (DNAT) while substituting source address of the request to its own so that the 'server' will correctly send the response through the 'gateway' and not straightly to the 'client' (SNAT).



I typed the 'gateway's IP in the 'client's browser's address bar. Hooray! I saw the webpage! I thought I was done!



Except I wasn't. I then reloaded the page on the 'client'. And I got timeout error. I reloaded the page once again. Timeout again. I waited a teeny tiny bit and reloaded once again. This page the webpage was served correctly. So I reloaded for the final time and... timeout.



This confuses me. It seems that once a page is served things stop working for a while. Why is that happening? Where is my mistake?



I should note that typing the 'server's address in the 'client's browser (as opposed to typing the 'gateway's address) does not cause such problems.










share|improve this question
















Homework assignment...



There are 3 computers in a local network: 192.168.0.185 (the 'client'), 192.168.0.129 (the 'gateway') and 192.168.0.81 (the 'server'). The 'server' is running a HTTP server, so typing 192.168.0.81 in a browser's address bar from any of the other two computers displays a webpage.



The assignment is to set up NAT in the so-called 'gateway' in such a way that typing its IP address (192.168.0.129) in the 'client's browser will display the webpage served by the 'server'. This is my solution attempt:



echo 1 > /proc/sys/net/ipv4/ip_forward

iptables -t nat -A PREROUTING -p tcp -d 192.168.0.129 --dport 80 -j DNAT --to 192.168.0.81:80
iptables -t nat -A POSTROUTING -p tcp -d 192.168.0.81 --dport 80 -j SNAT --to 192.168.0.129:80


This (I hoped) would make the 'gateway' redirect requests made to it to the 'server' (DNAT) while substituting source address of the request to its own so that the 'server' will correctly send the response through the 'gateway' and not straightly to the 'client' (SNAT).



I typed the 'gateway's IP in the 'client's browser's address bar. Hooray! I saw the webpage! I thought I was done!



Except I wasn't. I then reloaded the page on the 'client'. And I got timeout error. I reloaded the page once again. Timeout again. I waited a teeny tiny bit and reloaded once again. This page the webpage was served correctly. So I reloaded for the final time and... timeout.



This confuses me. It seems that once a page is served things stop working for a while. Why is that happening? Where is my mistake?



I should note that typing the 'server's address in the 'client's browser (as opposed to typing the 'gateway's address) does not cause such problems.







networking iptables nat






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 22 mins ago







gaazkam

















asked 28 mins ago









gaazkamgaazkam

3581514




3581514













  • could be a problem with the web server

    – jsotola
    25 mins ago











  • @jsotola I don't think so; please see the edited question.

    – gaazkam
    21 mins ago











  • @jsotola Because the assignment says I have to configure the 'gateway' in such a way to make this possible.

    – gaazkam
    17 mins ago



















  • could be a problem with the web server

    – jsotola
    25 mins ago











  • @jsotola I don't think so; please see the edited question.

    – gaazkam
    21 mins ago











  • @jsotola Because the assignment says I have to configure the 'gateway' in such a way to make this possible.

    – gaazkam
    17 mins ago

















could be a problem with the web server

– jsotola
25 mins ago





could be a problem with the web server

– jsotola
25 mins ago













@jsotola I don't think so; please see the edited question.

– gaazkam
21 mins ago





@jsotola I don't think so; please see the edited question.

– gaazkam
21 mins ago













@jsotola Because the assignment says I have to configure the 'gateway' in such a way to make this possible.

– gaazkam
17 mins ago





@jsotola Because the assignment says I have to configure the 'gateway' in such a way to make this possible.

– gaazkam
17 mins ago










0






active

oldest

votes











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',
autoActivateHeartbeat: false,
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%2f494721%2fwhy-does-my-nat-setup-only-work-properly-from-time-to-time%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f494721%2fwhy-does-my-nat-setup-only-work-properly-from-time-to-time%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

Accessing regular linux commands in Huawei's Dopra Linux

Can't connect RFCOMM socket: Host is down

Kernel panic - not syncing: Fatal Exception in Interrupt