Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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

1 Answer 1

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


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.