How to make tap interfaces persistent after reboot? Announcing the arrival of Valued Associate...

Is there any way for the UK Prime Minister to make a motion directly dependent on Government confidence?

Maximum summed powersets with non-adjacent items

8 Prisoners wearing hats

Withdrew £2800, but only £2000 shows as withdrawn on online banking; what are my obligations?

If a VARCHAR(MAX) column is included in an index, is the entire value always stored in the index page(s)?

Trademark violation for app?

Amount of permutations on an NxNxN Rubik's Cube

How do pianists reach extremely loud dynamics?

How to Make a Beautiful Stacked 3D Plot

What does the "x" in "x86" represent?

Why wasn't DOSKEY integrated with COMMAND.COM?

Do wooden building fires get hotter than 600°C?

How could we fake a moon landing now?

What causes the direction of lightning flashes?

How come Sam didn't become Lord of Horn Hill?

Dating a Former Employee

How to answer "Have you ever been terminated?"

How would a mousetrap for use in space work?

Is there a kind of relay only consumes power when switching?

old style "caution" boxes

Is the Standard Deduction better than Itemized when both are the same amount?

Fantasy story; one type of magic grows in power with use, but the more powerful they are, they more they are drawn to travel to their source

Should I use a zero-interest credit card for a large one-time purchase?

What does "lightly crushed" mean for cardamon pods?



How to make tap interfaces persistent after reboot?



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)Can't create tap interface on Debianrouting a secondary IP-addr. of a different private network on the same interfaceVirtual Box Bridged network w/ Static IP Win7 host Ubuntu GuestConfigure network Linux on VMware (Nat or Bridged)Wired Network Occasionally Fails (Debian)how to network between 2 ubuntu virtual machines (so that i can open a user via SSH from VM1 on VM2)Manually assign an IPCannot connect to internet in Kali LinuxInterconnecting two networks connected by two linux routers on Raspberry PiAdd persistent static route - AWS InstanceStatic route produces host unreachable error





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







22















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 192.168.1.1/24 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
address 192.168.1.121
netmask 255.255.255.0
pre-up /usr/sbin/tunctl -u ajn -t tap1


But for some reason, it doesn't work.



Any ideas?










share|improve this question





























    22















    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 192.168.1.1/24 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
    address 192.168.1.121
    netmask 255.255.255.0
    pre-up /usr/sbin/tunctl -u ajn -t tap1


    But for some reason, it doesn't work.



    Any ideas?










    share|improve this question

























      22












      22








      22


      7






      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 192.168.1.1/24 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
      address 192.168.1.121
      netmask 255.255.255.0
      pre-up /usr/sbin/tunctl -u ajn -t tap1


      But for some reason, it doesn't work.



      Any ideas?










      share|improve this question














      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 192.168.1.1/24 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
      address 192.168.1.121
      netmask 255.255.255.0
      pre-up /usr/sbin/tunctl -u ajn -t tap1


      But for some reason, it doesn't work.



      Any ideas?







      linux networking ubuntu network-interface






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 19 '14 at 3:28









      AJNAJN

      244129




      244129






















          2 Answers
          2






          active

          oldest

          votes


















          20














          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.






          share|improve this answer


























          • 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: gist.github.com/velis74/ab75a46893eaed8bd08b8c6292b2737a

            – velis
            Jan 8 '18 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, en.wikipedia.org/wiki/TUN/TAP, which one do you wish to create?

            – MariusMatutiae
            Jan 8 '18 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 '18 at 10:31











          • Turns out I was only missing an auto tap0 stanza. Gist updated accordingly.

            – velis
            Jan 8 '18 at 10:51



















          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





          share|improve this answer










          New contributor




          ehsan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.





















            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "3"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f854401%2fhow-to-make-tap-interfaces-persistent-after-reboot%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            20














            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.






            share|improve this answer


























            • 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: gist.github.com/velis74/ab75a46893eaed8bd08b8c6292b2737a

              – velis
              Jan 8 '18 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, en.wikipedia.org/wiki/TUN/TAP, which one do you wish to create?

              – MariusMatutiae
              Jan 8 '18 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 '18 at 10:31











            • Turns out I was only missing an auto tap0 stanza. Gist updated accordingly.

              – velis
              Jan 8 '18 at 10:51
















            20














            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.






            share|improve this answer


























            • 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: gist.github.com/velis74/ab75a46893eaed8bd08b8c6292b2737a

              – velis
              Jan 8 '18 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, en.wikipedia.org/wiki/TUN/TAP, which one do you wish to create?

              – MariusMatutiae
              Jan 8 '18 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 '18 at 10:31











            • Turns out I was only missing an auto tap0 stanza. Gist updated accordingly.

              – velis
              Jan 8 '18 at 10:51














            20












            20








            20







            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.






            share|improve this answer















            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.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Dec 20 '14 at 7:08

























            answered Dec 19 '14 at 11:25









            MariusMatutiaeMariusMatutiae

            39.1k954101




            39.1k954101













            • 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: gist.github.com/velis74/ab75a46893eaed8bd08b8c6292b2737a

              – velis
              Jan 8 '18 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, en.wikipedia.org/wiki/TUN/TAP, which one do you wish to create?

              – MariusMatutiae
              Jan 8 '18 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 '18 at 10:31











            • Turns out I was only missing an auto tap0 stanza. Gist updated accordingly.

              – velis
              Jan 8 '18 at 10:51



















            • 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: gist.github.com/velis74/ab75a46893eaed8bd08b8c6292b2737a

              – velis
              Jan 8 '18 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, en.wikipedia.org/wiki/TUN/TAP, which one do you wish to create?

              – MariusMatutiae
              Jan 8 '18 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 '18 at 10:31











            • Turns out I was only missing an auto tap0 stanza. Gist updated accordingly.

              – velis
              Jan 8 '18 at 10:51

















            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: gist.github.com/velis74/ab75a46893eaed8bd08b8c6292b2737a

            – velis
            Jan 8 '18 at 7:47





            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: gist.github.com/velis74/ab75a46893eaed8bd08b8c6292b2737a

            – velis
            Jan 8 '18 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, en.wikipedia.org/wiki/TUN/TAP, which one do you wish to create?

            – MariusMatutiae
            Jan 8 '18 at 9:03





            @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, en.wikipedia.org/wiki/TUN/TAP, which one do you wish to create?

            – MariusMatutiae
            Jan 8 '18 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 '18 at 10:31





            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 '18 at 10:31













            Turns out I was only missing an auto tap0 stanza. Gist updated accordingly.

            – velis
            Jan 8 '18 at 10:51





            Turns out I was only missing an auto tap0 stanza. Gist updated accordingly.

            – velis
            Jan 8 '18 at 10:51













            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





            share|improve this answer










            New contributor




            ehsan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.

























              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





              share|improve this answer










              New contributor




              ehsan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.























                0












                0








                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





                share|improve this answer










                New contributor




                ehsan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.










                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






                share|improve this answer










                New contributor




                ehsan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.









                share|improve this answer



                share|improve this answer








                edited 14 hours ago





















                New contributor




                ehsan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.









                answered 14 hours ago









                ehsanehsan

                11




                11




                New contributor




                ehsan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.





                New contributor





                ehsan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.






                ehsan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Super User!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f854401%2fhow-to-make-tap-interfaces-persistent-after-reboot%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Couldn't open a raw socket. Error: Permission denied (13) (nmap)Is it possible to run networking commands...

                    VNC viewer RFB protocol error: bad desktop size 0x0I Cannot Type the Key 'd' (lowercase) in VNC Viewer...

                    Why not use the yoke to control yaw, as well as pitch and roll? Announcing the arrival of...