I am attempting to create a network interface using “ip link add”. Specifically a veth interface; however, this problem occurs no matter the interface type.
Ex: sudo VAR=somename ip link add $VAR type dummy
results in an interface named “dummy1” instead of “somename”. This is the same behaviour as if there was no name specified to begin with.
Ex: sudo VAR=somename ip link add name $VAR type dummy
results in the error ‘both “name” and “dev” cannot be used when creating devices.’ which makes sense if the $VAR is either being completely ignored or is being treated as an empty string.
Ex: sudo VAR=somename ip link add also_$VAR type dummy
results in an interface named “also_”. Which is consistent with the other two examples, but still doesn’t really help me figure out why I can’t get “ip link add” to recognize an environment variable.
Encapsulating the $VAR in curly braces such as ${VAR} doesn’t help. Setting up my variable as a global variable doesn’t help. Executing this from a script file rather than the command line doesn’t change anything. I cannot for the life of me find anything like this problem on the internet. The MAN pages for ip and ip-link don’t appear to make any reference to variables or the $, let alone mention any problems with them. I can’t find any restrictions to ifnames that would suggest I cannot use variables with them.
Is it possible to use a bash environment variable as part of (or the entirety of) the name of a network interface being set up via the “ip link add” command?
Thank you.
David Schumacher is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.