0

I have 2 hosts: A and B inside 1 local network. (A ---> B)
Host A (192.168.1.1) has no access to the telegram server (149.154.167.50:80)
Host B (192.168.1.2) has an access (46-Ubuntu x86_64 GNU/Linux, ufw status: inactive)
I want to set-up 2 rules:

  • Host A should redirect all his local traffic that goes to 149.154.167.50 (port 80) --> to the host B.
  • Host B should accept incoming traffic on port 64080 and redirect it to 149.154.167.50:80

What I've done:

On the A side:

sysctl -w net.ipv4.ip_forward=1
sysctl -w net.ipv4.conf.eth0.route_localnet=1

iptables -t nat -I PREROUTING -d 149.154.167.50 -p tcp --dport 80 -j DNAT --to 192.168.1.2:64080
iptables -t nat -A POSTROUTING -j MASQUERADE

On the B side:

sudo iptables -t nat -A PREROUTING -p tcp --dport 64080 -j DNAT --to-destination 149.154.167.50:80
sudo iptables -t nat -A POSTROUTING -p tcp --dport 80 -d 149.154.167.50 -j SNAT --to-source 192.168.1.1
sudo iptables -A FORWARD -p tcp --dport 80 -d 149.154.167.50 -j ACCEPT

Also I've added an option to test it from the localhost (on the B host):

sudo iptables -t nat -A OUTPUT -p tcp --dport 64080 -d 192.168.1.1 -j DNAT --to-destination 149.154.167.50:80

It does not work because:
with curl I can connect from the B localhost: curl 192.168.1.1:64080 (successful + response)
from A host nothing happens when I try to do the same: curl 192.168.1.1:64080
Did I miss something?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.