我在 ubuntu 服务器上提供了静态 IP,通过在 /etc/network/interfaces 中添加 IP 配置
内容是
auto lo
iface lo inet loopback
# Static IP to eth0
auto eth0
iface eth0 inet static
address 192.168.20.2
netmask 255.255.255.0
gateway 192.168.20.255
dns-nameservers 202.158.3.7 8.8.8.8
我在 /etc/resolv.conf 中配置 DNS
内容是
# 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 127.0.1.1
nameserver 8.8.8.8
我在 /etc/hosts 中配置
127.0.0.1 localhost
192.168.20.2 user #IP Address for eth0
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouter
当我重新启动配置错误
$ sudo ifdown eth0 && sudo ifup eth0
ifdown: interface eth0 not configured
RTNETLINK: file exists
Failed to bring up eth0
然后我使用命令重新启动配置
$ sudo service networking restart
stop: Job failed while stopping
start: Job is already running: networking
我使用命令再次重新启动
$ sudo service network-manager restart
network-manager: unrecognized service
我不知道为什么,请帮帮我
答案1
首先,您有一个非法网关。您不能拥有具有地址的真实机器*.*.*.255
。我注意到的第二件事是您没有缩进行文。内容/etc/network/interfaces
应为(替换192.168.20.254
为您的真实网关地址):
auto lo
iface lo inet loopback
# Static IP to eth0
auto eth0
iface eth0 inet static
address 192.168.20.2
netmask 255.255.255.0
gateway 192.168.20.254
dns-nameservers 192.168.1.1 8.8.8.8
完成更改后,重新启动系统(这将消除服务无法重新启动的任何问题)。然后您就可以开始了。