How to create post-up and pre-down routes in interfaces file?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








up vote
0
down vote

favorite












I recently installed a new VM using Ubuntu 16.04, but I am unable to copy the post-up and pre-down rules that I use in my 14.04 install.



Can you please advise what to use? I've added a few notes to indicate what each of my edited out ips are



Example of the 14.04 config:



# The primary network interface
auto eth0
iface eth0 inet static
address x.x.x.109 #vm ip
netmask 255.255.255.255
broadcast x.x.x.109 #vm ip
post-up route add x.x.x.254 dev eth0 #root machine gateway
post-up route add default gw x.x.x.254 #root machine gateway
pre-down route del x.x.x.254 dev eth0 #root machine gateway
pre-down route del default gw x.x.x.254 #root machine gateway
dns-nameservers 213.186.33.99 8.8.8.8






share|improve this question






















  • Sorry, but can anyone help?
    – Biff
    May 3 at 8:58














up vote
0
down vote

favorite












I recently installed a new VM using Ubuntu 16.04, but I am unable to copy the post-up and pre-down rules that I use in my 14.04 install.



Can you please advise what to use? I've added a few notes to indicate what each of my edited out ips are



Example of the 14.04 config:



# The primary network interface
auto eth0
iface eth0 inet static
address x.x.x.109 #vm ip
netmask 255.255.255.255
broadcast x.x.x.109 #vm ip
post-up route add x.x.x.254 dev eth0 #root machine gateway
post-up route add default gw x.x.x.254 #root machine gateway
pre-down route del x.x.x.254 dev eth0 #root machine gateway
pre-down route del default gw x.x.x.254 #root machine gateway
dns-nameservers 213.186.33.99 8.8.8.8






share|improve this question






















  • Sorry, but can anyone help?
    – Biff
    May 3 at 8:58












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I recently installed a new VM using Ubuntu 16.04, but I am unable to copy the post-up and pre-down rules that I use in my 14.04 install.



Can you please advise what to use? I've added a few notes to indicate what each of my edited out ips are



Example of the 14.04 config:



# The primary network interface
auto eth0
iface eth0 inet static
address x.x.x.109 #vm ip
netmask 255.255.255.255
broadcast x.x.x.109 #vm ip
post-up route add x.x.x.254 dev eth0 #root machine gateway
post-up route add default gw x.x.x.254 #root machine gateway
pre-down route del x.x.x.254 dev eth0 #root machine gateway
pre-down route del default gw x.x.x.254 #root machine gateway
dns-nameservers 213.186.33.99 8.8.8.8






share|improve this question














I recently installed a new VM using Ubuntu 16.04, but I am unable to copy the post-up and pre-down rules that I use in my 14.04 install.



Can you please advise what to use? I've added a few notes to indicate what each of my edited out ips are



Example of the 14.04 config:



# The primary network interface
auto eth0
iface eth0 inet static
address x.x.x.109 #vm ip
netmask 255.255.255.255
broadcast x.x.x.109 #vm ip
post-up route add x.x.x.254 dev eth0 #root machine gateway
post-up route add default gw x.x.x.254 #root machine gateway
pre-down route del x.x.x.254 dev eth0 #root machine gateway
pre-down route del default gw x.x.x.254 #root machine gateway
dns-nameservers 213.186.33.99 8.8.8.8








share|improve this question













share|improve this question




share|improve this question








edited Apr 30 at 10:15

























asked Apr 30 at 10:02









Biff

11




11











  • Sorry, but can anyone help?
    – Biff
    May 3 at 8:58
















  • Sorry, but can anyone help?
    – Biff
    May 3 at 8:58















Sorry, but can anyone help?
– Biff
May 3 at 8:58




Sorry, but can anyone help?
– Biff
May 3 at 8:58










1 Answer
1






active

oldest

votes

















up vote
0
down vote













Try with up and down instead of post-up and pre-down.



Example :



auto eth0
iface eth0 inet static
address 192.168.1.1
netmask 255.255.255.0
up route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.1.1


Or, but I didn't test it, you can write a bash script and put it in the folder /etc/network/if-up.d/ and /etc/network/if-down.d/ (you can use the variable $IFACE to know which interface is getting a connection).



In /etc/network/if-up.d/some-script:



#!/bin/bash

if [[ $IFACE == "eth0" ]]; then
ip route add x.x.x.0/24 via x.x.x.254 dev $IFACE
fi


Hope this help.






share|improve this answer






















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "89"
    ;
    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',
    convertImagesToLinks: true,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1030048%2fhow-to-create-post-up-and-pre-down-routes-in-interfaces-file%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    Try with up and down instead of post-up and pre-down.



    Example :



    auto eth0
    iface eth0 inet static
    address 192.168.1.1
    netmask 255.255.255.0
    up route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.1.1


    Or, but I didn't test it, you can write a bash script and put it in the folder /etc/network/if-up.d/ and /etc/network/if-down.d/ (you can use the variable $IFACE to know which interface is getting a connection).



    In /etc/network/if-up.d/some-script:



    #!/bin/bash

    if [[ $IFACE == "eth0" ]]; then
    ip route add x.x.x.0/24 via x.x.x.254 dev $IFACE
    fi


    Hope this help.






    share|improve this answer


























      up vote
      0
      down vote













      Try with up and down instead of post-up and pre-down.



      Example :



      auto eth0
      iface eth0 inet static
      address 192.168.1.1
      netmask 255.255.255.0
      up route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.1.1


      Or, but I didn't test it, you can write a bash script and put it in the folder /etc/network/if-up.d/ and /etc/network/if-down.d/ (you can use the variable $IFACE to know which interface is getting a connection).



      In /etc/network/if-up.d/some-script:



      #!/bin/bash

      if [[ $IFACE == "eth0" ]]; then
      ip route add x.x.x.0/24 via x.x.x.254 dev $IFACE
      fi


      Hope this help.






      share|improve this answer
























        up vote
        0
        down vote










        up vote
        0
        down vote









        Try with up and down instead of post-up and pre-down.



        Example :



        auto eth0
        iface eth0 inet static
        address 192.168.1.1
        netmask 255.255.255.0
        up route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.1.1


        Or, but I didn't test it, you can write a bash script and put it in the folder /etc/network/if-up.d/ and /etc/network/if-down.d/ (you can use the variable $IFACE to know which interface is getting a connection).



        In /etc/network/if-up.d/some-script:



        #!/bin/bash

        if [[ $IFACE == "eth0" ]]; then
        ip route add x.x.x.0/24 via x.x.x.254 dev $IFACE
        fi


        Hope this help.






        share|improve this answer














        Try with up and down instead of post-up and pre-down.



        Example :



        auto eth0
        iface eth0 inet static
        address 192.168.1.1
        netmask 255.255.255.0
        up route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.1.1


        Or, but I didn't test it, you can write a bash script and put it in the folder /etc/network/if-up.d/ and /etc/network/if-down.d/ (you can use the variable $IFACE to know which interface is getting a connection).



        In /etc/network/if-up.d/some-script:



        #!/bin/bash

        if [[ $IFACE == "eth0" ]]; then
        ip route add x.x.x.0/24 via x.x.x.254 dev $IFACE
        fi


        Hope this help.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited May 7 at 12:25

























        answered May 7 at 11:10









        Eraseth

        1299




        1299



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1030048%2fhow-to-create-post-up-and-pre-down-routes-in-interfaces-file%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How do so many people here on Academia.SE, and in general, afford lavish higher education programs?

            Unable to upgrade pip

            Cutting all the characters after the last /