garywill / linux-router

Set Linux as router in one command. Support Internet sharing, redsocks, Wifi hotspot, IPv6. Can also be used for routing VM/containers 🛰️
GNU Lesser General Public License v2.1
1.73k stars 155 forks source link

Unable to create wifi-hotspot on Raspberry Pi 3 #46

Closed andber1 closed 8 months ago

andber1 commented 2 years ago

The raspberry only has a wlan interface, no ethernet. I want to create a wifi hotspot on the raspberry so that I can connect to the raspberry from other devices (e.g. via ssh). I tried the following command: sudo lnxrouter -n --ap wlan0 MyAccessPoint --no-virt Beforehand I disabled wifi via sudo rfkill block wifi.

I can see the message Setting up completed.... The hotspot is present for a few seconds, but then disappears. After a few seconds I get this message: dnsmasq: failed to create listening socket for 192.168.178.28: Address already in use However, the used IP address is 192.168.19.1 and DHCP range is 192.168.19.10 - 192.168.19.250.

Am I using lnxrouter wrong, do I have to configure something beforehand or is this a bug? Thanks very much for any help.

garywill commented 2 years ago

Please provide more log:

  1. full log of lnxrouter running (use lnxrouter -g 192.168.19.1 to have a fixed ip)
  2. sudo ss -tulpn
  3. ip addr
  4. ip route
andber1 commented 2 years ago

I should mention that wlan0 is used for internet connection on the raspberry (ip range 192.168.178.0/24 is my local network with internet connection). I want to create a hotspot on wlan0 without internet connection instead. I tried to disable wlan0 via sudo rfkill block wifi and sudo systemctl disable wpa_supplicant. But creating a hotspot still does not work. The raspberry image is untouched, only wlan was configured for internet connection.

Here the logs: 1.

$ sudo lnxrouter -n --ap wlan0 MyAccessPoint --no-virt --country DE -g 192.168.19.1
WARN: brmfmac driver doesn't work properly with virtual interfaces and
      it can cause kernel panic. For this reason we disallow virtual
      interfaces for your adapter.
      For more info: https://github.com/oblique/create_ap/issues/203
