Network Interfaces don't come up properly on startup

I have this unusual problem in a Virtual Box Server...  For some reason the 2nd networking device does not connect on boot up and there is an error when I issue the command:
sudo /etc/init.d/networking restart

However if I use:   sudo ifconfig enp0s8 down  followed by sudo ifconfig enp0s8 up  
then I am magically connected.

I know I'm good because I can or can't ping the gateway 192.168.14.3  (and the host computer can ping back the Virtual Machine)

I would also appreciate any info on how you went about diagnosing the problem.

-------------------------------
Here is my interfaces file
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
#
# To restart interfaces sudo /ect/init.d/networking restart

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto enp0s3
iface enp0s3 inet dhcp

# The secondary network interface
auto enp0s8
iface enp0s8 inet static
        address 192.168.14.25
        netmask 255.255.255.0
        gateway 192.168.14.3

----------------------------
and here is the  pertinant section from journalctl -xe
-- Subject: Unit networking.service has begun start-up
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit networking.service has begun starting up.
Feb 07 20:17:58 personalserver1 ifup[1462]: RTNETLINK answers: File exists
Feb 07 20:17:58 personalserver1 ifup[1462]: Failed to bring up enp0s8.
Feb 07 20:17:58 personalserver1 systemd[1]: Reloading.
Feb 07 20:17:59 personalserver1 systemd[1]: snapd.refresh.timer: Adding 3h 13min 16.803887s random time.
Feb 07 20:17:59 personalserver1 systemd[1]: apt-daily.timer: Adding 10h 1min 40.024647s random time.
Feb 07 20:17:59 personalserver1 systemd[1]: snapd.refresh.timer: Adding 3h 27min 46.091373s random time.
Feb 07 20:17:59 personalserver1 systemd[1]: networking.service: Main process exited, code=exited, status=1/FAILURE
Feb 07 20:17:59 personalserver1 systemd[1]: Failed to start Raise network interfaces.
-- Subject: Unit networking.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit networking.service has failed.
--
-- The result is failed.
Feb 07 20:17:59 personalserver1 systemd[1]: networking.service: Unit entered failed state.
Feb 07 20:17:59 personalserver1 systemd[1]: networking.service: Failed with result 'exit-code'.
Feb 07 20:17:59 personalserver1 sudo[1445]: pam_unix(sudo:session): session closed for user root
Daniel KruegerCS StudentAsked:
Who is Participating?
 
Daniel KruegerCS StudentAuthor Commented:
Ok so that was enough to point me in the right direction... I'm surprised I still had a bit of a problem with all the different configurations I ried though.

So keeping the interface at boot time in order... On the virtual machine I did the following
I set Adapter No 1 to the Host Only adapter
Adapter 2 to the Nat Network

The settings in Virtual Box are a bit jumbled around.  In the Virtual Box Player 5.1+ versions they use a Virtual Box Manager.  Here I made the Virtual Box Host Only Ethernet Adapter to have an IPv4 address of 192.168.14.3  and made sure the DHCP was off.

The NAT Network however is managed under file->preferences (under the player's file->preferences not the machine's preferences)  That was clicked to support DHCP.

Finally the machine settings.. as described above the Adapter 1-->host only and Adapter 2-NAT Network

Then... I changed the order around in the interfaces file
based on the information above  
      enp0s3 is to be mapped to Adapter 1
      enp0s8 is to be mapped to Adapter 2

So now the interfaces file reflects this natural order of things.  Since there is no DHCP supplied with Adapter 1 I put the manual / static settings for enp0s3 and let DHCP that is supplied on Adapter 2 take care of the assignment for enp0s8

// From my /etc/network/interfaces file
# The primary network interface
auto enp0s3
iface enp0s3 inet static
        address 192.168.14.25
        netmask 255.255.255.0
        gateway 192.168.14.3


# The secondary network interface
auto enp0s8
iface enp0s8 inet dhcp
0
 
Hitendra KataraLinux System adminCommented:
Hello sir,
You are using the two interface card to use the internet and in ubuntu by default, it starts the primary NIC card at the boot time, so set the secondary NIC at first priority at the time of booting. Kindly follow the link for it https://askubuntu.com/questions/626888/changing-the-priority-of-network-interface
0
 
Daniel KruegerCS StudentAuthor Commented:
One more thing to finish this off
I had to add a route for the NAT Network to the routing table...

old table
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.14.3    0.0.0.0         UG    0      0        0 enp0s3
10.0.2.0        0.0.0.0         255.255.255.0   U     0      0        0 enp0s8
192.168.14.0    0.0.0.0         255.255.255.0   U     0      0        0 enp0s3

Open in new window



sudo route add default gw 10.0.2.1 enp0s8

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.0.2.1        0.0.0.0         UG    0      0        0 enp0s8
0.0.0.0         192.168.14.3    0.0.0.0         UG    0      0        0 enp0s3
10.0.2.0        0.0.0.0         255.255.255.0   U     0      0        0 enp0s8
192.168.14.0    0.0.0.0         255.255.255.0   U     0      0        0 enp0s3

Open in new window

0
 
Daniel KruegerCS StudentAuthor Commented:
Well the provided solution was not very detailed and really didn't full explain the nuances of the Virtual Box environment.  I suspect others will have similar problems with other virtualization environments.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.