avahi-autoipd的link-local实验参考:
https://developer.apple.com/library/archive/qa/qa1357/_index.html
前提:
下面命令二选一:
route add 169.254.0.0 mask 255.255.0.0 169.254.0.111 /
route add 0.0.0.0 mask 0.0.0.0 169.254.0.222
ipconfig
linux设备上安装avahi-autoipd程序
apt-get install avahi-autoipd
//安装后会多出一个/etc/avahi/avahi-autoipd.action的脚本文件
//让设备在开机启动的时候默认在后台运行, 具体命令查看avahi-autoipd --help
linux设备上执行
/etc/avahi/avahi-autoipd.action eth0 169.254.0.210
ifconfig
下面是/etc/avahi/avahi-autoipd.action脚本内容
set -e
# Command line arguments:
# $1 event that happened:
# BIND: Successfully claimed address
# CONFLICT: An IP address conflict happened
# UNBIND: The IP address is no longer needed
# STOP: The daemon is terminating
# $2 interface name
# $3 IP adddress
if [ -x /bin/ip -o -x /sbin/ip ] ; then
# We have the Linux ip tool from the iproute package
case "$1" in
BIND)
ip addr add "$3"/16 brd 169.254.255.255 label "$2:avahi" scope link dev "$2"
;;
CONFLICT|UNBIND|STOP)
ip addr del "$3"/16 brd 169.254.255.255 label "$2:avahi" scope link dev "$2"
;;
*)
echo "Unknown event $1" >&2
exit 1
;;
esac
elif [ -x /bin/ifconfig -o -x /sbin/ifconfig ] ; then
# We have the old ifconfig tool
case "$1" in
BIND)
ifconfig "$2:3" inet "$3" netmask 255.255.0.0 broadcast 169.254.255.255 up
;;
CONFLICT|STOP|UNBIND)
ifconfig "$2:3" down
;;
*)
echo "Unknown event $1" >&2
exit 1
;;
esac
else
echo "No network configuration tool found." >&2
exit 1
fi
exit 0