飛行派工作日誌《七》

在考察路由表之後

【 dhcpcd.conf 管理 wlan1 】

pi@raspberrypi:~ route Kernel IP routing table Destination     Gateway         Genmask         Flags Metric Ref    Use Iface default         5.168.168.1     0.0.0.0         UG    202    0        0 eth0 default         192.168.8.1     0.0.0.0         UG    303    0        0 wlan0 default         192.168.8.1     0.0.0.0         UG    304    0        0 wlan1 5.168.168.0     *               255.255.255.0   U     202    0        0 eth0 192.168.8.0     *               255.255.255.0   U     303    0        0 wlan0 192.168.8.0     *               255.255.255.0   U     304    0        0 wlan1 pi@raspberrypi:~

 

【network interface 管理 wlan1 】

pi@raspberrypi:~ route Kernel IP routing table Destination     Gateway         Genmask         Flags Metric Ref    Use Iface default         5.168.168.1     0.0.0.0         UG    202    0        0 eth0 default         192.168.8.1     0.0.0.0         UG    303    0        0 wlan0 5.168.168.0     *               255.255.255.0   U     202    0        0 eth0 link-local      *               255.255.0.0     U     304    0        0 wlan1 192.168.8.0     *               255.255.255.0   U     0      0        0 wlan1 192.168.8.0     *               255.255.255.0   U     303    0        0 wlan0 pi@raspberrypi:~

 

發現此事與

Link-local address

In a computer network, a link-local address is a network address that is valid only for communications within the network segment (link) or the broadcast domain that the host is connected to.

Link-local addresses are not guaranteed to be unique beyond a single network segment. Routers therefore do not forward packets with link-local addresses.

For protocols that have only link-local addresses, such as Ethernet, hardware addresses assigned by manufacturers in networking elements are unique, consisting of a vendor identification and a serial identifier.

Link-local addresses for IPv4 are defined in the address block 169.254.0.0/16, in CIDR notation. In IPv6, they are assigned with the prefix fe80::/64, although being defined as the block fe80::/10.[1]

 

有關︰

DHCPCD(8) BSD System Manager’s Manual DHCPCD(8)

NAME
dhcpcd — a DHCP client

SYNOPSIS
dhcpcd [-46ABbDdEGgHJKLMpqTV] [-C, –nohook hook] [-c, –script script]
[-e, –env value] [-F, –fqdn FQDN] [-f, –config file]
[-h, –hostname hostname] [-I, –clientid clientid]
[-i, –vendorclassid vendorclassid] [-l, –leasetime seconds]
[-m, –metric metric] [-O, –nooption option]
[-o, –option option] [-Q, –require option]
[-r, –request address] [-S, –static value]
[-s, –inform address[/cidr]] [-t, –timeout seconds]
[-u, –userclass class] [-v, –vendor code, value]
[-W, –whitelist address[/cidr]] [-w, –waitip [4 | 6]]
[-y, –reboot seconds] [-X, –blacklist address[/cidr]]
[-Z, –denyinterfaces pattern] [-z, –allowinterfaces pattern]
[interface] […]

……

Local Link configuration
If dhcpcd failed to obtain a lease, it probes for a valid IPv4LL address
(aka ZeroConf, aka APIPA). Once obtained it restarts the process of
looking for a DHCP server to get a proper address.

When using IPv4LL, dhcpcd nearly always succeeds and returns an exit code of 0. In the rare case it fails, it normally means that there is a
reverse ARP proxy installed which always defeats IPv4LL probing. To disable this behaviour, you can use the -L, –noipv4ll option.

───

Network Working Group S. Cheshire
Request for Comments: 3927 Apple Computer
Category: Standards Track B. Aboba
Microsoft Corporation
E. Guttman
Sun Microsystems
May 2005

Dynamic Configuration of IPv4 Link-Local Addresses
Status of This Memo

This document specifies an Internet standards track protocol for the
Internet community, and requests discussion and suggestions for
improvements. Please refer to the current edition of the “Internet
Official Protocol Standards” (STD 1) for the standardization state
and status of this protocol. Distribution of this memo is unlimited.

Copyright Notice

Copyright (C) The Internet Society (2005).
Abstract

To participate in wide-area IP networking, a host needs to be
configured with IP addresses for its interfaces, either manually by
the user or automatically from a source on the network such as a
Dynamic Host Configuration Protocol (DHCP) server. Unfortunately,
such address configuration information may not always be available.
It is therefore beneficial for a host to be able to depend on a
useful subset of IP networking functions even when no address
configuration is available. This document describes how a host may
automatically configure an interface with an IPv4 address within the
169.254/16 prefix that is valid for communication with other devices
connected to the same physical (or logical) link.

IPv4 Link-Local addresses are not suitable for communication with
devices not directly connected to the same physical (or logical)
link, and are only used where stable, routable addresses are not
available (such as on ad hoc or isolated networks). This document
does not recommend that IPv4 Link-Local addresses and routable
addresses be configured simultaneously on the same interface.

 

於是回到 network interface 的老路︰

pi@raspberrypi:~ route Kernel IP routing table Destination     Gateway         Genmask         Flags Metric Ref    Use Iface default         5.168.168.1     0.0.0.0         UG    202    0        0 eth0 default         192.168.8.1     0.0.0.0         UG    303    0        0 wlan0 5.168.168.0     *               255.255.255.0   U     202    0        0 eth0 192.168.8.0     *               255.255.255.0   U     0      0        0 wlan1 192.168.8.0     *               255.255.255.0   U     303    0        0 wlan0 pi@raspberrypi:~

 

cat /etc/dhcpcd.conf
# A sample configuration for dhcpcd.
# See dhcpcd.conf(5) for details.

# Allow users of this group to interact with dhcpcd via the control socket.
#controlgroup wheel

# Inform the DHCP server of our hostname for DDNS.
hostname

# Use the hardware address of the interface for the Client ID.
clientid
# or
# Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361.
#duid

# Persist interface configuration when dhcpcd exits.
persistent

# Rapid commit support.
# Safe to enable by default because it requires the equivalent option set
# on the server to actually work.
option rapid_commit

# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
# Most distributions have NTP support.
option ntp_servers
# Respect the network MTU.
# Some interface drivers reset when changing the MTU so disabled by default.
#option interface_mtu

# A ServerID is required by RFC2131.
require dhcp_server_identifier

# Generate Stable Private IPv6 Addresses instead of hardware based ones
slaac private

# A hook script is provided to lookup the hostname if not set by the DHCP
# server, but it should not be run by default.
nohook lookup-hostname

# interface wlan1
# static ip_address=192.168.8.1/24
# static routers=192.168.8.1
# static domain_name_servers=192.168.8.1

denyinterfaces wlan1

 

cat /etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will “exit 0” on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ “$_IP” ]; then
printf “My IP address is %s\n” “$_IP”
fi

ifconfig wlan1 192.168.8.1

exit 0