2

I have a raspberry pi 3 and I'm currently using it as a internet hotspot: I use a ethernet cable to get the connection, and the WiFi card to share it. (Eth0 --> Wlan0). The only problem with this is that I can't do any port forwarding with the devices connected to it... I have searched for many hours with no successful results, I tried 'iptables' (which i'm not familiar with...) with still no success...
So here are some infos that might help: (ifconfig on the raspberry pi)

pi@raspberrypi:~ $ ifconfig
eth0      Link encap:Ethernet  HWaddr b8:27:eb:1b:c6:ec  
          inet addr:192.168.0.37  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: 2a01:e35:2f32:7120:ba27:ebff:fe1b:c6ec/64 Scope:Global
          inet6 addr: fe80::ba27:ebff:fe1b:c6ec/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:789 errors:0 dropped:1 overruns:0 frame:0
          TX packets:344 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:73638 (71.9 KiB)  TX bytes:43983 (42.9 KiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:180 errors:0 dropped:0 overruns:0 frame:0
          TX packets:180 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:12958 (12.6 KiB)  TX bytes:12958 (12.6 KiB)

wlan0     Link encap:Ethernet  HWaddr b8:27:eb:4e:93:b9  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:13 errors:0 dropped:13 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:2775 (2.7 KiB)  TX bytes:0 (0.0 B)  

And 'ifconfig' on my PC:

nuf@nufPC ~ $ ifconfig
enp4s0f2  Link encap:Ethernet  HWaddr 74:d0:2b:ba:93:db  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:1552790 errors:0 dropped:0 overruns:0 frame:0
          TX packets:880671 errors:0 dropped:7 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1836089487 (1.8 GB)  TX bytes:99384524 (99.3 MB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:1279658 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1279658 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:88890909 (88.8 MB)  TX bytes:88890909 (88.8 MB)

wlp3s0    Link encap:Ethernet  HWaddr 24:fd:52:3c:f6:ee  
          inet addr:10.0.0.17  Bcast:10.0.0.255  Mask:255.255.255.0
          inet6 addr: fe80::675:363e:5f61:f10c/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:71245 errors:0 dropped:0 overruns:0 frame:0
          TX packets:49945 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:76745606 (76.7 MB)  TX bytes:7135427 (7.1 MB)  

So for exemple I would like to create a server which use the port 1337 I can't directly forward it to my box, I need to forward it to my Raspberry which forward it to my box I guess... I hope you can help me :)

3

I have used:

iptables --flush
iptables --table nat --flush
iptables --delete-chain
iptables --table nat --delete-chain
iptables --table nat --append POSTROUTING --out-interface eth0 -j MASQUERADE
iptables --append FORWARD --in-interface wlan0 -j ACCEPT

iptables -t nat -A PREROUTING -p tcp -m tcp --dport (PORT NUMBER) -j DNAT --to-destination (COMPUTER IP CONNECTED TO PI)
iptables -t nat -A POSTROUTING -d (COMPUTER IP CONNECTED TO PI) -p tcp -m tcp --dport (PORT NUMBER) -j MASQUERADE

Your Answer

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

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