Methods of payment Abuse

Changing TTL in Linux

25.10.2022, 02:28

These networks are transmitted by packets. Packets pass through several other network nodes before reaching their destination to end up at the beginning of the destination's local network and then directly to the destination. It is not uncommon for such packets to go astray. To direct them to the right path in the network, each packet is given a certain lifetime.

The TTL parameter is responsible for its lifetime. This is the number of nodes the packet can pass before being destroyed. During the passage of each node, the TTL value decreases until the time reaches a value of zero The higher the TTL, the more confusing networks the packet can traverse.

How to change the TTL in Linux

The low-level TTL network parameters in Linux are controlled by the kernel. It can be configured using the kernel configuration interface. What TTL is the system using?

Let's use the ping command:

$ ping 127.0.0.1

Changing TTL in Linux

In the packet sending data, we can see the TTL with which the packet was sent. We can see that the value used is 64. For Windows, a TTL value of 128 is used. Usually this is enough, as there are at least 20-30 routers between network nodes. It is not always worth changing the TTL so that packets can reach their destination.

Adjusting the parameters

Changing the TTL is possible by adjusting the net.ipv4.ip_default_ttl parameter.

We try such a command:

$ sudo sysctl -w net.ipv4.ip_default_ttl=65

To make the changes persist after a reboot you can write this line of settings to the /etc/sysctl.conf file:

$ sudo vi /etc/sysctl.conf

net.ipv4.ip_default_ttl=65

After TTL will be 65:

Changing TTL in Linux

If you don't want to change the kernel settings, you can modify the TTL to packets as they pass through the iptables network filter. To do this, run a command like this:

$ iptables -t mangle -A POSTROUTING -j TTL --ttl-set 65

This will also work. Changing the Linux TTL is not difficult at all.