当我尝试连接macvlan
到互联网时,没有成功。我使用命名空间来实现这一点。我还查看了这个问题的评论 -如何将 macvlan 连接到互联网?
我有 AWS 的 EC2(Ubuntu 20.04)虚拟机,在其中执行了以下命令:
sudo ip netns add net1;
sudo ip link add macvlan1 link eth0 type macvlan mode bridge;
sudo ip link set macvlan1 netns net1;
sudo ip netns exec net1 ip address add 172.31.20.45 peer 172.31.16.1/32 dev macvlan1;
sudo ip netns exec net1 ip link set macvlan1 up; sudo ip netns exec net1 ip link set lo up;
sudo ip netns exec net1 ip route add default via 172.31.16.1;
sudo ip netns exec net1 su -c "screen";
尝试从命名空间 ping Google 的 DNS 服务器(连接到互联网)
root@aws:/home/meliwex# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
From 172.31.20.45 icmp_seq=1 Destination Host Unreachable
尝试 ping 网关
root@aws:/home/meliwex# ping 172.31.16.1
PING 172.31.16.1 (172.31.16.1) 56(84) bytes of data.
From 172.31.20.45 icmp_seq=1 Destination Host Unreachable
ifconfig
主机中的输出(我保持输出简单):
docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 9001
inet 172.31.20.45 netmask 255.255.240.0 broadcast 172.31.31.255
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
主机的路由表:
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 172.31.16.1 0.0.0.0 UG 100 0 0 eth0
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
172.31.16.0 0.0.0.0 255.255.240.0 U 0 0 0 eth0
172.31.16.1 0.0.0.0 255.255.255.255 UH 100 0 0 eth0
命名空间中的输出ifconfig
(我保持输出简单):
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
macvlan1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 9001
inet 172.31.20.45 netmask 255.255.255.255 broadcast 0.0.0.0
命名空间的路由表:
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 172.31.16.1 0.0.0.0 UG 0 0 0 macvlan1
172.31.16.1 0.0.0.0 255.255.255.255 UH 0 0 0 macvlan1
那么可以解决这个问题吗?