为什么当我设置静态 IP(服务器 12.10)时 eth0 消失了?

noo*_*kes 9 server 12.10 static-ip

出于某种原因,如果我尝试设置静态 IP 地址,我的 eth0 将从ifconfig的输出中消失。我在网关笔记本电脑上运行 Ubuntu 服务器 12.10。

auto eth0
iface eth0 inet dhcp
Run Code Online (Sandbox Code Playgroud)

然后在我运行时给出这个输出ifconfig

eth0      Link encap:Ethernet  HWaddr xx:xx:xx:xx:xx:xx  
          inet addr:192.168.1.101  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::2e0:b8ff:fee7:f71c/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:281 errors:0 dropped:0 overruns:0 frame:0
          TX packets:352 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:31874 (31.8 KB)  TX bytes:45369 (45.3 KB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:430 errors:0 dropped:0 overruns:0 frame:0
          TX packets:430 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:41740 (41.7 KB)  TX bytes:41740 (41.7 KB)
Run Code Online (Sandbox Code Playgroud)

当我更改为静态时:

auto eth0
iface eth0 inet static
       address 192.168.1.37
       netmask 225.225.225.0
       gateway 192.168.1.1
Run Code Online (Sandbox Code Playgroud)

...然后运行 ​​a service networking restart,我只从ifconfig以下位置获取环回块:

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:430 errors:0 dropped:0 overruns:0 frame:0
          TX packets:430 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:41740 (41.7 KB)  TX bytes:41740 (41.7 KB)
Run Code Online (Sandbox Code Playgroud)

但是,我可以强制使用静态 IP,ifconfig eth0 192.168.1.37 netmask 255.255.255.0但显然这会在重新启动时消失。

为什么一种方法行得通,而另一种不行?难道我做错了什么?

noo*_*kes 10

这是一个错字。我应该有 255.255.255.0 作为我的网络掩码,而是输入 225.225.225.0

感谢 qbi 帮助我看到了我的方式错误

  • 很容易看到这些数字,并认为它们是合理的。 (2认同)
  • 这是一个非常常见的错误,很难发现。我们的眼睛看到的是我们期望看到的。 (2认同)

jdt*_*ood -2

不要做service networking restart; 它已被弃用。

相反,ifdown eth0然后ifup eth0或简单地重新启动。

  • 这些并不能解决我的问题。我也不知道服务重置已被弃用;我之前使用过“/etc/init.d/networking restart”,而我的系统告诉我使用“servicenetworking restart” (2认同)