Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Network config for laptop
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
petterg
Guru
Guru


Joined: 25 Mar 2004
Posts: 500
Location: Oslo, Norway

PostPosted: Wed Sep 07, 2005 10:59 am    Post subject: Network config for laptop Reply with quote

I'm bringing a laptop around to 3 different networks. Is there any way to make it detect which network setting to use?

The behavior I'd like would be something like this:
- Try to get DHCP ip for a few seconds
- - if sucsess, done
- - else:
- - - Check if 192.168.1.1 is in use (default gateway at one location)
- - - - If 192.168.1.1 is used:
- - - - - set 192.168.1.1 as gateway
- - - - - check if 192.168.1.240 is available - if yes: use 192.168.1.240 as ip
- - - - - else: try another random ip in the same subnet, keep trying until available ip is found and use that ip.
- - - - else
- - - - - Check if 10.0.0.254 ip is in use (default gateway at one location)
- - - - - - (do the same stuff as for 192.168.1.* network)

Is this posible? There seems to be a lot of posibilities in /etc/conf.d/net, but I might need some kind of script for this?
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 Sep 07, 2005 11:54 am    Post subject: Reply with quote

Sounds like we need an arping module which maps a gateway IP config to our interface config so something like this could work

Code:

# List gateways to arping
arping_eth0="192.168.1.1 10.1.1.1"

# Map found gateways to config's
config_192168001001=( "192.168.1.240/24" )
fallback_192168001001=( "apipa" )
routes_192168001001=( "default via 192.168.1.1" )

config_010000000001=( "10.0.0.254/24" )
fallback_010000000001=( "apipa" )
routes_010000000001=( "default via 10.0.0.1" )


Care to code one?
_________________
Use dhcpcd for all your automated network configuration needs
Use dhcpcd-ui (GTK+/Qt) as your System Tray Network tool
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 Sep 07, 2005 1:06 pm    Post subject: Reply with quote

baselayout-1.12.0_pre9 will replace the apipa module with a arping module which does the above (slightly different config, check net.example) and apipa if no gateway is found

so this works

Code:
config_eth0=( "dhcp" )
fallback_eth0=( "arping" )

_________________
Use dhcpcd for all your automated network configuration needs
Use dhcpcd-ui (GTK+/Qt) as your System Tray Network tool
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 Sep 07, 2005 3:34 pm    Post subject: Reply with quote

Those that want to try it out, can grab it from here
http://dev.gentoo.org/~uberlord/baselayout/arping

Drop it into /lib/rcscripts/net.modules.d and delete the apipa module that 's currently there. Requires baselayout-1.12.0_pre8 (will ship with pre9).
_________________
Use dhcpcd for all your automated network configuration needs
Use dhcpcd-ui (GTK+/Qt) as your System Tray Network tool
Back to top
View user's profile Send private message
petterg
Guru
Guru


Joined: 25 Mar 2004
Posts: 500
Location: Oslo, Norway

PostPosted: Thu Sep 08, 2005 9:12 am    Post subject: Reply with quote

I thought arping only used ip's in the range 169.254.0.0 - 169.254.255.255.

Code:

config_eth0=( "dhcp" )
fallback_eth0=( "arping" )


How can I set an ip-adress that it will try before it tries the random adresses?

Maybe I missunderstod. Am I supposed to use the code from both of your postings or just one of them (depending if baselayout-1.12.0_pre9 is installed)?
Back to top
View user's profile Send private message
UberLord
Retired Dev
Retired Dev


Joined: 18 Sep 2003
Posts: 6835
Location: Blighty

PostPosted: Thu Sep 08, 2005 9:36 am    Post subject: Reply with quote

petterg wrote:
I thought arping only used ip's in the range 169.254.0.0 - 169.254.255.255.


That's the APIPA address range.
You use arping to see if an address is in use or not - APIPA uses this. However, you can use arping to find any ipv4 address, not just the APIPA range :)

Quote:

Code:

config_eth0=( "dhcp" )
fallback_eth0=( "arping" )


How can I set an ip-adress that it will try before it tries the random adresses?

Maybe I missunderstod. Am I supposed to use the code from both of your postings or just one of them (depending if baselayout-1.12.0_pre9 is installed)?


