关闭 Raspbian 上的网络

关闭 Raspbian 上的网络

我正在尝试设置 cron 以在夜间(从 23:00 到 8:00)关闭 Raspberry Pi 上的网络。

问题是这些命令都不能完成这项工作:

$ sudo service networking stop
$ sudo ifconfig eth0 down
$ sudo ifdown eth0

从输出来看,该命令似乎有效,但接口仍然有效(我可以ping 8.8.8.8并且它存在于ifconfig)。

这是内容/etc/network/interfaces

auto lo
iface lo inet loopback

auto eth0
allow-hotplug eth0
iface eth0 inet manual

auto wlan0
allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

auto wlan1
allow-hotplug wlan1
iface wlan1 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

ifconfig(屏蔽 MAC)的输出

eth0      Link encap:Ethernet  HWaddr xx:xx:xx:xx:xx:xx  
          inet addr:192.168.1.102  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1545 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1054 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:117138 (114.3 KiB)  TX bytes:156391 (152.7 KiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:8 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:1104 (1.0 KiB)  TX bytes:1104 (1.0 KiB)

的输出route -n

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.1     0.0.0.0         UG    202    0        0 eth0
192.168.1.0     0.0.0.0         255.255.255.0   U     202    0        0 eth0

有什么帮助吗?

答案1

询问并解决无法关闭网络

# service ifplugd stop && ifconfig eth0 down

cron,通过添加sudo crontab -e

0 23 * * * /usr/sbin/service ifplugd stop && /sbin/ifconfig eth0 down

0 8 * * * /usr/sbin/service ifplugd start && /sbin/ifconfig eth0 up

相关内容