# how to use netplug properly

## trs79

Hello,

I haven't been able to find out much from Google/Gentoo wikis, but I've emerged netplug and nothing seems to happen when I plug/unplug an ethernet cable.

Also, I noticed there isn't any netplug script in /etc/init.d, I'm wondering how the daemon should be started then? I've invoked it manually, via netplud -F, which starts a process for eth0, but nothing shows up when I plug/unplug an interace. Thanks for any help!

----------

## depontius

What are you wanting netplug to do?  From what I've seen, the biggest advantage to netplug is avoiding dhcp delays when your ethernet isn't plugged in.  If you want to start doing specific things based on network device plug/unplug actions, you should look at ifplugd instead.

----------

## khayyam

trs79 ...

basically, netplugd (and ifplugd) are intended to be intergrated into your network configuration, to do this all you need do is add it to the 'modules' handling the particular interface eg:

/etc/conf.d/net

```
modules_eth0="netplugd" # "plug" would also work
```

You then add the interface to start at the default run-level ... netplugd will then monitor the ethernet port for a cable connection and bring up the interface, run dhcp, etc.

```
ln -s /etc/init.d/net.lo /etc/init.d/net.eth0

rc-update add net.eth0 default
```

... all set.

HTH & best ...

khay

----------

## depontius

khayam...

You don't even have to work that hard.  In general, baselayout will "do the right thing" when you simply install netplug or ifplugd.  As mentioned, I use netplug (the lighter-weight of the two) simply to get rid of the dhcp timeout when my system isn't connected to any network.  No configuration was needed.  I'm not even sure that it's necessary to add net.eth0 to the default runlevel.  I have it that way out of a sense of history, but I'd swear that when my laptop is not connected and booting Gentoo, (unfortunately is usually boots RedHat) that I saw the dhcp delay - twice.  That was when I simply installed netplug and got rid of the delay.  (I so seldom boot Gentoo on that machine that I've never done a lot of grooming and settling in.)

The same would happen had I installed ifplugd, which I have also used before.  But ifplugd has the extra benefit of having a configuration directory in /etc where you can hook events.  That way you can set up "if X happens do Y, if U happens do V" type of stuff.

----------

## krinn

if you have two network cards, plugin the cable in the card2 while having define only the card1 won't gave you "nearly" anything.

nearly because even it won't work as the plug has been detect but the interface isn't define and so cannot be start, you should still get message in your dmesg.

so even with netplug, as long as the interface isn't define, you will see something that appears as "nothing happen".

and as udev write down the interface ref on first activation, you then can plug/unplug as long as you wish, the interfarce will never get trigger  :Razz: 

this mean you should check you don't have more than one network interface, because (as many today) if you have more than one, and only define one, you are pluging/unplugging the cable to a non define interface.

(if you don't understand what i mean it's normal, i don't understand it myself).

ln -s /etc/init.d/net.lo /etc/init.d/net.eth0

now plug/unplug the cable in net.eth1 will do nothing as long as net.eth1 isn't define

(that version looks easier to understand no? )

----------

## khayyam

 *depontius wrote:*   

> You don't even have to work that hard.  In general, baselayout will "do the right thing" when you simply install netplug or ifplugd.

 

depontius ... yes, but often "doing the right thing" turns out to be "not what I want" ... hehe. In my case I define what should handle each interface as I don't want plug on wlan0, currently its:

```
modules_wlan0="!plug wpa_supplicant"
```

I think that's what krinn was trying to point out ...

I wasn't aware that the interface would be brought up regardless of its being in a runlevel however, sounds like the evil doings of udev, in my case its likewise "historical". I can foresee a time when udev will take care of my email, enjoy my music collection, and otherwise replace me as the 'user' ... a bright and wonderfull future!

best ... khay

----------

