# Network detection programs

## Tarch

Hi all,

can someone tell me if there exists into the portage or some overlay one or more package able to do automatic network detection like whereami, divine, intuitively, laptop-netconf, laptop-net, netenv, please? I have used one of these, I don't remember which, basically the program was able to identify the network based on some parameters (e.g. looking for one ip, mac address, etc... into the network) and to bring up the right configuration. I have searched but I'haven't found nothing interesting related with gentoo.

Thanks in advance.

Bye.

P.S. Sorry for the poor english.

----------

## krinn

emerge -pv avahi

emerge -pv mDNSResponder

something like that ?

----------

## Tarch

Hi,

I have checked the packages but I would prefer something able to indentify a network and execute a command accordingly.

Thanks anyway!

Bye!

----------

## depontius

I've defined separate runlevels for known networks my laptop plugs into, as well as for no network and unknown networks.  Then I use ifplugd to detect network changes, and have hooked my own script into that.  When ifplugd finds a network change, it calls my script, and that switches me to the right runlevel for my current network situation.

In addition to changing the runlevel, which primarily controls which daemons are active, my script also tweaks several configuration files:

/etc/pam.d/system-auth - Switch between local and network-based authentication.

/etc/hosts.allow - Open or close host-based access based on which hosts I'm likely to see on the specific network.

/etc/X11/gdm/custom.conf - Allow tcp X11 connections on known networks, but -tcp-nolisten on unknown.

In the past I've also switched /etc/X11/xorg.conf because at one particular IP I'm usually docked, but I've learned to handle that with a more versatile /etc/X11/xorg.conf since then.

This script is so custom to the specific needs, and would require so much whitewashing, that there isn't much sense in posting it.  Given the spare time, I should try and generalize it and tuck the network-specific parts into configuration files.  Maybe I'll end up doing this when I migrate to baselayout-2.

EXTRA POINT...

My stuff is all based on plugging into a DHCP network.  I have no experience at all with zeroconf.  What happens when you plug a zeroconf/avahi configured system into a DHCP network?  Does it play well with DHCP, or does it give itself a zeroconf address and sit there alone wondering why nobody will communicate with it?  A few quick moments with google doesn't give me a clear answer, zeroconf is mostly caught up in how it doesn't need a DHCP server and doesn't say clearly what it does when there is one.

----------

## Tarch

Hi depontius,

Thanks for the suggestions, I will have to take a look to ifplugd, I need only to figure

out how to identify networks, beacuse not in all the cases I have a dhcp server.

Bye.

----------

## depontius

I believe the network scripts also have fallback options.  So you could start looking for dhcp, then fall back to either zeroconf or static IP, whichever is appropriate for you.  I don't know if the provisions are there in the standard net scripts, but it might even be possible to start looking for dhcp, then check for the presence of the default router you'd expect for static IP, then fall back to zeroconf.  The thing I see as annoying is that you'd want to do dhcp first, with its associated timeout.  I don't see much way around that, other than perhaps a custom script to try static IP first, then failover to dhcp if you can't find the default router.

----------

## Ankan

What about ARPING and APIPA?

Check out /etc/conf.d/net.example:

```

# ARPING Gateway configuration 

# and

# Automatic Private IP Addressing (APIPA)

# For arpingnet / apipa support, emerge net-misc/iputils or net-analyzer/arping

#

# This is a module that tries to find a gateway IP. If it exists then we use

# that gateways configuration for our own. For the configuration variables

# simply ensure that each octet is zero padded and the dots are removed.

# Below is an example.

#

#gateways_eth0="192.168.0.1 10.0.0.1"

#config_192168000001=( "192.168.0.2/24" )

#routes_192168000001=( "default via 192.168.0.1" )

#dns_servers_192168000001=( "192.168.0.1" )

#config_010000000001=( "10.0.0.254/8" )

#routes_010000000001=( "default via 10.0.0.1" )

#dns_servers_010000000001=( "10.0.0.1" )

# We can also specify a specific MAC address for each gateway if different

# networks have the same gateway.

#gateways_eth0="192.168.0.1,00:11:22:AA:BB:CC 10.0.0.1,33:44:55:DD:EE:FF"

#config_192168000001_001122AABBCC=( "192.168.0.2/24" )

#routes_192168000001_001122AABBCC=( "default via 192.168.0.1" )

#dns_servers_192168000001_001122AABBCC=( "192.168.0.1" )

#config_010000000001_334455DDEEFF=( "10.0.0.254/8" )

#routes_010000000001_334455DDEEFF=( "default via 10.0.0.1" )

#dns_servers_010000000001_334455DDEEFF=( "10.0.0.1" )

# If we don't find any gateways (or there are none configured) then we try and

# use APIPA to find a free address in the range 169.254.0.0-169.254.255.255

# by arping a random address in that range on the interface. If no reply is

# found then we assign that address to the interface.

# This is only useful for LANs where there is no DHCP server.

#config_eth0=( "arping" )

# or if no DHCP server can be found

#config_eth0=( "dhcp" )

#fallback_eth0=( "arping" )

# NOTE: We default to sleeping for 1 second the first time we attempt an

# arping to give the interface time to settle on the LAN. This appears to

# be a good default for most instances, but if not you can alter it here.

#arping_sleep=5

#arping_sleep_lan=7

# NOTE: We default to waiting 3 seconds to get an arping response. You can

# change the default wait like so.

#arping_wait=3

#arping_wait_lan=2

```

----------

## depontius

I think what you've shown is the "right" way to do what I suggested, and evidently it's fully supported by the Gentoo networking scripts.  (From what I understand, arping/apipa IS zeroconf.

So you first try dhcp, and fortunately it appears that you can give it a decently fast timeout, then you can configure it to try one of several static IPs by arp-pinging the associated router MACs, then it falls back to zeroconf.

----------

## Tarch

Hi,

thanks for pointing out the arping/apipa thing. It seemed strange to me that gentoo wasn't provided of native support for this type of configuration  :Very Happy: .

Bye & thanks!

----------

## deno

If you ask for laptop maybe is wpa_supplicant.conf(or wpa_supplicant.conf.example) all what you need?

----------

