Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have 2 network interfaces:

  • eth0 for LAN connection
  • wlan2 for wireless connection

I have set them static in the /etc/network/interfaces file. The problem is that I rarely have both connected at the same time and if the LAN is not connected, wlan2 doesn't work until I take down the eth0 manually with ifconfig.

Why does this happen?

I would like that when one interface is not connected it will be turned off automatically. How can I do that?

Here's the interfaces file:

auto eth0
iface eth0 inet static
address 192.168.1.130
netmask 255.255.255.0
network 192.168.1.0
dns-nameservers 8.8.8.8 8.8.4.4
up route add default gw 192.168.1.10 eth0
down route del default gw 192.168.1.10 eth0

auto wlan2
iface wlan2 inet static
wpa-ssid "dlink"
wpa-key-mgmt WPA-PSK
wpa-psk wpapass

address 192.168.1.150
netmask 255.255.255.0
network 192.168.1.0
dns-nameservers 8.8.8.8 8.8.4.4
up route add default gw 192.168.1.20 wlan2
down route del default gw 192.168.1.20 wlan2

NetworkManager.conf

[main]
 plugins=ifupdown,keyfile

[ifupdown]
 managed=true  
share|improve this question
    
"0 down vote favorite"? –  Hauke Laging Jun 28 '13 at 13:07
    
sorry I made a mistake :) –  Gappa Jun 28 '13 at 13:10
    
Do you have NetworkManager running? It should be handling this for you automatically. I have a similar setup with a eth0 and wlan0 and it switches back and forth just fine. –  slm Jun 28 '13 at 13:36
    
yes I have NetworkManeger running –  Gappa Jun 28 '13 at 13:44
    
it seems that networkManager can handle only non-eth0 interfaces in that way. So if I don't connect the wifi then it rightly doesn't enable the wlan interface. Moreover, the wlan gateway is never added. –  Gappa Jun 28 '13 at 14:10
show 2 more comments

1 Answer

up vote 0 down vote accepted

When you configure a wired network using /etc/network/interfaces, you tell Network Manager not to touch it. There is some documentation of this in the Debian Wiki NetworkManager article.

So, to make it work, your best bet is probably to remove (or comment out) your configuration in /etc/network/interfaces (except for lo) and entirely use Network Manager. You'll probably want to make them system connections, so they can be up before you log in.

Alternatively, you could set managed=true as shown in the wiki.

share|improve this answer
    
if you use Network Manager, will the interfaces be configured in single user mode? –  Sparr Jun 28 '13 at 15:24
    
@Sparr (Assuming here you're talking about the option labeled recovery in grub): Not by default, but you could change that by changing Network Manager's run levels (to make it start in S), or just run it with /etc/init.d/network-manager start. It also won't work with a NFS-mounted /usr, but I assume that doesn't exist here. –  derobert Jun 28 '13 at 15:30
    
I have added the network manager conf file –  Gappa Jun 28 '13 at 15:52
    
I'm sorry but how can I know if the interfaces are configured in single user mode? –  Gappa Jun 28 '13 at 15:56
    
@Gappa well, you'd boot into single user and check. I doubt its a huge issue, though, as you can just bring it up using NetworkManager or manually if you need to recover the system. –  derobert Jun 28 '13 at 16:52
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.