I have a number of interfaces available on Ubuntu 20.04 machine. Among others enx0c5b8f279a64
and usb0
with the later being used as the default one. I want to make sure that a particular process started in terminal will use only one of these interfaces (say enx0c5b8f279a64
even if the other interface is default). If this process is started and the selected enx0c5b8f279a64
inteface is down, it should not to even try to use any other interface as a fallback (as if other interfaces would not even exist from the perspective of this process).
I think that ip netns
is the way to go, but I have trouble implementing any working solution. I have tried https://superuser.com/a/750412 however I am getting Destination Host Unreachable
if I try to ping 8.8.8.8
:(
Relevant part of the ip a s
oputput:
9: enx0c5b8f279a64: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 12:12:12:12:12:12 brd ff:ff:ff:ff:ff:ff
inet 192.168.7.100/24 brd 192.168.7.255 scope global dynamic noprefixroute enx0c5b8f279a64
valid_lft 84611sec preferred_lft 84611sec
inet6 2323::2323:2323:2323:2323/64 scope link noprefixroute
valid_lft forever preferred_lft forever
10: usb0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
link/ether 34:34:34:34:34:34 brd ff:ff:ff:ff:ff:ff
inet 192.168.42.**47**/24 brd 192.168.42.255 scope global dynamic noprefixroute usb0
valid_lft 1858sec preferred_lft 1858sec
inet6 4545:454:545:4545:454:5454:5454:5454/64 scope global temporary deprecated dynamic
valid_lft 2461sec preferred_lft 0sec
inet6 5656:565:656:5656:5656:5656:5656:5656/64 scope global deprecated dynamic mngtmpaddr noprefixroute
valid_lft 2461sec preferred_lft 0sec
inet6 6767::6767:6767:6767:6767/64 scope link noprefixroute
valid_lft forever preferred_lft forever
and the route table:
route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.7.1 0.0.0.0 UG 100 0 0 enx0c5b8f279a64
0.0.0.0 192.168.42.129 0.0.0.0 UG 101 0 0 usb0
192.168.7.0 0.0.0.0 255.255.255.0 U 100 0 0 enx0c5b8f279a64
192.168.42.0 0.0.0.0 255.255.255.0 U 101 0 0 usb0
So far all the solutions that I have tried started in a similar way:
# create namespace
sudo ip netns add nspace0
# create link
sudo ip link add veth0 type veth peer name veth1
# move link
sudo ip link set veth1 netns nspace0
# DO SOME MAGIC
# (none of the solutions that I have tried to adapt here worked for me so far).
...
# run process in namespace (here I use curl as an example)
sudo ip netns exec nspace0 curl ifconfig.me/ip
But the problem is the MAGIC
part. I have seen a number of approaches with bridges and other ip-forwarding solutions. Unfortunately none of these worked for me so far and I am not that versed in networking to be able to diagnose and fix.