Spinkieieie
Posts: 1
Joined: Fri Oct 05, 2018 9:52 pm

Port forwarding to a different interface ip:port

Fri Oct 05, 2018 10:04 pm

Hi Guys,
I'm having some issues trying to forward traffic from a specific port on eth1 to an ip address and port on eth0.

For example 192.168.3.1 is my usb 4g stick and where my ddns is going to, eth1 is sitting on 192.168.3.10, and i need to forward traffic from outside on the ddns port 15201 through the pi on eth0(192.168.1.1) to 192.168.1.101:15201. I've got about 4 different ports to do.
I've allowed ipv4 forwarding and now i've got to iptables and i'm baffled, i've been trying along the lines of;

iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 15201 -o eth0 --destination 192.168.1.101:15201 but it won't stick..! and is saying host/network not found.

Is anyone able to help - as i'm starting to go bald!
Also, is there an easy way to create eth1 as the default nic and gateway?

Kind Regards,
Steve

SurferTim
Posts: 1769
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Port forwarding to a different interface ip:port

Sat Oct 06, 2018 2:20 pm

This works with some devices.

Code: Select all

sudo iptables -t nat -A PREROUTING -p tcp --dport 8080 -j DNAT --to-destination 192.168.4.144:80
Edit /etc/sysctl.conf and uncomment

Code: Select all

net.ipv4.ip_forward=1

Return to “Networking and servers”