17

How do you change the TTL in macOS High Sierra?

In previous macOS versions, this could be done as follows...

Temporarily:

sudo sysctl -w net.inet.ip.ttl=65

Or permanently by creating or editing /etc/sysctl.conf to adding:

net.inet.ip.ttl=65

EDIT: Correction on testing the TTL

So if the TTL was previously set to 64 and I change it to 65, I should see a ping TTL increase by 1, however, in 10.13.5, this is not occurring.

2
  • 1
    Will it be applied to ipv6 protocol? Tried net.inet6.ip6.ttl=65 but get unknown oid error message from system.
    – basil
    Aug 25, 2018 at 6:07
  • 1
    @basil, want to try net.inet6.ip6.hlim=65
    – user994165
    Jun 11, 2020 at 0:58

2 Answers 2

10

The ways you gave are still honored.

What may have thrown you off is that ping reports the TTL of the ICMP echo reply received, which is controlled by the target host; that is, the machine that is responding to your ping. I do not think the ICMP echo (ping) protocol provides a way to influence what TTL the target host uses.

I verified this by running tcpdump and looking at what TTL was on my outgoing ICMP echo requests. Be sure to add at least one -v to tcpdump to see the TTLs.

sudo tcpdump -vi en0 icmp
2
  • My mistake on the interpretation of ping. Was about 6 months since I messed with this on an OS prior to High Sierra. So if I changed the TTL +1, for example from 64 to 65, I should see a ping TTL also increase by 1. Which I am not seeing in 10.13.5.
    – Brett
    Jul 6, 2018 at 21:30
  • @Brett I think you’re still misinterpreting the ping output. It has never shown you the TTL you’re sending on ICMP Echo Request packets you send. It shows you the TTL on the ICMP Echo Reply packets you receive, which have nothing to do with your local host’s TTL settings, and everything to do with the remote host’s TTL settings (minus the number of hops the replies took to get across the network to you). Prove this to yourself with tcpdump, or by pinging the TTL-adjusted Mac from another machine on your LAN (make your Mac the ping responder, not the ping requester).
    – Spiff
    Jul 6, 2018 at 22:14
7

Works for me on 10.15.2 (19C57) Catalina. -w is deprecated, and should be omitted.

sysctl net.inet.ip.ttl=65
net.inet.ip.ttl: 64 -> 65

ping localhost
PING localhost (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.040 ms
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.065 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=65 time=0.091 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=65 time=0.091 ms

Using a launch daemon to persist the setting after reboot: /Library/LaunchDaemons/com.gvalkov.ttl65.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.gvalkov.ttl65</string>
    <key>MachServices</key>
    <dict>
        <key>com.gvalkov.ttl65</key>
        <true/>
    </dict>
    <key>Program</key>
    <string>/usr/bin/sysctl</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/bin/sysctl</string>
        <string>net.inet.ip.ttl=65</string>
    </array>
    <key>UserName</key>
    <string>root</string>
    <key>GroupName</key>
    <string>wheel</string>
    <key>KeepAlive</key>
    <true/>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

Note: I hope I got the path to sysctl correctly! Please run which sysctl to obtain the actual path. I cannot currently check, because my MacBook Pro 2018 is being serviced again for swelling battery and stuck keys. :(

3
  • How do you do it permanently?
    – Tyler A.
    Mar 25, 2020 at 18:15
  • Use a launch daemon. I have extended my answer with a sample script. Mar 27, 2020 at 0:11
  • 1
    On this system, the path for sysctl is /usr/sbin/sysctl.
    – skeggse
    May 11, 2021 at 16:17

You must log in to answer this question.

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