树莓派3 设置静态ip dhcpcd vs /etc/network/interfaces
来源:互联网 发布:淘宝怎么引流 编辑:程序博客网 时间:2024/05/17 09:02
网上查找了下如何设置树莓派静态ip 有两种方案
1 修改/etc/dhcpcd.conf
2修改/etc/network/interfaces
具体有什么不同。我在如下网站发现也有人问,并且也有人给出答案。感觉可以我在此引用
question:
I have this configuration in /etc/network/interfaces:
auto loiface lo inet loopbackallow-hotplug wlan0iface wlan0 inet manual wpa-conf /etc/wpa_supplicant/wpa_supplicant.confallow-hotplug wlan1iface wlan1 inet manual wpa-conf /etc/wpa_supplicant/wpa_supplicant.confallow-hotplug wlan0#iface wlan0 inet dhcp iface wlan0 inet static address 192.168.0.110 netmask 255.255.255.0 network 192.168.0.1 gateway 192.168.0.1 wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf#iface default inet dhcpiface eth0 inet static address 192.168.0.115 netmask 255.255.255.0 network 192.168.0.1 gateway 192.168.0.1
The wireless static IP worked, but the eth0 didn't.
So I tried to do the config in /etc/dhcpcd.conf:
interface eth0static ip_address=192.168.0.115/24static routers=192.168.0.1static domain_name_servers=192.168.0.1
And it worked. I am confused and here are several questions:
When to use which file?
Why the wifi worked with /etc/network/interfaces but the eth0 didn't?
Does dhcpcd has somehow priority over /etc/network/interface?
How to check which service has priority or someting? And whichservice uses /etc/network/interface?
answer:
There are good points in all the answers to this question, but I think that there is some scope for addressing your specific questions directly.
- When to use which file?
I'm going to make the assumption that you are suffering from a general degree of confusion that is occurring at the moment (in the wider Raspberry Pi community) with the introduction of Debian 'Jessie' in place of Debian 'Wheezy'. This change has made a large number of tutorials at worst obsolete and at best confusing.
The answer to the question is that when using Wheezy it was normal to make changes to the/etc/network/interfaces
file for the purposes of setting up network interfaces (go figure). When using Jessie, it will be necessary to make changes to '/etc/dhcpcd.conf'. However, if making changes to a wireless connection (wlan0
) you will also need to make changes to /etc/wpa_supplicant/wpa_supplicant.conf
which is where you add the network ssid and password.
- Why the wifi worked with /etc/network/interfaces but the eth0 didn't?
I'm not sure how the wifi connection could have worked since there is some information missing from your files (ssid at the least). As janos pointed out, the priority of the etho connection details coming after the wlan0 details probably made them operative (since they would have been seen last by the process reading the file).
- Does dhcpcd has somehow priority over /etc/network/interface?
No, they're different and are designed to suit different purposes under Jessie. For the purposes of using Jessie in a fairly simple way you can pretty much ignore theinterfaces
file and work with dhcpcd.conf
and wpa_supplicant.conf
.
- How to check which service has priority or someting? And which service uses /etc/network/interface?
Again I'm going to make the assumption that the question is more of a 'Which file do I use and if I have to use one which takes priority?' question. The answer is that with the change from Wheezy to Jessie (and in a broader sense with the adoption of systemd) the configuration of `dhcpcd.conf' and 'wpa_supplicant.conf' will be the norm and the 'interfaces' file will be left to it's own devices.
What does this mean for you?
Well (again) making an assumption that you're trying to set up a hard wired (eth0) and wireless (wlan0) connections with static IP addresses, you would want yourinterfaces
file to be the default as it was initially installed;
# 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.dauto loiface lo inet loopbackiface eth0 inet manualallow-hotplug wlan0iface wlan0 inet manual wpa-conf /etc/wpa_supplicant/wpa_supplicant.confallow-hotplug wlan1iface wlan1 inet manual wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
You would want your dhcpcd.conf
file to include the connection details at the end of the file for both interfaces and the additional entries would probably look a bit like this;
# Custom static IP address for eth0.interface eth0static ip_address=192.168.0.115/24 //自己得ipstatic routers=192.168.0.1 //无线路由ipstatic domain_name_servers=192.168.0.1 //DNS 设成跟路由ip一样,网关忽略可以不要。# Custom static IP address for wlan0.interface wlan0static ip_address=192.168.0.115/24static routers=192.168.0.1static domain_name_servers=192.168.0.1
Lastly you would want to edit your wpa_supplicant.conf
file so that it includes the ssid for the wifi network and the password. It should probably look a bit like this;
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdevupdate_config=1network={ ssid="homenetwork" psk="h0mepassw0rd"}
I hope that covers it off. There is the very real possibility that my assumptions are incorrect, but since I recently went through a similar learning curve I'm hoping the data is useful.
回答的作者说啦。这主要是由于版本差异 Debian 'Jessie' in place of Debian 'Wheezy'.
我的是jessie选择修改的是 dhcpcd.conf
这个。其中作者也说了如何设置usb无线的配置文件。
设置好后 sudo reboot就可以啦。
原文的网址:https://raspberrypi.stackexchange.com/questions/39785/dhcpcd-vs-etc-network-interfaces
- 树莓派3 设置静态ip dhcpcd vs /etc/network/interfaces
- 解决修改/etc/network/interfaces不能设置树莓派固定IP
- Ubuntu IP设置 /etc/network/interfaces
- Ubuntu10.04 取消ADSL拨号设置还原/etc/network/interfaces
- 树莓派设置静态无线IP以及去掉启动时的dhcpcd
- Linux下c语言通过修改/etc/network/interfaces修改IP
- linux 下 /etc/network/interfaces 作用
- linux 下 /etc/network/interfaces 作用
- dhcpcd的静态IP配置方法
- Ubuntu 网卡配置文件/etc/network/interfaces重启失效
- Linux 网络接口配置(/etc/network/interfaces)
- ubuntu或linux网卡配置/etc/network/interfaces
- 设置树莓派静态IP
- 树莓派设置静态IP
- 树莓派设置静态IP
- 树莓派设置静态IP
- 树莓派3b+设置静态ip
- 树莓派3b+设置静态ip
- 二维数组和矩阵的区别?
- Unable to instantiate application com.android.tools.fd.runtime.BootstrapApplication
- 包package和访问权限
- 二叉排序
- Windows系统的MBR磁盘分区--MBR的结构和作用(三)之主磁盘分区的结构
- 树莓派3 设置静态ip dhcpcd vs /etc/network/interfaces
- 【我的Android进阶之旅】解决Center OS 64位系统编译Android APP报错error=2和finished with non-zero exit value 127
- java 计算你所得的工资,应缴的税!!!!
- 多个构造器参数时要考虑用构建器
- Java List接口
- 扩展spring schema 的方法, 代码下载
- git
- ActiveMQ(三)--ActiveMQ服务启动
- 远程连接 linux 进行操作