via: http://raspberrypi.stackexchange.com/questions/37920/how-do-i-set-up-networking-wifi-static-ip
The Raspbian released in May 2015 changed the way networking (and particularly WiFi) works.
This applies to the current Foundation releases of Raspbian Jessie and the last Raspbian Wheezy 2015-05-05 (no longer available).
This makes all the existing tutorials obsolete. (Note the tutorials can still be used if you want to use the older style of manual configuration, but you need to disable dhcpcd
.)
sudo systemctl stop dhcpcd.service
will stop (deactivate) dhcpcd
.
The newer configuration (based on dhcpcd
) has many advantages (and a few minor drawbacks) and is recommended for new users.
How to setup Raspbian Networking
If you are using an Ethernet connection with a router there should be no configuration required and it should work out of the box.
If you are using WiFi and the GUI set up by following the Foundation Guidelineshttps://www.raspberrypi.org/documentation/configuration/wireless/README.md
If you are using WiFi from the Command Line set up /etc/wpa_supplicant/wpa_supplicant.conf
by following https://www.raspberrypi.org/documentation/configuration/wireless/wireless-cli.md This is the only way to set up a network which does not broadcast SSID
.
This can also be used to setup a 'Headless' system e.g. using a serial console cable, but it MUCH easier if you can borrow a monitor and keyboard for setup. See below for another possible method using an Ethernet cable to a PC.
Networking Files
If you are running a recent Raspbian /etc/network/interfaces
should be as below. If you have changed it PUT IT BACK.
# 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
If the Foundation had setup dhcpcd
as the author intended /etc/network/interfaces
would not be needed. The 10-wpa_supplicant
hook automatically launches WPA supplicant on wireless interfaces and can be installed if desired.
The file /etc/wpa_supplicant/wpa_supplicant.conf
will be created/modified by the recommended setup methods, but can be setup by hand. It should contain something like the following:-
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="ESSID"
psk="Your_wifi_password"
}
If you need to connect to a private network (i.e. no broadcast SSID
) include the line scan_ssid=1
inside network={⋯}
. NOTE there are many other options which can be used see man wpa_supplicant.conf
.
Setup a Static IP Address
Questions about setting Static IP Address are among the most common on this site. There are very many tutorials (many wrong, obsolete or incomplete).
Disclaimer
Before proceeding I feel obliged to state that setting up a static address is NOT recommended. Telecommunications Engineers do not do this. Static IP Addresses can be the bane of a Network Administrator's life. There are situations where Static IP Addresses are necessary e.g. if you are running a DHCP server, or running on an isolated network with no DHCP server.
If you are determined to proceed anyway you should make sure you get it right. Adapted fromFoundation Network Tutorial
Find the Settings of your local Network
This is most easily done with the Pi itself, using DHCP, but can be done on any computer on your network, although the commands may differ on other systems.
Run either of the following (depending on whether you are using Ethernet or WiFi):
ip -4 addr show dev eth0 | grep inet
ip -4 addr show dev wlan0 | grep inet
which should give an output like:
inet 10.1.1.30/24 brd 10.1.1.255 scope global eth0
inet 10.1.1.31/24 brd 10.1.1.255 scope global wlan0
The first address is the IP address of your Pi on the network, and the part after the slash is the network size. It is highly likely that yours will be a /24.
The second address is the brd (broadcast) address of the network.
Find the address of your router (or gateway)
ip route | grep default | awk '{print $3}'
10.1.1.1
Finally note down the address of your DNS server, which is often the same as your gateway.
cat /etc/resolv.conf
# Generated by resolvconf
nameserver 10.1.1.1
Then follow ONE of the following options. (There are other methods not documented here. These are the most common on Raspbian.)
Network Interfaces method
Configure a static network adddress on your Pi in /etc/network/interfaces
auto eth0
iface eth0 inet static
address 10.1.1.30
netmask 255.255.255.0
gateway 10.1.1.1
allow-hotplug wlan0
iface wlan0 inet static
address 10.1.1.31
netmask 255.255.255.0
gateway 10.1.1.1
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
address
is the address from the command above (or another unused address on the same network),netmask
255.255.255.0 corresponds to network size/24
.gateway
is the address of your router (or gateway).
You can also specify dns-nameservers
, but this is generally not necessary.
The broadcast
is automatically derived from address
and netmask
and need not be specified.
For more detail see https://wiki.debian.org/NetworkConfiguration
You can set either or both eth0
or wlan0
Then disable the DHCP client daemon and switch to standard Debian networking:
sudo systemctl disable dhcpcd
sudo systemctl enable networking
Reboot for the changes to take effect:
sudo reboot
dhcpcd method
Leave /etc/network/interfaces
at its default (as above).
Edit /etc/dhcpcd.conf
as follows:-
Here is an example which configures a static address, routes and dns.
interface eth0
static ip_address=10.1.1.30/24
static routers=10.1.1.1
static domain_name_servers=10.1.1.1
interface wlan0
static ip_address=10.1.1.31/24
static routers=10.1.1.1
static domain_name_servers=10.1.1.1
ip_address
is the address and size from the command above (or another unused address on the same network),routers
is the address of your router (or gateway).domain_name_servers
is the DNS address(es) from /etc/resolv.conf.
(see man dhcpcd.conf
)
There is a good article on dhcpcd
at https://wiki.archlinux.org/index.php/dhcpcd The Fallback profile
is an alternative to static IP
Connecting a Computer to the Pi
Recent versions of Raspbian (which use dhcpcd
) allow ssh
to work over a link-local
address andavahi
(which is a zeroconf implementation) enables programs to discover hosts running on a local network.
This means you can plug the Pi into a Computer (with an Ethernet cable) or a local network router and connect without knowing the IP address.
You can easily connect from Linux and OS X with ssh pi@hostname.local
(the default hostname is raspberrypi
) This should work with popular GUI ssh
programs. This is sometimes problematic with some versions of Windows and networks which use .local in a non-standard way. (Seehttps://en.wikipedia.org/wiki/.local)
NOTE .local
resolution does not always work e.g. in rsync
. The following should resolve IP (and can be included in bash
scripts)RemotePi=$(getent hosts hostname.local | awk '{ print $1 }')
If you have multiple Pi you need to make sure each Pi has a unique hostname.
You can use a crossover cable, but you don't need one (most modern interfaces automatically detect).
One drawback of direct connection is that the Pi will have no Internet access and the date will not be set. You can copy the date from the host by running ssh pi@hostname.local sudo date -s$(date -Ins)
before connection.
Scope:
This tutorial is about setting up a normal Raspbian installation to access the internet using the included software. It also covers connections to other computers on the same network.
It is primarily aimed at helping new users struggling to get their Pi (especially WiFi) working .
It does NOT cover:-
- Other Network Managers.
- Running advanced networking on the Pi (e.g.
DHCP
servers, Tunnelling, VPN, Access Point).- Use of
ipv6
(although if you have anipv6
network this should work).- Alternate networking setups. (There are many different ways of setting up networking.)
相关推荐
# device/softwinner/polaris-common/rild/ip-up:system/etc/ppp/ip-up \ # device/softwinner/polaris-common/rild/3g_dongle.cfg:system/etc/3g_dongle.cfg \ # device/softwinner/polaris-common/rild/usb_mode...
# device/softwinner/polaris-common/rild/ip-up:system/etc/ppp/ip-up \ # device/softwinner/polaris-common/rild/3g_dongle.cfg:system/etc/3g_dongle.cfg \ # device/softwinner/polaris-common/rild/usb_mode...
2011/12/22 09:27 1,493,743 VS5ICM_M05_Networking.pdf 2012/03/05 10:27 4,088,051 VS5ICM_M06_Storage.pdf 2011/12/22 09:28 1,801,139 VS5ICM_M07_VMManagement.pdf 2011/12/22 09:28 908,076 VS5ICM_M08_Data...
#$(eval $(call nf_add,IPT_CORE,CONFIG_IP_NF_TARGET_REJECT, $(P_V4)nf_reject_ipv4)) $(eval $(call nf_add,IPT_CORE,CONFIG_NETFILTER_XT_MATCH_TIME, $(P_XT)xt_time)) $(eval $(call nf_add,IPT...
# device/softwinner/polaris-common/rild/ip-up:system/etc/ppp/ip-up \ # device/softwinner/polaris-common/rild/3g_dongle.cfg:system/etc/3g_dongle.cfg \ # device/softwinner/polaris-common/rild/usb_mode...
This course is intended for those seeking an introduction to IP Networking and how it is used in wireless networks. Learning Objectives After completing this course, the student will be able to: • ...
# device/softwinner/polaris-common/rild/ip-up:system/etc/ppp/ip-up \ # device/softwinner/polaris-common/rild/3g_dongle.cfg:system/etc/3g_dongle.cfg \ # device/softwinner/polaris-common/rild/usb_mode...
/'___ \ /'___ \ /'___ \ / \ \ __ / / \ \ __ / __ __ __ / \ \ __ / \ \,__ \\ \,__ \ / \ \ / \ \ \ \ \,__ \ \ \ \ _ / \ \ \ _ / \ \ \ _ \ \ \ \ \ _ / \ \ _ \ \ \ _ \ \ \ ____ / \ \ _ \ \ / _ / \ / _ ...
### 一次成功的CGI漏洞入侵案例分析 #### CGI漏洞概览 在网络安全领域,网站的安全防护至关重要。然而,即便管理员采取了多种措施进行防御,也难以完全避免出现漏洞。CGI(Common Gateway Interface)作为早期一种...
Linux_IP_Networking
- **DHCP服务器**:动态主机配置协议服务器,自动分配IP地址给网络设备。 - **计费服务器**:处理网络服务费用计算的服务器。 - **安全策略服务器**:实施和管理网络安全策略的服务器。 - **软件服务器**:提供...
Data_and_Computer_Communications_Networking_and_Internetworking
如何安装配置vShield_Manager_5.1_vCloud_Networking_and_Security(图文版)
TCP/IP Core Networking Guide 官方文档 [免费版] TCP/IP Core Networking Guide The TCP/IP Core Networking Guide provides you with in-depth technical information to help you understand, manage, and ...
IBM在线课堂内容,设计容器和kubernetes网络入门知识,非常适合新手
1_James_F_Kurose,_Keith_Ross_Computer_Networking_A_Top_Down_Approach.pdf
Linux Kernel_Networking Implementation and Theory Linux 內核與網絡實現與理論 英文版
redhat网联管理官方中文手册Red_Hat_Enterprise_Linux-7-Networking_Guide-zh-CN.pdf
《Linux TCP/IP Stack Networking for Embedded Systems》是针对嵌入式系统设计的一份深入解析Linux网络协议栈的重要资源。这份资料详细介绍了Linux操作系统中用于处理网络通信的核心组件——TCP/IP协议栈,涵盖了从...