树莓派使用静态ip启动

一般做法:
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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值