Ubuntu: Virtualbox Ubuntu Network Bridge auto create on machine start



Question:

I am using Ubuntu 16.04 images

I follow this tutorial

The last part, make the network permanent part does not work in my scenario.

At this point, the network bridge will be detatched from eth1 if you reboot the machine. So here are two more things to make the setting permanent.

Update /etc/network/interfaces like this:

auto eth1 iface eth1 inet manual      pre-up ifconfig $IFACE up     post-down ifconfig $IFACE down  

And add the following command on /etc/rc.local (before exit 0):

brctl addif docker1 eth1  

After I reboot the machine, I can't ping the IP from my host. So I suspect is rc.local did not work.

I also tried to remove the -e parameter in rc.local file, but after reboot, still not working.


Next I try solution 2

Create a file docker-network.sh in directory /etc/init.d:

#!/bin/sh  sudo ip addr del 192.168.33.10/24 dev eth1  sudo brctl addif docker1 eth1  

Make it executable:

sudo chmod +x /etc/init.d/docker-network.sh  

Create symlinks for my script for various runlevels:

sudo update-rc.d docker-network.sh defaults  

After I restart my virtual machine. I still can't ping direct to the machine. However, after I SSH to the machine I run /etc/init.d/docker-network.sh then I am able to ping it.

So how do I make sure it able to run after I reboot?

UPDATE

I run sudo systemctl enable rc-local.service and restart. Then I run sudo systemctl status rc-local

vagrant@vagrant:~$ sudo systemctl status rc-local  ● rc-local.service - /etc/rc.local Compatibility     Loaded: loaded (/lib/systemd/system/rc-local.service; static; vendor preset:    Drop-In: /lib/systemd/system/rc-local.service.d             â""â"€debian.conf     Active: active (exited) since Mon 2017-08-21 09:27:56 UTC; 10min ago    Process: 1247 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)      Tasks: 0     Memory: 0B        CPU: 0    Aug 21 09:27:56 vagrant systemd[1]: Starting /etc/rc.local Compatibility...  Aug 21 09:27:56 vagrant sudo[1259]:     root : TTY=unknown ; PWD=/ ; USER=root ;  Aug 21 09:27:56 vagrant sudo[1259]: pam_unix(sudo:session): session opened for u  Aug 21 09:27:56 vagrant sudo[1308]:     root : TTY=unknown ; PWD=/ ; USER=root ;  Aug 21 09:27:56 vagrant sudo[1308]: pam_unix(sudo:session): session opened for u  Aug 21 09:27:56 vagrant rc.local[1247]: bridge eth1 does not exist!  Aug 21 09:27:56 vagrant systemd[1]: Started /etc/rc.local Compatibility.  


Solution:1

Ubuntu is now turned into using systemd since started in Ubuntu 15.04 beta version and rc.local is "off" by default in 16.04.

You can enable rc.local by the following command and reboot your Ubuntu.

sudo systemctl enable rc-local.service  

You would like to check the active status by the following command:

sudo systemctl status rc-local  

Based on the line printed from above command result:

Aug 21 09:27:56 vagrant rc.local[1247]: bridge eth1 does not exist

It means rc.local is triggered your script and it got executed but sometimes rc.locsl executing at very first when booting and it cause some interruption to be happen when executing the commands/script in your rc.local.

I suggest to put one sleep x before your command/script should run in rc.local (where x can specify value in seconds, may you need to increase this xseconds to see when it works), also you can do sleep x in your script before executing the main command.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »