我有一台运行 ubuntu 的 Linux 服务器。我前段时间设置了这个东西,并设置了一个静态 IP,到目前为止一切都很好。今天,我家突然出现电涌,服务器现在使用了错误的 IP 地址,忽略了 /etc/network/interfaces 文件,我无法重新启动网络。
是否配置
ifconfig
enp3s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.8 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::a250:98ca:d9cc:188 prefixlen 64 scopeid 0x20<link>
ether 30:85:a9:8d:fa:d5 txqueuelen 1000 (Ethernet)
RX packets 815 bytes 731980 (731.9 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 695 bytes 86443 (86.4 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 255 bytes 21586 (21.5 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 255 bytes 21586 (21.5 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
接口文件
cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
auto enp3s0
iface enp3s0 inet dhcp
auto lo enp3s0
iface lo inet loopback
iface enp3s0 inet static
address 192.168.1.7
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 75.75.75.75 75.75.76.76
解析为两个主机名(这对我来说毫无意义)
hostname -I
192.168.1.8 192.168.1.7
网络重启失败
sudo /etc/init.d/networking restart
[....] Restarting networking (via systemctl): networking.serviceJob for networking.service failed because the control process exited with error code.
See "systemctl status networking.service" and "journalctl -xe" for details.
failed!
systemctl status 网络服务
systemctl status networking.service
● networking.service - Raise network interfaces
Loaded: loaded (/lib/systemd/system/networking.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2019-08-09 22:05:47 MDT; 25s ago
Docs: man:interfaces(5)
Process: 2137 ExecStart=/sbin/ifup -a --read-environment (code=exited, status=1/FAILURE)
Main PID: 2137 (code=exited, status=1/FAILURE)
Aug 09 22:05:46 SilverServer dhclient[2160]: DHCPACK of 192.168.1.8 from 192.168.1.1 (xid=0x7b2bf54d)
Aug 09 22:05:46 SilverServer ifup[2137]: DHCPACK of 192.168.1.8 from 192.168.1.1 (xid=0x7b2bf54d)
Aug 09 22:05:46 SilverServer ifup[2137]: RTNETLINK answers: File exists
Aug 09 22:05:47 SilverServer dhclient[2160]: bound to 192.168.1.8 -- renewal in 37852 seconds.
Aug 09 22:05:47 SilverServer ifup[2137]: bound to 192.168.1.8 -- renewal in 37852 seconds.
Aug 09 22:05:47 SilverServer ifup[2137]: RTNETLINK answers: File exists
Aug 09 22:05:47 SilverServer ifup[2137]: ifup: failed to bring up enp3s0
Aug 09 22:05:47 SilverServer systemd[1]: networking.service: Main process exited, code=exited, status=1/FAILURE
Aug 09 22:05:47 SilverServer systemd[1]: networking.service: Failed with result 'exit-code'.
Aug 09 22:05:47 SilverServer systemd[1]: Failed to start Raise network interfaces.
我希望服务器使用 192.168.1.7 启动,但我只能通过 192.168.1.8 使用 putty 连接到它。我已经花了两个小时解决这个问题,但一无所获。请帮忙,我很乐意澄清任何问题,也很乐意尝试任何方法。
谢谢!
答案1
您已将 enp3s0 设置为使用 dhcp 和静态 IP 地址。
将您的更改/etc/network/interfaces
为此...
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
auto enp3s0
iface enp3s0 inet static
address 192.168.1.7
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 75.75.75.75 75.75.76.76