Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
For laptop users: different network configurations
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
xkl
n00b
n00b


Joined: 27 Sep 2003
Posts: 3

PostPosted: Sat Sep 27, 2003 3:17 pm    Post subject: For laptop users: different network configurations Reply with quote

I think this is one of the main problems for laptop users. With this hack you will be able to switch between as many network configurations as you want. E.g. your home network, your work network, your university network and all networks of all your friends.

You are only three changes away from this. The first thing is a change deep in the startup files of the system.

Get the file /sbin/runscript.sh, change the line

Code:
[ "${NETSERVICE}" = "yes" ] && source "$(add_suffix /etc/conf.d/net)"


to

Code:
[ "${NETSERVICE}" = "yes" ] && source "$(add_suffix tc/conf.d/${myservice%.*})"


Now you are able to have more than one network configuration in /etc/conf.d. This is done in the following way:

Make your different config files named liked this:
Code:
/etc/conf.d/net.home
/etc/conf.d/net.work
/etc/conf.d/net.uni
/etc/conf.d/net.dhcp


Make some hard links to /etc/init.d/net.eth0:
Code:
/etc/init.d/net.home.eth0
/etc/init.d/net.work.eth0
/etc/init.d/net.uni.eth0
/etc/init.d/net.dhcp.eth0


Finally create some new runlevels in /etc/runlevels:
Code:
/etc/runlevels/home
/etc/runlevels/work
/etc/runlevels/uni
/etc/runlevels/dhcp

(these names do not need to be like those of the net config)

and add your init scripts to them:

Code:
rc-update add tri home
rc-update add tra home
rc-update add tru home
rc-update add lala home
rc-update add net.home.eth0 home


do the same for work/uni/dhcp

basically, you want to have the same scripts in it as in your default runlevel, except the net.eth0.

you can change your virtual runlevel with
Code:
rc home
rc work
rc dhcp

and so on....


Ok, the second and the third step is needed to boot into a plenty of runlevels.
Check out one unused "real" runlevel from inittab, I use 4 for this. And edit the according line to

Code:
l4:4:wait:/sbin/rc $PROFILE


so that the variable $PROFILE controls the runlevels. To choose the runlevel before bootup, add the assignment to $PROFILE to your bootmanager. I use grub and my grub.conf looks like this:
Code:

title=home
kernel /vmlinuz 4 root=xxx PROFILE=home

title=work
kernel /vmlinuz 4 root=xxx PROFILE=work

title=uni
kernel /vmlinuz 4 root=xxx PROFILE=uni

title=dhcp
kernel /vmlinuz 4 root=xxx PROFILE=dhcp



Please try this, test it and tease it in every way. Post your results.

Kai


Last edited by xkl on Wed Oct 15, 2003 7:29 am; edited 2 times in total
Back to top
View user's profile Send private message
hulk2nd
Guru
Guru


Joined: 25 Mar 2003
Posts: 512
Location: Freiburg, Germany

PostPosted: Mon Sep 29, 2003 7:08 pm    Post subject: Reply with quote

weee!

looks really great, gonna test it immediately. but one question:
Code:
Make some hard links to /etc/init.d/net.eth0:
/etc/conf.d/net.home.eth0
/etc/conf.d/net.work.eth0
/etc/conf.d/net.uni.eth0
/etc/conf.d/net.dhcp.eth0


not to "/etc/init.d/net.home.eth0" etc???

and shouldnt it be
Code:
[ "${NETSERVICE}" = "yes" ] && source "$(add_suffix /etc/conf.d/${myservice%.*})"

instead of
Code:
[ "${NETSERVICE}" = "yes" ] && source"$(add_suffix tc/conf.d/${myservice%.*})"



greets,
hulk
Back to top
View user's profile Send private message
xianx
Tux's lil' helper
Tux's lil' helper


Joined: 09 Aug 2003
Posts: 126
Location: Canada

PostPosted: Tue Sep 30, 2003 5:00 pm    Post subject: Exactly what i'm looking for!! Reply with quote

Yes Yes Yes! I just got my Wireless working last night (It was a long shot, ended up using acx100 and the Windows drivers that came on the CD 8O [USR2210 PCMCIA if anyone is interested])

And i'd like to know how to use multiple networks. I havent tried this yet, (i'm still at work) but i have a few questions already:

What do you do with resolv.conf? Obviously each network will have different DNS.

I actually will use eth0 for work, and wlan0 for home/coffee shops/etc. How does this change things?

thanks! :)
_________________
if at first you dont succeed, Skydiving is not for you.
#make love not war!
Back to top
View user's profile Send private message
al
Guru
Guru


Joined: 26 Dec 2002
Posts: 304
Location: Scotland

PostPosted: Thu Oct 02, 2003 8:45 pm    Post subject: Reply with quote

Looks good.I'll have to try that sometime!

:)

Posted using links.
Back to top
View user's profile Send private message
nacul
n00b
n00b


Joined: 12 Feb 2003
Posts: 9
Location: Irvine, CA

PostPosted: Sat Oct 11, 2003 8:15 pm    Post subject: Why no quickswitch Reply with quote

Hi,

I solved the same problem in a different way:
Code:
 emerge quickswitch


This is a simple script that can set many different parameters in the system. I use it only to configure the network, but it seems very powerful. By the way, no need to create new runlevels, links, and so on. I got it up and running in 5 minutes.

All you have to do is edit /etc/quickswith/switchto.conf.
Then, in the command prompt:
Code:
 switchto home
switchto office
switchto girl
switchto whatever_profile_you_have


My 2 cents

Andre
Back to top
View user's profile Send private message
xkl
n00b
n00b


Joined: 27 Sep 2003
Posts: 3

PostPosted: Wed Oct 15, 2003 7:18 am    Post subject: Reply with quote

hulk2nd wrote:
weee!

looks really great, gonna test it immediately. but one question:
Code:
Make some hard links to /etc/init.d/net.eth0:
/etc/conf.d/net.home.eth0
/etc/conf.d/net.work.eth0
/etc/conf.d/net.uni.eth0
/etc/conf.d/net.dhcp.eth0


not to "/etc/init.d/net.home.eth0" etc???


Yes.

hulk2nd wrote:

and shouldnt it be
Code:
[ "${NETSERVICE}" = "yes" ] && source "$(add_suffix /etc/conf.d/${myservice%.*})"

instead of
Code:
[ "${NETSERVICE}" = "yes" ] && source"$(add_suffix tc/conf.d/${myservice%.*})"




yes, I thought it was cut and pasted....

xkl
Back to top
View user's profile Send private message
xkl
n00b
n00b


Joined: 27 Sep 2003
Posts: 3

PostPosted: Wed Oct 15, 2003 7:24 am    Post subject: Re: Exactly what i'm looking for!! Reply with quote

xianx wrote:


And i'd like to know how to use multiple networks. I havent tried this yet, (i'm still at work) but i have a few questions already:

What do you do with resolv.conf? Obviously each network will have different DNS.


this is quite easy, I have multiple resolv.conf/hosts/... files, and let them copy to /etc/resolv.conf on each change of the runlevel.

xianx wrote:

I actually will use eth0 for work, and wlan0 for home/coffee shops/etc. How does this change things?



It shouldn't, but try it.

xkl
Back to top
View user's profile Send private message
optilude
Apprentice
Apprentice


Joined: 29 May 2002
Posts: 248
Location: England

PostPosted: Wed Oct 15, 2003 10:57 pm    Post subject: Alternatively... Reply with quote

For a slightly more generic solution, you could try my hprofile set of scripts:

https://forums.gentoo.org/viewtopic.php?t=46180

This integrates with the Gentoo runlevel model to let you arbitrarily replace configuration files and change runlevels based on an arbitrary condition. Simply put, this means you can use hprofile to automatically select the appropriate version of your configuration files (and individual users can change configuration files in their home directories), and your runlevel at boot, depending on your hardware configuration.

