在 linux 中分配静态 ip

Assigning static ip in linux

我试过为我的树莓派电脑分配静态IP,但重启后没有分配。我的 /etc/networ/interfaces 文件如下所示:

auto lo

iface lo inet loopback
iface eth0 inet static
address 192.168.1.2
netmask 255.255.255.0
gateway 192.168.1.1
#iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

重新启动并使用 ifconfig 命令后,显示地址不同。我应该怎么做才能让它从文件中分配数据?

它是 /etc/network/interfaces 而不是 /etc/networ/interfaces 而且您忘记添加:

 auto eth0
 iface eth0 inet static

你应该做的:

 /etc/init.d/networking restart

 ifdown eth0 
 ifup eth0

不要重新启动,还要确保 192.168.1.2 尚未使用。

尝试改变

auto lo

auto lo eth0

因为这将使 ifup -a 运行 在系统启动期间也配置 eth0。 (参见 man interfaces)。