1

consider these values which are stored in their respected files in this path: /proc/sys/net

/core/rmem_default 32768
/core/rmem_max 65536
/core/wmem_default 32768
/core/wmem_max 65536
/core/somaxconn 1024
/core/netdev_max_backlog 3000
/ipv4/tcp_rmem "4096 32768 65536"
/ipv4/tcp_wmem "4096 32768 65536"
/ipv4/tcp_low_latency 1
/ipv4/tcp_slow_start_after_idle 0
/ipv4/tcp_timestamps 1
/ipv4/tcp_tw_recycle 1
/ipv4/tcp_tw_reuse 1
/ipv4/tcp_window_scaling 1

How can we get and set above values using terminal?

0

3 Answers 3

1

You can get the values easily but can't set them without root access because the files are read-only (rw-r-r) for "others".

Get the values

  1. Use D. Gibbs's answer to setup ADB.
  2. Launch Terminal/cmd in PC and enter:

    adb shell  
    find /proc/sys/net/ -type f | while read -r file; do echo $file $(cat $file); done
    
    • find will find the files under the location /proc/sys/net/. Tweak the location if the need arises.
    • while read will read each line of the previous output as a file,
    • do will allow execution of tasks (echo "filename" and show its value using cat),
    • done to complete the task.
    • Sources: 1, 2.

    Snippet of output:

    /proc/sys/net/core/dev_weight 64
    /proc/sys/net/core/message_burst 10
    /proc/sys/net/core/message_cost 5
    /proc/sys/net/core/netdev_budget 300
    /proc/sys/net/core/netdev_max_backlog 1000
    /proc/sys/net/core/netdev_tstamp_prequeue 1
    
  3. You may save the output into a file by using > <FILENAME> at the end of the step 2's last command.

  4. Some files won't be saved or shown because of file permissions. In that case, root the device and repeat the aforesaid steps using su after adb shell command.

Set the values

Now that you've a table of file -> value, you can change the value using echo, provided that you've root access.

  1. In the terminal, enter:

    adb shell 
    su 
    echo <VALUE> > <FILE_PATH>
    

    Change <VALUE> with the value you want to set and <FILEPATH> with the path of the file. E.g.

    echo 46 > proc/sys/net/core/dev_weight 
    

You can apply the steps in a terminal app on Android as well. Just make minor changes relevant to the environment, like > <FILENAME> in find command, and not using adb shell.

0

You can use ADB(Android Debugging Bridge) to access these files on the device. There are two things you need to do to get ADB working:

  1. Install ADB: You can find many tutorials of installing ADB for Windows from Google or use the provided link.
  2. You must enable ADB debugging on your device then start a command prompt on Windows to access the shell.

After you open a command prompt (Windows: Click start-> type in cmd in the search bar, then click on Command prompt) type in adb shell to start the Android shell. After than, simply navigate to the directory of your choosing cd /proc/sys/net.

0

sysctl is a standard Linux tool to set/get kernel configuration in /proc/sys/, available on Android as toybox applet. Or you may use busybox applet.

~$ /system/bin/sysctl --help
usage: sysctl [-aAeNnqw] [-p [FILE] | KEY[=VALUE]...]

Read/write system control data (under /proc/sys).

-a,A    Show all values
-e      Don't warn about unknown keys
-N      Don't print key values
-n      Don't print key names
-p      Read values from FILE (default /etc/sysctl.conf)
-q      Don't show value after write
-w      Only write values (object to reading)

Use a terminal emulator app or adb shell:

~# sysctl net.ipv4.tcp_timestamps=1
~$ sysctl net.ipv4.tcp_timestamps
1

Setting values is only allowed to root.


RELATED:

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .