This is a read-only archive. Find the latest Linux articles, documentation, and answers at the new Linux.com!

Linux.com

Feature

CLI Magic: ifup, ifdown, ifstatus

By Joe Barr on February 06, 2006 (8:00:00 AM)

Share    Print    Comments   

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
              IPADDR=192.168.1.110
              NETMASK=255.255.255.0
              GATEWAY=192.168.1.1
              HOSTNAME='linux'
              DOMAIN='lan'
              DNS=192.168.1.1
              DHCPSIADDR=192.168.1.1
              DHCPCHADDR=XX:XX:XX:XX:XX:XX
              REBINDTIME=37800
eth0 is up
2: eth0:  2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,NOTRAILERS,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 192.168.1.110/24 brd 192.168.1.255 scope global eth0
    inet6 fe80::250:8dff:fe4e:9dd0/64 scope link
       valid_lft forever preferred_lft forever
    eth0      IP address: 192.168.1.110/24
Configured routes for interface eth0:
  169.254.0.0 - 255.255.0.0 eth0
Active routes for interface eth0:
  192.168.1.0/24  proto kernel  scope link  src 192.168.1.110
  169.254.0.0/16  scope link
  default via 192.168.1.1
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.

Share    Print    Comments   

Comments

on CLI Magic: ifup, ifdown, ifstatus

Note: Comments are owned by the poster. We are not responsible for their content.

ifstatus?

Posted by: Anonymous Coward on February 06, 2006 08:16 PM
i think u mean mii-tool

#

Re:ifstatus?

Posted by: Anonymous Coward on February 08, 2006 12:09 AM
why not just do a `service network restart` (if `service` is in your $PATH, otherwise its `/sbin/service`) which then means you don't have to know pathing information?

Just a thought.

#

I just run the network restart script...

Posted by: Anonymous Coward on February 06, 2006 08:20 PM
When I need to restart my networking interfaces (this is in the Red Hat/Fedora family of distros), I just use:

<nobr> <wbr></nobr>/etc/init.d/network restart


This restarts everything related to networks, which might be overkill if you've got 2 or more network interfaces (in which case you do indeed use ifdown/ifup for a single interface). BTW, why is there no "ifrestart" script (even if it was just a 2-liner that called "ifdown" then "ifup")?

#

Re:I just run the network restart script...

Posted by: Anonymous Coward on February 06, 2006 11:30 PM
Thanks for that tip I actually knew about ifup/ifdown, but not about the<nobr> <wbr></nobr>/etc/init.d thing.

On Debian "Sarge" the command is<nobr> <wbr></nobr>/etc/init.d/networking restart . Just thought I would mention it.

GermanyZulu

#

Re:I just run the network restart script...

Posted by: Anonymous Coward on February 07, 2006 12:00 PM
Yes, typically each distro has its own network start and stop script, carefully crafted to reflect its configuration and such. Shame, but I never run ifup/ifdown manually myself...

Gentoo :<nobr> <wbr></nobr>/etc/init.d/net.ethX restart
(X goes from 0 to how many network device you have)

#

Re:I just run the network restart script...

Posted by: Administrator on February 07, 2006 11:10 PM
On Redhat (possibly others?) I prefer<nobr> <wbr></nobr>/etc/rc.d/init.d/network reload<nobr> <wbr></nobr>... it only changes the status of those devices that are in the wrong state.

I have machines with two or three NICs, and if one or two are down, a 'network reload' as above will start those two and leave the unaffected NIC alone.

#

Another way to test your IP connectivity

Posted by: Anonymous Coward on February 06, 2006 11:38 PM
If ifstatus says that you're using DHCP, then you can do either this


    dhcpcd -k

    dhcpcd eth0

or this


    dhclient -r

    dhclient eth0

to see if you can renew your IP address. If you can't, then to eliminate any DHCP server problems (it does occasionally happen), just temporarily assign yourself a static IP address, like so, in the case of the author's network:


    ifconfig eth0 up 192.168.1.110 netmask 255.255.255.0

and then try pinging your default gateway of 192.168.1.1. That's how I do it on any distro. Of course, have a look at your link lights. Gotta make sure OSI Layer 1 is "configured" correctly.<nobr> <wbr></nobr>:-)

#

Back Pain relief