linux-router 0.6.6 (https://github.com/garywill/linux-router)
Released under LGPL, with no warranty. Use on your own risk.

PID: 1636
Target interface is wlan0 (b8:27:eb:4a:fd:e8) 
WARN: WiFi is not protected by password

haveged_watchdog PID: 1709

Starting hostapd
WARN: Low entropy detected. We recommend you to install `haveged'
hostapd PID: 1714
Configuration file: /dev/shm/lnxrouter_tmp/lnxrouter.wlan0.conf.fzUBF6/hostapd.conf
wlan0: interface state UNINITIALIZED->COUNTRY_UPDATE
Using interface wlan0 with hwaddr b8:27:eb:4a:fd:e8 and ssid "MyAccessPoint"
wlan0: interface state COUNTRY_UPDATE->ENABLED
wlan0: AP-ENABLED 

iptables v1.8.7 (nf_tables)
NOTICE: Not showing all operations done to iptables rules
No Internet sharing

WARN: Since you're using in this mode (no Internet share), make sure you've read Notice 1

iptables: allow DNS
ACCEPT  tcp opt -- in wlan0 out *  192.168.19.0/24  -> 192.168.19.1   tcp dpt:53 /* lrt1636wlan0 */
ACCEPT  udp opt -- in wlan0 out *  192.168.19.0/24  -> 192.168.19.1   udp dpt:53 /* lrt1636wlan0 */

iptables: allow dhcp
ACCEPT  udp opt -- in wlan0 out *  0.0.0.0/0  -> 0.0.0.0/0   udp dpt:67 /* lrt1636wlan0 */

Starting dnsmasq
Sep 26 15:36:51 dnsmasq[1735]: started, version 2.85 cachesize 150
Sep 26 15:36:51 dnsmasq[1735]: compile time options: IPv6 GNU-getopt DBus no-UBus i18n IDN2 DHCP DHCPv6 no-Lua TFTP conntrack ipset auth cryptohash DNSSEC loop-detect inotify dumpfile
Sep 26 15:36:51 dnsmasq[1735]: warning: no upstream servers configured
Sep 26 15:36:51 dnsmasq-dhcp[1735]: DHCP, IP range 192.168.19.10 -- 192.168.19.250, lease time 1h
Sep 26 15:36:51 dnsmasq-dhcp[1735]: DHCP, sockets bound exclusively to interface wlan0
Sep 26 15:36:51 dnsmasq[1735]: cleared cache
dnsmasq PID: 1735

== Setting up completed, now linux-router should be working ==
Sep 26 15:36:59 dnsmasq[1735]: failed to create listening socket for 169.254.72.198: Address already in use

2.

$ sudo ss -tulpn
Netid State  Recv-Q Send-Q  Local Address:Port  Peer Address:PortProcess                                
udp   UNCONN 0      0             0.0.0.0:5353       0.0.0.0:*    users:(("avahi-daemon",pid=325,fd=12))
udp   UNCONN 0      0      192.168.178.28:53         0.0.0.0:*    users:(("dnsmasq",pid=1173,fd=10))    
udp   UNCONN 0      0        192.168.19.1:53         0.0.0.0:*    users:(("dnsmasq",pid=1173,fd=6))     
udp   UNCONN 0      0             0.0.0.0:53         0.0.0.0:*    users:(("dnsmasq",pid=471,fd=4))      
udp   UNCONN 0      0             0.0.0.0:37686      0.0.0.0:*    users:(("avahi-daemon",pid=325,fd=14))
udp   UNCONN 0      0             0.0.0.0:67         0.0.0.0:*    users:(("dnsmasq",pid=1173,fd=4))     
udp   UNCONN 0      0             0.0.0.0:68         0.0.0.0:*    users:(("dhcpcd",pid=778,fd=13))      
udp   UNCONN 0      0                   *:5353             *:*    users:(("avahi-daemon",pid=325,fd=13))
udp   UNCONN 0      0                   *:53               *:*    users:(("dnsmasq",pid=471,fd=6))      
udp   UNCONN 0      0                   *:47949            *:*    users:(("avahi-daemon",pid=325,fd=15))
tcp   LISTEN 0      32            0.0.0.0:53         0.0.0.0:*    users:(("dnsmasq",pid=471,fd=5))      
tcp   LISTEN 0      128           0.0.0.0:22         0.0.0.0:*    users:(("sshd",pid=454,fd=3))         
tcp   LISTEN 0      32               [::]:53            [::]:*    users:(("dnsmasq",pid=471,fd=7))      
tcp   LISTEN 0      128              [::]:22            [::]:*    users:(("sshd",pid=454,fd=4))         

3.

$ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether b8:27:eb:4a:fd:e8 brd ff:ff:ff:ff:ff:ff
    inet 192.168.19.1/24 brd 192.168.19.255 scope global wlan0
       valid_lft forever preferred_lft forever
    inet 192.168.178.28/24 brd 192.168.178.255 scope global dynamic noprefixroute wlan0
       valid_lft 863947sec preferred_lft 755947sec

4.

$ ip route
default via 192.168.178.1 dev wlan0 proto dhcp src 192.168.178.28 metric 302 
192.168.19.0/24 dev wlan0 proto kernel scope link src 192.168.19.1 
192.168.178.0/24 dev wlan0 proto dhcp scope link src 192.168.178.28 metric 302 
garywill commented 2 years ago

In your ss log

"dnsmasq",pid=1173
"dnsmasq",pid=471

In lnxrouter log

 dnsmasq[1735]: failed to create listening socket for 169.254.72.198

The system may be serving DNS using dnsmasq, which may cause conflict. (3 different dnsmasq PIDs above) Try terminate some system services ( systemd stop dnsmasq.service? I'm not sure) till the ss output doesn't show any dnsmasq or :53

andber1 commented 2 years ago

Thanks very much for your help. I have to stop dnsmasq and dhcpcd. This works now:

sudo systemctl stop dhcpcd.service
sudo systemctl stop dnsmasq.service
sudo lnxrouter -n --ap wlan0 MyAccessPoint --no-virt --country DE -g 192.168.19.1