我正在按照有关如何在 Ubuntu 18.04 上设置 KVM 的教程进行操作。
有一句话说:“在开始制作虚拟机之前,您需要设置一个网桥。”
于是我继续操作,但是我需要设置网桥吗?
无论如何。
我按照建议做了。我发现我当前的界面是什么样的:
ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: p1p1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000
link/ether 24:b6:fd:59:e7:ff brd ff:ff:ff:ff:ff:ff
3: wlp9s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 84:4b:f5:1b:0a:0b brd ff:ff:ff:ff:ff:ff
inet 192.168.1.140/24 brd 192.168.1.255 scope global noprefixroute wlp9s0
valid_lft forever preferred_lft forever
inet6 fe80::902b:af87:1a9:a671/64 scope link noprefixroute
valid_lft forever preferred_lft forever
4: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 52:54:00:89:7d:ba brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
5: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc fq_codel master virbr0 state DOWN group default qlen 1000
link/ether 52:54:00:89:7d:ba brd ff:ff:ff:ff:ff:ff
然后我修改 /etc/network/interfaces 文件
修改前的原始文件如下所示:
cat /etc/network/interfaces
auto lo
iface lo inet loopback
经过修改后,我将教程中推荐的内容添加到文件中,如下所示:
cat /etc/network/interfaces
auto lo br0
iface lo inet loopback
iface wlp9s0 inet manual
iface br0 inet dhcp
bridge_ports wlp9s0
修改文件后,我重启了电脑,但仍然没有网络连接。重启后 ip a 命令如下所示:
ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: p1p1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000
link/ether 24:b6:fd:59:e7:ff brd ff:ff:ff:ff:ff:ff
3: wlp9s0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether 84:4b:f5:1b:0a:0b brd ff:ff:ff:ff:ff:ff
4: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1000
link/ether ae:cc:72:45:90:92 brd ff:ff:ff:ff:ff:ff
inet 169.254.8.154/16 brd 169.254.255.255 scope link br0:avahi
valid_lft forever preferred_lft forever
inet6 fe80::accc:72ff:fe45:9092/64 scope link
valid_lft forever preferred_lft forever
5: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 52:54:00:89:7d:ba brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
6: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc fq_codel master virbr0 state DOWN group default qlen 1000
link/ether 52:54:00:89:7d:ba brd ff:ff:ff:ff:ff:ff
这里哪里出了错误?我遗漏了什么吗?
答案1
由于网络配置冲突,您遇到了麻烦。由于 Ubuntu 17.10 默认使用 Netplan。配置保存在“/etc/netplan/*.yaml 文件”中。
根据您使用的 Ubuntu 版本(服务器或桌面),配置默认由网络渲染器 networkd 或 NetworkManager 处理。
NetworkManager(Ubuntu 桌面)配置文件位于“/etc/NetworkManager/”。networkd(Ubuntu 服务器)配置文件位于“/etc/systemd/network/”。
您应该将“/etc/network/interfaces”文件恢复为默认值,并使用 Netplan(服务器)或 NetworkManger(桌面)创建桥接连接。在进行任何更改之前,请务必备份所有文件,以便您可以轻松地恢复到原始工作配置。
以下是一些文档和答案的链接,希望能对您有所帮助。
如何在 Linux 上使用 nmcli(NetworkManager)添加网桥
Netplan Bridged 示例
#01-network-manager-all.yaml
network:
version: 2
renderer: networkd
ethernets:
enp3s0:
dhcp4: no
bridges:
br0:
dhcp4: yes
interfaces:
- enp3s0
网络管理器
$ nmcli con show
$ nmcli connection show --active
$ sudo nmcli con add ifname br0 type bridge con-name br0
$ sudo nmcli con add type bridge-slave ifname eno1 master br0
$ nmcli connection show
$ sudo nmcli con down "Wired connection 1"
$ sudo nmcli con up br0
$ nmcli con show