For some reason everytime I connect to my VM I have to manually launch these two commands for it to connect to the Internet.

route add dev eth0
route add default gw

Is there a way I can automate this so that I don't have to do this manually every time?

  • 1
    the the machines ip address dhcp or static?
    – chaos
    Dec 28 '13 at 20:48
  • 3
    Please give us some more information. What OS is the VM running, CentOS? Do you have root access to it?
    – terdon
    Dec 28 '13 at 20:50
  • Please post the output of ip address show and ip route show from within your VM before you enter these commands.
    – Bananguin
    Dec 28 '13 at 23:40

You can create an /etc/sysconfig/network-scripts/route-eth0 file with the content like this if you use multiple routes:

default via dev eth0 via dev eth0 via dev eth0

For the default gateway you need to add this line :


To the file /etc/sysconfig/network

Link: https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/5/html/Deployment_Guide/s1-networkscripts-static-routes.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.