三台电脑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