How to reconnect network cable programmatically

openSUSE 11.2
My network connection breaks almost every day. I don’t know whose this problem - is it my system or my provider. Everything goes ok until some moment when network disappears and ping my gateway returns “Unreachable host”. In that situation i usually plug out cable and plug it in again - now network works.
I wounder if there is a way to do something from console which has the same effect as plugging out/in cable?
Or may be more preferred way - can i know what exactly doesn’t work when network disappears? What i must repair? May be it save me from reconnecting cable

Clarification, by cable do you mean a lan cable or a broadband cable? I’ll assume you mean lan cable.

You could try as root:

service network restart

Please provide some more information: kernel version, desktop and version, whether controlled with ifup or a network manager, computer make/model, and ethernet card.

Give us that info and get back to us here.

Yes, i mean lan cable.
My system:
openSUSE 11.2 (x86_64)

uname -a
Linux host-120-5-75 2.6.31.8-0.1-desktop #1 SMP PREEMPT 2009-12-15 23:55:40 +0100 x86_64 x86_64 x86_64 GNU/Linux

kde4-config --version
Qt: 4.5.3
KDE: 4.3.4 (KDE 4.3.4) “release 2”

I use ifup.

cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 15
model name : Intel(R) Core™2 Duo CPU E6750 @ 2.66GHz
stepping : 11
cpu MHz : 1998.000
cache size : 4096 KB
physical id : 0
siblings : 2
core id : 0
cpu cores : 2
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 10
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm constant_tsc arch_perfmon pebs bts rep_good pni dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm lahf_lm tpr_shadow vnmi flexpriority
bogomips : 5331.83
clflush size : 64
cache_alignment : 64
address sizes : 36 bits physical, 48 bits virtual
power management:

processor : 1
vendor_id : GenuineIntel
cpu family : 6
model : 15
model name : Intel(R) Core™2 Duo CPU E6750 @ 2.66GHz
stepping : 11
cpu MHz : 1998.000
cache size : 4096 KB
physical id : 0
siblings : 2
core id : 1
cpu cores : 2
apicid : 1
initial apicid : 1
fpu : yes
fpu_exception : yes
cpuid level : 10
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm constant_tsc arch_perfmon pebs bts rep_good pni dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm lahf_lm tpr_shadow vnmi flexpriority
bogomips : 5331.76
clflush size : 64
cache_alignment : 64
address sizes : 36 bits physical, 48 bits virtual
power management:

I don’t know what exactly you need to know about ethernet card. Here is what i found

PCI 19.0: 0200 Ethernet controller
[Created at pci.318]
UDI: /org/freedesktop/Hal/devices/pci_8086_294c
Unique ID: rBUF.I8NDuGkSsw1
SysFS ID: /devices/pci0000:00/0000:00:19.0
SysFS BusID: 0000:00:19.0
Hardware Class: network
Model: “Intel 82566DC-2 Gigabit Network Connection”
Vendor: pci 0x8086 “Intel Corporation”
Device: pci 0x294c “82566DC-2 Gigabit Network Connection”
SubVendor: pci 0x8086 “Intel Corporation”
SubDevice: pci 0x0001
Revision: 0x02
Driver: “e1000e”
Driver Modules: “e1000e”
Device File: eth0
Memory Range: 0x93200000-0x9321ffff (rw,non-prefetchable)
Memory Range: 0x93224000-0x93224fff (rw,non-prefetchable)
I/O Ports: 0x3400-0x341f (rw)
IRQ: 31 (14817 events)
HW Address: 00:19:d1:9e:9e:59
Link detected: yes
Module Alias: “pci:v00008086d0000294Csv00008086sd00000001bc02sc00i00”
Driver Info #0:
Driver Status: e1000e is active
Driver Activation Cmd: “modprobe e1000e”
Config Status: cfg=no, avail=yes, need=no, active=unknown

If you want something else - just tell me how to get it.
Thanks for your reply

Put a this tiny script in ~/bin/ with a short name you can remember easily.

Do something like this
#!/bin/bash
sudo /etc/init.d/network restart

It would be convenient to implement something like this to /etc/sudoers
%users ALL = NOPASSWD: /etc/init.d/network

Call the script from the command line (when it is placed in ~/bin/ your system will know the PATH) or create a shortcut in your desktop environment or both.

Wrong driver module. To me it seems you need the e1000 driver. Can you try it?

Could very well be. Please issue command below, right after a network disconnect:

