# DHCP fail-over to a static IP

## aja

Hi, folks

This should be fairly simple, but I'm danged if I can find a reference. 

I have a laptop that normally has a static IP on my network.  However, when I travel (or go to a cafe) with it, I would like it to go to DHCP to be able to use internet connections, etc.

How do I configure my laptop so that, if it fails to find a DHCP host, it will fail to a specific static address, default gateway, etc.

Tia.

----------

## brain

This is kind of a hack, and probably not the most elegant solution, but hey..it works.

Create an executable file somewhere, and toss this quick code in it (obviously changing the IP's for your own):

```
#!/bin/bash

if [ "`/sbin/ifconfig eth0 2> /dev/null | grep "inet" | gawk '{ print $2 }' | sed s/addr://`" = '' ]

   then

   /sbin/ifconfig eth0 10.1.0.150 netmask 255.255.0.0

   /sbin/route add default gw 10.1.0.1

fi
```

Next, edit your /etc/conf.d/local.start to run that file at boot.

All it does is to see if ETH0 got an ipaddress from earlier in the init.  If not, assign one.

You may want to go in to your /etc/init.d files that have a "need" set on "net" (like samba and the like) and change it to "use".   See the RC script docs for the details.   That just keeps services from failing because DHCPCD didn't find an address (annoying on laptops)

----------

## aja

Sorry for ignoring you.  The problem above got moved to the bottom of the stack by a typoed make.conf followed by a emerge -e world.  Putting out fires and trying to get system up right now.

Thanks for your notes - I'll try the script when I get things back up.  A bit more involved than I was hoping for - but it has promise (I might also be able to modify it to handle some of the missing NFS share problems that I also have when traveling).

Appreciate your time.

----------

## kybber

 *aja wrote:*   

> (I might also be able to modify it to handle some of the missing NFS share problems that I also have when traveling).
> 
> 

 

Have you taken a look at automount? I use that on my laptop for NFS shares. It is absolutely brilliant once you set it up right. I recommend using symlinks to the various autofs-dirs and accessign the nfs drives through the symlinks. That way the name of the drive/dir is accessible at all times, and the drive will be mounted as you tab-complete the symlink.

----------

## ZagiFlyer

Have you looked at QuickSwitch? I used it when I needed to roam and it worked well.

----------

## aja

 *ZagiFlyer wrote:*   

> Have you looked at QuickSwitch? I used it when I needed to roam and it worked well.

 

THAT's what I was looking for!  <scribble,scribble>  Will try it out.  TX.

----------

## aja

 *kybber wrote:*   

> 
> 
> Have you taken a look at automount? I use that on my laptop for NFS shares. 

 

Doh.  Of course.  I actually already have it installed.  Was on my list o 'thingstaconfigure'.  Tx for reminding me.  YP is a delight for laptops, too.

----------

