Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
the the machines ip address dhcp or static? – chaos Dec 28 '13 at 20:48
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
up vote 1 down vote accepted

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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