TTL and HL settings and how they help when modified

How To Tutorials related to Routers and Firmware
Forum rules
This forum is for tutorials only--not for help or assistance.
Post Reply
User avatar
Didneywhorl
Posts: 3232
Joined: Fri Mar 23, 2018 5:37 pm
Location: USA
Has thanked: 1228 times
Been thanked: 642 times
Contact:

TTL and HL settings and how they help when modified

Post by Didneywhorl »

I am going to make this one as short as I can, and hopefully it can still help many without everyone needing to repeat this information over and over again.


Note:
If you respond to this post with anything that does not help the “article” it will be deleted. Please do not ask questions about your device. Please read thoroughly. This is a tutorial post, not a post for you to get support with your setup. Go to the Questions and Support sections for that.



What is TTL?
TTL stands for "Time to Live" and in short is simply a decremental count of how many times a interwebz packet of data jumps from one device to the next to get to its destination. TTL is only for IPV4 protocol (nerd talk).

Your phone or router or computer, etc, will create a "packet" of data that is to be sent to somewhere that you are communicating with, like the google.com servers, so that you can receive information back. TTL number is one piece of information, in a simple number format, that your device places inside that packet.
Different device types (phone, PC, etc) will assign a number to the TTL value by default.

The computer then sends the packet away to be received at your computers chosen end point. Every device the packet goes through (like a router) to get to the end destination (remember, google servers to find out what kind of snake that was ;) ) will subtract a count of 1 (one) away from the current TTL value. This is called decrementing. So if the original value was 255, and the packet went through a single router, the TTL value then becomes 254.
Every single device that your packet "hops" through will remove a value of 1 (one) from the packets current TTL value.

The reason TTL is there is to stop the packet for jumping around the world wide web literally forever. Once the number reaches 0 (zero) the packet is killed off by the device that gets the priviledge of docking the packets TTL from 1 to 0.


That is about it. The super nerdy details may not be ultra-precise, but you get the point.


What is HL?
HL stands for "Hop Limit" and is the exact same thing as TTL, but for IPV6 protocol only. It is it's own parameter in the packet, and decrements by 1 (one) for every "hop" as well.

The IPV6 HL seems to be where many have found they had data monitoring “leaking”. Once they set the HL value, the hotspot data seemed to stop getting counted.


Why does TTL and HL matter to some of us?

TTL and HL are a parameter in the packet that some cellular network operators around the world use in order to determine whether or not the device that sent the packet is a cellular phone, or tablet, or a device using that cellular phone, or tablets, hotspot function.
As we in some places around the world, like the USA, know, cellular hotspot data use is EXPENSIVE.
Until the cellular carriers stop gouging it's customers over data use, we have to ensure we are NOT often using our hotspot data.

TTL and HL settings manipulation can, in some cases, work around this little metric. Allowing someone to use a PC over a cellular connection, and not get charged tons of ridiculous money for going over their hotspot data allotment for the month.

Does this work for all carriers, everywhere?

No. you have to try it to find out, or do a simple search around to find out.

Currently it seems, in the US, AT&T and Sprint do not use TTL/HL for hotspot data monitoring. They seem to use a specific APN for monitoring hotspot use.


What number do I set to do this?

That depends on the network operator, and your location. Some cellular companies use one number on the west coast, and another similar number on the east coast.

Different numbers can work, but the most common are 64, 65, and 117. Sometimes you have to try these, or even 1 or 2 above or below. This is for both TTL and HL.

So far it seems 117 works only with Verizon based networks.

64 and 65 seems to be the most common with T-Mobile and Verizon, and Verizon MVNOs.




How do I set my TTL and HL?


That depends on your device. The TTL and HL can be manipulated in the firewall iptables and ip6tables rules.

The devices I deal with the most are openWRT based and have the ability to use a the mangle function of the iptables and ip6tables commands. All the openWRT based routers on The Wireless Haven can do this. If your device can not use the mangle function of iptables or ip6tables I can’t help you. You typically need only a single device on your network that can do this, so you may need to add a simple router between your network and your internet connection. This tutorial isn’t being written to cover which devices can and cant do this, and how to do it when you can’t, etc, etc.

