USB-Ethernet to Wifi on Raspi Zero W

This forum is for topics specific to the Raspberry Pi and Arch Linux ARM

USB-Ethernet to Wifi on Raspi Zero W

Postby kay94 » Wed Nov 28, 2018 10:51 pm

Hi,

I'm having issues with my network setup. I want to give 'hp', which doesn't have wifi, access to the internet. I can't connect it to the router over Ethernet.
But I have a Raspi Zero W, which has wifi and also a device tree overlay to make the USB-OTG become an Ethernet over USB interface. I'm also planning for IPv6, but that's another story. For IPv4 it looks as follows:
$this->bbcode_second_pass_code('', '
________ ______________ ____
| Router |wifi --// //-- wlan0| Raspi Zero W |usb0 ------------ enp0s19f2u1| hp |
-------- -------------- ----
192.168.2.1/24 192.168.2.101/24 192.168.2.188/27
DHCP for 192.168.2.0/24 192.168.2.161/32
only from *.100 to *.150 DHCP for 192.168.2.160/27
')
The router is a crappy "Speedport".

Configuration on Raspberry Pi Zero W:
$this->bbcode_second_pass_code('', '
[root@pz ~]# cat /etc/systemd/system/own_wlan0_to_usb0.service
[Unit]
Description=USB-Ethernet to WLAN, 192.168.2.162 ... 192.168.2.190.
After=network.target

[Service]
Type=simple
Restart=on-failure
RestartSec=2s
ExecStartPre=/bin/sh /var/lib/dnsmasq/wlan0_to_usb0/script.sh
ExecStart=/usr/sbin/dnsmasq -k --conf-file=/var/lib/dnsmasq/wlan0_to_usb0/dnsmasq.conf
ExecReload=/bin/kill -HUP $MAINPID
ExecStop=/usr/bin/ip route del 192.168.2.160/27 dev usb0
ExecStop=/usr/bin/ip address del 192.168.2.161/32 dev usb0
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
')
$this->bbcode_second_pass_code('', '
[root@pz ~]# cat /var/lib/dnsmasq/wlan0_to_usb0/script.sh
ip link set usb0 up
ip addr add 192.168.2.161/32 dev usb0
ip route add 192.168.2.160/27 dev usb0
echo 1 > /proc/sys/net/ipv4/conf/usb0/proxy_arp
echo 1 > /proc/sys/net/ipv4/conf/wlan0/proxy_arp
echo 1 > /proc/sys/net/ipv4/ip_forward
')
$this->bbcode_second_pass_code('', '
[root@pz ~]# head /var/lib/dnsmasq/wlan0_to_usb0/dnsmasq.conf
domain-needed
bogus-priv
dhcp-authoritative
interface=usb0
expand-hosts
dhcp-range=192.168.2.162,192.168.2.190,1h
')
$this->bbcode_second_pass_code('', '
[root@pz ~]# ip a
[...]
2: usb0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
inet 192.168.2.161/32 scope global usb0
valid_lft forever preferred_lft forever
inet6 fe80::xxxx:xxxx:xxxx:xxxx/64 scope link
valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
inet 192.168.2.101/24 brd 192.168.2.255 scope global dynamic wlan0
valid_lft 301sec preferred_lft 301sec
inet6 xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx/64 scope global dynamic mngtmpaddr noprefixroute
valid_lft 604800sec preferred_lft 86400sec
inet6 fe80::xxxx:xxxx:xxxx:xxxx/64 scope link stable-privacy
valid_lft forever preferred_lft forever
')
$this->bbcode_second_pass_code('', '
[root@pz ~]# ip ro
default via 192.168.2.1 dev wlan0 proto dhcp src 192.168.2.101 metric 1024
192.168.2.0/24 dev wlan0 proto kernel scope link src 192.168.2.101
192.168.2.1 dev wlan0 proto dhcp scope link src 192.168.2.101 metric 1024
192.168.2.160/27 dev usb0 scope link
')
Configuration on HP box:
$this->bbcode_second_pass_code('', '
[kay@hp ~]$ ip a
[...]
4: enp0s19f2u1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
inet 192.168.2.188/24 brd 192.168.2.255 scope global noprefixroute enp0s19f2u1
valid_lft forever preferred_lft forever
inet6 fe80::xxxx:xxxx:xxxx:xxxx/64 scope link
valid_lft forever preferred_lft forever
')
$this->bbcode_second_pass_code('', '
[kay@hp ~]$ ip ro
default via 192.168.2.161 dev enp0s19f2u1 proto dhcp src 192.168.2.188 metric 204
192.168.2.0/24 dev enp0s19f2u1 proto dhcp scope link src 192.168.2.188 metric 204
')
It basically works, but is very unreliable. The connection to the internet initially is either not possible at all (although DNS seems to work right away) or stops and doesn't come back after some time. However, I noticed, that if I do the following, bits start to flow again:
$this->bbcode_second_pass_code('', '
[root@pz ~]# tcpdump -i wlan0
')
I can abort tcpdump after a second and the connection is stable for some time, not too long though. Can this be related to the fact I'm connecting an ethernet to a wifi?

Might the problem be, that I'm running a second DHCP server, even though it doesn't interfere with the router's one? I didn't find a way to forward DHCP communication from the usb0-interface to the router, but I'd be be open to suggestions for that.

NAT is not an option.

Thanks in advance for any suggestions!
Regards
kay94
 
Posts: 4
Joined: Wed Nov 28, 2018 10:41 pm

Re: USB-Ethernet to Wifi on Raspi Zero W

Postby kay94 » Thu Dec 06, 2018 7:45 pm

I finally found a solution by asking a colleague: Had to enable "promiscuous mode" on both interfaces of the Pi Zero W:

$this->bbcode_second_pass_code('', '
root@pi:~# ip link set promisc on dev usb0
root@pi:~# ip link set promisc on dev wlan0
')

Promiscuous mode tells the link-layer (layer 2, ethernet, below IP) to also listen to frames, which are not for the own MAC-address -- which is obviously, what tcpdump does while being active. Otherwise, AFAIK, those packets are just discarded and don't reach the IP or ARP layer (layer 3) at all (where they would be forwarded to the other interface, when there was a matching route or an ARP table entry).
kay94
 
Posts: 4
Joined: Wed Nov 28, 2018 10:41 pm

Re: USB-Ethernet to Wifi on Raspi Zero W

Postby bluescreener » Tue Mar 05, 2019 12:46 pm

You could also archive this by creating a bridge (layer 2) device on the Pi. That way your host HP would be assigned a DHCP lease directly from your router and the Pi could keep a single ip address (also assigned via DHCP).

Create the bridge and bring the interfaces up

$this->bbcode_second_pass_code('', '#ip link add br0 type bridge
#ip link set br0 up
#ip link set usb0 up
#ip link set wlan0 up ')

-Add interfaces to the bridge
$this->bbcode_second_pass_code('', '#ip link set dev usb0 master br0
#ip link set dev wlan0 master br0')

-Remove ip addresses from the interfaces
-Assign ip address to the bridge
$this->bbcode_second_pass_code('', 'ip address add 192.168.2.101/24 dev br0')
bluescreener
 
Posts: 4
Joined: Tue Mar 05, 2019 12:23 pm

Re: USB-Ethernet to Wifi on Raspi Zero W

Postby summers » Wed Mar 06, 2019 3:57 pm

Out of interest what route do you have have your router? I have a similar set up. On my router:
$this->bbcode_second_pass_code('', 'ip route
default via 195.166.xxx.xxx dev pppoa-wan
192.168.2.0/24 dev br-lan scope link src 192.168.2.1
192.168.7.0/24 via 192.168.2.111 dev br-lan
195.166.xxx.xxx dev pppoa-wan scope link src 84.93.xxx.xxx')
So in my case, my beagle network (192.168.7.*) live on my nas (192.168.2.111). And my router knows that all packets for the beagle network go via the nas. On the nas the route was set up by just bring up the interfaces.
$this->bbcode_second_pass_code('', 'ip route
default via 192.168.2.1 dev eth0 proto dhcp src 192.168.2.111 metric 1024
192.168.2.0/24 dev eth0 proto kernel scope link src 192.168.2.111
192.168.2.1 dev eth0 proto dhcp scope link src 192.168.2.111 metric 1024
192.168.7.16/30 dev usb0 proto dhcp scope link src 192.168.7.17 metric 203')
This means that *everyone* knows how to send packets to and from the beagle network.

Thats the hassle of not NATing, everyone needs to know where to send packets ...
summers
 
Posts: 984
Joined: Sat Sep 06, 2014 12:56 pm


Return to Raspberry Pi

Who is online

Users browsing this forum: No registered users and 12 guests