dmesg | tail -20

That should show the disconnect and maybe a reason why.

How can i do this change?

Please issue command below, right after a network disconnect:
dmesg | tail -20

ok, as far as i get the next disconnect

joostvanrooij, thanks. If nothing will help i’ll try your advice

How can i do this change?

There is a file /etc/modprobe.d/50-blacklist.conf

Edit this file and add a line (as user root)

blacklist e1000e

Then - still as root - type on the command line:

modprobe -r e1000e
modprobe e1000
rcnetwork restart

Check that the network is ok (visit some website).

Eventually reboot to check that the right module comes up now on boot. You do this on the command line with

lsmod

I learned deeper into this stuff and this is what i found on intel site:

The e1000e.x.x.x.x.tar.gz is designed to work with the Intel® 82571/2/3/4/7/8, 82566/7, and 82583 PCI-E family of controllers.

This driver includes support for Itanium® 2-based and Intel® EM64T systems.

If your adapter/connection is not 82571, 82572, 82573, 82574, 82566, 82567, or 82583 -based, you should use one of the following drivers:

  • igb-x.x.x.tar.gz driver supports all Intel® 82575/6-based gigabit network adapters/connections.

  • e1000-x.x.x.tar.gz driver supports all Intel® 8254x-based PCI and PCI-X gigabit network adapters/connections.


Also i went to yast to Network Settings and found there field “Module name” - there is only one available name - “e1000e”

So i afraid i can’t use e1000

Also i checked driver version:
**/sbin/ethtool -i eth0 **
driver: e1000e
version: 1.0.2-k2
firmware-version: 1.3-0
bus-info: 0000:00:19.0

So i decided to start from upgrading driver and now
/sbin/ethtool -i eth0
driver: e1000e
version: 1.1.3-NAPI
firmware-version: 1.3-0
bus-info: 0000:00:19.0

I’m going to wait a little and watch the difference - may be everything will be ok.
One thing to note - the previous e1000e driver file was 230 KB and the new one is 3.5MB - it’s huge difference! Is it normal?

Two more questions:
1)Why system doesn’t update drivers? - i always update system from yast and nevertheless i had such old driver.
2)the directory /lib/modules/2.6.31.8-0.1-desktop/kernel/drivers/net has a lot of drivers. Will i right if i say: all of them are unnecessary except my e1000e

So i afraid i can’t use e1000

  1. The e1000 driver comes with your 11.2 distro. It is already there. Look here: kernel/drivers/net/e1000/e1000.ko

  2. The source code of the e1000 driver explicitely lists your ethernet card in a few comments to the code:

grep 82566 e1000_hw.c
        e1000_set_pci_ex_no_snoop(hw, PCI_EX_82566_SNOOP_ALL);
* Work-around for 82566 power-down: on D3 entry-
* Work-around for 82566 Kumeran PCS lock loss:
        ew32(GCR, PCI_EX_82566_SNOOP_ALL);

Snippet from /usr/src/linux/Documentation/networking/e1000.txt :

  - The following adapters do not support Jumbo Frames:
     Intel(R) 82562V 10/100 Network Connection
     Intel(R) 82566DM Gigabit Network Connection
     Intel(R) 82566DC Gigabit Network Connection
     Intel(R) 82566MM Gigabit Network Connection
     Intel(R) 82566MC Gigabit Network Connection
     Intel(R) 82562GT 10/100 Network Connection
     Intel(R) 82562G 10/100 Network Connection

This makes me believe the code should support your NIC.

  1. The e1000e should support your card as well:
grep 82566DC-2 ich8lan.c
 * 82566DC-2 Gigabit Network Connection

This is why this driver is automatically selected. But there is a good chance that e1000 works better for your setup. That’s why I would try it. You can always go back.

Thanks to all for help.
I think my problem is solved. A week has passed after updating network driver and during this period i never experienced my problem any more.
And i want to repeat my questions, because they are really important:
1)Why system doesn’t update drivers? - i always update system from yast and nevertheless i had such old driver.
2)the directory /lib/modules/2.6.31.8-0.1-desktop/kernel/drivers/net has a lot of drivers. Will i right if i say: all of them are unnecessary except my e1000e

Thanks

For you and for the moment yes. However, unused drivers are not loaded so don’t take up any RAM. And it’s inadvisable to delete unused drivers because you might need them if you change your hardware, and the small amount of disk space you recover would hardly be worth it.