Can't ifdown eth0 (main interface)
Check the contents of the file /run/network/ifstate
. ifup
and ifdown
use this file to note which network interfaces can be brought up and down. Thus, ifup
can be easily confused when other networking tools are used to bring up an interface (e.g. ifconfig
).
From man ifup
The program keeps records of whether network interfaces are up or down. Under exceptional circumstances these records can become inconsistent with the real states of the interfaces. For example, an interface that was brought up using ifup and later deconfigured using
ifconfig
will still be recorded as up. To fix this you can use the--force
option to forceifup
orifdown
to run configuration or deconfiguration commands despite what it considers the current state of the interface to be.
ifdown
is a high-level program which does a lot of things you might not need. Additionally, it isn't available everywhere. The more portable way might work for you:
$ sudo ifconfig eth0 down
If you then can't ifup
it, you likely have some configuration problem. Manually bringing it up with ifconfig eth0 up
probably isn't the right thing in that case. On Debian, ifup
is a binary executable, so you'd probably have to strace
it to figure out where it's getting hung up:
$ sudo strace -e open ifup eth0
That will tell you which files ifup
is opening while it works, which might clue you into the problem.
On other systems (e.g. RHEL and derivatives) ifup
is a shell script, so it's a lot easier to debug:
# sh -x `which ifup` eth0
Running a shell script with sh -x
makes it print every line it runs, so you can trace the execution.
I've seen this before when ethX wasn't properly configured in
/etc/network/interfaces
. This needs something like:-
auto eth0
iface eth0 inet dhcp
Even with an improperly configured /etc/network/interfaces
file, you can still bring down eth0 with:
$ sudo ip link set eth0 down