Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 为静态IP配置的Raspberry Pi也会获得DHCP IP_Linux_Networking_Raspberry Pi_Dhcp_Static Ip Address - Fatal编程技术网

Linux 为静态IP配置的Raspberry Pi也会获得DHCP IP

Linux 为静态IP配置的Raspberry Pi也会获得DHCP IP,linux,networking,raspberry-pi,dhcp,static-ip-address,Linux,Networking,Raspberry Pi,Dhcp,Static Ip Address,我已经为静态IP配置了Raspberry Pi。我的/etc/network/interfaces如下所示: auto lo iface lo inet loopback auto eth0 allow-hotplug eth0 iface eth0 inet static address 192.168.1.2 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255 gateway 192.168.1.1 然而,出

我已经为静态IP配置了Raspberry Pi。我的
/etc/network/interfaces
如下所示:

auto lo
iface lo inet loopback

auto eth0
allow-hotplug eth0
iface eth0 inet static
address 192.168.1.2
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1
然而,出于某种奇怪的原因,每次我重新启动我的Pi或路由器时,我的Pi都会得到请求的IP(192.168.1.2)和DHCP地址(192.168.1.18)。所以我的Pi有两个地址

当然,这不一定是个问题,我只是觉得很奇怪。我做错什么了吗?还是不够?我的路由器几乎完全被锁定以进行管理,但我可以为设备输入静态IP——如果我配置Pi,这是必要的吗

动态地址在
ifconfig
中不明显:

eth0      Link encap:Ethernet  HWaddr b8:27:eb:5d:87:71
          inet addr:192.168.1.2  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:236957 errors:0 dropped:34 overruns:0 frame:0
          TX packets:260738 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:35215632 (33.5 MiB)  TX bytes:70023369 (66.7 MiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:27258 errors:0 dropped:0 overruns:0 frame:0
          TX packets:27258 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:3397312 (3.2 MiB)  TX bytes:3397312 (3.2 MiB)

但是我也可以ping、ssh和.18上的所有内容。

连接到接口eth0的IP地址可以通过
IP地址查看。可能是eth0配置了两个IP地址192.168.1.2和192.168.1.18

您还可以通过向接口eth0添加多个IP地址

sudo ip addr add <IP address> dev eth0

由于您可以如上所述将多个IP地址添加到接口
eth0
,因此我认为解决问题的方法是从
/etc/network/interfaces
文件中删除
auto eth0
行。

是的,显然是auto eth0。当时我没看到。很抱歉反应太晚,但我认为迟做总比不做好。。。
sudo ip addr del 192.168.1.18 dev eth0