Go Back   DaemonForums > OpenBSD > OpenBSD General

OpenBSD General Other questions regarding OpenBSD which do not fit in any of the categories below.

Thread Tools Display Modes
  #1   (View Single Post)  
Old 4 Days Ago
brudan brudan is offline
Port Guard
Join Date: Dec 2018
Posts: 29
Default how to prioritize "join" entries in /etc/hostname.if

I'm rocking OpenBSD 6.4-stable on my Thinkpad T400 laptop. I use the internet exclusively over wifi. I'd like to somehow configure things so that if my phone's hotspot is on, laptop always connects to it instead of home, work, or other hotspot.

My /etc/hostname.athn0 looks like this:

join home_sweet_home wpakey PassWorD
join AndroidAP wpakey paSSwOrd
join work_bitter_work wpakey pasSwORd 
The hostname.if(5) man page has no mention of join. ifconfig(8) man page mentions join but not how to prioritize multiple appearances of it in hostname.if.

Does anyone know how to prioritize the join entries, so that one SSID (AndroidAP in my case) is always given priority over the others?

P.S. In his second post here, developer phessler mentions an Apple-like algorithm for choosing the network, but no mention of how to manually specify priority.

Last edited by brudan; 4 Days Ago at 07:54 PM. Reason: P.S. with link to undeadly.org
Reply With Quote
  #2   (View Single Post)  
Old 4 Days Ago
brudan brudan is offline
Port Guard
Join Date: Dec 2018
Posts: 29

Never mind. I just rolled my own. I deleted /etc/hostname.athn0 and now I just run the script below as root at boot. No fancy algorithm here: The SSIDs are searched in order, first one found connects.



	# these will be tried in order, so put favored networks on top:
	ssid="AndroidAP"; key="paSSworD"; search && connect && exit 0
	ssid="Work-Visitor"; key=""; search && connect && exit 0
	ssid="home_sweet_home"; key="PassWoRd"; search && connect && exit 0

	exit 1

	ifconfig athn0 down && ifconfig athn0 up && sleep 5
	ifconfig athn0 scan | grep -v ieee80211 > $available_networks # the line with ieee80211 lists prior connection, which may not be currently available

	grep -q "$ssid" "$available_networks"

	if [ -n "$key" ]; then
		ifconfig athn0 nwid "$ssid" wpakey "$key" && dhclient athn0 
		ifconfig athn0 nwid "$ssid" -wpakey && dhclient athn0

P.S. The weak part of the script is the get_available_networks function: Sometimes a hotspot is not detected by the scan, even though there is good signal. Anything I can do to make the scan more reliable?

Last edited by brudan; 3 Days Ago at 06:03 PM.
Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
OpenBSD gains Wi-Fi "auto-join" e1-531g News 1 12th July 2018 06:33 PM
Difference between"arp info overwritten" and " duplicate IP address " varag OpenBSD Security 1 6th April 2015 02:57 PM
How to replace "ectags" with "ctags"? fender0107401 OpenBSD Packages and Ports 5 16th April 2013 10:01 AM
Fixed "xinit" after _7 _8, "how" here in case anyones' "X" breaks... using "nvidia" jb_daefo Guides 0 5th October 2009 09:31 PM
"Thanks" and "Edit Tags". diw Feedback and Suggestions 2 29th March 2009 12:06 AM

All times are GMT. The time now is 05:21 AM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick