The Computer Oracle

How to make tap interfaces persistent after reboot?

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: RPG Blues Looping

--

Chapters
00:00 How To Make Tap Interfaces Persistent After Reboot?
00:40 Accepted Answer Score 24
01:49 Answer 2 Score 0
02:49 Answer 3 Score 0
03:13 Thank you

--

Full question
https://superuser.com/questions/854401/h...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#linux #networking #ubuntu #networkinterface

#avk47



ACCEPTED ANSWER

Score 24


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 192.168.1.121/24 dev tap1
    up ip link set dev tap1 up
    post-up ip route del 192.168.1.0/24 dev tap1 
    post-up ip route add 192.168.1.121/32 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 192.168.1.0/24 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 192.168.1.121/32 dev tap1

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

     ip route add 192.168.1.0/24 dev eth0/wlan0 

That's all.




ANSWER 2

Score 0


There are a few more steps you might need to do:

  1. Add a new routing table Edit /etc/iproute2/rt_tables to add a new routing table. Call it routing table “rt2” and set its preferences to 1:
    55     local
    254     main
    253     default
    0       unspec
    1       rt2
  1. As explained in the previous answer, create a tap interface, but then you need to configure the new routing tables, and set routing rules. Add to /etc/network/interfaces:
   #create a tap interface and make it persistent
    iface tap1 inet manual 
    pre-up ip tuntap add tap1 mode tap user root
    pre-up ip addr add 192.168.1.121/24 dev tap1
    up ip link set dev tap1 up
    post-up ip route del 192.168.1.0/24 dev tap1 
    post-up ip route add 192.168.1.121/32 dev tap1
    post-down ip link del dev tap1

    #configure the new routing table so that network 192.168.1.0 can be reached through the tap1 interface
    post-up ip route add 192.168.1.0/24 dev tap1 src 192.168.1.121 table rt2

    #set the default gateway to be 192.168.1.10
    post-up ip route add default via 192.168.1.10 dev tap1 table rt2

    #set rules so that traffic from and to 192.168.1.121 use the rt2 routing table 
    post-up ip rule add from 192.168.1.121/24 table rt2
    post-up ip rule add to 192.168.1.121/24 table rt2
sudo ifup tap1

To test it:

ip route list table rt2
ip rule show



ANSWER 3

Score 0


Follow the Simple Steps:

Step 1: Install uml-utilities using

sudo apt-get install uml-utilities

Step 2: Add the below commands in /etc/network/interfaces

auto tap0
iface tap0 inet static
address 192.168.100.1
netmask 255.255.255.0
pre-up /usr/bin/tunctl -t tap0

Step 3: Reboot the Machine and execute the command ifconfig Changes you've made it should reflect