LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices

Reply
 
Search this Thread
Old 09-03-2003, 08:21 AM   #1
mrtwice
Member
 
Registered: Feb 2002
Distribution: xubuntu 8.10
Posts: 225

Rep: Reputation: 31
if( ethernet-cable-is-plugged-in ) { ...


In windows, it will tell you if you have a network cable plugged in or not. How would you do this in Linux? Thanks.
 
Old 09-03-2003, 03:02 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
Take a look at the output of "ifconfig" It shows "RUNNING" for that device if the cable is connected.
 
Old 09-03-2003, 04:43 PM   #3
mrtwice
Member
 
Registered: Feb 2002
Distribution: xubuntu 8.10
Posts: 225

Original Poster
Rep: Reputation: 31
It does, however it is pretty slow. It took almost a minute for it to show that it was back up. That is not acceptable for what I want to do with it. I am trying to set up my laptop to not wait for a dhcp lease on startup when the eth0 cable is unplugged. If anyone else has an idea, I am all ears.
 
Old 09-03-2003, 04:55 PM   #4
dubman
Member
 
Registered: Jan 2003
Distribution: Redhat 9, Fedora Core 1, Suse 8
Posts: 188

Rep: Reputation: 30
try checking your messages at /var/log/messages or dmesg

--dubman
 
Old 09-03-2003, 09:14 PM   #5
tang
LQ Newbie
 
Registered: Sep 2003
Location: NYC
Distribution: Mandrake 9.1
Posts: 8

Rep: Reputation: 0
--------------------------------------------------------------------------------------
I am trying to set up my laptop to not wait for a dhcp lease on startup when the eth0 cable is unplugged. If anyone else has an idea, I am all ears.
--------------------------------------------------------------------------------------

I just turned off start network at boot (Mandrake Control Center ->Network and Internet -> DrakConnect -> Expert mode -> Configure LAN -> started on boot: no)

boot time is much faster since it doesn't look for dhcp and when you need net access just click on Activate (same location as above)
 
Old 09-04-2003, 08:34 AM   #6
mrtwice
Member
 
Registered: Feb 2002
Distribution: xubuntu 8.10
Posts: 225

Original Poster
Rep: Reputation: 31
Checking the messages isn't really what I am after. I want to be able to run some kind of command that will check. Then, I will use that command in my startup script to not start that device if the ethernet cord is not plugged in.

tang: not everyone runs mandrake my friend. I run slackware. I appreciate your input though.
 
Old 09-04-2003, 08:45 AM   #7
tang
LQ Newbie
 
Registered: Sep 2003
Location: NYC
Distribution: Mandrake 9.1
Posts: 8

Rep: Reputation: 0
didn't think about that it erks me sometimes when i read a post that mentions 'go to blah and do blah' without explaining how to get to blah in the first place (assuming if you're posting cause you don't know how to fix something, you probably don't know how to get to where you're supposed to fix it)

you as in anyone, not you-you

will pay more attention to what i'm posting, thanks for the tip
hope you find what you're looking for
 
Old 09-06-2003, 07:54 AM   #8
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
I've only just found this one but this may be better for you:
mii-tool -w
 
Old 09-06-2003, 10:46 AM   #9
horlix
LQ Newbie
 
Registered: Sep 2003
Location: Swansea, UK
Distribution: redhat
Posts: 16

Rep: Reputation: 0
perhaps you could reduce the amount of time the dhcp client will wait for a reply from your dhcp server so that even with no ethernet cable your startup time will not greatly increase.

think theres a timeout setting in /etc/dhclient.conf or thereabouts.
 
Old 09-08-2003, 08:21 AM   #10
mrtwice
Member
 
Registered: Feb 2002
Distribution: xubuntu 8.10
Posts: 225

Original Poster
Rep: Reputation: 31
david_ross:

Thaks for the help. That was exactly what I was looking for.
 
Old 09-08-2003, 10:38 AM   #11
mrtwice
Member
 
Registered: Feb 2002
Distribution: xubuntu 8.10
Posts: 225

Original Poster
Rep: Reputation: 31
Actually, mii-tool was not quite what I was looking for. It did not provide an option (that I could see) that would allow me to just run the command and then look at the return value to see what was returned.

However, mii-tool is actually derived from mii-diag which did provide the option i was looking for (by passing -s as an argument). So, here is my rc.inet1 (slackware network start up script):

<----------------------rc.inet1------------------------------>

rsyring@dell:~$ cat /etc/rc.d/rc.inet1
#! /bin/sh
# /etc/rc.d/rc.inet1
# This script starts up the base networking system.
#
# Version:
# @(#)/etc/rc.d/rc.inet1 8.1 Tue May 28 15:27:39 PDT 2002 (pjv)

# Edit these values to set up your first Ethernet card (eth0):
IPADDR="127.0.0.1" # REPLACE with YOUR IP address!
NETMASK="255.255.255.0" # REPLACE with YOUR netmask!
# Or, uncomment the following lines to set up eth0 using DHCP:
USE_DHCP=yes
# If using DHCP, do media check first to prevent slow start-ups:
MEDIA_CHECK=yes

# If your provider requires a DHCP hostname, uncomment and edit below:
#DHCP_HOSTNAME="CCHOSTNUM-A"

# Edit these values to set up your second Ethernet card (eth1),
# if you have one. Otherwise leave it configured to 127.0.0.1,
# or comment it out, and it will be ignored at boot.
IPADDR2="127.0.0.1" # REPLACE with YOUR IP address!
NETMASK2="255.255.255.0" # REPLACE with YOUR netmask!
# Or, uncomment the following lines to set up eth1 using DHCP:
USE_DHCP2=yes
# If using DHCP, do media check first to prevent slow start-ups,
MEDIA_CHECK2=yes

# If your provider requires a DHCP hostname, uncomment and edit below:
#DHCP_HOSTNAME2="CCHOSTNUM-A"

# Edit the next line to point to your gateway:
GATEWAY="" # REPLACE with YOUR gateway!

# You shouldn't need to edit anything below here.

# Set up the loopback interface:
/sbin/ifconfig lo 127.0.0.1
/sbin/route add -net 127.0.0.0 netmask 255.0.0.0 lo

#set-up a variable so DHCP does not run when eth0 media is not ready
MEDIA_STATUS=OK
if [ "$MEDIA_CHECK" = "yes" -a "$USE_DHCP" = "yes" ]; then # do media check
echo "Getting status of eth0 interface..."
/sbin/mii-diag -s eth0 >/dev/null 2>&1
if [ ! $? = 0 ]; then # eth0 is not ready for DHCP
MEDIA_STATUS="NOT_OK"
echo "DHCP will not run on eth0 because the media is not ready!"
fi
fi


# Set up the eth0 interface:
if [ "$USE_DHCP" = "yes" -a "$MEDIA_STATUS" = "OK" ]; then # use DHCP to set everything up:
echo "Attempting to configure eth0 by contacting a DHCP server..."
# Add the -h option to the DHCP hostname:
if [ ! "$DHCP_HOSTNAME" = "" ]; then
DHCP_HOSTNAME="-h $DHCP_HOSTNAME"
fi
/sbin/dhcpcd -t 10 ${DHCP_HOSTNAME} -d eth0
elif [ ! "$IPADDR" = "127.0.0.1" -a ! "$IPADDR" = "" ]; then # set up IP statically:
# Determine broadcast and network addresses from the IP address and netmask:
BROADCAST=`/bin/ipmask $NETMASK $IPADDR | cut -f 1 -d ' '`
NETWORK=`/bin/ipmask $NETMASK $IPADDR | cut -f 2 -d ' '`
# Set up the ethernet card:
echo "Configuring eth0:"
echo "ifconfig eth0 ${IPADDR} broadcast ${BROADCAST} netmask ${NETMASK}"
/sbin/ifconfig eth0 ${IPADDR} broadcast ${BROADCAST} netmask ${NETMASK}
# If that didn't succeed, give the system administrator some hints:
if [ ! $? = 0 ]; then
echo "Your eth0 card was not initialized properly. Here are some reasons why this"
echo "may have happened, and the solutions:"
echo "1. Your kernel does not contain support for your card. Including all the"
echo " network drivers in a Linux kernel can make it too large to even boot, and"
echo " sometimes including extra drivers can cause system hangs. To support your"
echo " ethernet, either edit /etc/rc.d/rc.modules to load the support at boot time,"
echo " or compile and install a kernel that contains support."
echo "2. You don't have an ethernet card, in which case you should run netconfig"
echo " and configure your machine for loopback. (Unless you don't mind seeing this"
echo " error...)"
fi
fi # set up eth0

...ditto for eth1, etc ...
 
Old 10-08-2006, 05:32 AM   #12
beanerjo
Member
 
Registered: Aug 2004
Location: New Zealand
Distribution: Slackware
Posts: 40

Rep: Reputation: 15
Very helpful

This is exactly what I have been looking for. Thanks!!!

Note: "mii-tool eth0" does it too (I think). mii-tool is contained in the Slackware tcpip package (at least in version 11.0).

Last edited by beanerjo; 10-08-2006 at 05:36 AM.
 
Old 10-08-2006, 07:56 AM   #13
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 70
What about netplugd or ifplugd
 
Old 10-08-2006, 02:57 PM   #14
ARC1450
Member
 
Registered: Jun 2005
Location: Odenton, MD
Distribution: Gentoo
Posts: 290

Rep: Reputation: 30
Quote:
Originally Posted by osor
What about netplugd or ifplugd
Vote for netplug here. . .works very well, and I've never had issues with it.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
plugged in lan cable, still "not connected'' message shows New@Mandrake Linux - Networking 5 10-14-2004 11:56 AM
What happens when a network cable is plugged in ? balajipriya Linux - Networking 1 08-12-2004 09:10 AM
No X when ethernet is plugged in! zaicheke Slackware 31 07-26-2004 04:53 PM
dhcpcd, no network cable plugged in meyert Slackware 3 04-28-2004 08:34 PM
Automatically Connect when cable is plugged in?? NovaBurst Fedora 2 02-18-2004 09:15 AM


All times are GMT -5. The time now is 11:29 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration