Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[solved] Switching between network configurations?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
dr.nil
n00b
n00b


Joined: 18 Jul 2007
Posts: 47

PostPosted: Fri Mar 08, 2013 12:43 am    Post subject: [solved] Switching between network configurations? Reply with quote

Hi,

I usually use DHCP on my laptop. But sometimes I visit a client where I need a special network config (more than one IP addres on the eth0 interface, different routes). To switch network configs I edit /etc/conf.d/net commenting out DHCP and enabling the settings for that customer. Back in the hotel I need DHCP again so the whole config editing begins again.

Is there a better way to switch network configs via a simple command or even a GUI for that?

-dirk


Last edited by dr.nil on Fri May 24, 2013 12:22 am; edited 1 time in total
Back to top
View user's profile Send private message
BillWho
Veteran
Veteran


Joined: 03 Mar 2012
Posts: 1600
Location: US

PostPosted: Fri Mar 08, 2013 1:00 am    Post subject: Reply with quote

dr.nil,

Try using two files, net.dhcp and net.home. Then it's just a matter of setting a symlink to the proper file.
_________________
Good luck :wink:

Since installing gentoo, my life has become one long emerge :)
Back to top
View user's profile Send private message
syn0ptik
Apprentice
Apprentice


Joined: 09 Jan 2013
Posts: 265

PostPosted: Fri Mar 08, 2013 4:47 am    Post subject: Reply with quote

or change the MAC-address on client side, for proper configuration.
Back to top
View user's profile Send private message
dr.nil
n00b
n00b


Joined: 18 Jul 2007
Posts: 47

PostPosted: Fri Mar 08, 2013 8:18 am    Post subject: Reply with quote

syn0ptik wrote:
or change the MAC-address on client side, for proper configuration.


I'm not sure I understand how this is supposed to help?
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6228
Location: Room 101

PostPosted: Fri Mar 08, 2013 11:39 am    Post subject: Reply with quote

dr.nl ...

This is really a task for runlevels.

Firstly, remove all the network related services you have currently added to the 'default' runlevel (net.eth0, sshd, ntp-client, etc), then create a runlevel for this specific configuration:
Code:
# mkdir /etc/runlevels/test
# rc-update -s add default test

Now we have replicated 'default' into 'test', all the services set to start in 'default' will also be set to run in 'test'. Here we used '-s, --stack', which is not mentioned in the above linked docs, however, its the best method of replicating a particular runlevel, and saves having to sym-link each file individually (see man rc-update for more details).

Now, add whatever services should start in runlevel 'test':
Code:
# rc-update add net.eth0 test
# rc-config list test
Init scripts to be started by runlevel test
   net.eth0

Note that this doesn't list all the services in 'defualt' (those we '--stacked'), only those explicitly added to 'test'.

Next create specific a 'net.$RC_RUNLEVEL' configuration file for the runlevel, in the above example that would be /etc/conf.d/net.test, so one configuration for each network setup to match your runlevel(s). You should then remove/empty 'net' as each network setup is configured seperately.

This done, you should be able to call "rc test" and the network, and services set to run in that runlevel, should start/restart. Calling "rc default" should switch back to the "default" runlevel (ie, sans networking).

You can add as many runlevels as you wish, each with a specific network configuration and/or services. You can also configure 'softlevel=runlevel' to boot to a specific configuration (see the docs above).

best ... khay
Back to top
View user's profile Send private message
kimmie
Guru
Guru


Joined: 08 Sep 2004
Posts: 531
Location: Australia

PostPosted: Fri Mar 08, 2013 1:23 pm    Post subject: Reply with quote

Perhaps you could try the ARPING module? It looks to me like this allows you to probe for specific gateways using arp (well, /usr/share/doc/openrc*/net.example.bz2 talks about gateways, but any known host on the network should do) and then apply config based on what's found. You could have an overall fallback to dhcp.

I also have various alternate configs /etc/conf.d/net for the same reason as you, so I'm going to give this a try myself....
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6228
Location: Room 101

