# [solved, by ifplugd] problems with netplug, dhcpcd, fallback

## kimmie

Hi gentooples,

I have a network interface eth1 that I want to behave like this:

If no cable is connected don't configure it with an IP

When cable is connected try and get an IP using dhcp

If dhcp fails then use a static fallback address.The idea being, sometimes the DHCP server isn't active on the lan attached to eth1 (usually because I've shutdown the entire lan to get some relief from the fan noise). But I still want to use the printer, so I need a static address.

Heres my /etc/conf.d/net

```

# Change mac address of wlan to match that when booted under vmware, so

# the machine has same IP with normal and vm boot

mac_wlan="00:50:56:00:00:ee"

modules_wlan=("!plug" "wpa_supplicant")

wpa_supplicant_wlan="-Dwext"

#associate_timeout_wlan=30

# dhcp is default anyway, not necessary

# config_wlan=("dhcp")

dhcpcd_wlan=("-L")   # no zero conf (private address)

# We don't want to use 192.168.99.x as a gateway just because there's a DHCP server,

# the primary gateway is wlan. Otherwise we end up with multiple default routes and apps

# using UPnP (skype, vuze) barf.

config_eth1=("dhcp")

dhcp_eth1="nogateway release"

plug_timeout="0"

dhcpcd_eth1=("-t 5 -L")

fallback_eth1=( "192.168.99.99/24 netmask 255.255.255.0" )
```

This nearly works. But on boot if no cable is plugged into eth1. the fallback address is always used anyway. Then if I plug in the cable netplug thinks the interface is already "inned" and does nothing, so the dhcp lookup doesn't happen. If I then unplug the cable AGAIN and then plug it in AGAIN I get what I want, netplug sees the phy go down and up, then DHCP gets tried, and if that fails it fallsback to the static address.

I've had a good look at /etc/conf.d/net.example but I can't work out how to get it to work. It seems that fallback_eth1 happens if netplug doesn't see the PHY as up.... 

 :Question:  thanks for any pointersLast edited by kimmie on Sun Sep 20, 2009 2:09 am; edited 1 time in total

----------

## Master Shake

Are you looking for a script to do this or would you mind using something like networkmanager (knetworkmanager for kde and nm-applet for Gnome).

networkmanager works like the networkmanager on Windows does.  If you want a script, I'm afraid I cannot help you there.

----------

## kimmie

I guess I ocould look into nm-applet, but to my mind it should be possible with just using /etc/conf.d/net. I don't really want this to be dependent on having a desktop session. 

EDIT: I guess what I want is to understand why it doesn't work as expected, and then to fix it within the baselayout framework.

Below is a detailed look at what I see at the console and in the syslog wen I stop eth1, then start it again with no cable connected. What I don't understand are the lines I've marked --->. Why is netplug INNING the inteface when there's no cable connected? And if it is, why isn't DHCP being tried? And what is meant by in the syslog by 'rc-scripts: no loaded modules provided "plug" (plug_start)'? whag

If I plugged in a cable straight after the scenario below, then the interface would stay configured at the fallback 192.168.99.99. If I pulled it out, then plugged it in again, the right thing would happen, first DHCP, then fallback. If I had started eth1 with a cable plugged in, the right thing would happen too: DHCP then fallback. It's only when I start with no cable connected that I have the problem.

```
$ sudo /etc/init.d/net.eth1 stop

* Unmounting network filesystems ...   [ ok ]

 * Stopping eth1

 *   Loading networking modules for eth1

 *     modules: apipa arping ccwgroup macchanger macnet rename netplugd iwconfig wpa_supplicant essidnet iptunnel ifconfig pppd system dhcpcd ip6to4

 *   Bringing down eth1

 *     Stopping netplug on eth1 ...       [ ok ]

 *     Shutting down eth1 ...              [ ok ]

Sep 19 15:12:30 dandelion sudo:      gid : TTY=pts/1 ; PWD=/home/gid ; USER=root ; COMMAND=/etc/init.d/net.eth1 stop

Sep 19 15:12:30 dandelion sudo: pam_unix(sudo:session): session opened for user root by gid(uid=0)

Sep 19 15:12:30 dandelion sudo: pam_unix(sudo:session): session closed for user root

Sep 19 15:12:31 dandelion netplugd[17455]: caught signal 15 - exiting

Sep 19 15:12:31 dandelion [45158.726402] b44: eth1: powering down PHY

$ /etc/init.d/net.eth1 start

 * Starting eth1

 *   Loading networking modules for eth1

 *     modules: apipa arping ccwgroup macchanger macnet rename netplugd iwconfig essidnet iptunnel ifconfig pppd system dhcpcd ip6to4

 *       netplugd provides plug

 *       iwconfig provides wireless

 *       ifconfig provides interface

 *       pppd provides ppp

 *       dhcpcd provides dhcp

 *   Configuring eth1 for MAC address 00:14:22:EC:EC:C3 ...               [ ok ]

 *   Starting netplug on eth1 ...                                         [ ok ]

 *     Backgrounding ...

Sep 19 15:13:52 dandelion sudo:      gid : TTY=pts/1 ; PWD=/home/gid ; USER=root ; COMMAND=/etc/init.d/net.eth1 start

Sep 19 15:13:52 dandelion sudo: pam_unix(sudo:session): session opened for user root by gid(uid=0)

Sep 19 15:13:52 dandelion sudo: pam_unix(sudo:session): session closed for user root

---->  Sep 19 15:13:53 dandelion netplugd[3854]: /etc/netplug.d/netplug eth1 in -> pid 3854

---->  Sep 19 15:13:54 dandelion rc-scripts: No loaded modules provide "plug" (plug_start)

---->  Sep 19 15:13:57 dandelion netplugd[3853]: eth1: state INNING pid 3854 exited status 0

$ sudo ifconfig eth1

eth1      Link encap:Ethernet  HWaddr 00:14:22:ec:ec:c3

          inet addr:192.168.99.99  Bcast:192.168.99.255  Mask:255.255.255.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:0 errors:0 dropped:0 overruns:0 frame:0

          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

          Interrupt:18
```

----------

## kimmie

Well, I solved the problem by switching to ifplugd, which does what you'd expect: on boot, cable out = interface down, cable in = interface up.

There's an existing bug https://bugs.gentoo.org/show_bug.cgi?id=253925 about this problem. Looks like netplugd is in need of some lovin'.

My /etc/conf.d/net now looks like: 

```
# check kernel drivers work, otherwise it picks ethtool (works too)

ifplugd_eth1="--api-mode=mii" 

config_eth1=("dhcp")

# don't want a gateway for this interface, more than one default route

# confuses the crap out of things that use UPnP (vuze, skype)

# We release to remove ourselves from dns on eth1, then we'll be

# found by the upstream (wlan) dchp/dnsrelay

dhcp_eth1="nogateway release"

dhcpcd_eth1=("-L -t 10")

# fall back so we can still talk to the printer on this network even

# without dhcp

fallback_eth1=( "192.168.99.99/24" )
```

Last edited by kimmie on Mon Sep 21, 2009 3:52 am; edited 1 time in total

----------

## Master Shake

Interesting, I'll have to look in to ifplugd.  I think I remember hearing about it some time ago.

----------

