How do you change the TTL in macOS High Sierra?

Solution 1:

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

Solution 2:

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. :(