Static IP workaround



Hi list,

Here's a workaround we found to the static-IP problem (being able to tell 
networkmanager to fall back to a static IP if DHCP is not available). 
I'll appreciate any feedback, suggestions or corrections.

I know that this issue is supposed to be addressed in 0.7 in a much cleaner 
and better way, but I imagine many users like us are 'stuck' not being able 
to use NetworkManager's wonderful features because of the lack of static IP 
support. This was tested on Debian unstable.

The idea:
- dhclient will try to fetch an IP address from DHCP
- If there's a timeout, dhclient will use a predefined 'lease' configured to 
the static address
- the problem here is that although dhclient succeeds, networkmanager sees the 
timeout and decides that IP was not received. The patch fixes this using an 
ugly hack

Mini howto:
1. Download the source (e.g. apt-get source network-manager)
2. edit the file:
network-manager-0.6.3/src/dhcp-manager/nm-dhcp-manager.c
and change the section that starts with "case DHCDBD_TIMEOUT" as follows:

case DHCDBD_TIMEOUT:            /* timed out contacting DHCP server */ 
                        nm_info ("Static IP override"); 
                        state = DHCDBD_BOUND; 
                        if (nm_act_request_get_stage (req) == 
NM_ACT_STAGE_IP_CONFIG_START) 
                         { 
                                
nm_device_activate_schedule_stage4_ip_config_get (req); 
                                  remove_timeout (manager, req); 
                                                } 
 
                      break; 

(sorry for not submitting a proper patch file) 

3. Compile (e.g. dpkg-buildpackage)
4. Install (e.g. dpkg -i network-manager_0.6.3-2_i386.deb)

This will cause networkmanager to think that dhclient got a valid IP even 
though the request timed out.

5. Now to assign the static IP, we used a configuration option in dhclient.
In dhclient.conf:

a. Make sure "timeout" is set to something small (e.g. 10)
b. Add the following section:
lease {
  interface "lan";
  fixed-address 192.168.1.66;
  option subnet-mask 255.255.255.0;
  option routers 192.168.1.1;
  option domain-name-servers 192.168.1.2;
  renew 2 2030/1/12 00:00:01;
  rebind 2 2030/1/12 00:00:01;
  expire 2 2030/1/12 00:00:01;
}

Of course, change the parameters to fit your configuration.

4. Now, when dhclient times out (after 10 seconds) it will fall back to this 
static lease. You need to have resolvconf installed and make sure to symlink 
all dhclient.conf files to this one (I had files in /etc/dhclient.conf 
and  /etc/dhcp3/dhclient.conf)

- Aviram




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]