I use this so I can boot gentoo both within vmware and on its own, changing runlevels and files such as modules.autoload and XF86Config to files appropriate for the hardware configuration.

One important advantage over the original post here, besides being general purpose, is that it requires no manual editing of any gentoo rc scripts, which means that your changes won't be overwritten when you update baselayout etc. :-)

Best wishes,
Martin
_________________
--
"Life is both a major and a minor key" -- Travis
Back to top
View user's profile Send private message
xentric
Guru
Guru


Joined: 16 Mar 2003
Posts: 410
Location: Netherlands

PostPosted: Thu Oct 16, 2003 7:08 pm    Post subject: Reply with quote

After following xkl's little howto I just want to add a couple of changes that I needed
to make in order to get this to work...

1. Remove pcmcia from all runlevels:
Code:
$ rc-update del pcmcia


2. Add the following to my /etc/init.d/net.*.eth0 files so pcmcia is started when you start
one of the net.*.eth0 scripts:
Code:
depend() {
        need pcmcia
}


3. Run depscan:
Code:
$ depscan.sh


4. Add net.*.eth0 script to the matching runlevel:
Code:
$ rc-update add net.home.eth0 home
$ rc-update add net.work.eth0 work
$ rc-update add net.dhcp.eth0 dhcp


5. I use LILO so I had to add PROFILE to the append line:
Code:
image=/boot/bzImage-2.4.20-r7
        label=dhcp
        root=/dev/hda5
        append="PROFILE=dhcp idebus=33"

image=/boot/bzImage-2.4.20-r7
        label=home
        root=/dev/hda5
        append="PROFILE=home idebus=33"

image=/boot/bzImage-2.4.20-r7
        label=work
        root=/dev/hda5
        append="PROFILE=work idebus=33"


Now I can boot into the desired runlevel from the LILO bootmenu :D
Thanks guys!
Back to top
View user's profile Send private message
tomapd
n00b
n00b


Joined: 26 Aug 2003
Posts: 22
Location: Sendai

PostPosted: Thu Oct 16, 2003 7:38 pm    Post subject: Reply with quote

Thanks for a nice tip!!!
It's much better than my way. :P
Back to top
View user's profile Send private message
xmoy
Tux's lil' helper
Tux's lil' helper


Joined: 03 Aug 2004
Posts: 108
Location: .ch

PostPosted: Wed Sep 22, 2004 6:28 pm    Post subject: Reply with quote

