View previous topic :: View next topic |
Author |
Message |
toralf Developer
Joined: 01 Feb 2004 Posts: 3919 Location: Hamburg
|
Posted: Fri Apr 17, 2015 12:23 pm Post subject: macchanger + WLAN + dhcpcd + openrc timing problems |
|
|
The config see below won't work always during boot. Sometimes I do get Code: | [ERROR] Could not change MAC: interface up or insufficient permissions: Device or resource busy
* ERROR: cannot start cupsd as net.wlp3s0 would not start
* ERROR: cannot start dnsmasq as net.wlp3s0 would not start
* ERROR: cannot start ntp-client as net.wlp3s0 would not start
| during boot. In such a case sometimes even a "sudo /etc/init.d/net.wlp3s0 restart" won't help, so I have to reboot the (hardened) stable Gentoo. Now I do wonder, if I could run "macchanger" much more earlier in the udev - init phase ? Which udev init script I should use there to have the MAC address change already done before openrc starts the network init scripts ? Code: | # /etc/conf.d/net
#
# KVM
#
bridge_br0="tap0"
config_br0="192.168.1.254/16"
brctl_br0="setfd 0
sethello 10
stp off"
rc_net_br0_need="net.tap0"
config_tap0="null"
tuntap_tap0="tap"
tunctl_tap0="-u tfoerste"
# LAN
#
config_enp0s25="null"
# don't play well with macchanger
#
#config_wlp3s0="dhcp"
preup(){
if [[ "$IFACE" = "wlp3s0" ]]; then
macchanger -r $IFACE
:
fi
}
postup(){
if [[ "$IFACE" = "br0" ]]; then
sysctl -w net.ipv4.conf.br0.forwarding=1
fi
}
predown(){
if [[ "$IFACE" = "br0" ]]; then
sysctl -w net.ipv4.conf.br0.forwarding=0
fi
}
postdown(){
if [[ "$IFACE" = "wlp3s0" ]]; then
macchanger -p $IFACE
:
fi
} | filed bug #547020 |
|
Back to top |
|
|
UberLord Retired Dev
Joined: 18 Sep 2003 Posts: 6835 Location: Blighty
|
|
Back to top |
|
|
toralf Developer
Joined: 01 Feb 2004 Posts: 3919 Location: Hamburg
|
Posted: Mon Apr 20, 2015 8:47 am Post subject: |
|
|
UberLord wrote: | This isn't a bug in the software, the error is in your preup() function which assumes the interface will be down.
Once the interface is "up", the scripts won't actually take it "down" when stopping.
Code: |
preup()
{
if [ "$IFACE" = wlp3s0 ]; then
ifconfig "$IFACE" down
macchanger -r "$IFACE"
:
fi
}
|
| Ah, what I already tried , was Code: | ifconfig "$IFACE" down
macchanger -r "$IFACE"
ifconfig "$IFACE" up | which won't worked right, but will try your suggestion too. That's why I filed https://bugs.gentoo.org/show_bug.cgi?id=547020 |
|
Back to top |
|
|
UberLord Retired Dev
Joined: 18 Sep 2003 Posts: 6835 Location: Blighty
|
|
Back to top |
|
|
lost+found Guru
Joined: 15 Nov 2004 Posts: 509 Location: North~Sea~Coa~s~~t~~~
|
Posted: Mon Apr 20, 2015 11:29 am Post subject: |
|
|
Does it make a difference, if the syntax mentioned in /usr/share/doc/netifrc-0.2.2/net.example.bz2 is used (instead of running macchanger in a `preup')?
Code: | # For changing MAC addresses using the below, emerge net-analyzer/macchanger
# - to randomize the last 3 bytes only
#mac_eth0="random-ending"
# - to randomize between the same physical type of connection (e.g. fibre,
# copper, wireless) , all vendors
#mac_eth0="random-samekind"
# - to randomize between any physical type of connection (e.g. fibre, copper,
# wireless) , all vendors
#mac_eth0="random-anykind"
# - full randomization - WARNING: some MAC addresses generated by this may NOT
# act as expected
#mac_eth0="random-full"
# custom - passes all parameters directly to net-analyzer/macchanger
#mac_eth0="some custom set of parameters" |
Also it might help to separate any services related to networking, and the rest, in different runlevels:
In runlevel `default': any services that need networking + the stacked runlevel `nonetwork'
In runlevel `nonetwork': any services not networking related (including the display manager)
Then, instead of just restarting the network interface, use:
Code: | # rc nonetwork && rc default |
This might solve problems with depending services.
(And if the network interfaces have their real MAC addresses put back in `nonetwork', you're able to restart Udev after an upgrade safely.) |
|
Back to top |
|
|
toralf Developer
Joined: 01 Feb 2004 Posts: 3919 Location: Hamburg
|
Posted: Thu Apr 23, 2015 2:05 pm Post subject: |
|
|
I tried : Code: | mac_wlp3s0="random-samekind" | but got either Code: | * Bringing up interface wlp3s0
* Changing MAC address of wlp3s0 ...
RTNETLINK answers: Operation not possible due to RF-kill
* Failed to set MAC address [ !! ] | or Code: | * Bringing up interface wlp3s0
Current MAC: 00:1d:d7:29:0f:cd (Algolith)
Permanent MAC: e8:b1:fc:9d:87:85 (Intel Corporate)
[ERROR] Could not change MAC: interface up or insufficient permissions: Device or resource busy
* Starting wpa_supplicant on wlp3s0 ...
|
Tweaking /etc/init.d/net.lo is the only reliable way.
(BTW ofcourse I forgot to put xdm into "nonetwork" when I switched the fist time to ) |
|
Back to top |
|
|
lost+found Guru
Joined: 15 Nov 2004 Posts: 509 Location: North~Sea~Coa~s~~t~~~
|
Posted: Thu Apr 23, 2015 3:27 pm Post subject: |
|
|
toralf wrote: | RTNETLINK answers: Operation not possible due to RF-kill |
Don't know if this is good or bad news, but according to Internet this is a driver issue. The good news is, there's a kernel option: `CONFIG_RFKILL', and a userspace tool: net-wireless/rfkill. I think the driver uses rfkill on its own (to unblock the controller), but if that fails it can be scripted maybe.
In the Bluetooth wiki there are a few lines about using rfkill manually. |
|
Back to top |
|
|
toralf Developer
Joined: 01 Feb 2004 Posts: 3919 Location: Hamburg
|
Posted: Thu Apr 23, 2015 4:45 pm Post subject: |
|
|
Good hint.
But if I use "rfkill unblock 0" within preup(), then I do always just run into the subsequent issue Code: | [ERROR] Could not change MAC: interface up or insufficient permissions: Device or resource busy
|
|
|
Back to top |
|
|
toralf Developer
Joined: 01 Feb 2004 Posts: 3919 Location: Hamburg
|
Posted: Fri Apr 24, 2015 12:21 pm Post subject: |
|
|
lost+found wrote: | Does it make a difference, if the syntax mentioned in /usr/share/doc/netifrc-0.2.2/net.example.bz2 is used (instead of running macchanger in a `preup')? | BTW, is there any chance to get the SSID coded into the config option, eg. to exclude the MAC changing at home (at least with WLAN router I eventually run into permanent connection problems, till I removed the outdated entries from the past) |
|
Back to top |
|
|
lost+found Guru
Joined: 15 Nov 2004 Posts: 509 Location: North~Sea~Coa~s~~t~~~
|
Posted: Sat Apr 25, 2015 7:44 am Post subject: |
|
|
toralf wrote: | lost+found wrote: | Does it make a difference, if the syntax mentioned in /usr/share/doc/netifrc-0.2.2/net.example.bz2 is used (instead of running macchanger in a `preup')? | BTW, is there any chance to get the SSID coded into the config option, eg. to exclude the MAC changing at home (at least with WLAN router I eventually run into permanent connection problems, till I removed the outdated entries from the past) |
The easiest way, I think, is creating a parallel runlevel `home' (again with `nonetwork' stacked into it). When you switch runlevel from `default' to `nonetwork' to `home', completely different settings can be read from the file `/etc/conf.d/net.home' (/etc/conf.d/net is only used when there's no file with the runlevel name extension).
So `rc nonetwork && rc home' will then just restart everything related to the home network. To be able to switch or start a default at boot time, softlevel=home, softlevel=nonetwork etc. will work. It's possible to have separate settings for other services too (sshd?), in this wiki example. The downside is that there are much more files to maintain, and it might not work when not everything is closed down in `nonetwork' as seems to be the case... (can dhcpcd be killed?)
Maybe something like this is usefull in preup etc.:
Code: | RL=`/bin/rc-status -r`
if [ "$RL" != "home" ]; then
... |
|
|
Back to top |
|
|
UberLord Retired Dev
Joined: 18 Sep 2003 Posts: 6835 Location: Blighty
|
Posted: Sat Apr 25, 2015 8:36 am Post subject: |
|
|
toralf wrote: | BTW, is there any chance to get the SSID coded into the config option, eg. to exclude the MAC changing at home (at least with WLAN router I eventually run into permanent connection problems, till I removed the outdated entries from the past) |
No, because the interface needs to be UP to learn the SSID but down to change it.
When it's up, it's already too late - the MAC address is part of the 802.11 frames. _________________ Use dhcpcd for all your automated network configuration needs
Use dhcpcd-ui (GTK+/Qt) as your System Tray Network tool |
|
Back to top |
|
|
vhuto n00b
Joined: 24 Apr 2015 Posts: 2
|
Posted: Sun Apr 26, 2015 11:49 am Post subject: |
|
|
How are you, guys.
toralf wrote: | But if I use "rfkill unblock 0" within preup(),
|
Rfkill blocks radio emission. So, toralf, you should use "rfkill block 0" or "rfkill block wifi", etc.
Then a wireless interface will be down. At this timing, its MAC address can be changed. Maybe...
===== below is all about my Gentoo =====
I also had the same trouble with mac_wlan0="random-ending" in conf.d/net.
So, I wrote udev rule like:
Code: | SUBSYSTEM=="net", ACTION=="add", RUN+="/usr/bin/macchanger -e %k"
SUBSYSTEM=="net", ACTION=="remove", RUN+="/usr/bin/macchanger -p %k" |
This had worked for a while, but comes worse. i dont know why.
For now, using my init script:
Code: | #!/sbin/runscript
depend() {
after udev
before dhcpcd
}
start() {
ebegin "Changing MAC Addresses"
macchanger -e eno1
macchanger -e wlo1
eend $?
} |
(Apparently it's should be rewritten with elegance )
On my Gentoo system,
- WiFi is blocked since booting system by Rfkill module setting.
- Dhcpcd daemon starts by its init script at default runrevel and provides net service.
- And I don't have complex setting about networking. (Using dhcpcd for ethernet, moreover, wpa_supplicant for wlan)
So, I have removed net.eno1 and net.wlo1 from runlevels and those settings from conf.d/net. Dhcpcd daemon takes care of those things.
Also, Dhcpcd starts wpa_supplicant daemon through its hook-script: /lib/dhcpcd/dhcpcd-hooks/10-wpa_supplicant
Code: | ----- /etc/dhcpcd.conf -----
#nohook wpa_supplicant
env wpa_supplicant_driver=wext
----- |
Last edited by vhuto on Wed Apr 29, 2015 9:33 am; edited 1 time in total |
|
Back to top |
|
|
Doron n00b
Joined: 28 Sep 2006 Posts: 48
|
Posted: Mon Apr 27, 2015 2:11 pm Post subject: |
|
|
I may be able to help, since I had similar issues and after some debugging managed to
find the issue;
Currently I have installed:
[I] net-analyzer/macchanger
Available versions: 1.7.0
It seems that since 1.6.0 (yes..) the output of macchanger changed.
so net-misc/netifrc-0.2.2 was looking for the wrong string....
You can see it all in: https://bugs.gentoo.org/show_bug.cgi?id=504458 (which I found after digging the code for too long).
Bottom line, you should use net-misc/netifrc-0.2.3 by adding a keyword to it
and use the standard way in the conf file:
#mac_eth0="random-anykind" _________________ Common sense is not so common. (Voltaire) |
|
Back to top |
|
|
toralf Developer
Joined: 01 Feb 2004 Posts: 3919 Location: Hamburg
|
|
Back to top |
|
|
vhuto n00b
Joined: 24 Apr 2015 Posts: 2
|
Posted: Wed Apr 29, 2015 9:51 am Post subject: |
|
|
Oh, 0.2.3, 0.2.3...let me try it.
I restored the netifrc standard way. It successfully changes MAC address.
(The code config_interface="dhcp" dosen't work, so I added a dhcpcd service in boot runlevel.)
WiFi connection is eventually not established. I need restart of wpa_supplicant for it.
Code: | wpa_cli terminate
wpa_supplicant -iwlo1 -Dwext -c/etc/wpa_supplicant/wpa_supplicant.conf -B
|
Also on my environment above, I need this restart every time after changing MAC address. Perhaps my customizing is odd a bit
Anyway sorry for noise. Congrats |
|
Back to top |
|
|
|