![LXC容器无法访问LAN或互联网](https://linux22.com/image/98981/LXC%E5%AE%B9%E5%99%A8%E6%97%A0%E6%B3%95%E8%AE%BF%E9%97%AELAN%E6%88%96%E4%BA%92%E8%81%94%E7%BD%91.png)
我正在尝试使用桥接网络设置 Linux 容器。
这是我设置桥的方法:http://www.ericsbinaryworld.com/2016...he-connection/
这是我安装容器的方法:http://www.ericsbinaryworld.com/2016...etting-up-lxc/
当我lxc-attach -n lemmy
进入容器时,我在容器内无法访问互联网。
我忘记了一个简单的步骤吗?
它在使用 macvtap 的 KVM 虚拟机中运行,并且虚拟机本身能够访问网络。
我为尝试调试问题所做的其他相关信息/事情。
主机操作系统:Fedora 24。虚拟机:CentOS 7 - 名为 Airship 在 Airship 内部,一个容器 - 名为 Lemmy。
第一轮调试:我启动了VM - Airship。以 root 身份登录 Airship。
ping www.google.com
作品。
lxc-start -n lemmy -d
lxc-attach -n lemmy
现在我在容器内。
ping 8.8.8.8
让我明白
connect: Network is unreachable
所以我做了一个ip a,看起来接口没有起来。检查了 systemctl status network.service ,显然它处于失败状态。当我尝试 systemctl start network.service 时,它只是停留在那里,似乎没有完成。
第二轮调试:当我执行 systemctl status network.service 时 - 看起来它在尝试获取 DHCP 地址时停滞不前。所以我编辑了以下文件:
/etc/sysconfig/network-scripts/ifcfg-eth0
具有:
DEVICE=eth0
ONBOOT=yes
IPADDR="192.168.1.36"
PREFIX="24"
GATEWAY="192.168.1.1"
DNS1="192.168.1.7"
DOMAIN="mushroomkingdom"
HOSTNAME=
NM_CONTROLLED=no
TYPE=Ethernet
MTU=
现在它出现了并且有一个IP地址。但我无法联系到本地或互联网上的任何人。
Dmesg 显示:
[ 3932.778454] virbr0: port 2(vethFXTSQ3) entered forwarding state
[ 4089.412588] virbr0: received packet on eth0 with own address as source address
它可以 ping 通自身和主机。
[root@lemmy ~]# ping 192.168.1.36
PING 192.168.1.36 (192.168.1.36) 56(84) bytes of data.
64 bytes from 192.168.1.36: icmp_seq=1 ttl=64 time=0.030 ms
64 bytes from 192.168.1.36: icmp_seq=2 ttl=64 time=0.034 ms
64 bytes from 192.168.1.36: icmp_seq=3 ttl=64 time=0.019 ms
64 bytes from 192.168.1.36: icmp_seq=4 ttl=64 time=0.031 ms
[root@lemmy ~]# ping 192.168.1.35
PING 192.168.1.35 (192.168.1.35) 56(84) bytes of data.
64 bytes from 192.168.1.35: icmp_seq=1 ttl=64 time=0.085 ms
64 bytes from 192.168.1.35: icmp_seq=2 ttl=64 time=0.047 ms
但如果我尝试本地 DNS:
[root@lemmy ~]# ping 192.168.1.7
PING 192.168.1.7 (192.168.1.7) 56(84) bytes of data.
From 192.168.1.36 icmp_seq=1 Destination Host Unreachable
From 192.168.1.36 icmp_seq=2 Destination Host Unreachable
From 192.168.1.36 icmp_seq=3 Destination Host Unreachable
您可能会要求的其他事项:
[root@airship ~]# lxc-info -n lemmy
Name: lemmy
State: RUNNING
PID: 3802
IP: 192.168.1.36
CPU use: 0.18 seconds
BlkIO use: 92.50 KiB
Memory use: 1.11 MiB
KMem use: 0 bytes
Link: vethFXTSQ3
TX bytes: 3.24 KiB
RX bytes: 54.10 KiB
Total bytes: 57.34 KiB
在托管容器的虚拟机上:
[root@airship ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
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: ens4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 52:54:00:3d:99:5c brd ff:ff:ff:ff:ff:ff
inet 192.168.254.214/24 brd 192.168.254.255 scope global dynamic ens4
valid_lft 2308sec preferred_lft 2308sec
inet6 fe80::5054:ff:fe3d:995c/64 scope link
valid_lft forever preferred_lft forever
3: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master virbr0 state UP qlen 1000
link/ether 52:54:00:64:f5:67 brd ff:ff:ff:ff:ff:ff
4: virbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
link/ether 52:54:00:64:f5:67 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.35/24 brd 192.168.1.255 scope global virbr0
valid_lft forever preferred_lft forever
inet6 fe80::5054:ff:fe64:f567/64 scope link
valid_lft forever preferred_lft forever
8: vethFXTSQ3@if7: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master virbr0 state UP qlen 1000
link/ether fe:6f:c5:df:0e:e1 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet6 fe80::fc6f:c5ff:fedf:ee1/64 scope link
valid_lft forever preferred_lft forever
和:
[root@airship ~]# brctl show
bridge name bridge id STP enabled interfaces
virbr0 8000.52540064f567 no eth0
vethFXTSQ3