Network profiles with arping

Introduction
This article is mainly for users that use portable computers and need to adjust their network configuration very often, depending on the network they want to connect.

Required software
In order to achieve this you need to emerge the following:



Emerge them:

Configuration
Edit using your favorite editor. Consider the following scenario. You want to create three network profiles, one for your home network, one for your work network and one that will handle networks with DHCP:


 * Home: static, IP: 10.0.0.10, gateway: 10.0.0.138
 * Work: static, IP: 192.168.10.5, gateway: 192.168.10.1
 * DHCP: dynamic, IP: DHCP

This is what your configuration should look like:

Tips

 * If you want to have common DNS servers for all profiles use something like this:


 * If you experience long DHCP delays include the following if you are using net-misc/dhcpcd in order to reduce the timeout to 5 seconds:


 * Consider using the following for keeping relevant configuration intact in case DHCP comes into play:

Spoofing IP Address
Some routers do not respond to requests under the default arping behaviour, which uses a fake source address of 0.0.0.0. In these cases, you have to use arping2 to spoof a valid source address for your interface. You can test this with the following command:

arping2

For example, for interface eth0 and a gateway address of 10.0.0.1:

arping2

If these commands do not print a MAC address (of the form ab:cd:ef:01:23:45) then it is possible that the gateway will not respond to arping with the 0.0.0.0 source address. In this case you can spoof a genuine address, which may resolve the problem. It is easiest to use the address which you intend to receive. To spoof an IP address for arping use the following syntax in /etc/conf.d/net:

The gateway MAC address is not required unless you move between different networks with the same gateway IP address. In most cases this can safely be left blank. (This will result in a double-comma between the gateway address and the desired spoof IP address!)

To illustrate: for a gateway with address 10.0.0.1 that does not respond to the arping2 command above, and for a desired address of 10.0.0.42, the following configuration will use a spoof IP:

Note that you should not use a source address that may be in use by another host on the network. This can cause all sorts of problem, including kicking them off the network. You should use only the IP address that you have been assigned on the network.

Same Gateway on Different Networks
In case different networks use the same gateway, you can include a specific MAC address for each gateway. For example, I use a laptop to connect to different networks, and it might be the case that another network has the same gateway that my home network. In that case, I use the MAC address of my home router (00:14:BF:F6:F0:FB) to give my laptop a particular IP address (192.168.1.102) in my home network.