我們先來看一下樹梅派網卡的默認的相關配置:
網卡的配置文件:/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 //設置eth0的狀態遵循手冊 allow-hotplug wlan0 //允許-熱插拔 wlan0 iface wlan0 inet manual //設置wlan0為狀態遵循手冊 wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf //wpa協議文件的位置 allow-hotplug wlan1 //允許-熱插拔 wlan1 iface wlan1 inet manual //設置wlan1為狀態遵循手冊 wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf //wpa協議文件的位置
這個文件的網卡設置方式是方式是和dhcpcd一起使用的,如果要使用靜態IP,請參考/etc/dhcpcd.conf和man dhcpcd.conf文件。
iface lo inet loopback 設置名稱為lo的網卡,為本地回環
iface eth0 inet manual 設置名稱為eth0的網卡,網卡服從本地的系統的默認配置文件:/etc/network/interfaces.dpkg-old
allow-hotplug wlan0 設置名稱為wlan0的網卡,網卡的配置服從配置文件並支持熱插拔:/etc/wpa_supplicant/wpa_supplicant.conf
靜態配置文件:/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
eth0的默認配置手冊:/etc/network/interfaces.dpkg-old
auto lo //自動獲取 iface lo inet loopback //測試回路 iface eth0 inet dhcp //eth0的網絡IP為dhcp(自動獲取)
wlan0網卡配置文件:/etc/wpa_supplicant/wpa_supplicant.conf
country=GB ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1