I added this to my net.eth0 (after start() { )

Code:
        0<&2 2<&-

        default="192.168.0.2"
        echo -n "ip [$default] "
        read ip
        if [[ $ip = "" ]]; then
                ip="$default"
        fi

        if [[ $ip = "dhcp" ]]; then
                iface_eth0="$ip"
        else

                default="192.168.0.255"
                echo -n "broadcast [$default] "
                read bc
                if [[ $bc = "" ]]; then
                        bc="$default"
                fi

                default="255.255.255.0"
                echo -n "netmask [$default] "
                read nm
                if [[ $nm = "" ]]; then
                        nm="$default"
                fi

                iface_eth0="$ip broadcast $bc netmask $nm"
        fi

Now, I can enter an IP address when net.eth0 is started (if I just press enter, the default value is used). If I enter 'dhcp', dhcp is used
_________________
:wq
Back to top
View user's profile Send private message
Massimo B.
Veteran
Veteran


Joined: 09 Feb 2005
Posts: 1776
Location: PB, Germany

PostPosted: Sun Jun 26, 2005 4:15 pm    Post subject: Reply with quote

Right now this is the part of my /sbin/runscipt.sh with the modified line:
Code:
# Source configuration files.
# (1) Source /etc/conf.d/${myservice} to get initscript-specific
#     configuration (if it exists).
# (2) Source /etc/conf.d/net if it is a net.* service
# (3) Source /etc/rc.conf to pick up potentially overriding
#     configuration, if the system administrator chose to put it
#     there (if it exists).

[[ -e $(add_suffix /etc/conf.d/${myservice}) ]] && source "$(add_suffix /etc/conf.d/${myservice})"
[[ -e $(add_suffix /etc/conf.d/net) ]]          && \
[[ ${NETSERVICE} == "yes" ]]                    && source "$(add_suffix /etc/conf.d/${myservice%.*})"
[[ -e $(add_suffix /etc/rc.conf) ]]             && source "$(add_suffix /etc/rc.conf)"

But I don't understand, why the first line with ${myservice} is not sufficient to do the job.
For example, my service is called net.lan-fh.eth0 and my conf.d file is called net.lan-fh.
So {myservice%.*} should look for a lan-fh.eth0%.*, but it works. Where is my error in reasoning?
_________________
HP ZBook Power 15.6" G8 i7-11800H|HP EliteDesk 800G1 i7-4790|HP Compaq Pro 6300 i7-3770
Back to top
View user's profile Send private message
UberLord
Retired Dev
Retired Dev


Joined: 18 Sep 2003
Posts: 6835
Location: Blighty

PostPosted: Wed Jun 29, 2005 11:08 am    Post subject: Reply with quote

OK - this is vastly out of date. Here's what works with >=baselayout-1.11.12

if /etc/conf.d/${configfile}.${runlevel} exists then use that
else
if /etc/conf.d/${configfile} exists then use that

${configfile} is any file in /etc/conf.d which corresponds to a matching /etc/init.d/${script}
(exception - all net.xxx scripts load conf.d/net)
${runlevel} is the current runlevel

So in the runlevel foobar
/etc/init.d/vsftpd
load /etc/conf.d/vsftpd.foobar if it exists, otherwise /etc/conf.d/vsftpd

/etc/init.d/vsftpd.virtual -> /etc/init.d/vsftpd (symbolic link)
load /etc/conf.d/vsftpd.virtual.foobar if it exists, otherwise /etc/conf.d/vsftpd.virtual

/etc/init.d/net.eth0 -> /etc/init.d/net.lo (symbolic link)
load /etc/conf.d/net.foobar if it exists, otherwise /etc/conf.d/net

To change runlevel at boot, append "softlevel=foobar" to your kernel line. This would change you to the foobar runlevel.
You can use "rc foobar" to do the same thing at the command prompt.
Back to top
View user's profile Send private message
househead
n00b
n00b


Joined: 30 Oct 2003
Posts: 70
Location: Manchester, UK

PostPosted: Thu Jul 14, 2005 1:04 pm    Post subject: Reply with quote

Uberlord > how does this behaviour work with the /etc/conf.d/wireless file? or should I put my runlevel-specific wireless settings in /etc/conf.d/net?
_________________
Athlon 2000 XP | 512MB DDR | GeForce MX440 | 200GB ATA133
AJP 888e Clevo | P4 2.53gHz | 512Mb DDR | Radeon 9000M | 40Gb HD
Back to top
View user's profile Send private message
jamapii
l33t
l33t


Joined: 16 Sep 2004
Posts: 637

PostPosted: Thu Jul 14, 2005 1:58 pm    Post subject: Reply with quote

I prefer (and use) a much simpler solution. I don't change any baselayout files, I don't make a lot of copies of config files, I don't create additional links in /etc/init.d/... and (optionally) I try to trim down the number of runlevels.

My first approach is to create runlevels if necessary. The "softlevel" variable contains the runlevel name. Now I take advantage of the fact that (almost all) /etc/conf.d/... files are just shell scripts sourced in, so I make the variables depend on $softlevel.

This may be doomed if the config files aren't really meant to be shell scripts, but I still prefer it over maintaining a baselayout patch, initscript links and multiple copies of nearly identical conf.d files. With my solution, the complex and ugly stuff is contained in a few config files.

Depending on the location, I put preup() / postup() functions in the environment that fix the config files for dependent services, e.g. sendmail and ntpd.

My favourite ultimate solution would be to detect the location automatically at boot, possibly by switching on all network cards and trying to find out what MAC addresses are on the net, using $softlevel as a hint. That's what I did on the old laptop. Using dhcp as much as possible is also a good thing for laptops.

The order in which config files are sourced is important, up to recently it was just simply backwards - generic overrides specific. But the changes mentioned by UberLord seem to make it much more complex, so it should be used with caution.

I won't use separate config files for runlevels if it prevents the generic file from being sourced, because it probably involves a lot of duplication. But if the config files someday aren't treated as scripts anymore, I'll have to find a new solution.
Back to top
View user's profile Send private message
househead
n00b
n00b


Joined: 30 Oct 2003
Posts: 70
Location: Manchester, UK

PostPosted: Thu Jul 14, 2005 2:24 pm    Post subject: Reply with quote

I actually think the baselayout method is far simpler. I just need to figure out a method (without using dhcp) that I can use different DNS servers depending whether I am on the wired work network, or my wirleless home (vpn'd) network
_________________
Athlon 2000 XP | 512MB DDR | GeForce MX440 | 200GB ATA133
AJP 888e Clevo | P4 2.53gHz | 512Mb DDR | Radeon 9000M | 40Gb HD
Back to top
View user's profile Send private message
jamapii
l33t
l33t


Joined: 16 Sep 2004
Posts: 637

PostPosted: Thu Jul 14, 2005 5:39 pm    Post subject: Reply with quote

househead wrote:
I just need to figure out a method (without using dhcp) that I can use different DNS servers depending whether I am on the wired work network, or my wirleless home (vpn'd) network


You can use separate runlevels and change or switch /etc/resolv.conf depending on the runlevel in a preup() or postup() shell function. But as long as you use different network adapters in different locations, you can take a shortcut.

In /etc/conf.d/net.eth0 write
Code:
postup() { cp /etc/resolv.conf.work /etc/resolv.conf; }
and in /etc/conf.d/net.wlan0 (assuming it's called wlan0)
Code:
postup() { cp /etc/resolv.conf.home /etc/resolv.conf; }
or add the line to your existing postup() function. It is important to use postup() because this is only executed if the network starts successfully. Also, there must be no postup() in /etc/conf.d/net because it would take precedence. If eth0 starts even at home, ping a known ip address before copying, like "ping -c 2 -w 2 10.23.45.67 && cp ..."
Back to top
View user's profile Send private message
Massimo B.
Veteran
Veteran


Joined: 09 Feb 2005
Posts: 1776
Location: PB, Germany

PostPosted: Sun Jul 31, 2005 11:43 am    Post subject: Reply with quote

So finally I have to correct my (still working) net configs to the new baselayout.
That's the interesting point:
UberLord wrote:

/etc/init.d/net.eth0 -> /etc/init.d/net.lo (symbolic link)
load /etc/conf.d/net.foobar if it exists, otherwise /etc/conf.d/net

So I don't need anymore in /etc/init.d
Code:
net.wlan-dhcp.eth1 -> net.lo*
net.wlan-mops.eth1 -> net.lo*
net.wlan-other.eth1 -> net.lo*
?
Just net.eth0 and net.eth1, with the apropriate conf.d/net.wlan-mops, net.wlan.other according to the runlevel?

Disadvantage would be, that I can't start anymore a specific network by /etc/init.d/net.wlan-other.eth1 start don't care which runlevel is up.
Would be fine if I get the large list of networks working with the runlevel method. I still don't have the courage to use ifplugd.
_________________
HP ZBook Power 15.6" G8 i7-11800H|HP EliteDesk 800G1 i7-4790|HP Compaq Pro 6300 i7-3770


Last edited by Massimo B. on Mon Aug 01, 2005 3:28 pm; edited 1 time in total
Back to top
View user's profile Send private message
Massimo B.
Veteran
Veteran


Joined: 09 Feb 2005
Posts: 1776
Location: PB, Germany

PostPosted: Sun Jul 31, 2005 1:36 pm    Post subject: Reply with quote

It doesn't work the way you've told:
Code:
# ls -al /etc/init.d/net*
/etc/init.d/net.eth0 -> net.lo*
/etc/init.d/net.eth1 -> net.lo*
/etc/init.d/net.lo*

# rc-status wlan-schanz
Runlevel: wlan-schanz
 airport                                                                                                            [ started ]
 net.eth1                                                                                                             [   off ]

# cat /etc/conf.d/net.wlan-schanz |grep -v '#'
config_eth1=( "192.168.10.22/24" )
routes_eth1=( "default via 192.168.10.200" )

# /etc/init.d/net.eth1 restart
 * Starting eth1
 *   Bringing up eth1
 *     Configuration not set for eth1 - assuming dhcp
So it doesn't look for my net.[runlevel]. I had a look into /sbin/runscript.sh:
Code:
#line61:
[[ -e $(add_suffix /etc/conf.d/${myservice}) ]] && source "$(add_suffix /etc/conf.d/${myservice})"
[[ -e $(add_suffix /etc/conf.d/net) ]]          && \
[[ ${NETSERVICE} == "yes" ]]                    && source "$(add_suffix /etc/conf.d/net)"
Finally it only loads net? My baselayout is 1.11.13.

Someone has started a bugreport for me.

By the way, if I start the runlevel:
Code:
rc wlan-schanz
 * Lade Airport-Modul ...                                                                                                [ ok ]
 * WARNING:  "net.eth1" has already been started.
..net.eth1 doesn't start, because net.lo is in the boot runlevel. Before I have changed my hardlinks to net.lo into softlinks (as the doc explains), this wasn't the case.
_________________
HP ZBook Power 15.6" G8 i7-11800H|HP EliteDesk 800G1 i7-4790|HP Compaq Pro 6300 i7-3770
Back to top
View user's profile Send private message
dirtyd
n00b
n00b


Joined: 11 Apr 2005
Posts: 3

PostPosted: Sun Nov 13, 2005 10:19 pm    Post subject: How to change /etc/reslv.conf depending on softlevel Reply with quote

Check this out:

http://www.gentoo.org/doc/en/handbook/2005.1/handbook-x86.xml?full=1#book_part4

specifically:

Code:

# We can define nameservers and other things too
# NOTE: DHCP will override these unless it's told not too
dns_servers_ESSID1=( "192.168.0.1" "192.168.0.2" )
dns_domain_ESSID1="some.domain"
dns_search_domains_ESSID1="search.this.domain search.that.domain"

# You override by the MAC address of the Access Point
# This handy if you goto different locations that have the same ESSID
config_001122334455=( "dhcp" )
dhcpcd_001122334455="-t 10"
dns_servers_001122334455=( "192.168.0.1" "192.168.0.2" )




You can also use those same variables with ethx suffixes like this for eth0:
Code:

dns_servers_eth0=("192.168.0.1" "192.168.0.2" )
dns_search_domains_eth0="my.local.domain.name my.private.domain.name my.providers.domain.name"

etc.


You may want to just use the default, dhcp, and set just what you need based on interface. Like so:

Code:

# If picking your own ip while getting everything else from dhcp
# was your only goal then this line is all you need
dhcpcd_eth0="-t 5 -s 192.168.0.100"

# Set your own ip and gateway and inform the dhcp server about your ip
dhcpcd_eth1="-t 5 -s 192.168.2.100 -G 192.168.0.1"
# Don't use the dns servers from your dhcp server.  Maybe for security reasons they are bogus  ;)
dhcp_eth1="nodns"
dns_servers_eth1=("192.168.2.1" "192.168.2.2" )



And lastly in that same document is the big scary ifplugd in simplified cut and paste format.
It's at the bottom of the document in section 6.b.
http://www.gentoo.org/doc/en/handbook/2005.1/handbook-x86.xml?full=1#book_part4_chap6

This all works with the new RC_USE_CONFIG_PROFILE variable in /etc/conf.d/rc. Meaning you can
add a softlevel=home t your kernel parameters to make a /etc/conf.d/net.home override /etc/conf.d/net.
And you can also execute "rc home" to get the same effect.
_________________
Be careful what you wish for.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum