外置网卡设置为Ad-hoc模式,实现多台电脑互相通信

三台电脑Ad-hoc通信

iwconfig查看网卡型号
ifconfig查看网卡ip

第一台电脑

bash 复制代码
sudo systemctl stop NetworkManager
sudo iwconfig wlx90de803014a8 mode ad-hoc
sudo iwconfig wlx90de803014a8 essid "CPS-IBSS"
sudo iwconfig wlx90de803014a8 channel 1
sudo ip addr add 192.168.120.2/24 dev wlx90de803014a8 #不同电脑设置不同ip
sudo ip link set wlx90de803014a8 up

第二台电脑

bash 复制代码
sudo systemctl stop NetworkManager
sudo iwconfig wlx90de80306872  mode ad-hoc
sudo iwconfig wlx90de80306872 essid "CPS-IBSS"
sudo iwconfig wlx90de80306872 channel 1
sudo ip addr add 192.168.120.3/24 dev wlx90de80306872
sudo ip link set wlx90de80306872 up

第三台电脑

bash 复制代码
sudo systemctl stop NetworkManager
sudo iwconfig wlx90de800092f7 mode ad-hoc
sudo iwconfig wlx90de800092f7 essid "CPS-IBSS"
sudo iwconfig wlx90de800092f7 channel 1
sudo ip addr add 192.168.120.4/24 dev wlx90de80306872
sudo ip link set wlx90de800092f7 up
bash 复制代码
pc@pc-NUC11TNKi7:~$ ssh tju@192.168.100.2
ssh: connect to host 192.168.100.2 port 22: No route to host

三台电脑之间可以ping通,但是断掉120.2的那台,其它都ping不通了

猜测可能是路由选择了某个中继,他们之间并不是直接连通的,待解决

参考【小小洋洋优质博主】

原因是ad-hoc模式至少需要三台电脑,假设用4台,随意断掉一台,他们之间就可以ping通

使用配置文件配置

bash 复制代码
sudo nano /etc/network/interfaces
bash 复制代码
auto wlx90de803014a8 
iface wlx90de803014a8 inet static
    address 192.168.120.2
    netmask 255.255.255.0
	network 192.168.120.0
    broadcast 192.168.120.255
    wireless-channel 1
    wireless-essid CPS-IBSS
    wireless-mode ad-hoc

开关某个网卡命令

bash 复制代码
sudo ifconfig wlx90de803014a8 down
sudo ifconfig wlx90de803014a8 up
相关推荐
orion572 天前
Missing Semester Class1:course overview and introduction of shell
linux
用户120487221612 天前
Linux驱动编译与加载
linux·嵌入式
用户805533698032 天前
Input 子系统架构:Core、Handler、Driver 三层是怎么协作的
linux·嵌入式
用户805533698032 天前
RK-Forge外设系列开篇 - 把板子从「能启动」变成「能用」:Ethernet/SPI/MMC 三个纯接线外设
linux·github·嵌入式
七歌杜金房3 天前
我终于又有了自己的 Linux 电脑
linux·debian·mac
tntxia4 天前
linux curl命令详解_curl详解
linux
扛枪的书生4 天前
Linux 网络管理器用法速查
linux
顺风尿一寸4 天前
Java Socket 内核之旅:从 SocketChannel.read() 到 tcp_recvmsg 与 epoll 的完整调用链路
linux
XIAOHEZIcode4 天前
Ubuntu 终端美化全栈指南:Bash 到 Kitty 踩坑实录
linux·ubuntu·命令行
唐青枫4 天前
别再只会用 cron:Linux systemd Timer 定时任务实战详解
linux