1

So I currently have a Minecraft server running on a computer in my house and would like to port forward it. However, the computer is in a separate room to the router and doesn't have WiFi. In order to get around this issue I have setup a Raspberry Pi 3 which runs this code at startup in order to take the WiFi connection on the Pi and forward it to the Ethernet port.

This part is working fine, however, as this is running on a separate sub-net (192.168.2.* instead of the 192.168.1.* that my main router runs on) I am unable to access it unless I am connected to that particular sub-net thus, making it impossible to port forward as my router cannot physically see the server.

I am looking for a solution (ideally using iptables) that will take the port on the server connected to eth0 (192.168.2.93:19132) and make it accessible via the Pi (192.168.1.101:19132) so the I can port-forward the port on the Pi and it will give me access to the server externally.

Sorry for the long winded explanation, it's my first post and I don't really know how to explain what I'm trying to do, anymore info needed just ask. Thanks in advance!

2 Answers 2

0

This is not specific to the PI.

Use this command:

iptables -t nat -A PREROUTING -p tcp -d 192.168.2.93 --dport 19132 -j DNAT --to 192.168.1.101:19132

Replace tcp with udp if you need UDP.

The options -d and --dport specify the original destination host and port. DNAT means destination NAT, you want a different destination. --to sprcifies that destination. Table nat and chain PREROUTING is the place to do this.

Edit

You also need to make sure the there is a route back to the original host. The easiest way to do that is to point the default route on 192.168.1.101 to the address of the PI, that is the address of the PI on the eth0 interface.

3
  • Thank you very much, I will test this solution tonight and let you know how things go. Commented May 3, 2019 at 6:04
  • Okay, so I have just tried this out and it doesn't appear to work unfortunately. Running sudo iptables -S shows the rules created by wifi-to-eth-route.sh but not the command that you suggested. Also, when running nmap on 192.168.1.101 it shows that the port is not open and I am unable to connect to the server. Any ideas? Commented May 3, 2019 at 15:35
  • 1
    To show the rules in the nat table, use iptables -t nat -S. Run tcpdump -n -i any port 19132 to see the network traffic.
    – RalfFriedl
    Commented May 3, 2019 at 16:48
0

Okay, thank you very much for your time. This proved to be causing me more problems than it was worth and I managed to find an old USB WiFi dongle lying around so have set that up instead. If I had the knowledge of iptables I am sure your answer would've worked however, I find it very confusing :-(.

Just to clarify a few things, this setup is temporary for a friend who wants the server by the weekend, in time I will setup a proper Ethernet connection to solve the problem properly but I need to see how popular it will be for now (Minecraft's kinda old).

Also, as has previously been mentioned, this is not specific to the Pi and will work with any Linux OS that uses iptables however, I posted it under Raspberry Pi to be as precise as possible as I know the Pi has some slight quirks with some software that make it different to others.

Thanks to RalfFriedl for the time spent to answer my question, it's really appreciated and if I hadn't found a simpler solution I would've persevered and I'm sure his solution would've worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.