On Monday 10 November 2003 02:10 pm, Richard Urwin wrote: > On Monday 10 Nov 2003 2:18 am, Greg Meyer wrote: > > I have a laptop that connects to my office e-mail server as an IMAP > > client. Sometimes I am outside the firewall, and in this case, I can > > connect to the server using the server's fqdn. When I am inside the > > firewall, I can connect to the server by making an entry in my /etc/hosts > > file for it that aliases it's private ip to it's netbios name (it is an > > Exchange 5.5 server). In order to connect, I simply change the > > servername in kmail depending on where I am. > > > > So now my question, is there any way to set up my hosts/resolv.conf/tmdns > > to look for the server in the local network first and if it cannot find > > it to look it up in the DNS so that I don't have to constantly change the > > setup in kmail? > > > > Since the local addressing scheme in place at my company is quite unique > > I would even be open to doing something like having a script called in > > rc.local check to see what the network ip block of the local network is > > and writing out a hosts file that would have an entry for the server if I > > am on the right network, although I have no idea how to actually > > implement that. > > You mean something like: > > cp /etc/hosts.base /etc/hosts > if (/sbin/ifconfig eth0 | grep 192.168.7>/dev/null) > then cat /etc/hosts.extra >> /etc/hosts > fi > > (test it first, of course) Thanks again for pointing me in the right direction, For posterity's sake here is what I have done. I took this challenge as an opportunity to get more familiar with shell scripting. Despite the fact that there are probably many improvements that can be made to make it more universal, it works for my needs. I post it here for future reference for anyone looking for a similar solution.
#!/bin/bash #This is the network startup script that is handy for a laptop #computer that has to move between different networks. We are booting with a #base modules.conf and hosts file and appending it based upon the network #profile we want to maintain. The reason modules.conf is involved is that on #some network we want the wireless interface to be eth0 and on others we want #it to be eth1. By using the aliases in modules.conf, we can load the #interfaces in any order we like. #Define variables #Set the profile PROFILE=$1 #You must be root to run this script, so we test and then exit if #whoami does not return root if test `whoami` != root ; then echo "You must be the system administrator to run this script" echo "Please become root user and try again" exit fi #Test and make sure a profile was specified if test "$PROFILE" = "" ; then echo "You must specify a valid network profile" echo "Syntax: network.sh <profile>" exit fi #Give some feedback to the user echo "Setting parameters for $PROFILE networking profile" #Set up hosts and modules.conf #The related hosts.$PROFILE files should contain the addresses on the local #net that need to be resolved by name. The related modules.conf.$PROFILE #files should contain the proper aliases for the order we want the network #interfaces to load. cp /etc/hosts.base /etc/hosts cat /etc/hosts.$PROFILE >> /etc/hosts echo "Creating hosts file... done." #The copying of modules.conf.base must be done as part of the initscripts so #that a basic modules.conf file is available at boot that does not contain #any network aliases. This is so the other hardware modules can be loaded #but no network interfaces are brought up by before we know what profile we #want to run under. Perhaps this can always be done at shutdown, but is #probably better as part of rc.sysinit. cp /etc/modules.conf.base /etc/modules.conf cat /etc/modules.conf.$PROFILE >> /etc/modules.conf echo "Creating module aliases... done." #If we get this far we can bring up the interfaces echo "Bringing up the network interfaces" ifup eth0.$PROFILE ifup eth1.$PROFILE echo "done" echo "Profile $PROFILE loaded" -- /g "Outside of a dog, a man's best friend is a book, inside a dog it's too dark to read" -Groucho Marx
Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com