We use some essential cookies to make our website work.

We use optional cookies, as detailed in our cookie policy, to remember your settings and understand how you use our website.

User avatar
marciokoko
Posts: 336
Joined: Sat Aug 27, 2016 4:33 pm

How to disable wireless interface from /etc/network/interfaces

Fri Sep 04, 2020 2:20 am

Id like to know what to edit to disable my wifi from /etc/network/interfaces?

Code: Select all

# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

#auto eth0
iface eth0 inet manual

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

allow-hotplug wlan1
iface wlan1 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
I was thinking about commenting out the allow-hotplug wlan0 with a # but i just wanna double check first.

User avatar
kerry_s
Posts: 8430
Joined: Thu Jan 30, 2020 7:14 pm

Re: How to disable wireless interface from /etc/network/interfaces

Fri Sep 04, 2020 3:15 am

just add:

Code: Select all

dtoverlay=disable-wifi
to /boot/config.txt

User avatar
marciokoko
Posts: 336
Joined: Sat Aug 27, 2016 4:33 pm

Re: How to disable wireless interface from /etc/network/interfaces

Fri Sep 04, 2020 2:52 pm

Thanks. I would like to do it in the network/interfaces/ if possible because I want an easier way to reactivate it when necessary.

User avatar
DougieLawson
Posts: 43580
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK

Re: How to disable wireless interface from /etc/network/interfaces

Fri Sep 04, 2020 3:03 pm

marciokoko wrote:
Fri Sep 04, 2020 2:52 pm
Thanks. I would like to do it in the network/interfaces/ if possible because I want an easier way to reactivate it when necessary.
The problem with that is it breaks your networking. Everything you'd like to do on a standard RaspiOS installation to configure all parts of networking is done in /etc/dhcpcd.conf.
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on Bluesky or by LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

User avatar
marciokoko
Posts: 336
Joined: Sat Aug 27, 2016 4:33 pm

Re: How to disable wireless interface from /etc/network/interfaces

Fri Sep 04, 2020 4:26 pm

ok what do you recommend; here is my issue:

I have a rpi connected to my router via a powerline adapter. The rpi runs 2 python scripts that I need to run constantly. So Ive added this to my rc.local:

Code: Select all

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi

#added2rebootRunTmuxReconnectSchedule
echo > /tmp/test1.txt
sleep 10
tmux new -d -s mqttListen 'python /home/pi/Documents/python/mqttReceive.py' \; set -t m$
tmux new -d -s tsrbrclocal 'python /home/pi/Documents/python/tsrb430v3.py' 
#sudo -u pi bash /home/pi/tmux_start.sh &

exit 0
Whenever the rpi goes down due to power outs, it reboots fine of course, and apparently those 2 scripts are launched just fine as well, because whenever i log into it via ssh, both tmux sessions are always running fine. But mqttReceive.py tmux session has this network unreachable error:

Code: Select all

Traceback (most recent call last):
  File "/home/pi/Documents/python/mqttReceive.py", line 49, in <module>
    client.connect(MQTT_SERVER, 1883, 60)
  File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 839, in connect
    return self.reconnect()
  File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 962, in reconnect
    sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0))
  File "/usr/lib/python2.7/socket.py", line 571, in create_connection
    raise err
socket.error: [Errno 101] Network is unreachable
Ive noticed that sometimes after a pwoerout, the rpi is unpingable and I confirm with the router when I find the reserved IP address for that rpi is not on the dhcp list. So it must be that although the router comes back and the rpi comes back after a powerout, rpi seems to not be able to reconnect to the router for some reason.

So Ive been asking about how to make sure the network adapter is always up and working. It was suggested that I create a check for a connection by creating a checkwifi.sh file and making it executable. I know its called checkwifi.sh but it should also work for the lan connection since there is nothing specific in it about just the wlan0 or even the eth0 for that matter:

Code: Select all

#!/bin/bash
#ping the router to check the wifi connection
ping -c4 192.168.1.1 > /dev/null
# if exit code ($?) of the ping command is failed (not 0) then reconnect
if  [ $? != 0 ]
then       
    systemctl restart dhcpcd
fi
and here is /etc/network/interfaces:

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

Code: Select all

auto lo
iface lo inet loopback

#auto eth0
iface eth0 inet manual

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

