Results 1 to 8 of 8

Thread: Permanent routing (Ubuntu 13.04)

  1. #1
    Join Date
    Sep 2013
    Beans
    5

    Question Permanent routing (Ubuntu 13.04)

    I have 2 connections: wlan0 (gw: 192.168.1.1) and eth0 (gw: 192.168.2.1).
    My default connection is wlan0, but I wanted some websites load through my eth0, so I set up routing for those websites/IPs like this:

    Code:
    route add -net 31.135.208.0/21 gw 192.168.2.1 dev eth0
    This works, however is not permanent (disappears after reboot). I tried to put this code in /etc/network/interfaces like this:

    Code:
    up route add -net 31.135.208.0/21 gw 192.168.2.1 dev eth0
    but when I restart Ubuntu, it starts without networking (it crashes). I also put these lines into that file:

    Code:
    auto eth0
    address 192.168.2.125
    gateway 192.168.2.1
    netmask 255.255.255.0
    but still system boots without networking.

    Currently I have put route command into /etc/rc.local, it works, but it is not permanent, because when I restart/re-connect my eth0 (for some reason), routing disappears.

    Some notes:
    I have long list of IPs to route.
    My router, which I connected eth0 is set to DHCP.
    I tried to connect eth0 both static and DHCP way.

    So, how do I set permanent routing?

    Thanks for you help!

  2. #2
    Join Date
    Jul 2013
    Location
    Wisconsin
    Beans
    4,952

    Re: Permanent routing (Ubuntu 13.04)

    One way to do it it using Upstart to detect when eth0 is connected

    Create a file /etc/init/custom-routes
    Code:
    # Document your need here so you remember it in six months.
    # The script runs each time the eth0 network device comes up.
    # WARNING: This script does not check which network you are connecting to. It's easy to add to the script if you wish.
    
    description "My custom routes for eth0 connections"
    
    start on net-device-up IFACE!=eth0
    
    script
    
    # Section 1 - If you want to test which network eth0 is connected to, do it here
    
    # Section 2 - Routing changes
    route add -net 31.135.208.0/21 gw 192.168.2.1 dev eth0
    # add more routes here
    # add even more routes here
    
    # Section 3 - Do something else, if desired
    
    end script
    You do not need to reboot to test the new Upstart job. Upstart monitors changes and loads them automatically. Merely plug in your ethernet cable.

  3. #3
    Join Date
    Sep 2013
    Beans
    5

    Re: Permanent routing (Ubuntu 13.04)

    Hey ian-weisser, sorry for late reply, for some reason gmail marked message from ubuntuforums as spam. Thanks very much for help, however, it is not working. I read about upstart jobs from their cookbook, it makes sense, but this simple script is not working. After some research, I changed script to following, but still no luck:

    Code:
    description "My custom routes for eth0 connections"
    
    start on (local-filesystems and net-device-up IFACE=eth0)
    
    script
        # Routing changes
        route add -net 31.135.208.0/21 gw 192.168.2.1 dev eth0
    
        # Just for test
        mkdir /home/azamat/Desktop/test
    
    end script
    Is there something wrong with script?
    Thanks!

  4. #4
    Join Date
    Jul 2013
    Location
    Wisconsin
    Beans
    4,952

    Re: Permanent routing (Ubuntu 13.04)

    Well, my syntax is slightly different (indenting, parentheses around the AND condition), probably due to age...
    but your syntax seems fine. For example, /etc/init/usplash.conf does it your way.

    What command are you using to test your upstart job?

  5. #5
    Join Date
    Sep 2013
    Beans
    5

    Re: Permanent routing (Ubuntu 13.04)

    Quote Originally Posted by ian-weisser View Post
    Well, my syntax is slightly different (indenting, parentheses around the AND condition), probably due to age...
    but your syntax seems fine. For example, /etc/init/usplash.conf does it your way.

    What command are you using to test your upstart job?
    I have just saved that file in /etc/init and plugging in-out my ethernet cable to check if script runs. I also tried to reboot computer, but it does not work..

  6. #6
    Join Date
    Sep 2013
    Beans
    5

    Re: Permanent routing (Ubuntu 13.04)

    If you are on askubuntu.com, you can submit your answer to the same question of mine: http://askubuntu.com/questions/33997...g-ubuntu-13-04
    and earn some votes from the people of askubuntu

  7. #7
    Join Date
    Jul 2013
    Location
    Wisconsin
    Beans
    4,952

    Re: Permanent routing (Ubuntu 13.04)

    Suggestion: Simplify a bit to get the test working. Then we can complicate it again

    This should work on *any* network device coming up.
    Code:
    description "My custom routes for eth0 connections"
    start on net-device-up
    
    script     
        mkdir /home/azamat/Desktop/test
    end script
    You can also force it using sudo service <servicename> start

  8. #8
    Join Date
    Sep 2013
    Beans
    5

    Re: Permanent routing (Ubuntu 13.04)

    Tried, here is output from terminal:

    Code:
    /etc/init$ ls -l | grep custom-routes
    -rw-rw-rw- 1 root root  134 Sep 19 17:09 custom-routes
    
    /etc/init$ sudo service custom-routes start
    custom-routes: unrecognized service
    Also tried to reconnect network cable, nothing happened..

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •