重启后无法在所有接口上启动 dhcpcd

重启后无法在所有接口上启动 dhcpcd

我有一个使用 scapy 库进行嗅探的 Python 脚本。我希望我的树莓派每隔 X 分钟重启一次,将我的 wifi 加密狗网卡置于监控模式并重新启动嗅探脚本。同时我需要通过以太网连接互联网。

我第一次尝试设置一个这样的 crontab

@reboot sudo shutdown -r +X
@reboot sudo ifconfig wlan1 up
@reboot sudo airmon-ng start wlan1 
@reboot sudo python myScript.py

并且它成功了。

pi@raspberrypi:~ $ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.87  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::4033:ce91:f9f7:c6c6  prefixlen 64  scopeid 0x20<link>
        ether b8:27:eb:26:91:26  txqueuelen 1000  (Ethernet)
        RX packets 164  bytes 17133 (16.7 KiB)
        RX errors 0  dropped 1  overruns 0  frame 0
        TX packets 196  bytes 33373 (32.5 KiB)
        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 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether b8:27:eb:73:c4:73  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan1mon: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        unspec 00-C0-CA-97-F0-1D-00-00-00-00-00-00-00-00-00-00  txqueuelen 1000  (UNSPEC)
        RX packets 6  bytes 832 (832.0 B)
        RX errors 0  dropped 6  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

但后来 raspberry 开始为无线网卡赋予不同的名称(wlan1 为内置无线网卡,wlan0 为外部 USB 适配器)。我的 python 脚本总是使用 wlan1mon 进行嗅探,所以我不希望发生这种变化。
因此,我启用了可预测接口,raspi-config并且 USB 适配器开始被命名,mac 地址在wlx????????????哪里。 一切似乎都正常,但是当我将 crontab 更改为????????????

@reboot sudo shutdown -r +X
@reboot sudo ifconfig wlx???????????? up
@reboot sudo airmon-ng start wlx???????????? 
@reboot sudo python myScript.py

如果我输入命令iwconfigwlx???????????? 被正确设置为 wlan1mon 因为接口名称太长 但是我没有通过以太网进行互联网连接并且 ifconfig 给了我这个:

pi@raspberrypi:~ $ ifconfig
enxb827eb269126: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::4033:ce91:f9f7:c6c6  prefixlen 64  scopeid 0x20<link>
        ether b8:27:eb:26:91:26  txqueuelen 1000  (Ethernet)
        RX packets 164  bytes 17133 (16.7 KiB)
        RX errors 0  dropped 1  overruns 0  frame 0
        TX packets 196  bytes 33373 (32.5 KiB)
        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 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan0 和 wlan1mon 不再存在,并且以太网接口字段 inet 丢失。iwconfig
反而给我这个:

pi@raspberrypi:~ $ iwconfig
enxb827eb269126 no wireless extensions 

wlan0    IEEE 802.11 ESSID:off/any
         Mode:Managed Access Point:Not-Associated
         Retry short limit:27 RTS thr:off Fragment thr:off
         Power Management:on

wlan1mon IEEE 802.11 Mode:Monitor Tx-Power=20dBm
         Retry short long limit:2 RTS thr:off Fragment thr:off
         Power Management:off

lo       no wireless extensions

相关内容