allow-hotplug wlan1
iface wlan1 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
But it keeps happening, after a powerout comeback, the router is up and fine, the rpi is up and running but that python script has the network unreachable error and it is confirmed that the rpi is not on the network.

I had switched over to wifi to see if it was the powerline adapter, but it happens on wifi as well. It has to be something with the configurations I have which are not enough to make the rpi get back on the router.

How do I FORCE my rpi to get back on the router's dhcp?

epoch1970
Posts: 8664
Joined: Thu May 05, 2016 9:33 am
Location: France

Re: How to disable wireless interface from /etc/network/interfaces

Fri Sep 04, 2020 4:43 pm

rc.local is basically executed whenever systemd thinks its time to do so. Nothing says network is up when rc.local is executed.
On raspios if you want to launch services, create a custom systemd unit file (that depends on target network.online, or something like that)

Again. Remove what you added to interfaces. Dhcpcd manages wlan* automatically.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

pidd
Posts: 6564
Joined: Fri May 29, 2020 8:29 pm
Location: Wirral, UK

Re: How to disable wireless interface from /etc/network/interfaces

Fri Sep 04, 2020 4:55 pm

You can put the following at the end of /etc/dhcpcd.conf

Code: Select all

denyinterfaces wlan0
then

either reboot or

Code: Select all

sudo systemctl restart dhcpcd

User avatar
marciokoko
Posts: 336
Joined: Sat Aug 27, 2016 4:33 pm

Re: How to disable wireless interface from /etc/network/interfaces

Fri Sep 04, 2020 5:19 pm

epoch1970 wrote:
Fri Sep 04, 2020 4:43 pm
rc.local is basically executed whenever systemd thinks its time to do so. Nothing says network is up when rc.local is executed.
On raspios if you want to launch services, create a custom systemd unit file (that depends on target network.online, or something like that)

Again. Remove what you added to interfaces. Dhcpcd manages wlan* automatically.
Ok

1. I understood rc.local was run on startup?

2. Which line(s) do I remove from /etc/network/interfaces? Most of those were there from the start, since install.

User avatar
marciokoko
Posts: 336
Joined: Sat Aug 27, 2016 4:33 pm

Re: How to disable wireless interface from /etc/network/interfaces

Fri Sep 04, 2020 5:21 pm

pidd wrote:
Fri Sep 04, 2020 4:55 pm
You can put the following at the end of /etc/dhcpcd.conf

Code: Select all

denyinterfaces wlan0
then

either reboot or

Code: Select all

sudo systemctl restart dhcpcd

Ok what will this take care of? Just preventing the wifi connectivity right?

User avatar
marciokoko
Posts: 336
Joined: Sat Aug 27, 2016 4:33 pm

Re: How to disable wireless interface from /etc/network/interfaces

Fri Sep 04, 2020 5:29 pm

Ok and in the crontab then I should probably change this:

Code: Select all

*/5 * * * * /bin/ping -q -c10 192.168.1.1 > /dev/null 2>&1 || (/sbin/ifdown --force wlan0 ;/sbin/ifup wlan0 ;/usr/bin/logger wifi on wlan0 restarted via crontab)
to this:

Code: Select all

*/5 * * * * /bin/ping -q -c10 192.168.1.1 > /dev/null 2>&1 || (/sbin/ifdown --force eth0 ;/sbin/ifup eth0 ;/usr/bin/logger wifi on eth0 restarted via crontab)
Since Im using eth0 (lan cable connection)

pidd
Posts: 6564
Joined: Fri May 29, 2020 8:29 pm
Location: Wirral, UK

Re: How to disable wireless interface from /etc/network/interfaces

Fri Sep 04, 2020 5:33 pm

marciokoko wrote:
Fri Sep 04, 2020 5:21 pm
Ok what will this take care of? Just preventing the wifi connectivity right?
Yes.

You need to put /etc/network/interfaces back to whatever it was before you edited it

On mine interfaces only has one active line

Code: Select all

source-directory /etc/network/interfaces.d
And in my case /etc/network/interfaces.d directory is empty

But I have fully disabled wireless so I don't know if that is normal.

User avatar
RaspbianUser1
Posts: 901
Joined: Thu Mar 05, 2020 6:34 pm
Location: ~/

Re: How to disable wireless interface from /etc/network/interfaces

Fri Sep 04, 2020 5:39 pm

