4

I have problem with adding a phyisical ethernet interface to a predefined namespace , adding that to interfaces file in pre-up/post-up event do not work. It adds eth to namespace, but ip address and LOWER_UP state never appear. Removing namespace in down event doesnt work either, making restart of networking service impractical: it flags it as failed if namespace already exist, in result interface never comes to "up" state.

auto lo iface lo inet loopback #description of other interfaces auto eth2 iface eth2 inet static address 196.10.10.200 network 196.10.10.0 gateway 196.10.10.100 netmask 255.255.255.0 pre-up ip netns add mynetns pre-up ip link set eth2 netns mynetns down ip netns delete mynetns 

Purpose ofthis is to keep a daemon software runningwhich works only in one interface present. The host contains multiple interfaces. Daemon can be relaunched and is created in upstart.

0

1 Answer 1

1

Overall OP's attempt will fail: even if the interface is put in the new network namespace, then the address assignment will be attempted in the initial namespace and fail. Only the manual method should be used, and everything configured with pre-up/up/down. Then it's simply juggling around ifupdown.

To avoid de-synchronization between interface state (including namespace existence) and ifupdown state because of previous manual attempts, I added a few || : to prevent failure. Those are not needed once everything is set correctly. As the manual method is still responsible to bring up the interface, a fake interface must still be created in place (but can be deleted later, see at the end of the answer).

I'm using modern syntax shortcut to configure in a namespace. In the past this might not have been available. If needed on a very old system, consider:

ip -n FOO BAR 

to be equivalent to:

ip netns exec FOO ip BAR 

and replace accordingly.

auto eth2 iface eth2 inet manual pre-up ip netns add mynetns || : pre-up ip link set eth2 netns mynetns || : pre-up ip link add eth2 type dummy || : pre-up ip -n mynetns link set eth2 up up ip -n mynetns address add 196.10.10.200/24 brd + up ip -n mynetns route add default via 196.10.10.100 dev eth2 down ip link del eth2 down ip -n mynetns link set eth2 netns 1 # prevents a rogue process to keep the interface "lost" down ip netns delete mynetns 

With this in place (and in this test the real eth2 faked with a macvlan interface hence @if2):

# ifup eth2 # ip -br link show dev eth2 eth2 UNKNOWN 5a:4e:5c:64:98:92 <BROADCAST,NOARP,UP,LOWER_UP> # ip -n mynetns -br link show dev eth2 eth2@if2 UP 12:34:56:78:9a:bc <BROADCAST,MULTICAST,UP,LOWER_UP> # ip -n mynetns -br route default via 196.10.10.100 dev eth2 196.10.10.0/24 dev eth2 proto kernel scope link src 196.10.10.200 # ifdown eth2 # ip -br link show dev eth2 eth2@enp2s0 DOWN 12:34:56:78:9a:bc <BROADCAST,MULTICAST> 

If that's an issue to keep a fake eth2 interface, simply replace:

 down ip link del eth2 

with:

 up ip link del eth2 

That way the dummy interface will be deleted right after its role is over: keep ifupdown happy when it wants to bring the interface up (and then there's no need to delete it later).

7
  • "modern syntax shortcut" might be not available, but actually I have to test. Environment this question was for strictly extension-free (and kernel 3.16 without chance to upgrade and very long life time - 10+ years). Can eth2 be any other name? Main reason why the problem had appeared that there are multiple physical interfaces while software in question designed to work only with one and chooses one at random which breaks its functionality (not configurable at all). Software have to be run automatically on boot on a headless host. There is little chance anyone would mess it manually Commented Jun 16, 2021 at 8:42
  • I picked the interface name in the question. So I used eth2 as you attempted. If you have other needs with other interfaces, this should be added in the question, as well as the goal: make the interface disappear. This could not be guessed, since you even assigned addresses to this interface. So you don't need any address on it? What is the OS? Debian 8? Something else? Please add all this in an update to the question. Commented Jun 16, 2021 at 8:54
  • Please check xyproblem.info to avoid wrong interpretation of the question. Commented Jun 16, 2021 at 9:17
  • OS is unidentifiable propietary but most features are ubuntu 14 except startup configuration, network managers and gui. I misunderstood that you called eth2 a dummy interface Commented Jun 16, 2021 at 9:58
  • Can you edit the initial question? With the OS and the reason you are asking the question ie: to prevent an application to fail. Commented Jun 16, 2021 at 10:04

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.