You use both. You have to instruct the interface config to use arping. That will then loop through the gateways in arping_eth0. If it finds one then it applies it's config (if any). If no gateways are found then we arping an APIPA address. This ensures that the interface should come up.

Maybe we need an option to arping but not apipa?
_________________
Use dhcpcd for all your automated network configuration needs
Use dhcpcd-ui (GTK+/Qt) as your System Tray Network tool
Back to top
View user's profile Send private message
petterg
Guru
Guru


Joined: 25 Mar 2004
Posts: 500
Location: Oslo, Norway

PostPosted: Fri Sep 09, 2005 10:41 pm    Post subject: Reply with quote

Thanx
I'll try this out...
Back to top
View user's profile Send private message
jamapii
l33t
l33t


Joined: 16 Sep 2004
Posts: 637

PostPosted: Sat Sep 10, 2005 2:21 pm    Post subject: Reply with quote

On my old laptop, I had a script that did this.

It probed various addresses until it was successful, and it looked at the MAC addresses in /proc/net arp (at least in old versions).

Now I'm relying on dhcp and on different runlevels for non-dhcp networks, but I will likely try the new arping module at some time :D

About the config/fallback system, I suggest to make it more flexible, to replace it with something that allows unlimited fallbacks (and not hardcode fallbacks in modules). My preferred configuration would be: first try "dhcp", then try "arping", then assign a static ip address.

This requires at least an arping that does not fall back to apipa, and a way to set up a second fallback. (Sounds like 2-dimensional arrays, or a fallback2_eth0, fallback3_eth0...)
Back to top
View user's profile Send private message
frozenJim
Guru
Guru


Joined: 18 Jun 2004
Posts: 341
Location: Montreal, Quebec, Canada

PostPosted: Sun Jul 30, 2006 1:56 pm    Post subject: So.. to SUMMARIZE... Reply with quote

Whooo boy 8O . Uber, you are getting me all excited here.

So if I need to access two networks:
Code:
Home: 192.168.2.7
DNS: 192.168.2.1
Gateway: 192.168.2.1

and
Code:
Work: 172.16.10.170
DNS: 172.16.10.10
Gateway: 172.16.10.1

Then is it correct to use the following in my /etc/conf.d/net?:
Code:
# List gateways to arping
arping_eth0="192.168.2.1 172.16.10.1"

# Map found gateways to config's
config_192168002001=( "192.168.2.7" )
fallback_192168001001=( "dhcp" )
routes_192168001001=( "default via 192.168.2.1" )

config_172016010001=( "172.16.10.170" )
fallback_172016010001=( "dhcp" )
routes_172016010001=( "default via 172.16.10.10" )

config_eth0=( "dhcp" )
fallback_eth0=( "arping" )


If I'm hearing you correctly, it will arping both known networks and then use the config for the one that it found.
  • If IP assignment fails, it will fallback to dhcp (available on both networks in my case).
  • If neither network is avialable the it will attempt an standard dhcp connection.
  • If THAT fails, then it will try arping whatever network to grab any available address that is not in use.


Am I even CLOSE to understanding?
And then, under the last scenario, how do i discover and set my dns/gateway addresses?
_________________
Who controls the past, controls the future. Who controls the present, controls the past.
Back to top
View user's profile Send private message
UberLord
Retired Dev
Retired Dev


Joined: 18 Sep 2003
Posts: 6835
Location: Blighty

PostPosted: Sun Jul 30, 2006 4:21 pm    Post subject: Re: So.. to SUMMARIZE... Reply with quote

frozenJim wrote:
Whooo boy 8O . Uber, you are getting me all excited here.

So if I need to access two networks:
Code:
Home: 192.168.2.7
DNS: 192.168.2.1
Gateway: 192.168.2.1

and
Code:
Work: 172.16.10.170
DNS: 172.16.10.10
Gateway: 172.16.10.1

Then is it correct to use the following in my /etc/conf.d/net?:
Code:
# List gateways to arping
arping_eth0="192.168.2.1 172.16.10.1"


gateways_eth0="192.168.2.1 172.16.10.1"

