nmcli 热点 dhcp 不工作

nmcli 热点 dhcp 不工作

我在 Raspberry Pi 上运行了 ubuntu server arm64 22.04,用作 wifi 热点,互联网连接由蜂窝调制解调器提供。我使用 networkmanager 和 modemmanager 来管理连接。所有软件包都已更新。

我已经能够使用 nmcli 创建 wifi 热点,并且可以将其他设备连接到该热点,但连接的设备仍处于“自分配 ip”状态,没有获得 ip 地址、路由器或子网掩码。在测试时,我尚未设置调制解调器,因为在热点工作之前,我需要用于 ssh 的 usb 端口。

dnsmasq 已安装,因为我需要它来启用 usb-gadget 模式,这样我就可以 ssh 进入 rpi。按照此处的说明操作(https://lozworld.com/lozwords/raspberry-pi-4b-as-an-ubuntu-2110-usb-gadget-tethered-to-an-ipad-pro)我做了以下配置更改:/etc/dnsmasq.d/usb:

interface=usb0
dhcp-range=10.55.0.2,10.55.0.6,255.255.255.248,1h
dhcp-option=3
leasefile-ro
port=0

在 /etc/default/dnsmasq 中:

DNSMASQ_EXCEPT="lo"

以下是我用来创建热点的命令:

nmcli con add type wifi ifname wlan0 con-name Hostspot autoconnect yes ssid Hostspot
nmcli con modify Hostspot 802-11-wireless.mode ap 802-11-wireless.band bg ipv4.method shared
nmcli con modify Hostspot wifi-sec.key-mgmt wpa-psk
nmcli con modify Hostspot wifi-sec.psk "veryveryhardpassword1234"
nmcli con up Hostspot

当热点 nmcli 连接建立后,运行 systemctl restart dnsmasq.service 将返回

Jul 22 16:01:04 raspberrypi systemd[1]: Starting dnsmasq - A lightweight DHCP and caching DNS server...
Jul 22 16:01:04 raspberrypi dnsmasq[1722]: dnsmasq: failed to bind DHCP server socket: Address already in use
Jul 22 16:01:04 raspberrypi dnsmasq[1722]: failed to bind DHCP server socket: Address already in use
Jul 22 16:01:04 raspberrypi dnsmasq[1722]: FAILED to start up
Jul 22 16:01:04 raspberrypi systemd[1]: dnsmasq.service: Control process exited, code=exited, status=2/INVALIDARGUMENT
Jul 22 16:01:04 raspberrypi systemd[1]: dnsmasq.service: Failed with result 'exit-code'.
Jul 22 16:01:04 raspberrypi systemd[1]: Failed to start dnsmasq - A lightweight DHCP and caching DNS server.

以下是“nmcli con show”的输出:

connection.id:                          Hotspot
connection.uuid:                        afbf8081-cb19-4d5e-8517-38c222607984
connection.stable-id:                   --
connection.type:                        802-11-wireless
connection.interface-name:              wlan0
connection.autoconnect:                 yes
connection.autoconnect-priority:        0
connection.autoconnect-retries:         -1 (default)
connection.multi-connect:               0 (default)
connection.auth-retries:                -1
connection.timestamp:                   1658497260
connection.read-only:                   no
connection.permissions:                 --
connection.zone:                        --
connection.master:                      --
connection.slave-type:                  --
connection.autoconnect-slaves:          -1 (default)
connection.secondaries:                 --
connection.gateway-ping-timeout:        0
connection.metered:                     unknown
connection.lldp:                        default
connection.mdns:                        -1 (default)
connection.llmnr:                       -1 (default)
connection.dns-over-tls:                -1 (default)
connection.wait-device-timeout:         -1
802-11-wireless.ssid:                   horsies
802-11-wireless.mode:                   ap
802-11-wireless.band:                   bg
802-11-wireless.channel:                0
802-11-wireless.bssid:                  --
802-11-wireless.rate:                   0
802-11-wireless.tx-power:               0
802-11-wireless.mac-address:            --
802-11-wireless.cloned-mac-address:     --
802-11-wireless.generate-mac-address-mask:--
802-11-wireless.mac-address-blacklist:  --
802-11-wireless.mac-address-randomization:default
802-11-wireless.mtu:                    auto
802-11-wireless.seen-bssids:            E4:5F:01:97:CB:A2
802-11-wireless.hidden:                 no
802-11-wireless.powersave:              0 (default)
802-11-wireless.wake-on-wlan:           0x1 (default)
802-11-wireless.ap-isolation:           -1 (default)
802-11-wireless-security.key-mgmt:      wpa-psk
802-11-wireless-security.wep-tx-keyidx: 0
802-11-wireless-security.auth-alg:      --
802-11-wireless-security.proto:         --
802-11-wireless-security.pairwise:      --
802-11-wireless-security.group:         --
802-11-wireless-security.pmf:           0 (default)
802-11-wireless-security.leap-username: --
802-11-wireless-security.wep-key0:      <hidden>
802-11-wireless-security.wep-key1:      <hidden>
802-11-wireless-security.wep-key2:      <hidden>
802-11-wireless-security.wep-key3:      <hidden>
802-11-wireless-security.wep-key-flags: 0 (none)
802-11-wireless-security.wep-key-type:  unknown
802-11-wireless-security.psk:           <hidden>
802-11-wireless-security.psk-flags:     0 (none)
802-11-wireless-security.leap-password: <hidden>
802-11-wireless-security.leap-password-flags:0 (none)
802-11-wireless-security.wps-method:    0x0 (default)
802-11-wireless-security.fils:          0 (default)
ipv4.method:                            shared
ipv4.dns:                               --
ipv4.dns-search:                        --
ipv4.dns-options:                       --
ipv4.dns-priority:                      0
ipv4.addresses:                         --
ipv4.gateway:                           --
ipv4.routes:                            --
ipv4.route-metric:                      -1
ipv4.route-table:                       0 (unspec)
ipv4.routing-rules:                     --
ipv4.ignore-auto-routes:                no
ipv4.ignore-auto-dns:                   no
ipv4.dhcp-client-id:                    --
ipv4.dhcp-iaid:                         --
ipv4.dhcp-timeout:                      0 (default)
ipv4.dhcp-send-hostname:                yes
ipv4.dhcp-hostname:                     --
ipv4.dhcp-fqdn:                         --
ipv4.dhcp-hostname-flags:               0x0 (none)
ipv4.never-default:                     no
ipv4.may-fail:                          yes
ipv4.required-timeout:                  -1 (default)
ipv4.dad-timeout:                       -1 (default)
ipv4.dhcp-vendor-class-identifier:      --
ipv4.dhcp-reject-servers:               --
ipv6.method:                            auto
ipv6.dns:                               --
ipv6.dns-search:                        --
ipv6.dns-options:                       --
ipv6.dns-priority:                      0
ipv6.addresses:                         --
ipv6.gateway:                           --
ipv6.routes:                            --
ipv6.route-metric:                      -1
ipv6.route-table:                       0 (unspec)
ipv6.routing-rules:                     --
ipv6.ignore-auto-routes:                no
ipv6.ignore-auto-dns:                   no
ipv6.never-default:                     no
ipv6.may-fail:                          yes
ipv6.required-timeout:                  -1 (default)
ipv6.ip6-privacy:                       -1 (unknown)
ipv6.addr-gen-mode:                     stable-privacy
ipv6.ra-timeout:                        0 (default)
ipv6.dhcp-duid:                         --
ipv6.dhcp-iaid:                         --
ipv6.dhcp-timeout:                      0 (default)
ipv6.dhcp-send-hostname:                yes
ipv6.dhcp-hostname:                     --
ipv6.dhcp-hostname-flags:               0x0 (none)
ipv6.token:                             --
proxy.method:                           none
proxy.browser-only:                     no
proxy.pac-url:                          --
proxy.pac-script:                       --
GENERAL.NAME:                           Hotspot
GENERAL.UUID:                           afbf8081-cb19-4d5e-8517-38c222607984
GENERAL.DEVICES:                        wlan0
GENERAL.IP-IFACE:                       wlan0
GENERAL.STATE:                          activated
GENERAL.DEFAULT:                        no
GENERAL.DEFAULT6:                       no
GENERAL.SPEC-OBJECT:                    /org/freedesktop/NetworkManager/AccessPoint/60
GENERAL.VPN:                            no
GENERAL.DBUS-PATH:                      /org/freedesktop/NetworkManager/ActiveConnection/20
GENERAL.CON-PATH:                       /org/freedesktop/NetworkManager/Settings/1
GENERAL.ZONE:                           --
GENERAL.MASTER-PATH:                    --
IP4.ADDRESS[1]:                         10.42.0.1/24
IP4.GATEWAY:                            --
IP4.ROUTE[1]:                           dst = 10.42.0.0/24, nh = 0.0.0.0, mt = 600
IP6.ADDRESS[1]:                         fe80::7d33:50b:86ba:ca37/64
IP6.GATEWAY:                            --
IP6.ROUTE[1]:                           dst = fe80::/64, nh = ::, mt = 1024

答案1

解决了!我卸载了 dnsmasq。dnsmasq-base 似乎已经接管了 DHCP 并使一切正常运行。

答案2

就我而言,原因是联邦水务局。它实际上并不适合任何比简单的单连接家庭计算机设置更复杂的情况。似乎连接共享以及一些自定义dnsmasq设置超出了其界面允许你配置的范围。

禁用它进行测试,使一切正常。
当然这不是真正的解决方案。
对我而言,真正的解决方案是直接使用nftables(或iptables用于旧系统)。或者使用更好的 GUI 工具将其用作后端。然后正确设置网络,通过桥接两个网络(“连接共享”),并设置防火墙以默认允许所有桥接传输流量(任何一方都不是桥接机器本身)。甚至 NetworkManager 也更像是敌人(/保姆)而不是朋友。这些简单的工具总是试图“简化”事情,以至于它们使除了最愚蠢的共同点之外的任何事情都变得更加困难。因此,作为一般答案,我建议始终先尝试使用完整的手动工具(ip,,, ...)。并且只有当它有效并且您了解它iwnft作用,并且您需要某些事情自动发生,并且不想自己编写脚本时,才可以使用任何“智能”工具。

另一个可能的事情是,在中设置多个接口/etc/dnsmasq.conf。但在我的情况下可能不是这样。;)

相关内容