add default route on boot

39,004

Solution 1

The right place should be the file /etc/network/interfaces. You add a line like:

up route add default gw 192.168.0.1 dev eth0

The IP address is the one of your default gateway and the last entry is the device name of your device.

Solution 2

Already long time ago, but none of the above described solutions worked for me. I finally found the solution in the comments in the ip-up file under the /etc/ppp directory in Ubuntu.

I created a script in the /etc/ppp/ip-up.d directory, where I put the route add command in.

The script is picked up automatically after the pptp connection was created. It works like a charm.

Solution 3

If you are using Network Manager, you can add a route via the Configure VPN... menu option under the networking widget. Then on the VPN, click on edit for the VPN you need to add a route to. Then under IPV4 settings, change Method to Automatic VPN. Then click on routes and add your route there (eg network 192.168.1.0 netmask 255.255.255.0 gateway 192.168.1.20) where the gateway is the VPN server you are connecting to.

Share:
39,004

Related videos on Youtube

fcosp
Author by

fcosp

Updated on September 17, 2022

Comments

  • fcosp
    fcosp over 1 year

    I'm trying to add a default route on my ppp0 connection, I want the default route points to that connection. I tried to add it in /etc/rc.local but I don't think that is the right place to do so. I would like to know where is the right place to accomplish this.

    • txwikinger
      txwikinger almost 14 years
      What kind of network interface are you talking about? eth, wireless, ... ?
    • fcosp
      fcosp almost 14 years
      ethernet, i need to add this "route add default gw xxx.xxx.xxx.xxx" but when the machine shutdown or restart it loses..
  • fcosp
    fcosp almost 14 years
    here is the las think i tried. The problem is that my conexion is ppp0, my eth0 is my LAN, and the eth1 is the ISP conexion... i put in /etc/network/interfaces "up route add default gw xxx.xxx.xxx.xxx dev eth1" also try with "up route add default gw xxx.xxx.xxx.xxx dev ppp0" and didnt work.. in both cases when i run netstat -nr i get this: Destination Gateway Genmask Flags MSS Window irtt Iface 0.0.0.0 0.0.0.0 0.0.0.0 U 0 0 0 ppp
  • fcosp
    fcosp almost 14 years
    if i run in command line "route add default gw xxx.xxx.xxx.xxx dev ppp0" Works! after run netstat -nr i get Destination Gateway Genmask Flags MSS Window irtt Iface 0.0.0.0 xxx.xxx.xxx.xxx 0.0.0.0 UG 0 0 0 ppp0
  • maco
    maco over 13 years
    Are you using Network Manager? It'll overwrite this setting.
  • djeikyb
    djeikyb about 13 years
    Is there a cli method / file to edit that isn't going to be immediately overwritten by NetworkManager?
  • AnthonyB
    AnthonyB almost 5 years
    Still works in 2019, even on Raspbian.