Aside from that it looks good. Although I'd set a timeout on the dhcp request - dhcpcd defaults to 60 seconds.
dhcpcd_eth0="-t 5"

5 should be good :)
Quote:
Am I even CLOSE to understanding?
And then, under the last scenario, how do i discover and set my dns/gateway addresses?


dnsservers_192168001001="12.3.4.5"
dnsdomain_192168001001="foo.bar.com"

You've already set the gateway by using the default route :)
_________________
Use dhcpcd for all your automated network configuration needs
Use dhcpcd-ui (GTK+/Qt) as your System Tray Network tool
Back to top
View user's profile Send private message
frozenJim
Guru
Guru


Joined: 18 Jun 2004
Posts: 341
Location: Montreal, Quebec, Canada

PostPosted: Mon Jul 31, 2006 4:49 pm    Post subject: Reply with quote

OK, I think I understand what we're doing here... but I'm not able to connect correctly. All I ever get is a dhcp address. Even if I comment out the fallback to dhcp line, I get a dhcp address.

WHY am I getting a dhcp address on the 172.17.10.1/19 network? What can I do differently to get my address? WHO is even requesting the dhcp address?

Code:

#note... the subnet is 255.255.224.0
gateways_eth0="172.16.10.1/19"

config_172016010001=( "172.16.10.170" )
#fallback_172016010001=( "dhcp" )
routes_172016010001=( "default via 172.16.10.1" )
dnsservers_172016010001="172.16.10.10"
dnsdomain_172016010001="ctsolutions.loc"

#config_eth0=( "dhcp" )
#fallback_eth0=( "arping" )
#fallback_eth0=( "dhcp" )

#-----------------------
# OLD SETTINGS, ALL COMMENTED OUT #
#-----------------------
#config_eth0=( "172.16.10.170 netmask 255.255.224.0 brd 172.16.31.255" )
#routes_eth0=( "default gw 172.16.0.1" )

modules=( "wpa_supplicant" )
wpa_supplicant_eth1="-Dwext"

_________________
Who controls the past, controls the future. Who controls the present, controls the past.
Back to top
View user's profile Send private message
UberLord
Retired Dev
Retired Dev


Joined: 18 Sep 2003
Posts: 6835
Location: Blighty

PostPosted: Mon Jul 31, 2006 5:02 pm    Post subject: Reply with quote

frozenJim wrote:
WHY am I getting a dhcp address on the 172.17.10.1/19 network? What can I do differently to get my address? WHO is even requesting the dhcp address?


You've commented out config_eth0 so it will default to dhcp. This is probably what you need

Code:
config_eth0=( "arping" )
fallback_eth0=( "dhcp" )

_________________
Use dhcpcd for all your automated network configuration needs
Use dhcpcd-ui (GTK+/Qt) as your System Tray Network tool
Back to top
View user's profile Send private message
frozenJim
Guru
Guru


Joined: 18 Jun 2004
Posts: 341
Location: Montreal, Quebec, Canada

PostPosted: Sun Aug 06, 2006 1:41 pm    Post subject: Reply with quote

'tis solved. As soon as I have few free minutes, I will write this up in the Gentoo-Wiki. Man you were so right about everyone turning green with envy when you just plug it in and get connected.

This truly is a development! No matter where i go, the laptop decides to assign my IP, assigns my the next avail IP or uses dhcp depending on the network. COOL!

Is it my imagination, or is it really showing intelligence in determining whether to use the wireless or Cat5 connection based on speed? It seems that whenever I have two connections concurrently, my laptop chooses to use the faster of the two.
_________________
Who controls the past, controls the future. Who controls the present, controls the past.
Back to top
View user's profile Send private message
UberLord
Retired Dev
Retired Dev


Joined: 18 Sep 2003
Posts: 6835
Location: Blighty

PostPosted: Tue Aug 08, 2006 9:10 am    Post subject: Reply with quote

baselayout-1.12 assigned higher metrics to wireless, vpn and ppp devices so we do prefer the faster ones by default :)
_________________
Use dhcpcd for all your automated network configuration needs
Use dhcpcd-ui (GTK+/Qt) as your System Tray Network tool
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