8

I've installed Debian in my VirtualBox (my host OS is Ubuntu). And there I configured two network interfaces: eth0 as NAT, and eth1 as Bridge.

NAT I need to have access to the internet in virtual OS, but Bridge I need because I want this virtual OS to be a part of my local network.

How to switch from these network interfaces? For example now I use eth0 (NAT), but some time later I need to turn off eth0 and turn on eth1.

P.S. There is no Desktop Environment in guest OS (Debian), so I need to do this in terminal.

Thanks in advance.

Larry Foobar
  • 359
  • 5
  • 14

3 Answers3

10

If both interface are configured in /etc/network/interfaces you can use

sudo ifup eth0

to bring eth0 up and

sudo ifdown eth0

to take eth0 down

Florian Diesch
  • 86,013
  • 17
  • 224
  • 214
  • 1
    Otherwise `ifconfig eth0 up/down` works fine although I guess some prefer the `ip link set eth0 up/down` now. – Steve-o Sep 11 '11 at 10:59
  • I've tried this before asking a question, but it didn't work. But thank you for noticing that both interfaces should be configured in `/etc/network/interfaces`. The second one wasn't configured by default, so I've added a few lines in `/etc/network/interfaces` file and it works now. – Larry Foobar Sep 11 '11 at 14:17
3

Normally I use

sudo ifdown eth0 && ifup eth1
sudo ifdown eth1 && ifup eth0

The 1st stops eth0 and starts eth1 and the second does it the other way around.

Rinzwind
  • 293,910
  • 41
  • 570
  • 710
0

On a virtualbox running Ubuntu 16.04

sudo ifdown eth0 didn't work giving Unknown interface eth0

I needed to do this instead:

Turn off network:

sudo ifconfig eth0 down

Turn on network:

sudo ifconfig eth0 up

(In my case there was no eth0 but there was enp0s3 so I replaced that above.)

User
  • 1,283
  • 2
  • 11
  • 12