ubuntu外置网卡配置AP模式

外置网卡RTL8811CU设置

UBUNTU使用RTL8811CU网卡(包含树莓派)

外置网卡配置AP模式流程

1. 检查网卡支持情况(是否支持AP模式)

iw list

在这里插入图片描述
找到以上部分,发现支持AP

2. 安装依赖

sudo apt-get update
sudo apt-get install hostapd dnsmasq 

3. 配置hostapd

创建和编辑hostapd配置文件

sudo gedit /etc/hostapd/hostapd.conf

更改配置文件如下,其中interface是ifconfig确定的模式,driver后面的驱动是固定的,不因为外置网卡下载不同驱动而改变

interface=wlx90de803014a8 #interface 参数定义了无线接口的名称
driver=nl80211  #driver 参数定义了使用的驱动程序,固定,不因为外置网卡设备名而改变
ssid=WL1             #wifi名称
channel=6           #channel 参数定义了网络所在的频道
auth_algs=1       #auth_algs 参数定义了用于身份验证的算法
hw_mode=g       #hw_mode 参数定义了硬件模式
ignore_broadcast_ssid=0   #ignore_broadcast_ssid 参数决定是否忽略广播的 SSID
wpa=3
wpa_passphrase=123456789    #密码
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

#wpa 参数定义了是否使用 WPA 加密
#wpa_passphrase 参数定义了 WPA 的密码
#wpa_key_mgmt 参数定义了 WPA 的密钥管理方式
#wpa_pairwise 参数定义了 WPA 的对等加密方式
#rsn_pairwise 参数定义了 RSN 的对等加密方式

查看无线接口名称如下,插拔外置网卡判断具体是哪个

ifconfig

在这里插入图片描述

4. 配置hostapd配置文件
编辑/etc/default/hostapd文件

sudo gedit /etc/default/hostapd

找到DAEMON_CONF=""这一行,并替换为

DAEMON_CONF="/etc/hostapd/hostapd.conf"

5. 配置dnsmasq

sudo gedit /etc/dnsmasq.conf

文件末尾加入

interface=wlx90de803014a8
dhcp-range=192.168.10.2,192.168.10.20,255.255.255.0,24h
port=5353

6. 配置网络接口

sudo gedit /etc/network/interfaces

添加以下配置

auto wlx90de803014a8
iface wlx90de803014a8 inet static
address 192.168.10.1
netmask 255.255.255.0

7. 重启服务

sudo systemctl restart hostapd
sudo systemctl restart dnsmasq

报错处理

sudo systemctl restart hostapd出现以下报错:

Job for dnsmasq.service failed because the control process exited with error code.
See "systemctl status dnsmasq.service" and "journalctl -xe" for detail

可以通过sudo systemctl status hostapd这个命令来查看具体错误原因

