I have been trying to follow multiple guides to setup a veth-pair for 2 namespaces which can communicate with each other on alpine linux. So far I have communication between namespaces working but neither namespace can connect/ping to any external ip/url.
Here is the guides configuration that i use exactly:
ip netns add namespace1
ip netns add namespace2
ip netns exec namespace1 ip address show
ip link add veth1 type veth peer name br-veth1
ip link add veth2 type veth peer name br-veth2
ip link set veth1 netns namespace1
ip link set veth2 netns namespace2
ip netns exec namespace1 ip address show
ip netns exec namespace1 ip addr add 192.168.1.11/24 dev veth1
ip netns exec namespace1 ip address show
ip netns exec namespace2 ip addr add 192.168.1.12/24 dev veth2
# Create the bridge device naming it `br1`
# and set it up:
ip link add name br1 type bridge
ip link set br1 up
ip link | grep br1
# Set the bridge veths from the default
# namespace up.
ip link set br-veth1 up
ip link set br-veth2 up
ip netns exec namespace1 ip link set veth1 up
ip netns exec namespace2 ip link set veth2 up
# Add the br-veth* interfaces to the bridge
# by setting the bridge device as their master.
ip link set br-veth1 master br1
ip link set br-veth2 master br1
bridge link show br1
ip addr add 192.168.1.10/24 brd + dev br1
ip -all netns exec ip route add default via 192.168.1.10
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -j MASQUERADE
I have also verified that /etc/sysctl.conf contains
net.ipv4.ip_forward = 1
and i have run this command also just in-case
sysctl -w net.ipv4.ip_forward=1
my resolv.conf contains :
nameserver 8.8.8.8
when i run
ip netns exec namespace1 ip route
I get the results:
192.168.1.0/24 dev veth1 proto kernel scope link src 192.168.1.11
If i run a regular ip route list i get:
192.168.56.0 eth0 proto kernel scope link src 192.168.56.217
192.168.1.0/24 dev br1 proto kernel scope link src 192.168.1.10
I have no idea why the setup above wont work as most guides seems to suggest that the host and namespaces should be capable of communicating after performing the MASQUERADE and setting the default route of the namespaces however networking isnt my core field of study so any suggestions would be extremely useful. If there is any information missing please feel free to drop a comment and I will try to provide it in-case I have missed something.