PostPosted: Fri Mar 08, 2013 2:47 pm    Post subject: Reply with quote

kimmie wrote:
Perhaps you could try the ARPING module? It looks to me like this allows you to probe for specific gateways using arp (well, /usr/share/doc/openrc*/net.example.bz2 talks about gateways, but any known host on the network should do) and then apply config based on what's found. You could have an overall fallback to dhcp.

kimmie ... that would be one solution, but you loose some flexibility, for example, having a specific postup() function for that network, or configuring seperate iptables rulesets, or using ${SVCNAME} in general. I guess that really depends on whats needed, but runlevels can make doing complicated setups fairly easy.

kimmie wrote:
I also have various alternate configs /etc/conf.d/net for the same reason as you, so I'm going to give this a try myself....

OK, you should see bug #458090 so that you don't fall foul of that. I'd be interested in hearing how you get along.

best ... khay
Back to top
View user's profile Send private message
dr.nil
n00b
n00b


Joined: 18 Jul 2007
Posts: 47

PostPosted: Sat Mar 09, 2013 6:06 pm    Post subject: Reply with quote

khayyam wrote:

This is really a task for runlevels.


khay, this looks like a very elegant solution. I have set it up and it works so far. The only thing that's a bit annoying is that I still manually have to stop the net.eth0 service before switching runlevels. Am I still missing something to fix this?

-dirk
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6228
Location: Room 101

PostPosted: Sun Mar 10, 2013 5:34 am    Post subject: Reply with quote

dr.nil wrote:
this looks like a very elegant solution. I have set it up and it works so far. The only thing that's a bit annoying is that I still manually have to stop the net.eth0 service before switching runlevels. Am I still missing something to fix this?


EDIT2: So scratch ALL that (previous content removed). I should really never take reports at face value. After spending sometime trying to figure out why exactly my (now removed) example didn't work as I expected (or why it worked, and then subsequently didn't) I thought to reproduce the issue as it was presented, and lo and behold the interfaces are treated uniquely for each runlevel and restarted.

I created two runlevels using two seperate network configurations, with different preup() nad postup() functions, services, and two seperate AP's to authenticate to ... and it works just as stated in the above post.

Code:
[root@host: ~]# rc test1
 * Caching service dependencies ...
 * Bringing up interface wlan0
 *   Running preup ...
 *     Reloading postfix  ...                                              [ ok ]
 *   Starting wpa_supplicant on wlan0 ...
 Successfully initialized wpa_supplicant                                   [ ok ]
 *   Starting wpa_cli on wlan0 ...                                         [ ok ]
 *   Backgrounding ... ...
 * WARNING: net.wlan0 has started, but is inactive
 * WARNING: pdnsd is scheduled to start when net.wlan0 has started
 * WARNING: ntp-client is scheduled to start when net.wlan0 has started
[root@host: ~]# rc test2
 * Stopping pdnsd ...                                                      [ ok ]
 * Bringing down interface wlan0
 *   Stopping dhcpcd on wlan0 ...                                          [ ok ]
 *   Stopping wpa_cli on wlan0 ...                                         [ ok ]
 *   Stopping wpa_supplicant on wlan0 ...                                  [ ok ]
 *   Running postdown ...
 *     Reloading postfix  ...                                              [ ok ]
 * Bringing up interface wlan0
 *   Running preup ...
 *   Starting wpa_supplicant on wlan0 ...
 Successfully initialized wpa_supplicant
 *   Starting wpa_cli on wlan0 ...                                         [ ok ]
 *   Backgrounding ... ...
 * WARNING: net.wlan0 has started, but is inactive

Both connections were established as configured, so what is happening your end I can only guess. My first guess would be that you still have net.eth0, or some service that 'need[s] net', in the 'default' runlevel but that wouldn't explain why the interface isn't restarted. Anyhow, without further info I can only speculate.

best ... khay
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security 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