In the popular firmware branch of openWRT called Rooter (or Goldenorb) you can set custom rules under the Network menu item “Firewall”. On the main Firewall page there are tabs along the top. One of these tabs says “Custom Rules”. Go in there.

Note: Do not use, or enable, the “Custom TTL” tab. It typically does not set the IPV6 HL.

In the text box on this page you can place your iptables mangle rules.

Other devices may have other interfaces to do this. Some have a simple interface that allows you to just enter a number for TTL and HL and it does the rules for you.


What rules do we use?

The perfect rules are up for debate, but here are my exact rules I use on all my routers that I need this for:

Code: Select all

# A Hashtag is in place if not using that line.
 
# Popular TTL values: 64 for Visible. 65 for Verizon, ATT and Tmobile. 117 is sometimes a working TTL for Verizon.
# When changing values, first place # on all the TTL value lines beginning, like this line itself has. Then click Restart Firewall.
# Then change all of the TTL values to what you need and then delete the #s at their lines beginning.
# Then click Restart Firewall. Changes should then be applied properly.
 
# Start-IP6-TTL-Fix
ip6tables -t mangle -I POSTROUTING -o wwan0 -j HL --hl-set 65
# End-IP6-TTL-Fix
 
# Start-IP4-TTL-Fix
iptables -t mangle -I POSTROUTING -o wwan0 -j TTL --ttl-set 64
# End-IP4-TTL-Fix


I paste this in the appropriate location and save and apply, or in some cases “Reset Firewall”.

These rules can also be set via CLI if you like, obviously just the iptables/ip6tables lines. If you don’t know what CLI is, you don’t need to be doing it. 😉





Will this always work this way?

Not at all. The networks are always trying to use ways to make sure they can charge us maximum dollar for data. So this may be completely outdated as quickly as the moment after I post this.



Good luck with yours!
Jayhawks659
Posts: 6
Joined: Mon Aug 23, 2021 4:48 am
Has thanked: 0
Been thanked: 0

Re: TTL and HL settings and how they help when modified

Post by Jayhawks659 »

I'm sure you probably would have covered this if so, but is there any way to use a device to find out the TTL and HL number in your current location instead of just using trial and error? For example, using your mobile phone with the SIM card installed to find out the TTL and HL and then put the card in your router and configure the settings? And I'm assuming if you travel with the router you'll have to go through trial and error again to find the right configuration for that location?
User avatar
Rich Hathaway
Posts: 218
Joined: Mon Mar 08, 2021 2:41 pm
Has thanked: 2 times
Been thanked: 70 times

Re: TTL and HL settings and how they help when modified

Post by Rich Hathaway »

Jayhawks659 wrote: Fri Aug 27, 2021 6:30 am is there any way to use a device to find out the TTL and HL number in your current location instead of just using trial and error?
Simply just connect to the device you are wanting to check and ping it, it will return your outgoing ttl
Jayhawks659
Posts: 6
Joined: Mon Aug 23, 2021 4:48 am
Has thanked: 0
Been thanked: 0

Re: TTL and HL settings and how they help when modified

Post by Jayhawks659 »

One more question that I hope is considered helpful to the original post. If you want to delete this, I understand.

You answered the question "what number do I set this to", but won't that depend on whether you are fixing the outgoing number on an end use device vs on your router? For example, I have read everywhere that Verizon mostly uses 65, but if I am connected to multiple devices wouldn't I want the outgoing TTL on my router set to 64? And should the TTL and HL always be the same number?

I did connect my cell phone to my router via Wi-Fi without the SIM card in. I turned off my mobile data and pinged it from my PC. The TTL returned was 64. I hope I did it right.
User avatar
Didneywhorl
Posts: 3232
Joined: Fri Mar 23, 2018 5:37 pm
Location: USA
Has thanked: 1228 times
Been thanked: 642 times
Contact:

Re: TTL and HL settings and how they help when modified

Post by Didneywhorl »

Jayhawks659 wrote: Sun Aug 29, 2021 11:54 am One more question that I hope is considered helpful to the original post. If you want to delete this, I understand.

You answered the question "what number do I set this to", but won't that depend on whether you are fixing the outgoing number on an end use device vs on your router? For example, I have read everywhere that Verizon mostly uses 65, but if I am connected to multiple devices wouldn't I want the outgoing TTL on my router set to 64? And should the TTL and HL always be the same number?

I did connect my cell phone to my router via Wi-Fi without the SIM card in. I turned off my mobile data and pinged it from my PC. The TTL returned was 64. I hope I did it right.
The TTL and HL are two different metrics, and I've found setting them that way worked for me. I always recommend people test what works for them. If doing it one way versus another works, then go for that. If you have no clue what to use, then set it to what has worked for others.

When pinging a device, always remember each device along the way will decrement the TTL number by one. If you set it to postroute mangle at 65 and after you ping it you get a value of 64 in your report, then something is decrementing it by one. I don't fully understand iptables and how every type of device in every scenario uses it, so I can't fully explain. I'm just trying to help those that have not info, to get somewhere.
carp4
Posts: 4
Joined: Sun May 15, 2022 9:38 am
Has thanked: 0
Been thanked: 0

Re: TTL and HL settings and how they help when modified

Post by carp4 »

Didneywhorl wrote: Sun Jun 06, 2021 11:22 am
The perfect rules are up for debate, but here are my exact rules I use on all my routers that I need this for:
Why did you set the HL one higher than the TTL? I’ve normally seen them equal. Thanks!
DDK65JAG
Posts: 18
Joined: Fri Jul 09, 2021 1:21 pm
Has thanked: 0
Been thanked: 2 times

Re: TTL and HL settings and how they help when modified

Post by DDK65JAG »

@carp4 I've asked that same question & never gotten an answer, maybe someday?
I use 64 for both TTL & HL when using a modem and TTL & HL of 65 when tethering.
I'm using Visible as my IP (I believe they're IPV6) and it works for me. DDK
User avatar
Didneywhorl
Posts: 3232
Joined: Fri Mar 23, 2018 5:37 pm
Location: USA
Has thanked: 1228 times
Been thanked: 642 times
Contact:

Re: TTL and HL settings and how they help when modified

Post by Didneywhorl »

Mysterious Mysterious! ;)


Honestly, just because. There is no reason. It's just what I do.
elesbb
Posts: 1
Joined: Mon Jun 06, 2022 8:49 pm
Has thanked: 0
Been thanked: 1 time

Re: TTL and HL settings and how they help when modified

Post by elesbb »

Made an account simply to reply to this thread. First, thanks OP for the great information. Was trying to figure out how to use ip6tables to bypass hotspot. I then learned ip6tables doesn't use TTL, but instead, HL. So thanks for showing me how to get it setup!

The original code would set the wwan0 interface (this is the hotspot interface, where your devices connect to) to have a TTL of 64 for IPV4.
It also sets the wwan0 interface (again the hotspot interface, where your devices connect to) to have an HL of 65 for IPV6. For my device, the hotspot interface is actually swlan0.

Normally, on the wwan0 interface, you would set your TTL/HL to 65. This means all packets coming from and to the wwan0 interface will have an HL/TTL of 65. Then, in the phone, the wwan0 interface sends those packets to the rment_data0 interface (will be different for each device). Now, the rmnet_data0 interface decreases that TTL/HL count by 1. This then sends the packets to the towers. In my understanding, the hotpsot interface should have a TTL 1+ the expected value that normally comes from the device. On android, I am pretty sure that is 64.

What I have done, and have not yet checked, but in theory, should work, is set the rmnet+ (+ is a wildcard which ip(6)tables associates to all interfaces which start with rmnet) to have that interface always set the TTL/HL to 64. I will be able to test this once I am unfortunately forced to T-Mobile SIM from Sprint.
speakerhead
Posts: 6
Joined: Mon Feb 08, 2021 3:23 am
Has thanked: 0
Been thanked: 1 time

Re: TTL and HL settings and how they help when modified

Post by speakerhead »

Dude you saved me more than you know. Got a new setup and for whatever reason couldn't get my speeds up unless I used a VPN. I've never had any trouble with how I changed the ttl but I ran across this just now and like magic I have 160mbps internet again.

My family was really starting to lose faith in me but now I'm back and it's all thanks to you
Post Reply

Return to “Tutorials”