我正在尝试让与enp3s0
我的以太网接口位于同一网络上的其他计算机可以访问虚拟机。
我的想法是为它创建一座桥梁,所以我的/etc/network/interfaces
看起来像这样:
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto enp3s0
iface enp3s0 inet static
address 192.168.1.111
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.254
dns-nameservers 192.168.1.254 8.8.8.8
auto brx
iface brx inet static
address 192.168.1.1
network 192.168.1.0
netmask 255.255.255.0
broadcast 192.168.1.255
bridge_ports enp3s0
一旦我保存该文件并使用以下命令重新加载网络服务,我就无法访问主机了:service networking restart
。
我可以使用 ssh 访问主机,但调试起来很麻烦。
结果如下ipt addr
:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
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: enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether d8:cb:8a:7e:b0:0e brd ff:ff:ff:ff:ff:ff
inet 192.168.1.111/24 brd 192.168.1.255 scope global enp3s0
valid_lft forever preferred_lft forever
inet6 fe80::dacb:8aff:fe7e:b00e/64 scope link
valid_lft forever preferred_lft forever
3: bond0: <BROADCAST,MULTICAST,MASTER> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether de:d1:a5:18:d7:9e brd ff:ff:ff:ff:ff:ff
4: wlp4s0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether 60:57:18:ed:85:91 brd ff:ff:ff:ff:ff:ff
5: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 52:54:00:f1:90:4d 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 pfifo_fast master virbr0 state DOWN group default qlen 1000
link/ether 52:54:00:f1:90:4d brd ff:ff:ff:ff:ff:ff
7: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:ca:92:29:7b brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 scope global docker0
valid_lft forever preferred_lft forever
inet6 fe80::42:caff:fe92:297b/64 scope link
valid_lft forever preferred_lft forever
8: br-55921dfae2b9: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:d2:f2:fd:9c brd ff:ff:ff:ff:ff:ff
inet 172.27.0.1/16 scope global br-55921dfae2b9
valid_lft forever preferred_lft forever
inet6 fe80::42:d2ff:fef2:fd9c/64 scope link
valid_lft forever preferred_lft forever
9: br-6126f091366d: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:fd:89:f7:3e brd ff:ff:ff:ff:ff:ff
inet 172.21.0.1/16 scope global br-6126f091366d
valid_lft forever preferred_lft forever
inet6 fe80::42:fdff:fe89:f73e/64 scope link
valid_lft forever preferred_lft forever
10: br-79007a99672c: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether 02:42:f2:63:b4:a8 brd ff:ff:ff:ff:ff:ff
inet 172.22.0.1/16 scope global br-79007a99672c
valid_lft forever preferred_lft forever
11: br-90998da5c46b: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:40:01:23:c5 brd ff:ff:ff:ff:ff:ff
inet 172.26.0.1/16 scope global br-90998da5c46b
valid_lft forever preferred_lft forever
inet6 fe80::42:40ff:fe01:23c5/64 scope link
valid_lft forever preferred_lft forever
12: br-d2baef82036f: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether 02:42:d3:e8:9a:4d brd ff:ff:ff:ff:ff:ff
inet 172.20.0.1/16 scope global br-d2baef82036f
valid_lft forever preferred_lft forever
13: br-af8f996c43db: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether 02:42:9f:b0:55:3d brd ff:ff:ff:ff:ff:ff
inet 172.19.0.1/16 scope global br-af8f996c43db
valid_lft forever preferred_lft forever
14: br-ca2d4fcf9238: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:90:b8:b5:b0 brd ff:ff:ff:ff:ff:ff
inet 172.18.0.1/16 scope global br-ca2d4fcf9238
valid_lft forever preferred_lft forever
inet6 fe80::42:90ff:feb8:b5b0/64 scope link
valid_lft forever preferred_lft forever
15: br-e7fe7e040ae1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether 02:42:48:58:a9:65 brd ff:ff:ff:ff:ff:ff
inet 172.30.0.1/16 scope global br-e7fe7e040ae1
valid_lft forever preferred_lft forever
17: vethbda138d@if16: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default
link/ether ea:b7:62:85:c5:37 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet6 fe80::e8b7:62ff:fe85:c537/64 scope link
valid_lft forever preferred_lft forever
19: veth4b4c337@if18: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-6126f091366d state UP group default
link/ether f2:7a:3d:06:a2:cf brd ff:ff:ff:ff:ff:ff link-netnsid 2
inet6 fe80::f07a:3dff:fe06:a2cf/64 scope link
valid_lft forever preferred_lft forever
21: vethd3629c0@if20: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-6126f091366d state UP group default
link/ether 7e:b6:9d:57:ff:cc brd ff:ff:ff:ff:ff:ff link-netnsid 6
inet6 fe80::7cb6:9dff:fe57:ffcc/64 scope link
valid_lft forever preferred_lft forever
23: veth8c752ba@if22: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-90998da5c46b state UP group default
link/ether 4e:28:c4:34:84:6a brd ff:ff:ff:ff:ff:ff link-netnsid 5
inet6 fe80::4c28:c4ff:fe34:846a/64 scope link
valid_lft forever preferred_lft forever
27: vethe4c8f38@if26: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-ca2d4fcf9238 state UP group default
link/ether f6:1f:d4:3c:5a:89 brd ff:ff:ff:ff:ff:ff link-netnsid 1
inet6 fe80::f41f:d4ff:fe3c:5a89/64 scope link
valid_lft forever preferred_lft forever
29: veth1e8562f@if28: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-ca2d4fcf9238 state UP group default
link/ether ca:a9:2f:24:50:54 brd ff:ff:ff:ff:ff:ff link-netnsid 3
inet6 fe80::c8a9:2fff:fe24:5054/64 scope link
valid_lft forever preferred_lft forever
33: veth243205b@if32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-55921dfae2b9 state UP group default
link/ether 52:55:7f:6e:71:ed brd ff:ff:ff:ff:ff:ff link-netnsid 7
inet6 fe80::5055:7fff:fe6e:71ed/64 scope link
valid_lft forever preferred_lft forever
41: vethabea4e4@if40: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default
link/ether 46:1a:a7:f4:85:40 brd ff:ff:ff:ff:ff:ff link-netnsid 9
inet6 fe80::441a:a7ff:fef4:8540/64 scope link
valid_lft forever preferred_lft forever
47: veth9e911aa@if46: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-55921dfae2b9 state UP group default
link/ether 16:c5:5a:58:21:2d brd ff:ff:ff:ff:ff:ff link-netnsid 10
inet6 fe80::14c5:5aff:fe58:212d/64 scope link
valid_lft forever preferred_lft forever
答案1
您需要将所有物理设备配置移至网桥,并将物理设备设置为“手动”。网桥设备将取代物理设备成为您使用的网络设备。
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto enp3s0
iface enp3s0 inet manual
auto brx
iface brx inet static
address 192.168.1.111
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.254
dns-nameservers 192.168.1.254 8.8.8.8
bridge_ports enp3s0
我不知道您使用哪种虚拟机,但这是我在 LXD 中为容器使用的设置。