If you would like to soft kill it you can run

Code: Select all

rfkill block wifi
(unblock to re-enable it)

User avatar
marciokoko
Posts: 336
Joined: Sat Aug 27, 2016 4:33 pm

Re: How to disable wireless interface from /etc/network/interfaces

Fri Sep 04, 2020 10:07 pm

pidd wrote:
Fri Sep 04, 2020 5:33 pm
marciokoko wrote:
Fri Sep 04, 2020 5:21 pm
Ok what will this take care of? Just preventing the wifi connectivity right?
Yes.

You need to put /etc/network/interfaces back to whatever it was before you edited it

On mine interfaces only has one active line

Code: Select all

source-directory /etc/network/interfaces.d
And in my case /etc/network/interfaces.d directory is empty

But I have fully disabled wireless so I don't know if that is normal.

Ok done, now how do I force the rpi to keep looking for the network and DEMAND an IP assignment?

pidd
Posts: 6564
Joined: Fri May 29, 2020 8:29 pm
Location: Wirral, UK

Re: How to disable wireless interface from /etc/network/interfaces

Sat Sep 05, 2020 2:09 am

I don't think your problem is with the Pi, I'm tempted to suspect its the router.

I've been playing with my ZeroW and it shows no sign of replicating this problem, I switched my router wifi off a number of times and for up to half an hour and as soon as I switched the wifi on again the Pi jumped straight back in.

The only difference could be that I have a static IP set up at the Pi end, there is no reservation in the router.

Code: Select all

interface wlan0
static ip_address=192.168.1.247/24
static routers=192.168.1.222
static domain_name_servers=208.67.222.222 208.67.220.220
The static address is outside the dhcp range of the router but inside its subnet range.

You are somewhat correct about network/interfaces, although everything is supposed to have been transferred to dhcpcd/wpa_supplicant, I can't find any proper references to wifi roaming mode other than than using network/interfaces one way or another. I was wondering if roaming mode would help. There is reference to it and some detail on the pi at /usr/share/doc/wpasupplicant/README.modes.gz which unlike most of the internet, should be up to date.

I can confirm my network.interfaces is empty on my wifi Pi apart from the link I put up earlier.

There is still an outstanding bodge for dhcpcd to alleviate a common router fault, currently with some routers you get a wifi stoppage roughly every 15 minutes, dhcp manages to get round it at the moment but there is usually a five second stoppage, the bodge is supposed to smooth that over a bit. If that comes through it might help - or it might not.

Anyway can you paste the output of

Code: Select all

iwconfig
and contents of

Code: Select all

/etc/dhcpcd.conf
And confirm you are using an up to date Rpios Buster.

User avatar
marciokoko
Posts: 336
Joined: Sat Aug 27, 2016 4:33 pm

Re: How to disable wireless interface from /etc/network/interfaces

Sat Sep 05, 2020 3:42 am

iwconfig:

Code: Select all

pi@raspberrypi:~ $ iwconfig
wlan0     IEEE 802.11bgn  ESSID:off/any  
          Mode:Managed  Access Point: Not-Associated   Tx-Power=31 dBm   
          Retry short limit:7   RTS thr:off   Fragment thr:off
          Power Management:on
          
lo        no wireless extensions.

eth0      no wireless extensions.

usb0      no wireless extensions.
dhcpcd.conf

Code: Select all

# A sample configuration for dhcpcd.
# See dhcpcd.conf(5) for details.

# Allow users of this group to interact with dhcpcd via the control socket.
#controlgroup wheel

# Inform the DHCP server of our hostname for DDNS.
hostname

# Use the hardware address of the interface for the Client ID.
clientid
# or
# Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361.
#duid

# Persist interface configuration when dhcpcd exits.
persistent

# Rapid commit support.
# Safe to enable by default because it requires the equivalent option set
# on the server to actually work.
option rapid_commit

# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
# Most distributions have NTP support.
option ntp_servers
# Respect the network MTU.
# Some interface drivers reset when changing the MTU so disabled by default.
#option interface_mtu

# A ServerID is required by RFC2131.
require dhcp_server_identifier

# Generate Stable Private IPv6 Addresses instead of hardware based ones
slaac private

# A hook script is provided to lookup the hostname if not set by the DHCP
# server, but it should not be run by default.
nohook lookup-hostname

Return to “General discussion”