How to change the default TTL of TCP/IP packets?

100,942

Solution 1

To change the default TTL of TCP/IP packets sent from your Linux computer you can run the following command:

sudo sysctl -w net.ipv4.ip_default_ttl=129

Or:

echo 129 | sudo tee /proc/sys/net/ipv4/ip_default_ttl

Or:

sudo bash -c 'echo 129 > /proc/sys/net/ipv4/ip_default_ttl'

But you have to run one of those commands whenever the computer boots. To make this setting persistent across reboots you could append the following line to the file /etc/sysctl.conf:

net.ipv4.ip_default_ttl=129

You should do the same with ipv6 instead of ipv4 if you want to change the settings for ipv6 as well.

Solution 2

for IPv6:

The other answer here says, "You should do the same with ipv6" but this does not work. IPv6 uses net.ipv6.conf.all.hop_limit and net.ipv6.conf.default.hop_limit. However, these values are overwritten by interface-specific names such as net.ipv6.conf.eth0.hop_limit. To change them all, use:

for N in $(sudo sysctl --all 2>/dev/null |grep -Eo "^net\.ipv6\.conf\.[^\.]+\.hop_limit"); do
    sudo sysctl --write "$N=128"
done

where 128 is the desired new value.

To make this permanent (survive reboot) for IPv4 and IPv6:

sudo sysctl --all 2>/dev/null |grep -E -e "^net\.ipv6\.conf\.[^\.]+\.hop_limit" -e "net.ipv4.ip_default_ttl" |sudo tee /etc/sysctl.d/11-custom-ttl-hop.conf
Share:
100,942

Related videos on Youtube

kostiamol
Author by

kostiamol

Updated on September 18, 2022

Comments

  • kostiamol
    kostiamol over 1 year

    I need to change the default TTL of TCP/IP packets sent from my Ubuntu computer. I found the solution for Windows:

    1. To make reg-file:

      Windows Registry Editor Version 5.00
      
      [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\servic es\Tcpip\Parameters]
      "DefaultTTL"=dword:00000081
      
    2. To execute this commands in console:

      netsh int ipv4 set glob defaultcurhoplimit=129
      netsh int ipv6 set glob defaultcurhoplimit=129
      

    The question is how should I translate this solution for Ubuntu?

  • Arya
    Arya almost 6 years
    I used nano to edit /proc/sys/net/ipv4/ip_default_ttl and now I can't see any of my wifi networks
  • Curious Sam
    Curious Sam about 2 years
    Not true for ipv6; in ipv6 they don't call it ttl anymore. The correct variable name for sysctl is net.ipv6.conf.default.hop_limit.