22

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?

Eric Carvalho
  • 53,609
  • 102
  • 137
  • 162
kostiamol
  • 333
  • 1
  • 2
  • 7

2 Answers2

38

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.

Eric Carvalho
  • 53,609
  • 102
  • 137
  • 162
  • I used nano to edit /proc/sys/net/ipv4/ip_default_ttl and now I can't see any of my wifi networks – Arya Jul 03 '18 at 03:47
  • 1
    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`. – Curious Sam Mar 12 '22 at 11:39
4

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
bitinerant
  • 819
  • 8
  • 14