Ubuntu 服务器 15.10 中的静态 IP

Ubuntu 服务器 15.10 中的静态 IP

我知道有很多关于设置静态 IP 的此类问题和教程,但我已经尝试了所有方法,但仍然无法获得静态 IP。互联网运行正常(我可以 ping google.com),但我没有获得我想要的 IP,我仍然获得一个随机 IP(通常是 192.168.1.8)

这是我的配置:

auto lo
auto lo intet loopback

auto lo enp2s0
iface lo inet loopback
iface enp0s3 inet static
        address 192.168.0.107
        netmask 255.255.255.0i
        gateway 192.168.1.1
dns-nameservers 200.45.191.35 200.45.48.233 

这是我输入时得到的配置文件

enp2s0    Link encap:Ethernet  HWaddr b8:70:f4:3f:8c:c5  
          inet addr:192.168.1.8  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::ba70:f4ff:fe3f:8cc5/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:380 errors:0 dropped:0 overruns:0 frame:0
          TX packets:363 errors:0 dropped:0 overruns:0 carrier:1
          collisions:0 txqueuelen:1000 
          RX bytes:34659 (34.6 KB)  TX bytes:63438 (63.4 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:65536  Metric:1
          RX packets:354 errors:0 dropped:0 overruns:0 frame:0
          TX packets:354 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:59253 (59.2 KB)  TX bytes:59253 (59.2 KB)

tun0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  
          inet addr:10.8.0.1  P-t-P:10.8.0.2  Mask:255.255.255.255
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

wlp3s0    Link encap:Ethernet  HWaddr 38:59:f9:c5:4d:5b  
          BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

这是路线

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.1.1     0.0.0.0         UG    0      0        0 enp2s0
10.8.0.0        10.8.0.2        255.255.255.0   UG    0      0        0 tun0
10.8.0.2        *               255.255.255.255 UH    0      0        0 tun0
192.168.1.0     *               255.255.255.0   U     0      0        0 enp2s0

这是我的减少/etc/resolv.conf

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 200.45.191.35
nameserver 200.45.48.233
search Home
/etc/resolv.conf (END)

谢谢!

答案1

在某一方面的变化/etc/network/interfaces

auto lo enp2s0
iface lo inet loopback

iface enp2s0 inet static
    address 192.168.1.107
    netmask 255.255.255.0
    gateway 192.168.1.1
    dns-nameservers 200.45.191.35 200.45.48.233 

答案2

除了使用正确的接口名称和更正网络掩码行(如注释中所建议)之外,您的文件还将该address字段列为 192.168.0.107,而不是 192.168.1.107。

您还需要删除以下两行:

auto lo enp2s0
iface lo inet loopback

并将其替换为:

auto enp2s0

所以你的整个/etc/network/interfaces文件应该是这样的:

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto enp2s0
iface enp2s0 inet static
 address 192.168.1.107
 netmask 255.255.255.0
 gateway 192.168.1.1
 dns-nameservers 200.45.191.35 200.45.48.233

您可以使用以下命令重新启动界面,而不必重新启动:

ifdown enp2s0 && enp2s0

相关内容