Score:0

internet in linux netns is unreachable , nexthop is wrong

jp flag

I have successfully setup 2 octoprints in 1 armbian linux on 2 different ports 5000 and 5001 by using netns. I can connect to them as 10.10.10.233:5000 and 10.10.10.233:5001 without any troubles. First of them (5000) is on the main system and has succesfull connection to Internet, second (5001 port) cant connect to internet, it can connect only to host via veth.

All setup is:

sudo ip link add dev virt01 type veth peer name virt02

sudo ip netns add octo2
sudo ip link set virt01 netns octo2
sudo ip netns exec octo2 ip addr add 10.1.1.1/24 dev virt01
sudo ip addr add 10.1.1.2/24 dev virt02
sudo ip netns exec octo2 ip link set dev virt01 up
sudo ip link set dev virt02 up
sudo ip netns exec octo2 ip link set lo up
sudo ip netns exec octo2 ip route add default via 10.1.1.2

#allow forward
sudo ip netns exec octo2 sysctl net.ipv4.ip_forward=1
echo 1 > /proc/sys/net/ipv4/ip_forward

At this point in host have:

netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         10.10.10.1      0.0.0.0         UG        0 0          0 eth0
10.1.1.0        0.0.0.0         255.255.255.0   U         0 0          0 virt02
10.10.10.0      0.0.0.0         255.255.255.0   U         0 0          0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth0

in netns:

sudo ip netns exec octo2 netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         10.1.1.2        0.0.0.0         UG        0 0          0 virt01
10.1.1.0        0.0.0.0         255.255.255.0   U         0 0          0 virt01

So connections from host are GOOD to Internet (via router 10.10.10.1/24) and to netns

orangepi:~$ ping 1.1.1.1
PING 1.1.1.1 (1.1.1.1) 56(84) bytes of data.
64 bytes from 1.1.1.1: icmp_seq=1 ttl=54 time=21.6 ms
64 bytes from 1.1.1.1: icmp_seq=2 ttl=54 time=21.4 ms

orangepi:~$ ping 10.1.1.1
PING 10.1.1.1 (10.1.1.1) 56(84) bytes of data.
64 bytes from 10.1.1.1: icmp_seq=1 ttl=64 time=0.242 ms

But from netns there is only connection to host and NO INTERNET:

orangepi:~$ sudo ip netns exec octo2 ping 10.1.1.2
PING 10.1.1.2 (10.1.1.2) 56(84) bytes of data.
64 bytes from 10.1.1.2: icmp_seq=1 ttl=64 time=0.250 ms

# ERROR HERE , NO INTERNET FROM NETNS:
orangepi:~$ sudo ip netns exec octo2 ping 1.1.1.1
PING 1.1.1.1 (1.1.1.1) 56(84) bytes of data.
^C
--- 1.1.1.1 ping statistics ---
2 packets transmitted, 0 received, 100% packet loss, time 1017ms

orangepi:~$ sudo ip netns exec octo2 traceroute 1.1.1.1
traceroute to 1.1.1.1 (1.1.1.1), 30 hops max, 60 byte packets
 1  _gateway (10.1.1.2)  0.288 ms  0.094 ms  0.079 ms
 2  * * *            
 3  * * *
 4  * * *
 5  * * *
 6  *^C

host's iptables:

orangepi:~$ sudo iptables -S
-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT

orangepi:~$ sudo iptables -S -t nat
-P PREROUTING ACCEPT
-P INPUT ACCEPT
-P OUTPUT ACCEPT
-P POSTROUTING ACCEPT

Also some data:

orangepi:~$ ip r
default via 10.10.10.1 dev eth0 proto dhcp metric 100
10.1.1.0/24 dev virt02 proto kernel scope link src 10.1.1.2
10.10.10.0/24 dev eth0 proto kernel scope link src 10.10.10.234 metric 100
169.254.0.0/16 dev eth0 scope link metric 1000

orangepi:~$ sudo ip netns exec octo2 ip r
default via 10.1.1.2 dev virt01
10.1.1.0/24 dev virt01 proto kernel scope link src 10.1.1.1

ed@orangepizero:~$ cat /proc/sys/net/ipv4/ip_forward
1

ed@orangepizero:~$ sudo ip netns exec octo2 cat /proc/sys/net/ipv4/ip_forward
1

orangepi:~$ sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 1

orangepi:~$ sudo ip netns exec octo2 sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 1

System have no ufw and other firewalls.

How to fix and give netns access to Internet?

Score:0
jp flag

Router, 10.10.10.1 got request from 10.1.1.1 (netns inside orangepi), so it forbids access to WAN as it have not route for it.

Fix: use NAT inside orangepi for 10.1.1.1 to be visible from router as 10.10.10.234 , so it will have access to Internet.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.