Paste details

/etc/rc.networking

markand

bash

month

#!/bin/sh
#
# /etc/rc.init -- basic networking script
#
# Copyright (c) 2019 David Demelier <markand@malikania.fr>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#

if [ -f /etc/rc.conf ]; then
	. /etc/rc.conf
fi

#
# This script is provided mostly for static configuration and/or more complex
# scenarios where the system administrator requires full control over the
# networking interfaces. Most people would prefer using dhcpcd for simple
# configurations or NetworkManager on desktop systems.
#
# The file /etc/rc.networking allows you to define functions for each interface
# and will automatically call "start" and "stop" at boot and shutdown
# respectively.
#
# See below for basic examples and uncomment the appropriate one.
#

lo()
{
	echo "Setting network interface: lo"

	case $1 in
	"start")
		ip link set dev lo up
		ip addr add 127.0.0.1 dev lo
		;;
	"stop")
		ip addr del 127.0.0.1 dev lo
		ip link set dev lo down
		;;
	esac
}

#
# Example 1: static IP on eth0 interface.
#
# eth0()
# {
# 	echo "Setting network interface: eth0"
#
# 	case $1 in
# 	"start")
# 		ip link set eth0 up
# 		ip addr add 192.168.0.1 dev eth0
# 		;;
# 	"stop")
# 		ip addr del 192.168.0.1 dev eth0
# 		ip link set eth0 down
# 		;;
# 	esac
# }

usage()
{
	echo "usage: $(basename $0) start|stop [interface]" 1>&2
	exit 1
}

if [ $# -eq 0 ]; then
	usage
	# NOTREACHED
fi

case $1 in
"start"|"stop")
	#
	# If no interface is given, iterate over all defined in
	# INTERFACES from /etc/rc.conf.
	#
	if [ $# -eq 1 ]; then
		for iface in $INTERFACES; do
			$iface $1
		done
	else
		$2 $1
	fi

	;;
*)
	usage
	# NOTREACHED
	;;
esac