Some tasks requires having tap interfaces configured + assign ownership. So, I am doing it manually:

sudo tuntap -u <username>
sudo ifconfig tap0 up
sudo ip a a dev tap0

or using

ip tuntap add dev tap0 mode tap user <username>

How can I make tap interfaces configuration peristent after reboots without adding these commands to a shell script and add to startup

What I have in mind is doing it through /etc/network/interfaces like the following:

iface tap1 inet static
pre-up /usr/sbin/tunctl -u ajn -t tap1

But for some reason, it doesn't work.

Any ideas?

up vote 16 down vote accepted

I cannot see, for the life of me, why this question should be down-voted. It is clear, correct, it has a well-defined answer. I have upvoted it.

You are using obsolete utilities like tunctl, you should use ip instead. The correct stanza for /etc/network/interfaces is:

    iface tap1 inet manual 
    pre-up ip tuntap add tap1 mode tap user root
    pre-up ip addr add dev tap1
    up ip link set dev tap1 up
    post-up ip route del dev tap1 
    post-up ip route add dev tap1
    post-down ip link del dev tap1

Your mistake was in using static instead of manual. The reason is that, since you are trying to give to the virtual interface an address in the same subnet as your main interfae (wlan0/eth0), when it tries automatically to add a local route,

    ip route add dev tap1

it finds that such a route already exists, and it complains. If you use manual instead of static, you are allowed to delete this route, which is of course useless.

Also, you should add a route

     ip route add dev tap1

to inform your kernel that there is an exception to the route

     ip route add dev eth0/wlan0 

That's all.

  • Something doesn't work for me here on ubuntu 17.10: my tun0 is not created - service networking status says that interface tun0 does not exist. Here's the interfaces file if anyone cares to take a look: – velis Jan 8 at 7:47
  • @velis Your new interface is called tap0, not tun0, that´s why it is not found. Please notice that tun and tap interfaces are fundamentally different,, which one do you wish to create? – MariusMatutiae Jan 8 at 9:03
  • Yes, it's called tap0. This answer is about creating a tap device, not a tun one. I fail to see how this can be the cause of my failure. The pre-up add device command executes perfectly from command line. – velis Jan 8 at 10:31
  • Turns out I was only missing an auto tap0 stanza. Gist updated accordingly. – velis Jan 8 at 10:51

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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