OpenBSD: automate wired/wifi network connection


Despite of missing applications like NetworkManager in OpenBSD, it’s possible to implement some kind of network autodetection, wired and wireless. I launch the following script in the boot process:

/etc/activatewifi.sh

#!/bin/sh

IF_WIRED=em0
IF_WIRELESS=iwn0

WIFI_SCRIPT=”/etc/wifinwid ${IF_WIRELESS}”

STATE_IF_WIRED=`ifconfig $IF_WIRED |grep status|cut -d: -f 2 |sed -E “s/ //g” `

echo “${IF_WIRED}: ${STATE_IF_WIRED}”

if [ “$STATE_IF_WIRED” = “nocarrier” ]; then
        `$WIFI_SCRIPT $IF_WIRELESS ` &
fi

Take note of ‘/etc/wifinwid’ script. This script can be grabbed from:

http://foad2.obtuse.com/beck/wifinwid

When OpenBSD is starting this script is executed, launching the wifi script is wired network is down. If my wired nic is up then the wifi script is not launched.

The main problem with this solution is when the wireless network is off. You need mannually activate the wired one. I use another script:

/etc/wifi_deactivate.sh

#!/bin/sh

ifconfig iwn0 192.168.50.10
route delete default
route delete default
dhclient em0

I assign a not real address for the wireless nic and delete the gateway. Maybe using configuration files like hostname.em0 or so is better.

About jjjesss

I'm a guy interested in technology, bsd fan and concerned about the world around.
This entry was posted in BSD, OpenBSD. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s