View previous topic :: View next topic |
Author |
Message |
dr.nil n00b
![n00b n00b](/images/ranks/rank_rect_0.gif)
![](images/avatars/gallery/Futurama/cartoon_futurama_bender.gif)
Joined: 18 Jul 2007 Posts: 47
|
Posted: Fri Mar 08, 2013 12:43 am Post subject: [solved] Switching between network configurations? |
|
|
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 |
|
![](templates/gentoo/images/spacer.gif) |
BillWho Veteran
![Veteran Veteran](/images/ranks/rank_rect_5_vet.gif)
![](images/avatars/11944701294f68e0ba14919.gif)
Joined: 03 Mar 2012 Posts: 1600 Location: US
|
Posted: Fri Mar 08, 2013 1:00 am Post subject: |
|
|
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
Since installing gentoo, my life has become one long emerge ![Smile :)](images/smiles/icon_smile.gif) |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
syn0ptik Apprentice
![Apprentice Apprentice](/images/ranks/rank_rect_2.gif)
![](images/avatars/2187279175166886b02003.gif)
Joined: 09 Jan 2013 Posts: 267
|
Posted: Fri Mar 08, 2013 4:47 am Post subject: |
|
|
or change the MAC-address on client side, for proper configuration. |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
dr.nil n00b
![n00b n00b](/images/ranks/rank_rect_0.gif)
![](images/avatars/gallery/Futurama/cartoon_futurama_bender.gif)
Joined: 18 Jul 2007 Posts: 47
|
Posted: Fri Mar 08, 2013 8:18 am Post subject: |
|
|
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 |
|
![](templates/gentoo/images/spacer.gif) |
khayyam Watchman
![Watchman Watchman](/images/ranks/rank-G-2-watchman.gif)
![](images/avatars/9397496074fd0189143bb7.png)
Joined: 07 Jun 2012 Posts: 6227 Location: Room 101
|
Posted: Fri Mar 08, 2013 11:39 am Post subject: |
|
|
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 |
|
![](templates/gentoo/images/spacer.gif) |
kimmie Guru
![Guru Guru](/images/ranks/rank_rect_3.gif)
![](images/avatars/188316714246c9845d589cf.gif)
Joined: 08 Sep 2004 Posts: 531 Location: Australia
|
Posted: Fri Mar 08, 2013 1:23 pm Post subject: |
|
|
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 |
|
![](templates/gentoo/images/spacer.gif) |
khayyam Watchman
![Watchman Watchman](/images/ranks/rank-G-2-watchman.gif)
![](images/avatars/9397496074fd0189143bb7.png)
Joined: 07 Jun 2012 Posts: 6227 Location: Room 101
|
Posted: Fri Mar 08, 2013 2:47 pm Post subject: |
|
|
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 |
|
![](templates/gentoo/images/spacer.gif) |
dr.nil n00b
![n00b n00b](/images/ranks/rank_rect_0.gif)
![](images/avatars/gallery/Futurama/cartoon_futurama_bender.gif)
Joined: 18 Jul 2007 Posts: 47
|
Posted: Sat Mar 09, 2013 6:06 pm Post subject: |
|
|
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 |
|
![](templates/gentoo/images/spacer.gif) |
khayyam Watchman
![Watchman Watchman](/images/ranks/rank-G-2-watchman.gif)
![](images/avatars/9397496074fd0189143bb7.png)
Joined: 07 Jun 2012 Posts: 6227 Location: Room 101
|
Posted: Sun Mar 10, 2013 5:34 am Post subject: |
|
|
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 |
|
![](templates/gentoo/images/spacer.gif) |
|
|
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
|
|