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