5

I'm trying to set up cron to turn off networking on my Raspberry Pi during the night (from 23:00 to 8:00).

The problem is that none of this commands do the job:

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

From the output it looks like the command worked but the interface is still up (I can ping 8.8.8.8 and it's present in ifconfig).

This is the content of /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

output of ifconfig (masked 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)

output of 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

Any help?

5
  • Add ipconfig and route -n after you tried to disable networking to you question. Jul 22 '15 at 12:55
  • i've added them
    – Matteo
    Jul 22 '15 at 12:59
  • After disabling they don't change
    – Matteo
    Jul 22 '15 at 13:24
  • Can you please add the statements you've put in your crontab? I'm assuming that stopping networking outside of cron works fine, or can you still ping 8.8.8.8 after ifconfig eth0 down? Also, which user's crontab were the commands in?
    – mjturner
    Jul 22 '15 at 14:27
  • I'm not adding to crontab yet because it doesn't work normally. pi@RaspberryPi:~$ sudo ifconfig eth0 down [sudo] password for pi: pi@RaspberryPi:~$ ping 8.8.8.8 PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data. 64 bytes from 8.8.8.8: icmp_req=1 ttl=56 time=39.6 ms 64 bytes from 8.8.8.8: icmp_req=2 ttl=56 time=39.4 ms ^C --- 8.8.8.8 ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 1001ms rtt min/avg/max/mdev = 39.458/39.536/39.615/0.213 ms pi@RaspberryPi:~$
    – Matteo
    Jul 22 '15 at 14:38
2

Asked and solved in Can't turn off network.

# service ifplugd stop && ifconfig eth0 down

In cron, added through 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.