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 must forward all traffic it receives on port 80 to
Solution attempt. Execute this on server to hopefully make it send its responses through
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?