无法在Ubuntu 16.04中正确设置静态IP
我正在尝试在Ubuntu 16.04中的接口上设置静态IP。 它适用于没有DHCP服务器或DNS配置的本地连接。 我试过从Edit Connections GUI和CLI中做到这一点并没有太多运气。
我已经四处搜索并发现了几个类似的问题( 设置静态IP Ubuntu 16.04等),但似乎无法自己获得正确的设置。
这就是我所处的位置……目前有三台设备连接到交换机。 一个配置为1.51,一个配置为1.20,这个16.04系统我试图配置为1.49。 51和20都很好地沟通。 我已经切换了电缆并尝试了不同的端口……所以我知道这不是一个物理问题。 而且,事实上,这个交换机上的其他系统之一是Ubuntu 14.04,其接口设置相同,但IP为51.这里唯一的问题似乎是Ubuntu 16.04系统。
16.04 / etc / network / interfaces文件:
# interfaces(5) file used by ifup(8) and ifdown(8) # The loopback network interface auto lo iface lo inet loopback # Primary network interface auto enp4s0 #iface enp4s0 inet dhcp iface enp4s0 inet static address 192.168.1.49 netmask 255.255.255.0 gateway 192.168.1.1 $ ifconfig enp4s0 Link encap:Ethernet HWaddr f4:8e:38:e7:39:31 inet addr:192.168.1.49 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::f68e:38ff:fee7:3931/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:258 errors:0 dropped:0 overruns:0 frame:0 TX packets:2123 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:28821 (28.8 KB) TX bytes:208448 (208.4 KB)
一切都很好看。 但是ping失败了。 无法ping入或退出。 对我来说最有趣的是从GUI查看界面时的网络掩码。 如果我从右上角的网络图标转到“编辑连接…”并编辑此界面,则会显示以下内容:
Address: 192.168.1.49 Netmask: 24 Gateway: 192.168.1.1
网络掩码为“24”? 这没有任何意义……但是来自CLI的ifconfig看起来很好。
我没有想法。 应该简单……?
谢谢。
编辑1:
Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.1.1 0.0.0.0 UG 100 0 0 enp4s0 169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 enp4s0 192.168.1.0 0.0.0.0 255.255.255.0 U 100 0 0 enp4s0
您尚未声明DNS名称服务器。 我建议你修改为:
# interfaces(5) file used by ifup(8) and ifdown(8) # The loopback network interface auto lo iface lo inet loopback # Primary network interface auto enp4s0 #iface enp4s0 inet dhcp iface enp4s0 inet static address 192.168.1.49 netmask 255.255.255.0 gateway 192.168.1.1 dns-nameservers 8.8.8.8 192.168.1.1
重启界面:
sudo ifdown enp4s0 && sudo ifup enp4s0
平:
ping -c4 www.ubuntu.com
如果你得到ping返回,你就完成了。
您的问题很可能与网络管理员进入您的配置有关。 由于您使用的是静态IP,并且不希望它们自动更改,因此您并不需要网络管理器。
您是否尝试使用sudo service network-manager stop
完全停用它,然后再次尝试连接。
如果您正在寻找手动桥接设置(例如,对于虚拟机):
按照Ubuntu帮助设置网桥的说明进行操作
- 在
/etc/network/interfaces
– 注释掉将要桥接的网络接口。 - 将所有静态设置放在
br0
下(例如iface br0 inet static
然后是地址,网络,网关,名称服务器等) - 清除arp:
ip addr flush enp2s0
(用你的界面替换enp2s0) - 重启网络:
systemctl restart networking
从dhcp到static时,第3步非常重要。 手册中没有提到它,但如果没有它,您的DNS和网关可能无法正常工作……
祝好运!