一般做法:
Don’t use /etc/network/interfaces to set static IP. Use /etc/dhcpcd.conf instead.
Restore your /etc/network/interfaces to the original file, or undo your changes:
sudo nano /etc/network/interfaces
Replace your changes with manual setting in /etc/network/interfaces:
iface eth0 inet manual
Configure dhcpcd:
sudo cp /etc/dhcpcd.conf /etc/dhcpcd.conf.bak
sudo nano /etc/dhcpcd.conf
Add your static profile options to the bottom of /etc/dhcpcd.conf:
interface eth0
static ip_address=192.168.1.100/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1
Reboot:
reboot
Another option is to disable dhcpcd. After you disable dhcpcd, you can use /etc/network/interfaces instead to set static IP.
Configure /etc/network/interfaces:
sudo cp /etc/network/interfaces /etc/network/interfaces.bak
sudo nano /etc/network/interfaces
Replace manual setting with static settings in /etc/network/interfaces:
auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
network 192.168.1.1
broadcast 192.168.1.255
gateway 192.168.1.1
Configure dhcpcd:
sudo cp /etc/dhcpcd.conf /etc/dhcpcd.conf.bak
sudo nano /etc/dhcpcd.conf
Add the option to the bottom of /etc/dhcpcd.conf:
denyinterfaces eth0
Or you can disable the dhcpcd service:
systemctl disable dhcpcd.service
Reboot:
reboot
Source:
Set Static IP address but also getting Dynamic: https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=111709
it is not a bug. Raspian’s own /etc/network/interfaces file even says to use /etc/dhcpcd.conf instead: “For static IP, consult /etc/dhcpcd.conf and ‘man dhcpcd.conf’”. It is Raspian’s recommended way of setting static IP.
可行方法:
I discovered that I can improve boot time by disabling dhcpcd (DHCP client that was doing DHCP Discover on all interfaces). Use this: sudo systemctl disable dhcpcd
FYI: dhcp client will still work on a per-interface basis according to /etc/network/interfaces which may contain an entry such as “iface eth0 inet dhcp”
Then re-set /etc/network/interfaces
auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 202.96.209.5 10.6.160.14 #你的dns服务器地址,dns服务器可以配置两个,第二个是备用的,这里我就配置一个
References:http://elinux.org/Configuring_a_Static_IP_address_on_your_Raspberry_Pi