I want to connect macvlan
to the internet, but i can't.
I added macvlan to the network namespace, what to do next?
I am using VPS server (Cloud VPS), OS Debian 10
My default gateway, outside the network namespace: 192.0.2.1
netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 192.0.2.1 0.0.0.0 UG 0 0 0 eth0
10.5.0.0 0.0.0.0 255.255.255.224 U 0 0 0 tun0
10.168.179.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
187.215.130.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
I tried to add a namespace, and attach macvlan to it:
ip netns add net1;\
ip link add macvlan1 link eth0 type macvlan mode bridge;\
ip link set macvlan1 netns net1;\
ip netns exec net1 ip addr add 187.215.130.107 dev macvlan1;\
ip netns exec net1 ip link set macvlan1 up; ip netns exec net1 ip link set lo up;\
ip netns exec net1 su -c "screen"
187.215.130.107
- the second public IP address of the server.
I tried to add a default gateway, inside the net1
namespace, but got the error:
ip route add default via 192.0.2.1
Error: Nexthop has invalid gateway.
route add default gw 192.0.2.1 dev macvlan1
SIOCADDRT: Network is unreachable
Route table is empty:
netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
curl http://ipecho.net/plain
curl: (6) Could not resolve host: ipecho.net
ping 192.0.2.1
connect: Network is unreachable
ping 192.168.0.1
connect: Network is unreachable
ping 10.5.0.1
connect: Network is unreachable
ping 187.215.130.0
connect: Network is unreachable
ping 10.168.179.0
connect: Network is unreachable
Inside the net1
namespace: 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
40: macvlan1@if2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 32:5d:65:12:b1:fe brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 187.215.130.107/32 scope global macvlan1
valid_lft forever preferred_lft forever
inet6 fe80::305d:65ff:fe12:b1fe/64 scope link
valid_lft forever preferred_lft forever
Outside the network namespace: 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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 52:54:ec:a6:68:1c brd ff:ff:ff:ff:ff:ff
inet 187.151.116.253/32 brd 187.151.116.253 scope global eth0
valid_lft forever preferred_lft forever
inet 187.215.130.107/24 brd 187.215.130.255 scope global eth0:1
valid_lft forever preferred_lft forever
inet6 fe80::5054:ecff:fea6:681c/64 scope link
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 52:54:00:09:08:9c brd ff:ff:ff:ff:ff:ff
inet 10.168.179.38/24 brd 10.168.179.255 scope global eth1
valid_lft forever preferred_lft forever
inet6 fe80::5054:ff:fe09:89c/64 scope link
valid_lft forever preferred_lft forever
10: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 100
link/none
inet 10.5.0.1/27 brd 10.5.0.31 scope global tun0
valid_lft forever preferred_lft forever
inet6 fe80::4235:badc:190b:2d1d/64 scope link stable-privacy
valid_lft forever preferred_lft forever
It looks like there is no bridge, between macvlan1 and eth0.
There was a bridge, until i moved macvlan1
to the net1
namespace.
What should I do now, to connect macvlan1
to eth0
?