RaspberryPi 静态IP设置重启还原或者设置无效的解决办法

由于网络环境的需要,我的树莓派需要从自动获取ip(DHCP)配置成静态ip( static )。于是在网络搜索了半天,也尝试了各种方法,其主要是修改/etc/network/interfaces 这个文件:

 cd /etc/network

sudo cp interfaces interfaces.old  #备份

sudo vi interfaces

该文件类似如下:

auto lo

iface lo inet loopback

iface eth0 inet dhcp

 

allow-hotplug wlan0

iface wlan0 inet manual

  wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

iface default inet dhcp

其中将iface eth0 inet dhcp更改为

auto eth0        #注意这一句若原先没有的话就一一定要加上,否则配置无效

iface eth0 inet static

address 192.168.1.10  #这里写你的ip地址

netmask 255.255.255.0    #子网掩码

gateway 192.168.1.1   #网关ip

最后删除或注释掉 iface default inet dhcp这一行(如果没有的话就不管了)

 

然后重启树莓派或者重启服务来应用配置:

sudo service networking restart

如果它提示“Warning:Unit file of networking.service changed on disk,'systemctl daemon-reload...'”

之类的,就执行命令:systemctl daemon-reload

然后再重启服务即可。

之后就ping一下某个网站,如果不能解析域名,就要配置dns:

sudo vi /etc/resolv.conf

然后添加:

nameserver 8.8.8.8

或者

nameserver 114.114.114.114

等等。。。最后保存再重启服务或者树莓派即可完成配置。

 

posted @ 2016-06-16 14:02  Leon_Thomas  阅读(3660)  评论(0)    收藏  举报