● hostapd.service - Advanced IEEE 802.11 AP and IEEE 802.1X/WPA/WPA2/EAP Authenticator
   Loaded: loaded (/lib/systemd/system/hostapd.service; disabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Tue 2024-04-30 16:42:09 CST; 3s ago
  Process: 15958 ExecStart=/usr/sbin/hostapd -P /run/hostapd.pid -B $DAEMON_OPTS ${DAEMON_CONF} (code=exited, status=1/FAILURE)

430 16:42:09 pc-NUC11TNKi7 systemd[1]: Starting Advanced IEEE 802.11 AP and IEEE 802.1X/WPA/WPA2/EAP Authenticator...
430 16:42:09 pc-NUC11TNKi7 hostapd[15958]: Configuration file: /etc/hostapd/hostapd.conf
430 16:42:09 pc-NUC11TNKi7 hostapd[15958]: Line 2: invalid/unknown driver 'rtl8821cu'
430 16:42:09 pc-NUC11TNKi7 hostapd[15958]: 1 errors found in configuration file '/etc/hostapd/hostapd.conf'
430 16:42:09 pc-NUC11TNKi7 hostapd[15958]: Failed to set up interface with /etc/hostapd/hostapd.conf
430 16:42:09 pc-NUC11TNKi7 hostapd[15958]: Failed to initialize interface
430 16:42:09 pc-NUC11TNKi7 systemd[1]: hostapd.service: Control process exited, code=exited status=1
430 16:42:09 pc-NUC11TNKi7 systemd[1]: hostapd.service: Failed with result 'exit-code'.
430 16:42:09 pc-NUC11TNKi7 systemd[1]: Failed to start Advanced IEEE 802.11 AP and IEEE 802.1X/WPA/WPA2/EAP Authenticator.
pc@pc-NUC11TNKi7:~$ 

以上报错是因为驱动使用了错误的rtl8821cu,修改驱动即可

sudo systemctl restart dnsmasq同样出现报错

Job for dnsmasq.service failed because the control process exited with error code.
See "systemctl status dnsmasq.service" and "journalctl -xe" for details.

同样通过这个查看报错信息sudo systemctl status dnsmasq.service

● dnsmasq.service - dnsmasq - A lightweight DHCP and caching DNS server
   Loaded: loaded (/lib/systemd/system/dnsmasq.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Tue 2024-04-30 16:46:19 CST; 1min 36s ago
  Process: 16137 ExecStart=/etc/init.d/dnsmasq systemd-exec (code=exited, status=1/FAILURE)
  Process: 16136 ExecStartPre=/usr/sbin/dnsmasq --test (code=exited, status=0/SUCCESS)

430 16:46:19 pc-NUC11TNKi7 systemd[1]: Starting dnsmasq - A lightweight DHCP and caching DNS server...
430 16:46:19 pc-NUC11TNKi7 dnsmasq[16136]: dnsmasq: syntax check OK.
430 16:46:19 pc-NUC11TNKi7 dnsmasq[16137]: dnsmasq: bad option at line 2 of /etc/dnsmasq.d/wlan0-ap.conf.save
430 16:46:19 pc-NUC11TNKi7 dnsmasq[16137]: bad option at line 2 of /etc/dnsmasq.d/wlan0-ap.conf.save
430 16:46:19 pc-NUC11TNKi7 systemd[1]: dnsmasq.service: Control process exited, code=exited status=1
430 16:46:19 pc-NUC11TNKi7 dnsmasq[16137]: 启动失败
430 16:46:19 pc-NUC11TNKi7 systemd[1]: dnsmasq.service: Failed with result 'exit-code'.
430 16:46:19 pc-NUC11TNKi7 systemd[1]: Failed to start dnsmasq - A lightweight DHCP and caching DNS server.

以上报错是因为在/etc/dnsmasq.d/wlan0-ap.conf.save这个文件的第二行出现错误字符

● dnsmasq.service - dnsmasq - A lightweight DHCP and caching DNS server
   Loaded: loaded (/lib/systemd/system/dnsmasq.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Thu 2024-05-02 11:59:37 CST; 13s ago
  Process: 5591 ExecStart=/etc/init.d/dnsmasq systemd-exec (code=exited, status=2)
  Process: 5590 ExecStartPre=/usr/sbin/dnsmasq --test (code=exited, status=0/SUCCESS)

5月 02 11:59:37 pc-NUC11TNKi7 systemd[1]: Starting dnsmasq - A lightweight DHCP and caching DNS server...
5月 02 11:59:37 pc-NUC11TNKi7 dnsmasq[5590]: dnsmasq: syntax check OK.
5月 02 11:59:37 pc-NUC11TNKi7 dnsmasq[5591]: dnsmasq: failed to create listening socket for port 53: 地址已在使用
5月 02 11:59:37 pc-NUC11TNKi7 dnsmasq[5591]: failed to create listening socket for port 53: 地址已在使用
5月 02 11:59:37 pc-NUC11TNKi7 dnsmasq[5591]: 启动失败
5月 02 11:59:37 pc-NUC11TNKi7 systemd[1]: dnsmasq.service: Control process exited, code=exited status=2
5月 02 11:59:37 pc-NUC11TNKi7 systemd[1]: dnsmasq.service: Failed with result 'exit-code'.
5月 02 11:59:37 pc-NUC11TNKi7 systemd[1]: Failed to start dnsmasq - A lightweight DHCP and caching DNS server

以上报错是因为端口53被同时占用,在 /etc/dnsmasq.conf中换一个端口即可

网络连接测试

找到另一台ubuntu,连接WL1网络,并且ping该地址

ping 192.168.10.1

发现还是ping不通,可以检查防火墙,命令如下sudo iptables -L -v

pc@pc-NUC11TNKi7:~$ sudo ufw status verbose
状态:不活动
pc@pc-NUC11TNKi7:~$ sudo iptables -L -v
Chain INPUT (policy ACCEPT 59 packets, 10776 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 13 packets, 1543 bytes)
 pkts bytes target     prot opt in     out     source               destination

还可以查看相关日志sudo journalctl -xe | grep hostapdsudo journalctl -xe | grep dnsmasq

发现warning: interface wlan0 does not currently exist,因此是dnsmasq.conf的interface写错了

  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值