Posted by: Anonymous Coward on May 28, 2006 05:46 PM
[URL=http://painrelief.fanspace.com/index.htm] Pain relief [/URL]

  [URL=http://lowerbackpain.0pi.com/backpain.htm] Back Pain [/URL]

  [URL=http://painreliefproduct.guildspace.com] Pain relief [/URL]
[URL=http://painreliefmedic.friendpages.com] Pain relief [/URL]
[URL=http://nervepainrelief.jeeran.com/painrelief<nobr>.<wbr></nobr> htm] Nerve pain relief [/URL]

#

relief joint

Posted by: Anonymous Coward on May 30, 2006 01:09 AM
[URL=http://nervepainrelief.jeeran.com/painrelief<nobr>.<wbr></nobr> htm] Nerve pain relief [/URL]
[URL=http://www.back.painreliefnetwork.net/lowbac<nobr>k<wbr></nobr> pain.htm] Low back pain [/URL]
[URL=http://blog.gala.net/uploads/painreliefback/<nobr>b<wbr></nobr> ackpainrelief.htm] Back pain relief [/URL]
[URL=http://www.weblog.ro/usercontent/13155/profi<nobr>l<wbr></nobr> es/kneepainrelief.htm] Knee pain relief [/URL]
[URL=http://www.info.painreliefnetwork.net/Pain-R<nobr>e<wbr></nobr> lief.html] Pain relief [/URL]
[URL=http://www.sitefights.com/community/scifi/pa<nobr>i<wbr></nobr> nrelief/painreliefpreved.htm] Pain relief [/URL]
[URL=http://www.info.painreliefnetwork.net/Medica<nobr>t<wbr></nobr> ion-Pain-Relief.html] Medication pain relief [/URL]
[URL=http://www.info.painreliefnetwork.net/Natura<nobr>l<wbr></nobr> -Pain-Relief.html] Natural pain relief [/URL]


[URL=http://painrelief.fanspace.com/index.htm] Pain relief [/URL]
[URL=http://lowerbackpain.0pi.com/backpain.htm] Back Pain [/URL]
[URL=http://painreliefproduct.guildspace.com] Pain relief [/URL]
[URL=http://painreliefmedic.friendpages.com] Pain relief [/URL]

#

Pain relief

Posted by: Anonymous Coward on May 30, 2006 01:21 AM
[URL=http://nervepainrelief.jeeran.com/painrelief<nobr>.<wbr></nobr> htm] Nerve pain relief [/URL]

  [URL=http://www.back.painreliefnetwork.net/lowbac<nobr>k<wbr></nobr> pain.htm] Low back pain [/URL]

  [URL=http://blog.gala.net/uploads/painreliefback/<nobr>b<wbr></nobr> ackpainrelief.htm] Back pain relief [/URL]

  [URL=http://www.weblog.ro/usercontent/13155/profi<nobr>l<wbr></nobr> es/kneepainrelief.htm] Knee pain relief [/URL]

  [URL=http://www.info.painreliefnetwork.net/Pain-R<nobr>e<wbr></nobr> lief.html] Pain relief [/URL]

  [URL=http://www.sitefights.com/community/scifi/pa<nobr>i<wbr></nobr> nrelief/painreliefpreved.htm] Pain relief [/URL]

  [URL=http://www.info.painreliefnetwork.net/Medica<nobr>t<wbr></nobr> ion-Pain-Relief.html] Medication pain relief [/URL]

  [URL=http://www.info.painreliefnetwork.net/Natura<nobr>l<wbr></nobr> -Pain-Relief.html] Natural pain relief [/URL]


  [URL=http://painrelief.fanspace.com/index.htm] Pain relief [/URL]

  [URL=http://lowerbackpain.0pi.com/backpain.htm] Back Pain [/URL]

  [URL=http://painreliefproduct.guildspace.com] Pain relief [/URL]
[URL=http://painreliefmedic.friendpages.com] Pain relief [/URL]

#

Hmm

Posted by: Anonymous Coward on February 07, 2006 12:47 AM
If you take the interface down with ifdown then take it up again by ifup will it also try to contact the DHCP server to obtain an IP address?

Also, it feels little silly to have 3 commands (ifup, ifdown, ifstatus) when they're all pretty related and maybe could be integrated into one command.

#

Re:Hmm

Posted by: Anonymous Coward on February 07, 2006 01:38 PM
Actually, they are all abreviations of the "ifconfig" command, so "ifup eth0"="ifconfig eth0 up", "ifdown eth0"="ifconfig eth0 down" and "ifstatus eth0"="ifconfig eth0". Ta-dah.

#

Important note

Posted by: Anonymous Coward on February 07, 2006 03:38 AM
In my experience, you need to be root or have those privileges, because otherwise it will say something like command not found.

#

Re:Important note

Posted by: Anonymous Coward on February 07, 2006 12:09 PM
Because normal users don't have<nobr> <wbr></nobr>/sbin in PATH. You can still type in the absolute path and run, although you need root to make any changes.

#

Re:ifstatus...

Posted by: Anonymous Coward on February 07, 2006 05:38 AM
It is usually in<nobr> <wbr></nobr>/sbin. Also, you should probably be root to run if*.

#

Re:ifstatus...

Posted by: Anonymous Coward on February 07, 2006 05:47 AM
It's not part of Fedora Core 4 only ifcfg, ifconfig ifdown, ifenslave, ifrename, and ifup. It is in opensuse 10 though.

#

Re:ifstatus...

Posted by: Anonymous Coward on February 07, 2006 09:47 PM
in that case you can use:


    ifconfig devicename
of just plain old

    ifconfig
and it will give you all of the interface information. Also:

  ifconfig eth0 down

  ifconfig eth0 up
work as well for bring devices up or down.

#

Re:ifstatus...

Posted by: Administrator on February 08, 2006 02:20 AM
It is ifstat in Slackware.

#

A daft Question

Posted by: Anonymous Coward on February 07, 2006 07:15 AM
Although the cable had fallen out, why does the interface have to be taken down and back up again to reconnect? Should it not just re-establish its connection?

#

Re:A daft Question

Posted by: Anonymous Coward on February 07, 2006 09:54 AM
it doesn't...try pinging the interface, pop out the cable, wait, then pop it back in...

Donald Ray Moore Jr. (mindrape)

#

Re:A daft Question

Posted by: Anonymous Coward on February 07, 2006 09:55 AM
err...pinging an ip accessible from the interface...

Donald Ray Moore Jr. (mindrape)

#

Re:A daft Question

Posted by: Anonymous Coward on February 07, 2006 12:14 PM
Depends which cable goes out. If the cable that is connected to your modem aka ISP, then ISP will ping(in ppp mean) your IP and if it won't get response for a while, it will shut its connection down. But if it's just a LAN on dhcp or something, it will stay alive longer even the cable is out.

#

Re:A daft Question

Posted by: Anonymous Coward on February 07, 2006 04:49 PM
Actually, on Mandriva this happens/works this very way.


BTW you can go into the Mandriva Control Center, system, services and restart the network there, no need to type!
<nobr> <wbr></nobr>;-)


On cli it's:

service network restart

and the commands that Joe gives also work fine on Mandriva. (Well I never used the status command, learnt something new here, thanks Joe!)


<a href="http://www.mandrake.tips.4.free.fr/" title="4.free.fr">aRTee</a 4.free.fr>

#

Re:A daft Question

Posted by: Joe Barr on February 07, 2006 02:02 PM
Because I power-cycled the router before I discovered the loose cable.

#

Just wrappers

Posted by: Anonymous Coward on February 07, 2006 10:24 AM
These are just wrappers to ifconfig, route and dhclient/dhcpcd on the interface, are distro specific and don't exist in the *NIX world. If you learn to use the real system commands, you can fix your connection without restarting all networking, or breaking any current connections.
BTW, I've never had to restart networking or do anything to an interface if all that happened is a cable was unplugged (using Gentoo...not that that should matter). Since the kernel keeps the interface in an up status (as in the article) the TCP session and state table is even maintained. I can unplug, wait a minute, and plug back in, and my ssh sessions don't even time out.

#

Re:Just wrappers

Posted by: Anonymous Coward on February 09, 2006 11:16 AM
This is mostly true.
The ifup/down/status commands are just scripts that call other utilities to do the actual work.
These scripts are implimented differently between different Linux distros. For example in SUSE the ifup/down/status scripts use the ip command (same functionality as ifconfig and route plus more in one command) as well as which ever dhcp client is used on the system (dhcpcd/dhclient).
These scripts (ifup/down/status) are also what are used by the network init script (/etc/init.d/network) to start and stop the network. They (in SUSE again) use the network configuration files in<nobr> <wbr></nobr>/etc/sysconfig/network/ to activate and configure the various network interfaces and routes at boot time (and whenever else you want to bring the interfaces up/down).
It is true that you can use the ip command (or ifconfig/route/etc.) to configure your network interfaces manually but the ifup/down/status scripts make it much easier to do in an managed fashion (i.e. saved address/route/etc. configurations).
I do also suggest that you learn how to use the ip/ifconfig/route/dhclient/etc. commands to configure your network manually when needed.

#

Back Pain relief

Posted by: Anonymous Coward on May 28, 2006 02:00 PM
[URL=http://painrelief.fanspace.com/index.htm] Pain relief [/URL]
[URL=http://lowerbackpain.0pi.com/backpain.htm] Back Pain [/URL]
[URL=http://painreliefproduct.guildspace.com] Pain relief [/URL]
[URL=http://painreliefmedic.friendpages.com] Pain relief [/URL]
[URL=http://nervepainrelief.jeeran.com/painrelief<nobr>.<wbr></nobr> htm] Nerve pain relief [/URL]

#

Better idea...

Posted by: Anonymous Coward on February 07, 2006 11:41 AM
Or you could just use a decent operating system where that's all a part of ifconfig.

#

Re:Better idea...

Posted by: Anonymous Coward on February 07, 2006 12:16 PM
If you have run a Linux, I guess ifconfig make you think ifup/down may not be programmers' 'if' =)

#

Use mii-tool or ethtool to check link status

Posted by: Anonymous Coward on February 07, 2006 04:09 PM
In linux you have two fine programs called mii-tool and ethtool that can show/set ethernet adapter settings.

Examples:
[root@host]# mii-tool eth0
eth0: negotiated 100baseTx-FD, link ok

[root@host]# ethtool eth0
Settings for eth0:

                Advertised auto-negotiation: Yes

                [Data deleted because of lameness filter]

                Speed: 100Mb/s

                Duplex: Full

                Link detected: yes

One or both should be present at most Linux distros, ifstatus does not exist on all distros..

#

Re:Use mii-tool or ethtool to check link status

Posted by: Anonymous Coward on August 04, 2006 10:18 PM
Thanks for the tip on ethtool!

Testing feedback on fc5:

I tried both mii-tool and ethtool on my machine using fc5 (fedora core 5) and found that only ethtool worked. Searching on the web indicated that the ethtool is the newer tool so I'm using that for now.

Regards

#

confused

Posted by: Anonymous Coward on February 07, 2006 05:20 PM
Then I noticed the line following the one that says "eth0 is up." NO-CARRIER was clearly saying that it wasn't connected.


What ?


I don't see the text NO-CARRIER anywhere in your article, other than in your sentence above.

#

Re:confused

Posted by: Joe Barr on February 07, 2006 11:20 PM
No, you're not confused. We are. A critical part of the output was snipped by our publishing system because I didn't code the < and > surrounding it correctly. The missing bits are:


<NO-CARRIER,BROADCAST,MULTICAST,NOTRAILERS,UP>


And it should be in the story now.

Thanks!

#

what about ifconfig?

Posted by: Anonymous Coward on February 07, 2006 05:42 PM
Don't you dare with ifconfig command?

#

ehh, just do a simple ifconfig

Posted by: Anonymous Coward on February 08, 2006 06:13 AM
ifconfig eth0 down ; ifconfig eth0 up

#

ifstatus...

Posted by: Administrator on February 07, 2006 12:02 AM
What distro? I check my fc4 and can't find ifstatus command.

#

CLI Magic: ifup, ifdown, ifstatus

Posted by: Anonymous [ip: 88.232.163.140] on December 14, 2007 03:46 PM
<a href="http://r10noktanet-seoyarismasi.blogspot.com" title="www.r10.net küresel ısınmaya hayır seo yarışması">www.r10.net küresel ısınmaya hayır seo yarışması</a>

#

This story has been archived. Comments can no longer be posted.



 
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya