How to switch between network interfaces from console?

7,860

Solution 1

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

Solution 2

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.

Share:
7,860

Related videos on Youtube

user1356805
Author by

user1356805

I'm a beginner developer and student from Russia, Ryazan. (Originally, from Moldova). I'm interested in web-developing, MVC-architecture (both client-side and server-side), open-source projects. Also I'm interested in computer vision, I program in Matlab and C++ (openCV) I'm fond of classic rock. I listen to Queen, Pink Floyd, E.L.O, The Who I don't use twitter and facebook, so for contacts you can use email or google+. My github page     My google+ page     My last.fm page

Updated on September 18, 2022

Comments

  • user1356805
    user1356805 over 1 year

    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.

    • Steve-o
      Steve-o over 12 years
      With or without NetworkManager?
    • user1356805
      user1356805 over 12 years
      without networkManager. There is no desktop environment in guest OS
  • Steve-o
    Steve-o over 12 years
    Otherwise ifconfig eth0 up/down works fine although I guess some prefer the ip link set eth0 up/down now.
  • user1356805
    user1356805 over 12 years
    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.