How can I set a gateway in a local network?
Homework disclaimer...
So I have computer A whose IP address happens to be 192.168.0.81
. This computer has a web server installed and exposes port 80. So typing 192.168.0.81
in the web browser address bar of any other computer of this local network displays this webpage.
But I also have another computer in this local network: 192.168.0.129
And my task is to configure the two in such a way that 192.168.0.129
will be a NAT gateway for 192.168.0.81
. All packets sent by 192.168.0.81
must go through 192.168.0.129
and 192.168.0.129
must forward all traffic it receives on port 80 to 192.168.0.81
.
Solution attempt. Execute this on server to hopefully make it send its responses through 192.168.0.129
:
route add default gw 192.168.0.129
Execute this on gateway to hopefully allow it to forward traffic from server to outside world:
echo 1 > /proc/sys/net/ipv4/ip_forward
Execute this on gateway to hopefully make it forward traffic it receives to server:
iptables -t nat -A PREROUTING -p tcp -d 192.168.0.129 --dport 80 -j DNAT --to 192.168.0.81:80
Yet it doesn't work. Typing 192.168.0.129
in the web browser address bar of another computer in this network (192.168.0.185
) displays browser error rather than this webpage. What am I doing wrong?
In an effort to somehow find out what's going on I tried logging all packets by issuing on both machines:
iptables -A INPUT -j LOG
iptables -A OUTPUT -j LOG
These are the results. It seems the server receives packets from the original request maker and tries to send some packets back. I'm seeing entries of this sort:
Dec 19 23:23:25 debian kernel: (...) IN= OUT=eth0 MAC=(...) SRC=192.168.0.185 DST=192.168.0.81 LEN=60 TOS=0x00 PREC=(blah blah this and subsequent stuff omitted for brevity)
Dec 19 23:23:25 debian kernel: (...) IN= OUT=eth0 SRC=192.168.0.81 DST=192.168.0.185 LEN=60 TOS=0x00 PREC=(...)
However, gateway's logs don't seem to show any relevant traffic.
How to fix this?
networking routing
|
show 1 more comment
Homework disclaimer...
So I have computer A whose IP address happens to be 192.168.0.81
. This computer has a web server installed and exposes port 80. So typing 192.168.0.81
in the web browser address bar of any other computer of this local network displays this webpage.
But I also have another computer in this local network: 192.168.0.129
And my task is to configure the two in such a way that 192.168.0.129
will be a NAT gateway for 192.168.0.81
. All packets sent by 192.168.0.81
must go through 192.168.0.129
and 192.168.0.129
must forward all traffic it receives on port 80 to 192.168.0.81
.
Solution attempt. Execute this on server to hopefully make it send its responses through 192.168.0.129
:
route add default gw 192.168.0.129
Execute this on gateway to hopefully allow it to forward traffic from server to outside world:
echo 1 > /proc/sys/net/ipv4/ip_forward
Execute this on gateway to hopefully make it forward traffic it receives to server:
iptables -t nat -A PREROUTING -p tcp -d 192.168.0.129 --dport 80 -j DNAT --to 192.168.0.81:80
Yet it doesn't work. Typing 192.168.0.129
in the web browser address bar of another computer in this network (192.168.0.185
) displays browser error rather than this webpage. What am I doing wrong?
In an effort to somehow find out what's going on I tried logging all packets by issuing on both machines:
iptables -A INPUT -j LOG
iptables -A OUTPUT -j LOG
These are the results. It seems the server receives packets from the original request maker and tries to send some packets back. I'm seeing entries of this sort:
Dec 19 23:23:25 debian kernel: (...) IN= OUT=eth0 MAC=(...) SRC=192.168.0.185 DST=192.168.0.81 LEN=60 TOS=0x00 PREC=(blah blah this and subsequent stuff omitted for brevity)
Dec 19 23:23:25 debian kernel: (...) IN= OUT=eth0 SRC=192.168.0.81 DST=192.168.0.185 LEN=60 TOS=0x00 PREC=(...)
However, gateway's logs don't seem to show any relevant traffic.
How to fix this?
networking routing
You seem to be mixing what is the destination and source... Better drawing in a sheet of poster in this cases. The route also does not seem to be needed.
– Rui F Ribeiro
Dec 19 '18 at 22:40
@RuiFRibeiro Am I? I'm re-reading my Q but can't find such a mistake. Could you point me where I mixed them?
– gaazkam
Dec 19 '18 at 22:44
Kind of late and sleepy here, but in the iptables rule I think it should be tcp -s ....129 (and not -d)
– Rui F Ribeiro
Dec 19 '18 at 23:05
@RuiFRibeiro Not sure, why? My thinking is that the gateway is supposed to forward packets sent to it (hence -d) to the server? With-s 196.168.0.129
the gateway will only forward to the server the packets it sends on its own. Either way, tried putting -s instead of -d, and now the server doesn't seem to receive any packets when ...185 makes its request :(
– gaazkam
Dec 20 '18 at 9:27
Forwarding only works between different subnets. You are trying to route traffic on the same physical (layer 2) network through a gateway, which won't work (unless the .129 machine works like a bridge with two distinct network interfaces, but then again that's not forwarding really, that's bridging).
– wurtel
Dec 20 '18 at 10:47
|
show 1 more comment
Homework disclaimer...
So I have computer A whose IP address happens to be 192.168.0.81
. This computer has a web server installed and exposes port 80. So typing 192.168.0.81
in the web browser address bar of any other computer of this local network displays this webpage.
But I also have another computer in this local network: 192.168.0.129
And my task is to configure the two in such a way that 192.168.0.129
will be a NAT gateway for 192.168.0.81
. All packets sent by 192.168.0.81
must go through 192.168.0.129
and 192.168.0.129
must forward all traffic it receives on port 80 to 192.168.0.81
.
Solution attempt. Execute this on server to hopefully make it send its responses through 192.168.0.129
:
route add default gw 192.168.0.129
Execute this on gateway to hopefully allow it to forward traffic from server to outside world:
echo 1 > /proc/sys/net/ipv4/ip_forward
Execute this on gateway to hopefully make it forward traffic it receives to server:
iptables -t nat -A PREROUTING -p tcp -d 192.168.0.129 --dport 80 -j DNAT --to 192.168.0.81:80
Yet it doesn't work. Typing 192.168.0.129
in the web browser address bar of another computer in this network (192.168.0.185
) displays browser error rather than this webpage. What am I doing wrong?
In an effort to somehow find out what's going on I tried logging all packets by issuing on both machines:
iptables -A INPUT -j LOG
iptables -A OUTPUT -j LOG
These are the results. It seems the server receives packets from the original request maker and tries to send some packets back. I'm seeing entries of this sort:
Dec 19 23:23:25 debian kernel: (...) IN= OUT=eth0 MAC=(...) SRC=192.168.0.185 DST=192.168.0.81 LEN=60 TOS=0x00 PREC=(blah blah this and subsequent stuff omitted for brevity)
Dec 19 23:23:25 debian kernel: (...) IN= OUT=eth0 SRC=192.168.0.81 DST=192.168.0.185 LEN=60 TOS=0x00 PREC=(...)
However, gateway's logs don't seem to show any relevant traffic.
How to fix this?
networking routing
Homework disclaimer...
So I have computer A whose IP address happens to be 192.168.0.81
. This computer has a web server installed and exposes port 80. So typing 192.168.0.81
in the web browser address bar of any other computer of this local network displays this webpage.
But I also have another computer in this local network: 192.168.0.129
And my task is to configure the two in such a way that 192.168.0.129
will be a NAT gateway for 192.168.0.81
. All packets sent by 192.168.0.81
must go through 192.168.0.129
and 192.168.0.129
must forward all traffic it receives on port 80 to 192.168.0.81
.
Solution attempt. Execute this on server to hopefully make it send its responses through 192.168.0.129
:
route add default gw 192.168.0.129
Execute this on gateway to hopefully allow it to forward traffic from server to outside world:
echo 1 > /proc/sys/net/ipv4/ip_forward
Execute this on gateway to hopefully make it forward traffic it receives to server:
iptables -t nat -A PREROUTING -p tcp -d 192.168.0.129 --dport 80 -j DNAT --to 192.168.0.81:80
Yet it doesn't work. Typing 192.168.0.129
in the web browser address bar of another computer in this network (192.168.0.185
) displays browser error rather than this webpage. What am I doing wrong?
In an effort to somehow find out what's going on I tried logging all packets by issuing on both machines:
iptables -A INPUT -j LOG
iptables -A OUTPUT -j LOG
These are the results. It seems the server receives packets from the original request maker and tries to send some packets back. I'm seeing entries of this sort:
Dec 19 23:23:25 debian kernel: (...) IN= OUT=eth0 MAC=(...) SRC=192.168.0.185 DST=192.168.0.81 LEN=60 TOS=0x00 PREC=(blah blah this and subsequent stuff omitted for brevity)
Dec 19 23:23:25 debian kernel: (...) IN= OUT=eth0 SRC=192.168.0.81 DST=192.168.0.185 LEN=60 TOS=0x00 PREC=(...)
However, gateway's logs don't seem to show any relevant traffic.
How to fix this?
networking routing
networking routing
edited Dec 20 '18 at 9:28
asked Dec 19 '18 at 22:32
gaazkam
3531514
3531514
You seem to be mixing what is the destination and source... Better drawing in a sheet of poster in this cases. The route also does not seem to be needed.
– Rui F Ribeiro
Dec 19 '18 at 22:40
@RuiFRibeiro Am I? I'm re-reading my Q but can't find such a mistake. Could you point me where I mixed them?
– gaazkam
Dec 19 '18 at 22:44
Kind of late and sleepy here, but in the iptables rule I think it should be tcp -s ....129 (and not -d)
– Rui F Ribeiro
Dec 19 '18 at 23:05
@RuiFRibeiro Not sure, why? My thinking is that the gateway is supposed to forward packets sent to it (hence -d) to the server? With-s 196.168.0.129
the gateway will only forward to the server the packets it sends on its own. Either way, tried putting -s instead of -d, and now the server doesn't seem to receive any packets when ...185 makes its request :(
– gaazkam
Dec 20 '18 at 9:27
Forwarding only works between different subnets. You are trying to route traffic on the same physical (layer 2) network through a gateway, which won't work (unless the .129 machine works like a bridge with two distinct network interfaces, but then again that's not forwarding really, that's bridging).
– wurtel
Dec 20 '18 at 10:47
|
show 1 more comment
You seem to be mixing what is the destination and source... Better drawing in a sheet of poster in this cases. The route also does not seem to be needed.
– Rui F Ribeiro
Dec 19 '18 at 22:40
@RuiFRibeiro Am I? I'm re-reading my Q but can't find such a mistake. Could you point me where I mixed them?
– gaazkam
Dec 19 '18 at 22:44
Kind of late and sleepy here, but in the iptables rule I think it should be tcp -s ....129 (and not -d)
– Rui F Ribeiro
Dec 19 '18 at 23:05
@RuiFRibeiro Not sure, why? My thinking is that the gateway is supposed to forward packets sent to it (hence -d) to the server? With-s 196.168.0.129
the gateway will only forward to the server the packets it sends on its own. Either way, tried putting -s instead of -d, and now the server doesn't seem to receive any packets when ...185 makes its request :(
– gaazkam
Dec 20 '18 at 9:27
Forwarding only works between different subnets. You are trying to route traffic on the same physical (layer 2) network through a gateway, which won't work (unless the .129 machine works like a bridge with two distinct network interfaces, but then again that's not forwarding really, that's bridging).
– wurtel
Dec 20 '18 at 10:47
You seem to be mixing what is the destination and source... Better drawing in a sheet of poster in this cases. The route also does not seem to be needed.
– Rui F Ribeiro
Dec 19 '18 at 22:40
You seem to be mixing what is the destination and source... Better drawing in a sheet of poster in this cases. The route also does not seem to be needed.
– Rui F Ribeiro
Dec 19 '18 at 22:40
@RuiFRibeiro Am I? I'm re-reading my Q but can't find such a mistake. Could you point me where I mixed them?
– gaazkam
Dec 19 '18 at 22:44
@RuiFRibeiro Am I? I'm re-reading my Q but can't find such a mistake. Could you point me where I mixed them?
– gaazkam
Dec 19 '18 at 22:44
Kind of late and sleepy here, but in the iptables rule I think it should be tcp -s ....129 (and not -d)
– Rui F Ribeiro
Dec 19 '18 at 23:05
Kind of late and sleepy here, but in the iptables rule I think it should be tcp -s ....129 (and not -d)
– Rui F Ribeiro
Dec 19 '18 at 23:05
@RuiFRibeiro Not sure, why? My thinking is that the gateway is supposed to forward packets sent to it (hence -d) to the server? With
-s 196.168.0.129
the gateway will only forward to the server the packets it sends on its own. Either way, tried putting -s instead of -d, and now the server doesn't seem to receive any packets when ...185 makes its request :(– gaazkam
Dec 20 '18 at 9:27
@RuiFRibeiro Not sure, why? My thinking is that the gateway is supposed to forward packets sent to it (hence -d) to the server? With
-s 196.168.0.129
the gateway will only forward to the server the packets it sends on its own. Either way, tried putting -s instead of -d, and now the server doesn't seem to receive any packets when ...185 makes its request :(– gaazkam
Dec 20 '18 at 9:27
Forwarding only works between different subnets. You are trying to route traffic on the same physical (layer 2) network through a gateway, which won't work (unless the .129 machine works like a bridge with two distinct network interfaces, but then again that's not forwarding really, that's bridging).
– wurtel
Dec 20 '18 at 10:47
Forwarding only works between different subnets. You are trying to route traffic on the same physical (layer 2) network through a gateway, which won't work (unless the .129 machine works like a bridge with two distinct network interfaces, but then again that's not forwarding really, that's bridging).
– wurtel
Dec 20 '18 at 10:47
|
show 1 more comment
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f490028%2fhow-can-i-set-a-gateway-in-a-local-network%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f490028%2fhow-can-i-set-a-gateway-in-a-local-network%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
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
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
You seem to be mixing what is the destination and source... Better drawing in a sheet of poster in this cases. The route also does not seem to be needed.
– Rui F Ribeiro
Dec 19 '18 at 22:40
@RuiFRibeiro Am I? I'm re-reading my Q but can't find such a mistake. Could you point me where I mixed them?
– gaazkam
Dec 19 '18 at 22:44
Kind of late and sleepy here, but in the iptables rule I think it should be tcp -s ....129 (and not -d)
– Rui F Ribeiro
Dec 19 '18 at 23:05
@RuiFRibeiro Not sure, why? My thinking is that the gateway is supposed to forward packets sent to it (hence -d) to the server? With
-s 196.168.0.129
the gateway will only forward to the server the packets it sends on its own. Either way, tried putting -s instead of -d, and now the server doesn't seem to receive any packets when ...185 makes its request :(– gaazkam
Dec 20 '18 at 9:27
Forwarding only works between different subnets. You are trying to route traffic on the same physical (layer 2) network through a gateway, which won't work (unless the .129 machine works like a bridge with two distinct network interfaces, but then again that's not forwarding really, that's bridging).
– wurtel
Dec 20 '18 at 10:47