In my Virtual Machine I have two network interfaces (both bridge mode, I need bridge mode because I want to create a server). One of them is Ethernet (eth0) and the other WiFi (wlan0) - In the guest (CentOS) they are represented as enp0s3 and enp0s8.

I set static IPs for them, but the connection only works when my laptop is connected to an Ethernet cable. When I remove it and the laptop switches to WiFi, I get the problem, even with the interface enp0s8 (which in the VirtualBox config is wlan0)

Host: Ubuntu 14.04 Guest: CentOS

VirtualBox Network Settings:

* Adapter 1: 
  * Mode: Bridge
  * eth0
  * Network Card: Intel PRO/1000 MT Desktop (82540EM)
  * MAC: 080027BAC610
* Adapter 2
  * Mode: Bridge
  * wlan0
  * Network Card: Intel PRO/1000 MT Desktop (82540EM)
  * MAC: 080027F97DAE 

I have run the following commands:

[root@localhost network-scripts]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:ba:c6:10 brd ff:ff:ff:ff:ff:ff
    inet brd scope global enp0s3
       valid_lft forever preferred_lft forever
    inet6 fe80::99a9:d4a6:23c4:df9d/64 scope link
       valid_lft forever preferred_lft forever
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:f9:7d:ae brd ff:ff:ff:ff:ff:ff
    inet brd scope global enp0s8
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fef9:7dae/64 scope link
       valid_lft forever preferred_lft forever
[root@localhost network-scripts]# tracepath
 1?: [LOCALHOST]                                        pmtu 1500
 1:  localhost.localdomain                              3006.372ms !H
     Resume: pmtu 1500

ifcfg-enp0s3 represents the first adapter (eth0)

[root@localhost network-scripts]# cat ifcfg-enp0s3

ifcfg-enp0s8 represents the second adapter (wlan0).


Also we have the command ip r and the result of /etc/resolv.conf

[root@localhost network-scripts]# ip r
default via dev enp0s3  proto static  metric 100
default via dev enp0s8  proto static  metric 101 dev enp0s3  proto kernel  scope link  src  metric 100 dev enp0s8  proto kernel  scope link  src  metric 101
[root@localhost network-scripts]# cat /etc/resolv.conf
# Generated by NetworkManager

How can I make the connection work regardless of whether or not an Ethernet cable is plugged in?

  • Please don't post images of text. I typed out the contents, but you may want to check that I made no mistakes in transcription – Fox Apr 30 '17 at 4:28
  • @Fox Man, I'm so sorry about that. In fact, I prefer post the text code, but in this particular case, I installed the minimal CentOs in VirtualBox, and I couldn't copy the terminal output. I was afraid to type word by word, and because of this, make mistakes in typing – tdmsoares Apr 30 '17 at 5:37
  • 2
    The usual way to connect two interfaces "transparently" to the same network is to create a bridge interface that owns a single IP on the network, and attach the other interfaces to that bridge (see a Debian page on the matter for an example). The exact commands shown on the Debian page won't necessarily transfer, but it gives a general overview. Is there a reason you aren't doing this? – Fox Apr 30 '17 at 5:50

Having two connections on the same network needs to be done carefully (why would the system route to/from the wifi connection if the eth one is on the same network). Try moving the ethernet onto a different network from the wifi.

If you don't control the network and therefor can't change the addresses bring down the eth interface and then try to route:

sudo ip link set eth0 down

| improve this answer | |
  • Man, I can't believe it was so simple... I was realizing about bridges in host (ethernet and wifi) and other complex things, and the problem is solved only by disabling the eth0... As a beginner in Networks, it added a step foward in my learning (not use two network connections at same time). The only thing I am thinking, is in certain situations to create a proxy or router, and one network card is for internet and the another to LAN, but I think it needs a bit more of setup, right? BTW, you really saved my day, Thank you! – tdmsoares Apr 30 '17 at 5:44

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.