View previous topic :: View next topic |
Author |
Message |
Chili0_ n00b
Joined: 09 Oct 2017 Posts: 71
|
Posted: Thu Dec 09, 2021 9:24 am Post subject: [Solved]How permanently add a dummy card? |
|
|
Hi,
I add a device with:
Code: |
$ sudo ip link add name loop0 type dummy |
but after reboot, the loop0 device lost, my question is how add the device permanently? I use openrc.
Thanks _________________ Regards.
Last edited by Chili0_ on Fri Dec 10, 2021 1:01 pm; edited 1 time in total |
|
Back to top |
|
|
Chili0_ n00b
Joined: 09 Oct 2017 Posts: 71
|
Posted: Fri Dec 10, 2021 1:01 pm Post subject: |
|
|
A init.d script solve the problem.
Code: |
#!/sbin/openrc-run
SHDIR="/lib/netifrc/sh"
MODULESDIR="/lib/netifrc/net"
[ -z "${IN_BACKGROUND}" ] && IN_BACKGROUND="NO"
# shellcheck disable=SC2034
description="Configures network interfaces."
# Handy var so we don't have to embed new lines everywhere for array splitting
__IFS="
"
# Set the INIT to be openrc if this file is called directly
: "${INIT:=openrc}"
if [ -f "$SHDIR/functions.sh" ]; then
# shellcheck disable=SC1090
. "$SHDIR/functions.sh"
else
echo "$SHDIR/functions.sh missing. Exiting"
exit 1
fi
# Create per-interface nettree ordering, avoids race conditions and allows
# per-interface custom modules.
MODULESLIST="${RC_SVCDIR}/nettree$(get_interface)"
depend()
{
local IFACE IFVAR
IFACE=$(get_interface)
IFVAR=$(shell_var "${IFACE}")
if [ "$RC_UNAME" = Linux ] && [ "$IFACE" != lo ]; then
need sysfs
after modules
fi
after bootmisc
keyword -jail -prefix -vserver
case "${IFACE}" in
lo|lo0) ;;
*)
after net.lo net.lo0 dbus
need localmount
provide net
;;
esac
if [ "$(command -v "depend_${IFVAR}")" = "depend_${IFVAR}" ]; then
"depend_${IFVAR}"
fi
local dep prov
for dep in need use before after provide keyword; do
eval prov=\$rc_${dep}_${IFVAR}
if [ -n "${prov}" ]; then
"${dep}" "${prov}"
ewarn "rc_${dep}_${IFVAR} is deprecated."
ewarn "Please use rc_net_${IFVAR}_${dep} instead."
fi
done
}
start()
{
ip link add lo1 type dummy
ifconfig lo1 127.0.0.2 netmask 255.0.0.0
echo "net.lo1 127.0.0.2 created."
}
stop()
{
ip link del lo2
echo "net.lo1 127.0.0.2 removed."
} |
depend part copied from net.lo, btw net.lo and net.lo0 is the same thing. the dummy name should avoid name lo0. _________________ Regards. |
|
Back to top |
|
|
grknight Retired Dev
Joined: 20 Feb 2015 Posts: 1578
|
Posted: Fri Dec 10, 2021 3:10 pm Post subject: |
|
|
Using the script "start()" as an example:
Just create a symlink with net.lo1 to net.lo and put this in /etc/conf.d/net:
Code: | modules_lo1="dummy"
config_lo1="127.0.0.2/8" |
This avoids your "stop" typo as well |
|
Back to top |
|
|
Chili0_ n00b
Joined: 09 Oct 2017 Posts: 71
|
Posted: Tue Dec 14, 2021 6:10 am Post subject: |
|
|
grknight wrote: | Using the script "start()" as an example:
Just create a symlink with net.lo1 to net.lo and put this in /etc/conf.d/net:
Code: | modules_lo1="dummy"
config_lo1="127.0.0.2/8" |
This avoids your "stop" typo as well |
Thanks, I tried with:
Code: | ln -s /etc/init.d/net.lo /etc/init.d/net.lo2 |
and,
/etc/conf.d/net
Code: | modules_lo2="dummy"
config_lo2="127.0.0.2/8" |
But I got the following error:
Code: | $ sudo /etc/init.d/net.lo2 start
Password:
* Caching service dependencies ... [ ok ]
* Bringing up interface lo2
* ERROR: interface lo2 does not exist
* Ensure that you have loaded the correct kernel module for your hardware
* ERROR: net.lo2 failed to start |
_________________ Regards. |
|
Back to top |
|
|
grknight Retired Dev
Joined: 20 Feb 2015 Posts: 1578
|
Posted: Tue Dec 14, 2021 1:40 pm Post subject: |
|
|
Oops, seems I missed one setting:
Code: | modules_lo2="dummy"
config_lo2="127.0.0.2/8"
type_lo2="dummy"
|
|
|
Back to top |
|
|
szatox Advocate
Joined: 27 Aug 2013 Posts: 3103
|
Posted: Tue Dec 14, 2021 8:38 pm Post subject: |
|
|
Quote: | config_lo2="127.0.0.2/8" |
Man, this is sooo wrong.
At this point you have a conflict there and your routing table is a mess.
This is the same network as the default loopback. Except that it's not, because they are not connected to any device that would bridge them.
Why? Because /8 means your network prefix is 8 bits long. 8 bits only covers the first octet in an IP address. The first octet in both cases is 127.
Why do you want to have another loopback?
Why assign it to the same network?
How are you going to direct traffic to the other interface?
You do know you can just use any IP starting with 127 on that one loopback, don't you? You don't even have to explicitly assign the other IPs to this interface to use them, it operates in a promiscuous mode even if flags don't suggest it. Oh, and if you do actually want to do that, you can assign multiple IP addresses to a single interface too. |
|
Back to top |
|
|
grknight Retired Dev
Joined: 20 Feb 2015 Posts: 1578
|
Posted: Tue Dec 14, 2021 8:50 pm Post subject: |
|
|
szatox wrote: | Quote: | config_lo2="127.0.0.2/8" |
Man, this is sooo wrong.
At this point you have a conflict there and your routing table is a mess.
This is the same network as the default loopback. Except that it's not, because they are not connected to any device that would bridge them.
Why? Because /8 means your network prefix is 8 bits long. 8 bits only covers the first octet in an IP address. The first octet in both cases is 127.
Why do you want to have another loopback?
Why assign it to the same network?
How are you going to direct traffic to the other interface?
You do know you can just use any IP starting with 127 on that one loopback, don't you? You don't even have to explicitly assign the other IPs to this interface to use them, it operates in a promiscuous mode even if flags don't suggest it. Oh, and if you do actually want to do that, you can assign multiple IP addresses to a single interface too. |
I'll agree with everything here. My advice was to solve the OP even if it might be wrong.
Unfortunately, the final point given in this reply is difficult in modern times with OpenRC as it comes with the loopback script hardcoded to 127.0.0.1/8.
Sure one could modify it, as long as you merge in changes all of the time, or else add with a new script/local.d if nothing depended too early. |
|
Back to top |
|
|
Chili0_ n00b
Joined: 09 Oct 2017 Posts: 71
|
Posted: Wed Dec 15, 2021 2:04 am Post subject: |
|
|
Thanks you all, Learned a lot.
The reason I want another dummy net adapter is because of the port conflicts by two different service, and one service depends on the other, for some reason I can not modify the port, also need to create the dummy adapter early. _________________ Regards. |
|
Back to top |
|
|
szatox Advocate
Joined: 27 Aug 2013 Posts: 3103
|
Posted: Wed Dec 15, 2021 5:08 pm Post subject: |
|
|
Can you modify IP address these services bind to? Maybe it would be enough?
You can also assign multiple IP addresses to a single interface - though as mentioned earlier - with lo it should not be necessary. But you can do that, and you can do that in netifrc conf[/glep]ig file. |
|
Back to top |
|
|
grknight Retired Dev
Joined: 20 Feb 2015 Posts: 1578
|
Posted: Wed Dec 15, 2021 5:37 pm Post subject: |
|
|
szatox wrote: | Can you modify IP address these services bind to? Maybe it would be enough?
You can also assign multiple IP addresses to a single interface - though as mentioned earlier - with lo it should not be necessary. But you can do that, and you can do that in netifrc conf[/glep]ig file. |
By default, netifrc no longer controls the lo interface so its config is not used. Recent versions moved away to the loopback script provided by sys-apps/openrc itself.
One could always reverse that choice but must take caution when doing so preferably over a reboot.
Edit: every rebuild of OpenRC will restore the loopback script. So, it would be fun to manage. I cannot say what consequences of having 2 scripts controlling lo interface would be. |
|
Back to top |
|
|
Chili0_ n00b
Joined: 09 Oct 2017 Posts: 71
|
Posted: Thu Dec 23, 2021 5:10 am Post subject: |
|
|
Just learned, in fact , it doesn’t need to create a dummy card for local ports conflicts. Just use any address within 127.0.0.0/8, it is always there. _________________ Regards. |
|
Back to top |
|
|
|