How can I permanently delete tun interfaces

12,335

If your want to permanently delete any interface so that it does not appear after a reboot, then it depends on which service they are under the control of. If your used nm, then in essence it automatically creates tun/tap interfaces when your install openvpn and they cannot be removed using networkctl, but only by force with nmcli tool. There is one subtlety between nm and sn, when your activate sn, it is important for your to uninstall nm BEFORE installing for example 'openvpn', since nm automatically creates an interface for traffic tunneling and it remains in the list networkctl and it CANNOT remove it. But if your uninstall and deactivate nm before installing openvpn, then the created interfaces can be not created from and disappear from the networkctl list. So that your do not stumble over the created by nm interfaces, ... there is no beach in the list of networkctl and if your want to revolutionize then i advise your to use systemd-networkd, your can gradually get used to its syntax.

  • Nmcli is a command-line tool for controlling network-manager and reporting network status.
  • Networkctl may be used to introspect the state of the network links as seen by systemd-networkd.

Nmcli from network-manager.

shut down all interfaces after reboot managed by nm:

nmcli networking off

show interfaces/connection:

nmcli
nmcli general status
nmcli device show tun0
nmcli connection

temporarily disable/remove interface from nm until reboot:

nmcli device set autoconnect no tun0
nmcli device set managed no tun0
nmcli device delete tun0
uuidgen tun0

84a068f7-efe5-40c5-a813-3fc85fabdcc3 # replace it with yours uuid

nmcli connection delete 84a068f7-efe5-40c5-a813-3fc85fabdcc3

Networkctl from systemd-networkd.

In order to have a possibility to think about an adequate solution to the setting and not in a hurry to reinstall the system, then the only way to bypass unnecessary interfaces from nm is to create a config that uses sn of all the interfaces your need in /etc/default/grub, thereby adding their in autoload. to see the interfaces in networkctl, only which ones your are interested in, create a config 01-netcfg.yaml:

https://netplan.io/

sudo apt install bridge-utils net-tools ; reboot # use net-tools to display ifconfig list
sudo nano /etc/netplan/01-netcfg.yaml
netplan --debug generate

add the config you created to autoload:

sudo nano /etc/default/grub

replace the line:

GRUB_CMDLINE_LINUX=""

on:

GRUB_CMDLINE_LINUX="netcfg/do_not_use_netplan=true"

update-grub ; reboot
ifconfig

see all the interfaces you have:

networkctl status all

WARNING: systemd-networkd is not running, output will be incomplete.
Failed to request link: No such device

accordingly, your can see here that networkctl does not display until sn is running.

to shut down the interface before rebooting in networkctl:

sudo ifconfig tun0 down
sudo ip link set tun0 down
sudo ip link delete tun0
sudo systemctl restart systemd-networkd ; sudo systemctl status systemd-networkd
Share:
12,335
KeyszerS
Author by

KeyszerS

Nerd, pure and simple.

Updated on September 18, 2022

Comments

  • KeyszerS
    KeyszerS over 1 year

    I am running Ubuntu 19.10 with openvpn 2.4.7, and over time I have accumulated 40 tun devices, which all show up when I log in. ifconfig confirms that they are all there.

    So many tun adapters it can't show them all

    I have tried:

    • doing sudo ip link delete tun0 (and for all other devices)
    • doing sudo ip link delete tun0 and also doing sudo tunctl -d tun0 (which replies Set 'tun0' nonpersistent - and I've done this to all others too)
    • doing sudo ifconfig tun0 down (and all others)
    • removing and reinstalling openvpn (which removes all tun devices)

    But after a reboot, they all come back. The only way I can use my system is to remove openvpn and reinstall after every boot. They are not part of netplan.

    How can I delete them permanently?

    *Edit: Disabling IPv6 actually made these devices disappear. I cannot belive it. Disabling IPv6 should not be a solution.

    • Hack Saw
      Hack Saw over 4 years
      Have they been added to /etc/network/interfaces.d?
    • KeyszerS
      KeyszerS over 4 years
      @HackSaw No such folder exists on my system. they're nowhere to be found inside /etc/network (which contains if-down.d, if-pre-up.d and if-up.d as well as the file interfaces
    • Hack Saw
      Hack Saw over 4 years
      Oh, how odd. Is there an include line in /etc/network/interfaces? Or, for that matter, are the device not listed there? A useful trick I use often is to grep for thing in /etc: sudo grep -r tun3
    • KeyszerS
      KeyszerS over 4 years
      @HackSaw I got really excited when you suggested the grep -r command, didn't think of that. I tried it and got no results for tun3. I have removed openvpn and reinstalled, so right now I only have tun0 active. doing sudo grep -r tun0 only shows one hit and that's in my danted.conf file, which is telling my socks5 daemon what external interface to use. No other hits. I also tried searching in /dev
    • Hack Saw
      Hack Saw over 4 years
      Huh... well, now we're getting out of my depth, but it's worth grepping a few other areas, such are /var/run, /usr/libexec, and so on. I'd look at the areas which those other servers might decide to plant files in. You also might find clues by looking at /var/log. My fave command to use there is ls -ltr, which sorts the files most recently updated last. Good luck!
    • vidarlo
      vidarlo over 4 years
      What does ps aux | grep openvpn show?