UBports Robot Logo UBports Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Enabling MAC randomization

    Scheduled Pinned Locked Moved Unsolved Support
    17 Posts 5 Posters 203 Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
      Reply
      • Reply as topic
      Log in to reply
      This topic has been deleted. Only users with topic management privileges can see it.
      • fredldotmeF Offline
        fredldotme @nielsbasjes
        last edited by

        @nielsbasjes you can use systemd mount units for this, we allow writes to /etc/systemd/system:

        • Copy your modified NetworkManager.conf to /etc/writable as a safe spot
        • Create a file /etc/systemd/system/etc-NetworkManager-NetworkManager.conf.mount with the following contents:
        [Mount]
        What=/etc/writable/NetworkManager.conf
        Where=/etc/NetworkManager/NetworkManager.conf
        Type=none
        Options=bind
        
        [Install]
        WantedBy=local-fs.target
        
        • Enable the mount unit: sudo systemctl daemon-reload && sudo systemctl enable etc-NetworkManager-NetworkManager.conf.mount

        Let me know if it works for you, a quick reboot with this applied on my FP4 resulted in the same IP assigned as before.

        For a list of my contributions to Ubuntu Touch visit: https://fredl.me

        If you have enjoyed my work on Ubuntu Touch over the years, please donate to my causes:

        • PayPal: https://paypal.me/beidl
        • Liberapay: https://liberapay.com/fredldotme
        G 1 Reply Last reply Reply Quote 0
        • G Offline
          gpatel-fr @fredldotme
          last edited by

          @fredldotme said in Enabling MAC randomization:

          a quick reboot with this applied on my FP4 resulted in the same IP assigned as before.

          something like that should work, even if probably the unit file should include a before stanza, see below. However it could also depend on what is in the modified NetworkManager.conf.

          I tried it a bit differently, partly out of a (possibly outlandish) idea of 'don't change the NetworkManager.conf file ! it is distro controlled'. Well, lol, you for all intent and purpose are the distro here and you advise precisely that 🙂

          phablet@ubuntu-phablet:/userdata/system-data/etc/NetworkManager/conf.d$ ls
          randomwifimacaddress.conf

          cat randomwifimacaddress.conf
          [device]
          wifi.scan-rand-mac-address=yes

          [connection]
          wifi.cloned-mac-address=random

          cat /userdata/system-data/etc/systemd/system/etc-NetworkManager-conf.d.mount
          [Unit]
          Description=Mount unit for etc/NetworkManager/conf.d
          DefaultDependencies=no
          Requires=system.slice dev-sda17.device -.mount
          Conflicts=umount.target
          Before=umount.target local-fs.target
          Before=network-pre.service
          Wants=network-pre.service

          [Mount]
          Where=/etc/NetworkManager/conf.d
          What=/userdata/system-data/etc/NetworkManager/conf.d
          Options=rw,relatime,upperdir=/userdata/system-data/etc/NetworkManager/conf.d,lowerdir=/etc/NetworkManager/conf.d,workdir=/userdata/system-data/tmp
          Type=overlay

          [Install]
          WantedBy=network.target

          [there are very probably unnecessary things in this unit...]

          phablet@ubuntu-phablet:/userdata/system-data/etc/NetworkManager/conf.d$ ls /userdata/system-data/tmp -lart
          total 12
          d--------- 2 root root 4096 juil. 11 20:52 work
          drwxr-xr-x 3 700 root 4096 juil. 11 20:52 .
          drwxr-xr-x 9 root root 4096 nov. 11 01:38 ..

          after the usual systemd dance ; sudo systemctl daemon-reload, sudo systemctl start, sudo systemctl start etc-NetworkManager-conf.d.mount (to test), systemctl enable etc-NetworkManager-conf.d.mount (to validate before rebooting the phone), it seems to apply a new mac address after the restart or a disable/enable of Wifi on the phone.

          fredldotmeF 1 Reply Last reply Reply Quote 0
          • fredldotmeF Offline
            fredldotme @gpatel-fr
            last edited by

            @gpatel-fr I agree your approach using overlayfs is better, puts the file in the same place we would regularly put our customizations.

            For a list of my contributions to Ubuntu Touch visit: https://fredl.me

            If you have enjoyed my work on Ubuntu Touch over the years, please donate to my causes:

            • PayPal: https://paypal.me/beidl
            • Liberapay: https://liberapay.com/fredldotme
            G 1 Reply Last reply Reply Quote 0
            • G Offline
              gpatel-fr @fredldotme
              last edited by

              @fredldotme said in Enabling MAC randomization:

              using overlayfs is better

              Well, using overlayfs was mostly an experiment on my part (finding on the Internet an example of a mount unit with overlayfs was surprising difficult - finally I had to test on my PC to find a form that actually works - and the official way does not seem to work on Ubuntu 24.04 - it's possible than systemd is bugged at this point)
              The downside is, as each port has its own kernel, having overlayfs available is not a sure thing as having the possibility of bind-mounting. As I had no more experience with bind-mount than overlayfs, I used the most exciting possibility 🙂

              1 Reply Last reply Reply Quote 0
              • nielsbasjesN Offline
                nielsbasjes @gpatel-fr
                last edited by

                @gpatel-fr I have not tried this idea. I realized this is such an "extreme" way of settings this (also looking at the other replies) that I asked here first.

                My key question is : Is this the right direction or is there a simple, clean and reliable way of enabling MAC randomization.

                G 1 Reply Last reply Reply Quote 0
                • G Offline
                  gpatel-fr @nielsbasjes
                  last edited by

                  @nielsbasjes said in Enabling MAC randomization:

                  Is this the right direction or is there a simple, clean and reliable way of enabling MAC randomization.

                  If you don't know about it, @fredldotme is a pillar of UT, certainly the second ranked; so if he don't advise for a 'simpler, cleaner' solution, you can assume that there is no obvious one. Having the rootfs read-only is certainly a solid part of the core tenets of UT.

                  1 Reply Last reply Reply Quote 0
                  • U Offline
                    uxes @nielsbasjes
                    last edited by

                    @nielsbasjes mac random addresses are now pretty much a standart, it would be great if this implementation is shipped on our system by default , if you manage to get this working and send it upstream, that’d be awesome

                    nielsbasjesN G 2 Replies Last reply Reply Quote 0
                    • nielsbasjesN Offline
                      nielsbasjes @uxes
                      last edited by

                      @uxes I'm going to try it this weekend. If it works, where can I find the issue tracker/git repo to submit a patch proposal?

                      1 Reply Last reply Reply Quote 0
                      • G Offline
                        gpatel-fr @uxes
                        last edited by

                        @uxes said in Enabling MAC randomization:

                        shipped on our system by default

                        I am not sure that any phone is doing that by default.
                        It has also a downside for anyone using this phone with ssh, that is, the IP address affected by the Dhcp server (the wifi access point) will change often.
                        It's not a big deal but it can be annoying.

                        U Vlad NirkyV 2 Replies Last reply Reply Quote 1
                        • U Offline
                          uxes @gpatel-fr
                          last edited by

                          @gpatel-fr

                          While I don't have a formal, tangible report to cite, my practical experience dealing with a network of around a hundred devices daily at my company confirms this: Android, iOS, and macOS absolutely randomize their MAC addresses. This behavior makes reliable device tracking within the company difficult, though it admittedly ensures a better degree of anonymity for our users.

                          https://source.android.com/docs/core/connect/wifi-mac-randomization-behavior

                          https://support.apple.com/en-us/102509
                          By default, your device improves privacy by using a different MAC address for each Wi-Fi network.

                          G 1 Reply Last reply Reply Quote 0
                          • Vlad NirkyV Offline
                            Vlad Nirky @gpatel-fr
                            last edited by

                            @gpatel-fr
                            You could fix IP (as I did)

                            G 1 Reply Last reply Reply Quote 0
                            • G Offline
                              gpatel-fr @Vlad Nirky
                              last edited by

                              @Vlad-Nirky said in Enabling MAC randomization:

                              @gpatel-fr
                              You could fix IP

                              The option does not seem to be available in the phone UI - I guess that it can be done with some command line trickery. This is not something that is commonly done in Wifi networks where devices are rarely servers.

                              Vlad NirkyV 1 Reply Last reply Reply Quote 0
                              • G Offline
                                gpatel-fr @uxes
                                last edited by

                                @uxes said in Enabling MAC randomization:

                                Android, iOS, and macOS absolutely randomize their MAC addresses

                                there seem to be yet some level of configuration:

                                https://android.stackexchange.com/questions/225839/get-new-random-mac-for-same-ssid-without-factory-reset-on-android-10

                                what is done by the trick I posted is mostly the highest level, non persistent randomization (except the 'new Mac address every few days'). The article suggests that this can be too strong for some internal 'enterprise' networks that have special requirements. So some level of configuration could be necessary, no size fits all. When adding options in the UI, it gets so much more complicated to program that you begin to understand why it was not done before for UT.

                                1 Reply Last reply Reply Quote 0
                                • Vlad NirkyV Offline
                                  Vlad Nirky @gpatel-fr
                                  last edited by Vlad Nirky

                                  @gpatel-fr
                                  Not so hard and usefull
                                  you must know which yaml file is used for the wifi in /etc/netplan
                                  as root cd /etc/netplan and cat yaml files.
                                  nano 90-NM-5f1fe55a-2996-4485-b6b3-a75fe76edc62.yaml (ie)
                                  Then in the wifi one
                                  replace

                                        dhcp4: true 
                                  with
                                        dhcp4: false
                                        addresses:
                                          - [your wanted IP]/24 (or less)
                                        routes:
                                          - to: default
                                            via: [your router IP]
                                        nameservers:
                                          addresses: [your DNS1, your DNS2]
                                  

                                  save it
                                  and validate it by
                                  netplan apply

                                  G 1 Reply Last reply Reply Quote 0
                                  • G Offline
                                    gpatel-fr @Vlad Nirky
                                    last edited by

                                    @Vlad-Nirky said in Enabling MAC randomization:

                                    Not so hard and usefull

                                    yes that's a possibility. Another could be to stop and disable the mount unit + restarting the phone when staying at home.

                                    1 Reply Last reply Reply Quote 0
                                    • First post
                                      Last post