Ubuntu 作为 Wifi 扩展器

Ubuntu 作为 Wifi 扩展器

我正在尝试将我的 Ubuntu 服务器(Ubuntu 22.04.3 LTS)用作 wifi 扩展器,但在设置时遇到了问题。

所以我想连接到我的 Ubuntu 服务器上适配的 Wifi,并且所有流量都应该通过以太网连接路由到我的网关,并且 DHCP 也应该由我的网关路由器分配。

更新:

我取得了一些进展,网络连接现在似乎更稳定了(机器启动了),AP 启动了,但当我尝试连接它时却没有得到 IP 地址。所以不知何故我的 DHCP 没有传递到我的路由器/GW。

我当前的配置

network:
  version: 2
  renderer: networkd
  ethernets:
    enp6s18:
      dhcp4: no
      dhcp6: no

  wifis:
    wlan0:
      optional: true
      dhcp4: no
      dhcp6: no
      access-points:
        "my-Ap":
          password: "my-password"

  bridges:
   br0:
    optional: true
    dhcp4: no
    dhcp6: no
    addresses: [192.168.178.90/24]
    routes:
      - to: default
        via: 192.168.178.1
    interfaces: [enp6s18,wlan0]
    nameservers:
      addresses: [8.8.8.8]
    parameters:
      stp: true
      forward-delay: 4  

hostapd

country_code=DE
interface=wlan0

bridge=br0


ssid=my-Ap
hw_mode=g
channel=5
ieee80211n=1
wmm_enabled=1
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=mypassword
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

我还添加了 iptables 规则(重启后恢复)

sudo iptables -t nat -A POSTROUTING -o enp6s18 -j MASQUERADE  
sudo iptables -A FORWARD -i enp6s18 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT  
sudo iptables -A FORWARD -i wlan0 -o enp6s18 -j ACCEPT  

下面是 ifconfig 的输出

br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.178.90  netmask 255.255.255.0  broadcast 192.168.178.255
        inet6 fe80::20f:60ff:fe05:a1c0  prefixlen 64  scopeid 0x20<link>
        ether 00:0f:60:05:a1:c0  txqueuelen 1000  (Ethernet)
        RX packets 2288  bytes 274980 (274.9 KB)
        RX errors 0  dropped 459  overruns 0  frame 0
        TX packets 736  bytes 103313 (103.3 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
        inet6 fe80::42:d8ff:fe7e:9ceb  prefixlen 64  scopeid 0x20<link>
        ether 02:42:d8:7e:9c:eb  txqueuelen 0  (Ethernet)
        RX packets 811  bytes 122192 (122.1 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 609  bytes 193105 (193.1 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp6s18: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether e2:3c:44:6d:4f:7f  txqueuelen 1000  (Ethernet)
        RX packets 2545  bytes 321452 (321.4 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 918  bytes 113025 (113.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

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 84  bytes 6352 (6.3 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 84  bytes 6352 (6.3 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

veth18d0016: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::9470:4fff:feb5:9044  prefixlen 64  scopeid 0x20<link>
        ether 96:70:4f:b5:90:44  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 38  bytes 2232 (2.2 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

veth44b84e9: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::9857:36ff:fee3:1c2b  prefixlen 64  scopeid 0x20<link>
        ether 9a:57:36:e3:1c:2b  txqueuelen 0  (Ethernet)
        RX packets 70  bytes 41926 (41.9 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 147  bytes 14528 (14.5 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

veth85a1446: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::31:ffff:fed4:7794  prefixlen 64  scopeid 0x20<link>
        ether 02:31:ff:d4:77:94  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 38  bytes 2232 (2.2 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

veth8c4fd74: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::c48b:8cff:fef9:9e0e  prefixlen 64  scopeid 0x20<link>
        ether c6:8b:8c:f9:9e:0e  txqueuelen 0  (Ethernet)
        RX packets 579  bytes 74864 (74.8 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 410  bytes 127731 (127.7 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

veth93d8067: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::c4f9:22ff:fe7c:6af6  prefixlen 64  scopeid 0x20<link>
        ether c6:f9:22:7c:6a:f6  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 39  bytes 2342 (2.3 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vethcc72f4b: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::14b0:3dff:fed4:22a4  prefixlen 64  scopeid 0x20<link>
        ether 16:b0:3d:d4:22:a4  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 38  bytes 2232 (2.2 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vethf529f05: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::e0f5:1ff:fe83:7dd1  prefixlen 64  scopeid 0x20<link>
        ether e2:f5:01:83:7d:d1  txqueuelen 0  (Ethernet)
        RX packets 40  bytes 3604 (3.6 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 72  bytes 14240 (14.2 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:0f:60:05:a1:c0  txqueuelen 1000  (Ethernet)
        RX packets 18  bytes 3430 (3.4 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1387  bytes 114192 (114.1 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

答案1

好吧,我认为现在它已经工作了!

我所做的是

  1. 我从全新安装开始,一步一步进行。
  2. Netplan 配置相同
  3. hostapd 配置基本相同(我注意到我的 AP 名称在 hostapd 中是小写的,而在 netplan 中是大写的,所以我将其更改了)。
  4. 我没有添加IP规则。

现在它似乎基本上已经发挥作用了!

问题是,在启动期间,它需要大约 2 分钟来尝试配置网络,然后超时(?),然后完成启动并启动。

因此我也添加了optional: true以太网配置,这似乎解决了该问题!

相关内容