前言:
目前服务器领域centos7基本是主流的操作系统,而linux相对于Windows来说,软硬件方面的支持是差很多的,在硬件方面来说,以一个免驱的网卡为例,window xp可能不会自动识别到,但Windows10基本都会自动识别到,简简单单的即插即用。根本原因在Windows随着版本的升级,内置的各类网卡驱动更多,也因此Windows系统越来越大。
tips:什么是驱动?
驱动指的是操作系统层面的一组程序,该程序告诉操作系统的内核如何使用硬件,例如,网卡的启停,网卡的IP绑定,网卡的路由路径这些都是网卡驱动通知内核调用相关的程序,例如,ifconfig程序,做相应的动作来完成的。
而linux操作系统的内核一般是不集成过多的网卡的,主要在于linux一般是服务器用途,内核追求轻量化,因此,我们可以看到,linux 6.X的内核更新介绍里说某些网卡驱动已经集成到了内核中,也就是某些型号的网卡可以做到即插即用,而低版本的内核通常支持的硬件是比较少的,因此,某些情况下,某个硬件我们想使用的时候就必须升级内核了,简单来说,内核版本越高,那么,它可以识别的硬件种类越多,硬件识别之后,我们就可以安装相应的驱动来使用这些硬件了。通常我们是采用源码编译的方式安装驱动。
下面我将就在一台物理机通过编译方式安装水星的网卡驱动做一个介绍,本次实践基于虚拟机安装网卡驱动,见我的博客(本次相关文件都在下面这个文章内的网盘链接):
Linux|centos7操作系统|VMware虚拟机安装水星免驱USB网卡8188gu记录-CSDN博客
一,
服务器的信息
该服务器是一台比较老旧的服务器,硬件配置如下:
CPU: E52660 16核心
硬盘:259G 金士顿
主板:华南金牌770X
内存:16G
操作系统:centos7.5
网卡:主板网卡 芯片型号是r8168 USB网卡芯片型号是8188gu
操作系统的安装就不在这里废话了
二,
内核的升级
内核版本选择的是5,4,266版本,方式是rpm包直接安装
通常,内核的安装有两种方式,第一种是网上的各种deb,rpm包,该方式比较迅速,方便,基本不会有错误,第二种方式是手动编译方式,需要对内核比较熟悉,需要更多的定制功能,比如,linux系统对NTFS文件系统的支持,NET网咯的扩展性功能,EXT2文件系统的支持特殊的需求,以及一些自定义的自己编写的模块需要编译进内核。
本次实践选择的是使用现成的rpm包,rpm包下载地址是:
Index of /linux/kernel/el7/x86_64/RPMS
三,
Linux的gcc编译器问题
centos7的默认编译器版本是4.8版本,随着内核升级到了5.X版本,这个时候内核和编译器已经是不匹配了,因此,需要使用高版本的gcc编译器,本例中使用devtools版本的gcc9,将此gcc加入环境变量:
在/etc/profile文件末尾添加:
source /opt/rh/devtools-set/enable
添加后,执行命令 source /etc/profile
如果内核和gcc编译器版本不匹配会有什么样的后果呢?
基本上编译是不会成功的,一开始编译就一大堆报错,例如下面这样:
make ARCH=x86_64 CROSS_COMPILE= -C /lib/modules/3.10.0-862.14.1.0.h209.eulerosv2r7.x86_64/build M=/opt/rtl8188gu-master modules
make[1]: Entering directory `/usr/src/kernels/3.10.0-862.14.1.0.h209.eulerosv2r7.x86_64'CC [M] /opt/rtl8188gu-master/core/rtw_cmd.o
In file included from include/linux/kernel.h:11,from include/linux/cache.h:4,from include/linux/time.h:4,from include/linux/stat.h:18,from include/linux/module.h:10,from /opt/rtl8188gu-master/include/basic_types.h:76,from /opt/rtl8188gu-master/include/drv_types.h:26,from /opt/rtl8188gu-master/core/rtw_cmd.c:17:
include/linux/log2.h:22:1: warning: ignoring attribute ‘noreturn’ because it conflicts with attribute ‘const’ [-Wattributes]22 | int ____ilog2_NaN(void);| ^~~
/opt/rtl8188gu-master/core/rtw_cmd.c: In function ‘rtw_joinbss_cmd’:
/opt/rtl8188gu-master/core/rtw_cmd.c:1477:38: warning: taking address of packed member of ‘struct _WLAN_BSSID_EX’ may result in an unaligned pointer value [-Waddress-of-packed-member]1477 | pnetwork->network.IELength - 12, &psecnetwork->IELength,| ^~~~~~~~~~~~~~~~~~~~~~
/opt/rtl8188gu-master/core/rtw_cmd.c:1490:32: warning: taking address of packed member of ‘struct _WLAN_BSSID_EX’ may result in an unaligned pointer value [-Waddress-of-packed-member]1490 | pnetwork->network.IELength, &psecnetwork->IELength);| ^~~~~~~~~~~~~~~~~~~~~~
/opt/rtl8188gu-master/core/rtw_cmd.c:1494:57: warning: taking address of packed member of ‘struct _WLAN_BSSID_EX’ may result in an unaligned pointer value [-Waddress-of-packed-member]1494 | rtw_append_exented_cap(padapter, &psecnetwork->IEs[0], &psecnetwork->IELength);| ^~~~~~~~~~~~~~~~~~~~~~CC [M] /opt/rtl8188gu-master/core/rtw_security.o
In file included from include/linux/kernel.h:11,from include/linux/cache.h:4,from include/linux/time.h:4,from include/linux/stat.h:18,from include/linux/module.h:10,from /opt/rtl8188gu-master/include/basic_types.h:76,from /opt/rtl8188gu-master/include/drv_types.h:26,from /opt/rtl8188gu-master/core/rtw_security.c:17:
include/linux/log2.h:22:1: warning: ignoring attribute ‘noreturn’ because it conflicts with attribute ‘const’ [-Wattributes]22 | int ____ilog2_NaN(void);| ^~~CC [M] /opt/rtl8188gu-master/core/rtw_debug.o
In file included from include/linux/kernel.h:11,from include/linux/cache.h:4,from include/linux/time.h:4,
四,linux的固件问题
类似上面的gcc编译器问题,随着内核版本的升级,很多原内核的模块比如cfg80211也需要跟随升级,如果不升级,那么在加载新网卡模块的时候,可能会报错,如下图:
关键报错信息:cfg88211:failed to load regulatory.db
那么,我们的固件也就是firmware应该怎么更新呢?
其实比较的简单,/lib/firmware目录下就是centos7所使用的固件的存放目录,当然了,这个报错其实并不太影响网卡的驱动安装,因为,我在把网卡驱动安装完毕后,仍然有这个报错,但网卡是正常工作的,如果不希望看到这个报错,处理方案为:
手动从 https://mirrors.edge.kernel.org/pub/software/network/wireless-regdb/ 下载最新的包,解压缩后需要将文件 regulatory.db 和 regulatory.db.p7s 复制到/lib/firmware中
最终系统日志里在没有看到这个报错了(我下载的是wireless-regdb-2023.09.01.tar.gz)
[root@localhost firmware]# pwd
/lib/firmware
[root@localhost firmware]# ls -al reg*
-rw-r--r-- 1 root root 4896 Jan 18 23:16 regulatory.db
-rw-r--r-- 1 root root 1182 Jan 18 23:16 regulatory.db.p7s[root@localhost firmware]# ls -al /opt/test/wireless-regdb-2023.09.01/
total 192
drwxrwxr-x. 4 root root 4096 Sep 2 03:58 .
drwxr-xr-x. 7 root root 4096 Jan 18 07:12 ..
-rw-rw-r--. 1 root root 1871 Sep 2 03:58 CONTRIBUTING
-rwxrwxr-x. 1 root root 3672 Sep 2 03:58 db2bin.py
-rwxrwxr-x. 1 root root 4181 Sep 2 03:58 db2fw.py
-rwxrwxr-x. 1 root root 17490 Sep 2 03:58 dbparse.py
-rw-rw-r--. 1 root root 82408 Sep 2 03:58 db.txt
drwxrwxr-x. 2 root root 94 Sep 2 03:58 debian-example
-rwxrwxr-x. 1 root root 363 Sep 2 03:58 gen-pubcert.sh
-rw-rw-r--. 1 root root 25 Sep 2 03:58 .gitignore
-rw-rw-r--. 1 root root 880 Sep 2 03:58 LICENSE
-rw-rw-r--. 1 root root 3989 Sep 2 03:58 Makefile
-rw-rw-r--. 1 root root 1448 Sep 2 03:58 README
-rw-rw-r--. 1 root root 6668 Sep 2 03:58 regulatory.bin
-rw-rw-r--. 1 root root 1266 Sep 2 03:58 regulatory.bin.5
-rw-rw-r--. 1 root root 4896 Sep 2 03:58 regulatory.db
-rw-rw-r--. 1 root root 29 Sep 2 03:58 regulatory.db.5
-rw-rw-r--. 1 root root 1182 Sep 2 03:58 regulatory.db.p7s
-rw-rw-r--. 1 root root 451 Sep 2 03:58 sforshee.key.pub.pem
-rw-rw-r--. 1 root root 977 Sep 2 03:58 sforshee.x509.pem
-rw-rw-r--. 1 root root 49 Sep 2 03:58 sha1sum.txt
drwxrwxr-x. 2 root root 27 Sep 2 03:58 web
-rw-rw-r--. 1 root root 972 Sep 2 03:58 wireless-regdb.spec
我这里强调cfg80211这个模块是由于该模块是8188gu这个模块的依赖,相关证据如下:
[root@localhost firmware]# modinfo 8188gu |grep dep
depends: cfg80211
[root@localhost firmware]# lsmod |grep 8188gu
8188gu 1007616 0
cfg80211 704512 1 8188gu
因此,保证cfg80211模块正常运行是非常必要的
由于操作系统的内核升级导致usb_modeswitch 切换U盘报错,报错如下:
tips:主要报错信息是Error:Sierra conrol message failed (error -7)
这个错误导致以下命令执行出错:
[root@localhost firmware]# usb_modeswitch -KW -v06bd -p 1a2b
Take all parameters from the command line* usb_modeswitch: handle USB devices with multiple modes* Version 2.4.0 (C) Josua Dietze 2016* Based on libusb1/libusbx! PLEASE REPORT NEW CONFIGURATIONS !DefaultVendor= 0x06bd
DefaultProduct= 0x1a2bStandardEject=1Look for default devices ...found USB ID 1d6b:0003found USB ID 2109:3431found USB ID 1d6b:0002found USB ID 0bda:1a2bfound USB ID 8087:0024found USB ID 1d6b:0002No devices in default mode found. Nothing to do. Bye!
两种解决方案,第一个是更新usb相关的模块,第二个是更新固件
usb相关模块有usb-storage,scsi-mod等等好几个模块,更新比较困难,因此,选择第二个方法:更新固件,更新固件后可以摆脱这个usb相关module的依赖,也就是说不需要管这些模块是否加载了
更新固件的方法为:从 https://mirrors.edge.kernel.org/pub/linux/kernel/firmware/下载后的最新 firmware 包存放在当前目录的lib文件夹下
我下载的是这个固件包:
[root@localhost firmware]# ls -al /opt/test/linux-firmware-20240115.tar.gz
-rwxr-xr-x. 1 root root 553601923 Jan 17 09:27 /opt/test/linux-firmware-20240115.tar.gz
解压上面的压缩包后,备份原/lib/firmware目录,删除原firmware目录下的所有内容,将解压出来的内容放置到原/lib/firmware目录下,无需重启服务器,即时生效
以上两个报错解决后,发现板载网卡也就是r8186在新内核下看不到了,翻遍日志也找不到任何有用的信息,而在旧内核下是可以看到这个网卡的
那么,如何知道板载网卡的芯片型号呢?
以旧内核进入系统后,使用ethtool 查看网卡信息就可以确定板载网卡的芯片信息了:
[root@localhost firmware]# ethtool -i enp5s0
driver: r8168
version: 8.047.05-NAPI
firmware-version:
expansion-rom-version:
bus-info: 0000:05:00.0
supports-statistics: yes
supports-test: no
supports-eeprom-access: no
supports-register-dump: yes
supports-priv-flags: no
以新内核进入系统后,开始make 素质三连,发现报错如下:
关键报错:fatal error:linux/pci-aspm.h:No such file or directory
打开报错的位置:
[root@localhost firmware]# sed -n '65,70p' /opt/test/Realtek-PCIe-GBE-NIC-Driver-master/r8168-8.047.04/src/r8168_n.c#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
#define dev_printk(A,B,fmt,args...) printk(A fmt,##args)
#else
#include <linux/dma-mapping.h>
#include <linux/moduleparam.h>
[root@localhost firmware]# sed -n '55,65p' /opt/test/Realtek-PCIe-GBE-NIC-Driver-master/r8168-8.047.04/src/r8168_n.c
#include <linux/init.h>
#include <linux/rtnetlink.h>
#include <linux/completion.h>#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26)
#include <linux/pci-aspm.h>
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,37)
#include <linux/prefetch.h>
#endif
经判断,这里是内核版本检查,可以删除,因此,删除这三行后,可以正常编译了:
删除的三行内容如下
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26)
#include <linux/pci-aspm.h>
#endif
剩下基本就是一路绿灯了,按照上面提到的虚拟机内安装网卡驱动的文章,一路畅通无阻的安装完毕了
五,
USB的即插即用实现
编辑/etc/udev/rules.d/70-persistent-ipoib.rules,该文件末尾添加三行内容如下:
[root@localhost r8168-8.047.04]# cat /etc/udev/rules.d/70-persistent-ipoib.rules
# This is a sample udev rules file that demonstrates how to get udev to
# set the name of IPoIB interfaces to whatever you wish. There is a
# 16 character limit on network device names though, so don't go too nuts
#
# Important items to note: ATTR{type}=="32" is IPoIB interfaces, and the
# ATTR{address} match must start with ?* and only reference the last 8
# bytes of the address or else the address might not match on any given
# start of the IPoIB stack
#
# Note: as of rhel7, udev is case sensitive on the address field match
# and all addresses need to be in lower case.
#
# ACTION=="add", SUBSYSTEM=="net", DRIVERS=="?*", ATTR{type}=="32", ATTR{address}=="?*00:02:c9:03:00:31:78:f2", NAME="mlx4_ib3"ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="0bda", ATTRS{idProduct}=="1a2b", RUN+="/usr/sbin/usb_modeswitch -K -v 0bda -p 1a2b"
ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="0bda", ATTRS{idProduct}=="1a2b", RUN+="/bin/bash -c 'modprobe 8188gu && echo 0bda 1a2b > /sys/bus/usb-serial/drivers/option1/new_id'"
ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="0bda", ATTRS{idProduct}=="1a2b", RUN+="/bin/bash -c 'modprobe 8188gu && echo 0bda 1a2b > /sys/bus/usb-serial/drivers/option1/new_id'"
idVendor和idProduct 是根据下面这个命令的倒数第三行得出的,因为是安装的8188gu这个驱动,因此modprobe 8188gu
[root@localhost r8168-8.047.04]# lsusb
Bus 003 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 002 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0bda:1a2b Realtek Semiconductor Corp.
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
重启服务器后可以看到非常快的就自动识别到了USB并自动挂载了8188gu 这个驱动
相关自动挂载的日志在/var/log/messages 文件内,内容如下:
Jan 18 23:17:50 localhost kernel: usb 1-1.1: New USB device found, idVendor=0bda, idProduct=b711, bcdDevice= 2.00
Jan 18 23:17:50 localhost kernel: usb 1-1.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Jan 18 23:17:50 localhost kernel: usb 1-1.1: Product: 802.11n WLAN Adapter
Jan 18 23:17:50 localhost kernel: usb 1-1.1: Manufacturer: Realtek
Jan 18 23:17:50 localhost kernel: usb 1-1.1: SerialNumber: 00E04CB82101
Jan 18 23:17:50 localhost kernel: sdb: sdb1 sdb2 < sdb5 >
六,
网卡功能的测试和网卡的若干管理方法介绍
WiFi连接:
第一种方式:
WiFi连接有很多种方法,这里使用nmcli的方式来连接WiFi,这种方法是最简单的:
扫描WiFi热点:
[root@localhost r8168-8.047.04]# nmcli device wifi lis
* SSID MODE CHAN RATE SIGNAL BARS SECURITY mywifi-WiFi5 Infra 5 54 Mbit/s 100 ▂▄▆█ WPA2 -- Infra 5 54 Mbit/s 100 ▂▄▆█ WPA2
* mywifi Infra 5 54 Mbit/s 90 ▂▄▆█ WPA2 ChinaNet-gTUm Infra 5 54 Mbit/s 80 ▂▄▆_ WPA1 WPA2 MIQI Infra 11 54 Mbit/s 55 ▂▄__ WPA1 WPA2 -- Infra 11 54 Mbit/s 55 ▂▄__ WPA1 WPA2 -- Infra 8 54 Mbit/s 50 ▂▄__ WPA2 zhwww Infra 8 54 Mbit/s 49 ▂▄__ WPA2 ChinaNet-6b4R Infra 2 54 Mbit/s 42 ▂▄__ WPA1 ChinaNet-wfJ9 Infra 10 54 Mbit/s 24 ▂___ WPA1 WPA2
nmcli直接连接:
mywifi是我的WiFi,可以看到网卡wlp0s26u1u1 成功连接名为mywifi的这个热点
[root@localhost r8168-8.047.04]# nmcli device wifi connect mywifi password 密码
Device 'wlp0s26u1u1' successfully activated with '00efc1c4-b849-4821-8f75-c5957cb6defd'.
第二种方式:
利用iw工具和wpa_suppliant工具配置WiFi连接
解压wireless-tools-29.zip(网盘里有),然后直接make && make install 输出日志如下:
[root@centos10 wireless_tools]# make
gcc -Os -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wpointer-arith -Wcast-qual -Winline -I. -MMD -fPIC -c -o iwlib.so iwlib.c
In file included from iwlib.c:14:
iwlib.c: In function ‘print_iface_version_info’:
iwlib.h:522:1: warning: inlining failed in call to ‘iw_get_ext’: call is unlikely and code size would grow [-Winline]522 | iw_get_ext(int skfd, /* Socket to the kernel */| ^~~~~~~~~~
iwlib.c:387:6: note: called from here387 | if(iw_get_ext(skfd, ifname, SIOCGIWNAME, &wrq) < 0)| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from iwlib.c:14:
iwlib.h:522:1: warning: inlining failed in call to ‘iw_get_ext’: call is unlikely and code size would grow [-Winline]522 | iw_get_ext(int skfd, /* Socket to the kernel */| ^~~~~~~~~~
iwlib.c:396:6: note: called from here396 | if(iw_get_ext(skfd, ifname, SIOCGIWRANGE, &wrq) < 0)| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from iwlib.c:14:
iwlib.c: In function ‘iw_get_range_info’:
iwlib.h:522:1: warning: inlining failed in call to ‘iw_get_ext’: call is unlikely and code size would grow [-Winline]522 | iw_get_ext(int skfd, /* Socket to the kernel */| ^~~~~~~~~~
iwlib.c:483:6: note: called from here483 | if(iw_get_ext(skfd, ifname, SIOCGIWRANGE, &wrq) < 0)| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from iwlib.c:14:
iwlib.c: In function ‘iw_get_priv_info’:
iwlib.h:522:1: warning: inlining failed in call to ‘iw_get_ext’: call is unlikely and code size would grow [-Winline]522 | iw_get_ext(int skfd, /* Socket to the kernel */| ^~~~~~~~~~
iwlib.c:623:10: note: called from here623 | if(iw_get_ext(skfd, ifname, SIOCGIWPRIV, &wrq) >= 0)| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from iwlib.c:14:
iwlib.c: In function ‘iw_set_basic_config’:
iwlib.h:522:1: warning: inlining failed in call to ‘iw_get_ext’: call is unlikely and code size would grow [-Winline]522 | iw_get_ext(int skfd, /* Socket to the kernel */| ^~~~~~~~~~
iwlib.c:748:6: note: called from here748 | if(iw_get_ext(skfd, ifname, SIOCGIWNAME, &wrq) < 0)| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from iwlib.c:14:
iwlib.h:522:1: warning: inlining failed in call to ‘iw_get_ext’: call is unlikely and code size would grow [-Winline]522 | iw_get_ext(int skfd, /* Socket to the kernel */| ^~~~~~~~~~
iwlib.c:761:10: note: called from here761 | if(iw_get_ext(skfd, ifname, SIOCSIWMODE, &wrq) < 0)| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from iwlib.c:14:
iwlib.h:506:1: warning: inlining failed in call to ‘iw_set_ext’: call is unlikely and code size would grow [-Winline]506 | iw_set_ext(int skfd, /* Socket to the kernel */| ^~~~~~~~~~
iwlib.c:773:10: note: called from here773 | if(iw_set_ext(skfd, ifname, SIOCSIWFREQ, &wrq) < 0)| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from iwlib.c:14:
iwlib.h:506:1: warning: inlining failed in call to ‘iw_set_ext’: call is unlikely and code size would grow [-Winline]506 | iw_set_ext(int skfd, /* Socket to the kernel */| ^~~~~~~~~~
iwlib.c:793:7: note: called from here793 | if(iw_set_ext(skfd, ifname, SIOCSIWENCODE, &wrq) < 0)| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from iwlib.c:14:
iwlib.h:506:1: warning: inlining failed in call to ‘iw_set_ext’: call is unlikely and code size would grow [-Winline]506 | iw_set_ext(int skfd, /* Socket to the kernel */| ^~~~~~~~~~
iwlib.c:813:10: note: called from here813 | if(iw_set_ext(skfd, ifname, SIOCSIWENCODE, &wrq) < 0)| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from iwlib.c:14:
iwlib.h:506:1: warning: inlining failed in call to ‘iw_set_ext’: call is unlikely and code size would grow [-Winline]506 | iw_set_ext(int skfd, /* Socket to the kernel */| ^~~~~~~~~~
iwlib.c:827:10: note: called from here827 | if(iw_set_ext(skfd, ifname, SIOCSIWNWID, &wrq) < 0)| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from iwlib.c:14:
iwlib.h:506:1: warning: inlining failed in call to ‘iw_set_ext’: call is unlikely and code size would grow [-Winline]506 | iw_set_ext(int skfd, /* Socket to the kernel */| ^~~~~~~~~~
iwlib.c:850:10: note: called from here850 | if(iw_set_ext(skfd, ifname, SIOCSIWESSID, &wrq) < 0)| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from iwlib.c:14:
iwlib.c: In function ‘iw_get_basic_config’:
iwlib.h:522:1: warning: inlining failed in call to ‘iw_get_ext’: call is unlikely and code size would grow [-Winline]522 | iw_get_ext(int skfd, /* Socket to the kernel */| ^~~~~~~~~~
。。。。。。。。。。。后面的略略略
[root@centos10 wireless_tools]# make install
install -m 755 -d /usr/local/lib/
install -m 755 libiw.so.29 /usr/local/lib/
ln -sfn libiw.so.29 /usr/local/lib//libiw.so
*** Don't forget to add /usr/local/lib/ to /etc/ld.so.conf, and run ldconfig as root. ***
install -m 755 -d /usr/local/sbin/
install -m 755 iwconfig iwlist iwpriv iwspy iwgetid iwevent ifrename /usr/local/sbin/
install -m 755 -d /usr/local/include/
install -m 644 iwlib.h /usr/local/include/
install -m 644 wireless.h /usr/local/include/
install -m 755 -d /usr/local/man//man8/
install -m 644 iwconfig.8 iwlist.8 iwpriv.8 iwspy.8 iwgetid.8 iwevent.8 ifrename.8 /usr/local/man//man8/
install -m 755 -d /usr/local/man//man7/
install -m 644 wireless.7 /usr/local/man//man7/
install -m 755 -d /usr/local/man//man5/
install -m 644 iftab.5 /usr/local/man//man5/
以上输出有一个温馨提示*** Don't forget to add /usr/local/lib/ to /etc/ld.so.conf, and run ldconfig as root. ***,因此,在/etc/ld.so.conf文件末尾添加/usr/local/lib/ 保存文件后,以root用户执行ldconfig命令激活此环境变量即可正常使用iw命令了
在使用iw之前,还需要激活网卡:
[root@centos10 wireless_tools]# ifconfig wls35u1 up
扫描WiFi(先查看网卡信息,记住网卡名称是wls35u1):
该扫描的信息比较全,需要重点关注目标WiFi网络的ESSID(网络名称)和BSSID(无线路由器的MAC地址),例如mywifi的ESSID是 mywifi,BSSID是50:33:F0:CD:21:D9
[root@centos10 wireless_tools]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host lovalid_lft forever preferred_lft foreverinet6 ::1/128 scope host valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 1000link/ether 00:0c:29:e8:89:a2 brd ff:ff:ff:ff:ff:ffinet 192.168.123.20/24 brd 192.168.123.255 scope global noprefixroute ens33valid_lft forever preferred_lft foreverinet6 fd15:4ba5:5a2b:1008:162e:7500:4e67:2fb1/64 scope global noprefixroute dynamic valid_lft 86387sec preferred_lft 14387secinet6 fe80::523b:7d77:34e9:fa42/64 scope link noprefixroute valid_lft forever preferred_lft forever
3: wls35u1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN group default qlen 1000link/ether 00:5c:c2:ce:dc:24 brd ff:ff:ff:ff:ff:ff[root@centos10 wireless_tools]# iwlist wls35u1 scan
wls35u1 Scan completed :Cell 01 - Address: 74:05:A5:DC:86:C2ESSID:"YBJ"Protocol:IEEE 802.11bgnMode:MasterFrequency:2.412 GHz (Channel 1)Encryption key:onBit Rates:144 Mb/sExtra:wpa_ie=dd160050f20101000050f20401000050f20401000050f202IE: WPA Version 1Group Cipher : CCMPPairwise Ciphers (1) : CCMPAuthentication Suites (1) : PSKExtra:IE: IEEE 802.11i/WPA2 Version 1Group Cipher : CCMPPairwise Ciphers (1) : CCMPAuthentication Suites (1) : PSKQuality=0/100 Signal level=18/100 Extra:fm=0003Cell 02 - Address: F4:32:3D:98:9A:39ESSID:"ChinaNet-6b4R"Protocol:IEEE 802.11bgnMode:MasterFrequency:2.417 GHz (Channel 2)Encryption key:onBit Rates:144 Mb/sExtra:wpa_ie=dd1a0050f20101000050f20202000050f2040050f20201000050f202IE: WPA Version 1Group Cipher : TKIPPairwise Ciphers (2) : CCMP TKIPAuthentication Suites (1) : PSKQuality=0/100 Signal level=23/100 Extra:fm=0001Cell 03 - Address: 38:21:87:7E:68:65ESSID:"midea_db_0821"Protocol:IEEE 802.11bgnMode:MasterFrequency:2.422 GHz (Channel 3)Encryption key:onBit Rates:72 Mb/sExtra:rsn_ie=30140100000fac040100000fac040100000fac020000IE: IEEE 802.11i/WPA2 Version 1Group Cipher : CCMPPairwise Ciphers (1) : CCMPAuthentication Suites (1) : PSKQuality=0/100 Signal level=13/100 Extra:fm=0003Cell 04 - Address: 50:33:F0:CD:21:D9ESSID:"mywifi"Protocol:IEEE 802.11bgnMode:MasterFrequency:2.432 GHz (Channel 5)Encryption key:onBit Rates:867 Mb/sExtra:rsn_ie=30140100000fac040100000fac040100000fac020000IE: IEEE 802.11i/WPA2 Version 1Group Cipher : CCMPPairwise Ciphers (1) : CCMPAuthentication Suites (1) : PSKIE: Unknown: DD9F0050F204104A0001101044000102103B00010310470010BC329E001DD811B286015033F0CD21D81021001852616C696E6B20546563686E6F6C6F67792C20436F72702E1023001C52616C696E6B20576972656C6573732041636365737320506F696E74102400065254323836301042000831323334353637381054000800060050F20400011011000B52616C696E6B4150535F3010080002008C103C000101Quality=0/100 Signal level=36/100 Extra:fm=0003
iwconfig wls35u2 essid mywifi key s:WiFi密码
创建WiFi的配置文件:
wpa_passphrase ESSID passphrase > /etc/wpa_supplicant.conf
例如,现在我需要连接mywifi,那么配置此WiFi的命令就是
wpa_passphrase mywif WiFi的密码 > /etc/wpa_supplicant.conf
连接WiFi:
[root@centos10 network-scripts]# wpa_supplicant -D nl80211 -i wls35u2 -c /etc/wpa_supplicant.conf -B
Successfully initialized wpa_supplicant
此时已经可以看到wls35u2这个网卡的ipv6地址了,但还没有ipv4的地址:
[root@centos10 network-scripts]# ifconfig wls35u2
wls35u2: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500inet6 fe80::25c:c2ff:fece:dc24 prefixlen 64 scopeid 0x20<link>ether 00:5c:c2:ce:dc:24 txqueuelen 1000 (Ethernet)RX packets 1229 bytes 122805 (119.9 KiB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 55 bytes 15762 (15.3 KiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
通过DHCP分配ip地址:
dhclient wls35u2
最终可以看到新网卡的ip地址,完结,撒花!!!!!