Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
networking scenarios
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
curmudgeon
Veteran
Veteran


Joined: 08 Aug 2003
Posts: 1523

PostPosted: Sat May 20, 2017 10:32 pm    Post subject: networking scenarios Reply with quote

One of the things I have never been able to figure out with gentoo is handling various network contingencies.

I would like to set up the following.

1. If there is a ethernet cable plugged in (and a connection) at boot, set up a specific set of parameters (static ip, dns servers, routes), and make sure that wireless networking is disabled.

2. If there is no ethernet cable, but a connection to a specific wireless access point on boot, set up a specific set of parameters (static ip, dns servers, routes), and make sure that wired networking is disabled.

3. If neither of the above conditions are met on boot, make sure that all networking is DISABLED until the user specifically enables and configures it.

Is there some way of doing that, and if so, can someone explain how? Thank you in advance.
Back to top
View user's profile Send private message
eccerr0r
Watchman
Watchman


Joined: 01 Jul 2004
Posts: 7051
Location: almost Mile High in the USA

PostPosted: Sun May 21, 2017 1:02 am    Post subject: Reply with quote

This is the problem that a static, init-based configuration has issues with.

What about the case where you've been connected to Ethernet, and then later disconnect it? Should it automatically switch over? And if you connect Ethernet while you've been on wireless?

I don't know if a script that does this, but in any case you will need a program to monitor status of all the network ports and switch accordingly. A full program does exist to do this: this is what NetworkManager does.

Networkmanager will unfortunately connect both Ethernet and wireless at the same time if both are available. However it gives Ethernet a lower metric and thus will favor Ethernet when opening new connections, so it's close to what you want... Both network addresses will respond as expected, which is pretty cool IMHO.
_________________
Intel Core i7 2700K@ 4.1GHz/HD3000 graphics/8GB DDR3/180GB SSD
What am I supposed watching?
Back to top
View user's profile Send private message
The Doctor
Moderator
Moderator


Joined: 27 Jul 2010
Posts: 2546

PostPosted: Sun May 21, 2017 2:45 am    Post subject: Reply with quote

Assuming you only care about boot up configuration I'd think a simple script would do.

This script is very incomplete and probably more than a few errors
Code:

#!/bin/bash

# ethernet check
if [ $(grep ""  /sys/class/net/eth0/carrier) -eq 1]
  exec ethernet_script
# wireless check
else if [$(some_command_I'm_too_lazy_to_look_up | grep network_name)]
   exec wireless_script
# default case
else
  ifconfig eth0 down
  ifconfig wlan0 down
fi


Is that what you are looking for?
_________________
First things first, but not necessarily in that order.

Apologies if I take a while to respond. I'm currently working on the dematerialization circuit for my blue box.
Back to top
View user's profile Send private message
charles17
Advocate
Advocate


Joined: 02 Mar 2008
Posts: 2583

PostPosted: Sun May 21, 2017 5:14 am    Post subject: Re: networking scenarios Reply with quote

curmudgeon wrote:
1. If there is a ethernet cable plugged in ...
On some laptops ethernet is combined with a physical rfkill switch. So if ethernet cable is plugged in, wireless is automatically switched of and dhcpcd then selects ethernet for connection.

curmudgeon wrote:
2. If there is no ethernet cable ....
Then rfkill is off and dhcpcd automatically selects wireless. wpa_supplicant then connects according to its settings.
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


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

PostPosted: Sun May 21, 2017 5:36 am    Post subject: Reply with quote

The Doctor ...

the problem with doing it outside of rc is that should you then need openntp, openresolv, or some other service, this will then want something to 'provide net' (and so will start a service that will do that causing your settings to go bye-bye). Also, there are other tie ins, like wpa_cli, which start/stop /etc/init.d/net.$IFACE based on CONNECTED/DISCONNECTED on the cntl_interface. Both of these will not be covered by an external script, so either you intergrate something more robust with /etc/conf.d/net (using 'preup()', etc) or use some other method to 'provide net' (ie, dhcpcd, newnet, ifplugd, netplug, etc).

Asuming this is a laptop (which by the sounds of it, it is) then the OP should be using the rfkill button as this should then trigger hotplug and which could be tied to ifplugd/netplug (via modules_$IFACE="plug"), ifplugd/netplug can then be configured to bring up eth0 on cable, and switch to wireless if/when it becomes available (again, via rfkill). As for the interfaces being 'down', I don't see how this matters, they are not 'active', and you will only save power by disabling them via hardware.

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