0

No matter what was the state during the last session. I want Wifi and Ethernet to be disabled to actively connect to the outside every time. I want to prevent every auto connect to a network.

Solutions should work with GNOME desktop and/or Pantheon desktop

Using Ubuntu 18.04

3
  • 1
    You haven't stated what OS/release.
    – guiverc
    Commented Nov 14, 2019 at 10:33
  • 2
    You can just untick connecting automatically when editing your connections.
    – FelixJN
    Commented Nov 14, 2019 at 10:59
  • @Fiximan that is a good idea!
    – aggsol
    Commented Nov 18, 2019 at 8:34

2 Answers 2

1

Unticking a "connect automatically" will add "autoconnect=false" under the "[connection]" block of the said connection in /etc/NetworkManager/system-connections. One thing is therefore just running a little script to add this line to all known connections if it is not there, yet:

#!/bin/bash
for f in /etc/NetworkManager/system-connections/*
do
  if [[ -f "${f}" && "$(grep 'autoconnect=false' "${f}")" == "" ]]
  then
    sed -e '/^\[connection\]$/aautoconnect=false' -e '/^\[connection\]$/q' -i "${f}"
  fi
done

Notably you want it to run before a network connection occurs and also after waking from suspending/hibernating. A systemd-service disable-autoconnect.service will do:

[Unit]
Description="Service to disable all autoconnections"
Before=network.target
After=sleep.target

[Service]
ExecStart=/path/to/above/script.sh
Type=oneshot

[Install]
WantedBy=sleep.target default.target
1

You coud add a @reboot cron task to run a script that will set all the interfaces down:

  1. sudo crontab -e
  2. add this line:

    @reboot /path/to/script

The script:

#!/bin/bash

for interface in `ip link | awk 'FNR%2 == 1 {print substr($2, 1, length($2)-1)}'`; do
    ip link set $interface down
done
1
  • But that will only on reboot. I might just log out and suspend the laptop. Mabye Anacron is also a way.
    – aggsol
    Commented Nov 18, 2019 at 8:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .