ValentinBELYN / icmplib

Easily forge ICMP packets and make your own ping and traceroute.
GNU Lesser General Public License v3.0
266 stars 46 forks source link

After upgrading to ubuntu 22.04 sysctl changes are needed again #78

Closed aseques closed 2 months ago

aseques commented 4 months ago

I have code I've written a few years ago that has been using icmplib since the beggining, on my system with ubuntu 22.04 it worked without any issues. A few days ago I updated to ubuntu 23.10 and I'm getting an error related to the permissions, it happens both on python 3.10 and 3.11 (on two different systems), and it only goes away after doing the _sysctl net.ipv4.ping_grouprange change. So I guess something has changed on the defaults since last version but I haven't been able to find it.

You could update the documentation here mentioning that after 22.04 it is capped again https://github.com/ValentinBELYN/icmplib/blob/433c6523f254a4d09ba0ebc2b71ddc15e123e0f8/docs/6-use-icmplib-without-privileges.md?plain=1#L27

The error is the following


Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/icmplib/sockets.py", line 88, in __init__
    self._sock = self._create_socket(
                 ^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/icmplib/sockets.py", line 452, in _create_socket
    return socket.socket(
           ^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/socket.py", line 232, in __init__
    _socket.socket.__init__(self, family, type, proto, fileno)
PermissionError: [Errno 13] Permission denied

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/icmplib/sockets.py", line 97, in __init__
    raise SocketPermissionError
icmplib.exceptions.SocketPermissionError: Root privileges are required to create the socket```
ValentinBELYN commented 2 months ago

Thanks for the information, this will be fixed in the next version 😉

kalvdans commented 2 months ago

Digged some more into this.

The sysctl seems to be set in Ubuntu 22.04 by systemd 249.11-0ubuntu3.11 /usr/lib/sysctl.d/50-default.conf

This file does not exist in Ubuntu 24.04 in systemd 255.2-3ubuntu2.

The file seems was added by https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/1721223 but later removed by some other merge in https://git.launchpad.net/~ubuntu-core-dev/ubuntu/+source/systemd

Please don't close the issue before the documentation update is checked into git.

aseques commented 1 month ago

I have just upgraded to 24.04 and I needed to change the values again I will propose a small change in the docs to make the change persistent across upgrades.