ifconfig
in the script#!/bin/sh
# PROVIDE: ucgetif
# REQUIRE: FILESYSTEMS
# BEFORE: netif
. /etc/rc.subr
name="ucgetif"
rcvar="ucgetif_enable"
start_cmd="${name}_start"
Bsd_dmesg="/sbin/dmesg"
Bsd_grep="/usr/bin/grep"
Bsd_sed="/usr/bin/sed"
Bsd_awk="/usr/bin/awk"
Bsd_cat="/bin/cat"
Bsd_ifconfig="/sbin/ifconfig"
Bsd_msgd="/var/run/dmesg.boot"
ucgetif_start() {
eth_patern="XXXX"
eth_X=$(${Bsd_cat} /etc/rc.conf | ${Bsd_grep} $eth_patern)
if [ -n $eth_X ]; then
eth_ifs=$(${Bsd_dmesg} | ${Bsd_sed} -n 's/^\(.*\):\ Ethernet\ address:.*/\1/p')
while ps -axg | grep -vw grep | grep -w dmesg > /dev/null; do sleep 1; done
$Bsd_sed -i '' -e "s/$eth_patern/$eth_ifs/g" /etc/rc.conf
while ps -axg | grep -vw grep | grep -w sed > /dev/null; do sleep 1; done
$Bsd_ifconfig $eth_ifs name "genet0"
while ps -axg | grep -vw grep | grep -w ifconfig > /dev/null; do sleep 1; done
fi
}
run_rc_command "$1"
run_rc_script
.Talking about firewalls and FreeBSD OS with many ethernet interfaces ( saying 4 interfaces [ em0, gbe0, em1, rl0 ] ) in this order.Tip, you can useifconfig_DEFAULT="...."
. That will always use the first detected ethernet card. Which is usually fine for most generic servers or embedded devices with only one ethernet adapter.
If you need to use a specific interface (for firewall rules for example), you could doifconfig_DEFAULT_name="eth0"
. Then base everything on the eth0 interface name. This little 'trick' would work fine for systems that only have one ethernet connection. No need to figure out if it's ng0, or em0, or igb0, it will automagically pick the first interface.
I do not know, I'd say yes.Talking about firewalls and FreeBSD OS with many ethernet interfaces ( saying 4 interfaces [ em0, gbe0, em1, rl0 ] ) in this order.
My question is : Will the kernel detect interfaces in the same order in every boot ?
Thank you
If you just need a list of interfaces;ifconfig -l
. No need to grep through system logs.
myscript_start()
{
local iface= # make sure there is no conflict with an other $iface variable
for iface in $(ifconfig -l); do
case "${iface}" in
lo[0-9]) : skip ;;
ng0)
/sbin/ifconfig ng0 inet 192.0.x.y/24 name eth0
/sbin/route add default 192.168.x.y
;;
em[0-9])
/sbin/dhclient ${iface}
;;
... ... ...
esac
done
}
If the /etc/start_if.⟨interface⟩ file is present, it is read
and executed by the sh(1) interpreter before configuring the
interface as specified in the ifconfig_⟨interface⟩ and
ifconfig_⟨interface⟩_alias⟨n⟩ variables.
I do the same thing. I think this is a great way to learn where everything is on the filesystem.Why do you feel you need to hardcode the paths?
It depends on the direction from which you approach the issue.I do the same thing. I think this is a great way to learn where everything is on the filesystem.
[strand.283] $ uname -s; which gzip
FreeBSD
/usr/bin/gzip
[pi3b.814] $ uname -s; which gzip
Linux
/bin/gzip
I think it is an heritage from other programming language ( PASCAL ) that I use frequently on UNIX systems ( FreeBSD, OpenBSD), & It is good for me to memory commands locations.Why do you feel you need to hardcode the paths?
/etc/rc: WARNING: $ucgetif_enable is not set properly - see rc.conf(5).
, the script is the same.The warning massage results from this piece of code from /etc/rc.subr:While booting, I see a warning
/etc/rc: WARNING: $ucgetif_enable is not set properly - see rc.conf(5).
, the script is the same.
Some one could you tel me the reason ??
...
checkyesno()
{
eval _value=\$${1}
debug "checkyesno: $1 is set to $_value."
case $_value in
# "yes", "true", "on", or "1"
[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
return 0
;;
# "no", "false", "off", or "0"
[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0)
return 1
;;
*)
warn "\$${1} is not set properly - see rc.conf(5)."
return 1
;;
esac
}
...
...
: ${ucgetif_enable:="NO"}
...