0

i am having issues with my raspberry pi zero W. so my setup is like this: I have a laptop which is connected to the internet over wifi (fedora 27 workstation) on interface wlp4s0.

now i want to bring the pi online by forwarding the traffic from my pi over the usb/ethernet through my computer to the router

I have connected my Rpi zero W over usb to my computer and installed P4wnP1 from here https://github.com/mame82/P4wnP1 by flashing stretch lite first and then cloning the repo and running the install.sh script.

Now the ip configured from that script is 172.16.0.1 and i can ssh to it by first setting the ip address of my usb /ethernet (whatever, im not sure what it is) interface to 172.16.0.2

apparently the names of my interfaces are kinda weird, but it is called enp0s20f0u6i3
btw can anyone tell me why my interface names are so weird?

so after changing the ip address of my interface i ssh into my pi and set my gateway with sudo route add -net default gw 172.16.0.2

now when i try to ping for example 8.8.8.8 from my pi i get

pi@MAME82-P4WNP1:~ $ ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
From 172.16.0.2 icmp_seq=1 Destination Port Unreachable
From 172.16.0.2 icmp_seq=2 Destination Port Unreachable
^C
--- 8.8.8.8 ping statistics ---
2 packets transmitted, 0 received, +2 errors, 100% packet loss, time 1001ms

my ifconfig on my computer looks like this

$ ifconfig
enp0s20f0u6: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::63c0:ffbc:48f3:107d  prefixlen 64  scopeid 0x20<link>
        ether fe:ac:74:85:37:dd  txqueuelen 1000  (Ethernet)
        RX packets 6  bytes 424 (424.0 B)
        RX errors 1  dropped 0  overruns 0  frame 0
        TX packets 20  bytes 4155 (4.0 KiB)
        TX errors 290  dropped 0 overruns 0  carrier 0  collisions 0

enp0s20f0u6i3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.16.0.2  netmask 255.255.0.0  broadcast 172.16.255.255
        inet6 fe80::c950:4a09:60ad:ff88  prefixlen 64  scopeid 0x20<link>
        ether 42:63:65:12:34:56  txqueuelen 1000  (Ethernet)
        RX packets 1013  bytes 72317 (70.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 679  bytes 75610 (73.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp0s31f6: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether c8:5b:76:6b:e4:90  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 16  memory 0xf1200000-f1220000  

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 391  bytes 37964 (37.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 391  bytes 37964 (37.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:08:e4:d3  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlp4s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.2.106  netmask 255.255.255.0  broadcast 192.168.2.255
        inet6 fe80::ebcf:d3b1:5a74:185e  prefixlen 64  scopeid 0x20<link>
        ether e4:a7:a0:99:2e:8d  txqueuelen 1000  (Ethernet)
        RX packets 7185  bytes 3038480 (2.8 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 7161  bytes 1399795 (1.3 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

and on my pi

pi@MAME82-P4WNP1:~ $ ifconfig
lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

usb1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.16.0.1  netmask 255.255.255.252  broadcast 172.16.0.3
        inet6 fe80::4063:65ff:fe65:4321  prefixlen 64  scopeid 0x20<link>
        ether 42:63:65:65:43:21  txqueuelen 1000  (Ethernet)
        RX packets 753  bytes 72772 (71.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1126  bytes 95763 (93.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.24.0.1  netmask 255.255.255.0  broadcast 172.24.0.255
        inet6 fe80::ba27:ebff:fe5e:ceb7  prefixlen 64  scopeid 0x20<link>
        ether b8:27:eb:5e:ce:b7  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 12  bytes 1216 (1.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

route -n on my computer:

$ route -n  
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.2.1     0.0.0.0         UG    600    0        0 wlp4s0
172.16.0.0      0.0.0.0         255.255.0.0     U     0      0        0 enp0s20f0u6i3
192.168.2.0     0.0.0.0         255.255.255.0   U     600    0        0 wlp4s0
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0

and on my pi:

pi@MAME82-P4WNP1:~ $ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.16.0.2      0.0.0.0         UG    0      0        0 usb1
172.16.0.0      0.0.0.0         255.255.255.252 U     0      0        0 usb1
172.24.0.0      0.0.0.0         255.255.255.0   U     0      0        0 wlan0

resolv.conf on my pi

pi@MAME82-P4WNP1:~ $ cat /etc/resolv.conf
# Generated by resolvconf
nameserver 10.46.0.1
nameserver 8.8.8.8
nameserver 8.8.4.4

and /etc/network/interfaces on my pi:

pi@MAME82-P4WNP1:~ $ cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d


dns-nameservers 8.8.8.8 8.8.4.4

auto usb0

iface usb0 inet manual

auto usb1

iface usb1 inet manual

I have been searching for a solution for almost 2 days now (like all day), but nothing worked.

although i could install git and clone the repo before i ran the install.sh file. But back then my pi did not have a static ip address, it would always be 169.254.xxx.xxx (pretty random). I retrieved the ip address from the pi with sudo tshark -i (interface) and then changed the ip of my interface to ssh into the pi.

i have tried so many things, like rebooted 20 times after making changes to resolv.conf or /etc/network/interfaces on the pi, but nothing worked.

can anyone help me with this?

And i think the problem is not the gateway on the pi. I think it is something on fedora that prevents the traffic from being rerouted.

I really don't know what to do. I just want the pi to get online.

any help would be very much appreciated.

UPDATE: all i needed to do was reset my iptables, i.e. iptables -F and set the outbound rule again iptables -t nat -A POSTROUTING -o wlp4s0 -j MASQUERADE. But I need to do this everytime I restart my computer and I cannot find a workaround to that. Maybe someone has an idea.

0

Flying over your initial description everything seems fine.

But two things are missing: - The host seems to have kernel IPv4 routing disabled - The host has no NAT/Masquerading on the outbound interface

Assuming wlp4s0 is your upstream interface (which seems so from the routing entries), enable outbound masquerading with something like:

iptables -t nat -A POSTROUTING -o wlp4s0 -j MASQUERADE

This will replace the source IP of every packet directed to wlp4s0 by the IP of this interface (src 172.16.0.1 is translated to 192.168.2.106).

In order to allow forwarding packets from the USB interface to the upstream interface, at all, run sth. like:

echo 1 > /proc/sys/net/ipv4/ip_forward

  • yes I did that. The problem was that I looked it up online and all the suggestions didn't work at first, so all the rules I set were messing everything up. So all I had to do was 'iptables -F' to reset and then set the rules. Thanks a lot for answering to my post though, I appreciate that. I also posted my problem here: unix.stackexchange.com/questions/418908/… you will find a detailed summary there as well. – Pink Panther Feb 6 '18 at 19:00
  • although strangely every time i reboot my computer i have to clear the iptables again and add the iptables -t nat -A POSTROUTING -o wlp4s0 -j MASQUERADE rule. Is there a way to make these changes persistent? I somehow cannot manage to do that – Pink Panther Feb 6 '18 at 19:11
0

Wait - change nothing!

You can enable ether over USB with two small changes on the base Stretch or Jessie Raspibian image.

Boot up your RPi and log in.

  1. Edit your /boot/config.txt file adding this line to the very bottom:

dtoverlay=dwc2

  1. Edit yoru /boot/cmdline.txt file next. Add this after the root wait parameter. Add no additional spaces or new lines.

modules-load=dwc2,g_ether

Next, simply ensure you plug in your RPi into the USB port, not power. And you can then SSH into your RPi via:

ssh pi@raspberrypi.local

And more importantly - your RPi now shares your host computers internet connection.

As a side note. The new network names are apart of Debian Stretch for hardware naming consistency. Otherwise known as Predictable Network Interface Names.

  • I did as you said, but it is still not working. and i have done those steps at the very beginning of my installation of stretch lite, but strangely modules-load=dwc2,g_ether was gone, but dtoverlay=dwc2 was still there. I still get destination port unreachable. – Pink Panther Jan 22 '18 at 7:45
  • my /boot/cmdline.txt looks like this dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=PARTUUID=99af8976-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait modules-load=dwc2,g_ether – Pink Panther Jan 22 '18 at 7:52
  • I think i found my error. when i change the ip of my interface the rules in iptables will still have the old ip address. how can i setup my rules accordingly to the new ip address? im sorry but i don't know how to work with ip tabes, i tried looking it up, but i am not able to add entries in the Chain FORWARD (policy ACCEPT) block. thanks in advance – Pink Panther Jan 22 '18 at 9:10
  • 1
    i got it to work now, all i had to do is sudo iptables -F, i.e. reset all chains. – Pink Panther Jan 22 '18 at 19:46

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.