February 6, 2006

CLI Magic: ifup, ifdown, ifstatus

Author: Joe Barr

User Level: Beginner

I've always assumed that ifup and ifdown were conditional commands that performed their assigned duties only if the interface device in question was up or down, as the command might be. I was dead wrong. I blame my mistake on being a programmer, rather than being stupid, but it's simply too close to call.

The if in ifup, ifdown, and ifstatus is not a programmer's if -- it's an abbreviation for interface. On the off chance that I'm not the only one who has misunderstood these commands because of their rather iffy names, here's what they really do and how they are used.

Ifup and ifdown are normally hidden from view and used only in scripts run at startup and shutdown time, so why would we care about them? Well, grasshopper, interfaces happen, that's why. Equipment malfunctions may leave you in need of these commands in between power on and power off.

Have you ever lost your connection to the Internet and ended up rebooting in order to restore it? One morning recently, the CAT 5 cable connecting my desktop to my Linksys router was pulled loose by a kitten foraging for Baud knows what behind my monitor. I didn't know that at the time -- all I knew was that my connection to the Internet suddenly stopped responding.
I checked the cable modem and the router, but didn't notice the cable that had been pulled loose from the back of the router. If I had known about ifstatus, I could have solved the puzzle at once.

The first clue

The format for this command is ifstatus interface-name -o options. To check the only Ethernet connection on my desktop box, without specifying any options, I would enter:

ifstatus eth0

After intentionally disconnecting the cable at the back of the router, I ran the command, and ifstatus had this to say:

    eth0      device: VIA Technologies, Inc. VT6102 [Rhine-II] (rev 74)
    eth0      configuration: eth-id-XX:XX:XX:XX:XX:XX
    eth0      DHCP client (dhcpcd) is running
eth0 is up
 mtu 1500 qdisc pfifo_fast qlen 1000mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether XX:XX:XX:XX:XX:XX brd ff:ff:ff:ff:ff:ff
    inet brd scope global eth0
    inet6 fe80::250:8dff:fe4e:9dd0/64 scope link
       valid_lft forever preferred_lft forever
    eth0      IP address:
Configured routes for interface eth0: - eth0
Active routes for interface eth0:  proto kernel  scope link  src  scope link
  default via
1 of 1 configured routes for interface eth0 up

At first glance, I thought it was telling me all was well when I knew it wasn't. Then I noticed the line following the one that says "eth0 is up." NO-CARRIER was clearly saying that it wasn't connected.

Once I determined the problem and put the cable back where it belonged, I could have resolved it without rebooting the desktop machine by using ifdown and ifup.

At first I tried ifup eth0, but all it would do is tell me the interface was already up. So I shut down the interface with ifdown eth0, then hit it with ifup again, and just like that I was reconnected.

I noticed that ifup and ifdown seem to have been replaced by ifupdown on my Ubuntu box, and it also has slightly different formats for the individual ifup and ifdown commands. I believe most Debian-based distributions do use ifupdown, so be sure to use man or info to check the proper format of the commands on your system.

Click Here!