飛行派工作日誌《六》

假使將問題輕輕放過,久而久之必模模糊糊,不知來去矣!!於是乎考之以樹莓派論壇,聽聽人們的經驗談,看看解決嘗試的方向︰

Configuring Network using dhcpcd

by Milliways » Sat May 30, 2015 2:57 am
I have installed the new `raspberrypi-net-mods` using `dhcpcd`. This works, but I am trying to understand why and how.
I have read the `dhcpcd` and `interfaces` `man` pages but these do not seem to apply to the actual interface.The `/etc/network/interfaces` used to contain `iface eth0 inet dhcp` which has been replaced by `iface eth0 inet manual`Where does the IP address come from? This seems to allocate the same IP reservation from my router.(I am trying to work out a configuration which will let my Pi work normally with dhcp on my home network, but allocate a `static` address so I can connect to the Pi over Ethernet (or ad-hoc WiFi) to my Mac in a remote environment with no router or internet access.)

……

by rpdom » Sun May 31, 2015 4:59 am
morgon wrote:Maybe I don’t understand your posting (and I may have one beer too many)

How many is too many? ;)

The new dhcpd seems to ignore the normal /etc/network/interfaces settings and just do its own thing. I might have a look at the reasoning for this and how to configure it one day, but for now I’m sticking with the old one that has worked since forever.

(I think the new one may need some GUI stuff to configure it? I run headless, so no idea)

───

Set Static IP address but also getting Dynamic

by kez » Sat Oct 31, 2015 9:59 am

This problem was plaguing me for ages. dhcpcd5 simply seems to ignore the interfaces file so you have to set exclusions in the dhcpcd.conf file. Really quick and easy to do.

Try adding the line:

denyinterfaces eth0

to /etc/dhcpcd.conf (change eth0 as required).

No need to make any extra changes in /etc/network/interfaces or uninstall anything.

man dhcpcd.conf for more info.

Sorry if I missed someone else posting this already or within a link to another post.

Kez

───

 

縱使有時某甲有用之法,某乙用之無效??至少可觀錯綜複雜脈絡也。因此在仔細閱讀 dhcpcd5 文件後︰

DHCPCD.CONF(5)              BSD File Formats Manual             DHCPCD.CONF(5)

NAME
     dhcpcd.conf — dhcpcd configuration file

DESCRIPTION
     Although dhcpcd can do everything from the command line, there are cases
     where it's just easier to do it once in a configuration file.  Most of
     the options found in dhcpcd(8) can be used here.  The first word on the
     line is the option and the rest of the line is the value.  Leading and
     trailing whitespace for the option and value are trimmed.  You can escape
     characters in the value using the \ character.

     Blank lines and lines starting with # are ignored.

     Here's a list of available options:

     allowinterfaces pattern
             When discovering interfaces, the interface name must match
             pattern which is a space or comma separated list of patterns
             passed to fnmatch(3).  If the same interface is matched in
             denyinterfaces then it is still denied.

 Manual page dhcpcd.conf(5) line 1 (press h for help or q to quit)

 

決定只用 dhcpcd5 程式來管理網路裝置︰

cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and ‘man dhcpcd.conf’

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

iface eth0 inet manual

allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

# allow-hotplug wlan1
# iface wlan1 inet manual
# wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

allow-hotplug wlan1
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

 

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

 

似乎一切正常哩!!

pi@raspberrypi:~ ifconfig  eth0      Link encap:Ethernet  HWaddr b8:27:eb:8a:12:64             inet addr:5.168.168.19  Bcast:5.168.168.255  Mask:255.255.255.0           inet6 addr: fe80::629a:af0a:4cf8:32ee/64 Scope:Link           UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1           RX packets:68235 errors:0 dropped:1 overruns:0 frame:0           TX packets:4257 errors:0 dropped:0 overruns:0 carrier:0           collisions:0 txqueuelen:1000            RX bytes:3208585 (3.0 MiB)  TX bytes:924909 (903.2 KiB)  lo        Link encap:Local Loopback             inet addr:127.0.0.1  Mask:255.0.0.0           inet6 addr: ::1/128 Scope:Host           UP LOOPBACK RUNNING  MTU:65536  Metric:1           RX packets:13934 errors:0 dropped:0 overruns:0 frame:0           TX packets:13934 errors:0 dropped:0 overruns:0 carrier:0           collisions:0 txqueuelen:1            RX bytes:1627106 (1.5 MiB)  TX bytes:1627106 (1.5 MiB)  wlan0     Link encap:Ethernet  HWaddr b8:27:eb:df:47:31             inet addr:192.168.8.124  Bcast:192.168.8.255  Mask:255.255.255.0           inet6 addr: fe80::593e:a20:e109:ff10/64 Scope:Link           UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1           RX packets:211713 errors:0 dropped:251 overruns:0 frame:0           TX packets:74349 errors:0 dropped:0 overruns:0 carrier:0           collisions:0 txqueuelen:1000            RX bytes:45854983 (43.7 MiB)  TX bytes:9146774 (8.7 MiB)  wlan1     Link encap:Ethernet  HWaddr 7c:dd:90:7a:62:5a             inet addr:192.168.8.1  Bcast:192.168.8.255  Mask:255.255.255.0           inet6 addr: fe80::9622:163b:b34c:5446/64 Scope:Link           UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1           RX packets:145426 errors:0 dropped:0 overruns:0 frame:0           TX packets:148126 errors:0 dropped:0 overruns:0 carrier:0           collisions:0 txqueuelen:1000            RX bytes:14265502 (13.6 MiB)  TX bytes:17429653 (16.6 MiB)  pi@raspberrypi:~ 

 

誰知其他電腦卻連不上耶??