树莓派3 设置静态ip dhcpcd vs /etc/network/interfaces
2017-07-15 11:05
204 查看
网上查找了下如何设置树莓派静态ip 有两种方案
1 修改/etc/dhcpcd.conf
2修改/etc/network/interfaces
具体有什么不同。我在如下网站发现也有人问,并且也有人给出答案。感觉可以我在此引用
question:
I have this configuration in /etc/network/interfaces:
The wireless static IP worked, but the eth0 didn't.
So I tried to do the config in /etc/dhcpcd.conf:
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
you will also need to make changes to
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 the
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 your
You would want your
Lastly you would want to edit your
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选择修改的是
设置好后 sudo reboot就可以啦。
原文的网址:https://raspberrypi.stackexchange.com/questions/39785/dhcpcd-vs-etc-network-interfaces
1 修改/etc/dhcpcd.conf
2修改/etc/network/interfaces
具体有什么不同。我在如下网站发现也有人问,并且也有人给出答案。感觉可以我在此引用
question:
I have this configuration in /etc/network/interfaces:
auto lo iface lo inet loopback 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 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 dhcp iface 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 eth0 static ip_address=192.168.0.115/24 static routers=192.168.0.1 static 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/interfacesfile 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.confwhich 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 the
interfacesfile and work with
dhcpcd.confand
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 your
interfacesfile 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.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
You would want your
dhcpcd.conffile 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 eth0 static ip_address=192.168.0.115/24 //自己得ip static routers=192.168.0.1 //无线路由ip static domain_name_servers=192.168.0.1 //DNS 设成跟路由ip一样,网关忽略可以不要。 # Custom static IP address for wlan0. interface wlan0 static ip_address=192.168.0.115/24 static routers=192.168.0.1 static domain_name_servers=192.168.0.1
Lastly you would want to edit your
wpa_supplicant.conffile 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=netdev update_config=1 network={ 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
相关文章推荐
- 树莓派的系统安装及分辨率设置
- 在树莓派上设置无线静态IP
- 树莓派Raspbian系统密码设置
- 树莓派最新sudo rasp-config 系统设置 时间 全屏设置
- 树莓派 Raspberry Pi 设置无线上网
- 修改树莓派更新源及设置代理配置
- 树莓派OSMC如何设置成中文
- 树莓派学前班——设置屏幕分辩率
- 【树莓派】【转】将树莓派Raspberry Pi设置为无线路由器(WiFi热点AP,RTL8188CUS芯片)
- 树莓派使用基本设置
- 树莓派入手(1) 设置无线网卡
- 将树莓派Raspberry Pi设置为无线路由器(WiFi热点AP,RTL8188CUS芯片)2
- 二、树莓派系统设置及静态IP
- 树莓派IP地址设置
- 树莓派“先设置IP后开机”
- [RaspberryPi] 树莓派显示设置和root权限获取
- 树莓派IP地址设置
- 【树莓派开发-Linux】linux创建用户、设置密码、修改用户、删除用户
- 树莓派设置中文
- 树莓派3 设置root用户自动登录