我有几个 Ubuntu 服务器(18.04.3)。它们连接到互联网和私有本地网络。但重新启动服务器后,它们无法连接到互联网。我必须通过本地网络连接服务器并重新启动服务networking
才能连接它们。
猫/等/网络/接口:
auto lo
iface lo inet loopback
#internet
auto eth0
iface eth0 inet dhcp
#local network
auto eth1
iface eth1 inet dhcp
sudo systemctl status networking.service(重启后):
● networking.service - Raise network interfaces
Loaded: loaded (/lib/systemd/system/networking.service; enabled; vendor preset: enabled)
Active: active (exited) since Mon 2019-09-23 12:19:57 UTC; 22min ago
Docs: man:interfaces(5)
Process: 829 ExecStart=/sbin/ifup -a --read-environment (code=exited, status=0/SUCCESS)
Process: 802 ExecStartPre=/bin/sh -c [ "$CONFIGURE_INTERFACES" != "no" ] && [ -n "$(ifquery --read-environment --list --exclude=lo)" ] && udevadm settle (code=exited, status=0/SUCCESS)
Main PID: 829 (code=exited, status=0/SUCCESS)
Sep 23 12:19:52 systemd[1]: Starting Raise network interfaces...
Sep 23 12:19:52 ifup[829]: /sbin/ifup: waiting for lock on /run/network/ifstate.eth0
Sep 23 12:19:57 ifup[829]: /sbin/ifup: waiting for lock on /run/network/ifstate.eth1
Sep 23 12:19:57systemd[1]: Started Raise network interfaces.
sudo systemctl status networking.service(重新启动网络服务后):
● networking.service - Raise network interfaces
Loaded: loaded (/lib/systemd/system/networking.service; enabled; vendor preset: enabled)
Active: active (exited) since Mon 2019-09-23 12:43:52 UTC; 1s ago
Docs: man:interfaces(5)
Process: 4151 ExecStop=/sbin/ifdown -a --read-environment --exclude=lo (code=exited, status=0/SUCCESS)
Process: 4286 ExecStart=/sbin/ifup -a --read-environment (code=exited, status=0/SUCCESS)
Process: 4272 ExecStartPre=/bin/sh -c [ "$CONFIGURE_INTERFACES" != "no" ] && [ -n "$(ifquery --read-environment --list --exclude=lo)" ] && udevadm settle (code=exited, status=0/SUCCESS)
Main PID: 4286 (code=exited, status=0/SUCCESS)
Tasks: 2 (limit: 4702)
CGroup: /system.slice/networking.service
├─4355 /sbin/dhclient -1 -4 -v -pf /run/dhclient.eth0.pid -lf /var/lib/dhcp/dhclient.eth0.leases -I -df /var/lib/dhcp/dhclient6.eth0.leases eth0
└─4451 /sbin/dhclient -1 -4 -v -pf /run/dhclient.eth1.pid -lf /var/lib/dhcp/dhclient.eth1.leases -I -df /var/lib/dhcp/dhclient6.eth1.leases eth1
Sep 23 12:43:52 ifup[4286]: DHCPREQUEST of 192.168.0.3 on eth1 to 255.255.255.255 port 67 (xid=0x28c16f37)
Sep 23 12:43:52 ifup[4286]: DHCPOFFER of 192.168.0.3 from 192.168.0.2
Sep 23 12:43:52 ifup[4286]: DHCPACK of 192.168.0.3 from 192.168.0.2
Sep 23 12:43:52 dhclient[4409]: DHCPDISCOVER on eth1 to 255.255.255.255 port 67 interval 3 (xid=0x376fc128)
Sep 23 12:43:52 dhclient[4409]: DHCPREQUEST of 192.168.0.3 on eth1 to 255.255.255.255 port 67 (xid=0x28c16f37)
Sep 23 12:43:52 dhclient[4409]: DHCPOFFER of 192.168.0.3 from 192.168.0.2
Sep 23 12:43:52 dhclient[4409]: DHCPACK of 192.168.0.3 from 192.168.0.2
Sep 23 12:43:52 dhclient[4409]: bound to 192.168.0.3 -- renewal in 2147483648 seconds.
Sep 23 12:43:52 ifup[4286]: bound to 192.168.0.3 -- renewal in 2147483648 seconds.
Sep 23 12:43:52 systemd[1]: Started Raise network interfaces.
有人能解释为什么会发生这种情况以及如何解决这个问题吗?
答案1
我认为您应该使用 Netplan 来配置您的网络接口。
在此链接中您可以找到简单的示例第一个是带有 DHCP 客户端的接口。
netplan.io。
您可以先检查位于此处的文件:
ls /etc/netplan/
编辑您找到的那个,使其看起来像这样(缩进非常重要):
network: version: 2 renderer: networkd ethernets: enp3s0: dhcp4: true
然后:
sudo netplan 尝试
这将检查您的编辑是否正确,并通知您任何错误。然后
sudo netplan 申请