现在,我尝试在 VM VirtualBox 上的 ubuntu-server(18.04) 中使用 netplan 设置静态 IP。我可以在本地桌面上使用 putty 访问 ubuntu-server(在 VM 中),但 ubuntu-server 无法访问互联网。
这是我的网络设置和 netplan 设置。
VirtualBox 网络设置
ubuntu-server 网络设置
适配器 1:NAT
适配器2:仅主机适配器
# /etc/netplan
# before
$ ls -al
drwxr-xr-x 2 root root 4096 Dec 24 16:20 .
drwxr-xr-x 94 root root 4096 Dec 24 12:46 ..
-rw-r--r-- 1 root root 529 Dec 24 16:20 50-cloud-init.yaml
# /etc/netplan/50-cloud-init.yaml
network:
ethernets:
enp0s3:
dhcp4: true
version: 2
# /etc/netplan
# after
$ ls -al
drwxr-xr-x 2 root root 4096 Dec 24 16:53 .
drwxr-xr-x 94 root root 4096 Dec 24 12:46 ..
-rw-r--r-- 1 root root 529 Dec 24 16:20 01-netcig.yaml
-rw-r--r-- 1 root root 383 Dec 24 16:53 50-cloud-init.yaml
# /etc/netplan/50-cloud-init.yaml
network:
ethernets:
enp0s3:
dhcp4: true
version: 2
# /etc/netplan/01-netcig.yaml
network:
ethernets:
enp0s8:
addresses: [192.168.56.102/24]
gateway4: 192.168.56.1
dhcp4: no
nameservers:
addresses: [8.8.8.8,8.8.4.4]
version: 2
$ ifconfig
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.2.15 netmask 255.255.255.0 broadcast 10.0.2.255
inet6 fe80::a00:27ff:fe4e:ace4 prefixlen 64 scopeid 0x20<link>
ether 08:00:27:4e:ac:e4 txqueuelen 1000 (Ethernet)
RX packets 2 bytes 1180 (1.1 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 10 bytes 1328 (1.3 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.56.102 netmask 255.255.255.0 broadcast 192.168.56.255
inet6 fe80::a00:27ff:fe9d:f985 prefixlen 64 scopeid 0x20<link>
ether 08:00:27:9d:f9:85 txqueuelen 1000 (Ethernet)
RX packets 105 bytes 10500 (10.5 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 69 bytes 10361 (10.3 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 80 bytes 5920 (5.9 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 80 bytes 5920 (5.9 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
我可以在本地桌面上使用 putty 访问 ubuntu-server,但我的 ubuntu-server 无法访问互联网。我无法发送 ping www.google.com,也无法命令“apt-get update”。
请帮我。
问题是什么....