Still no internet? How to prevent premature timeouts in Ubuntu?
Tags: linux, networking, discuss
Published: 2024-01-18 14:43:11

I have contributed to open data by hunting "Funklöcher" ("radio holes", as network dead zones are called in Germany) with the Federal Network Agency's [Breitbandmessung](https://www.breitbandmessung.de) network measurement tool, only to discover that "not no internet" still does not guarantee any usable connection. Similarly, there are some cheap router devices that popular ISPs send as a default, that work well enough for the majority of Windows, MacBooks, and iPhones, and everyone else should pay to rent or buy a FritzBox router. This has happened with various budget smartphones and older Lenovo laptops, but also my professional Linux laptop that rarely makes any trouble.

## Internet connections that don't send data

But what's happening? Latency problems probably cause this kind of issues when there is a good, or at least sufficient, internet connection that some devices can use without issues, but some can't.

I gathered a lot of log files using a Linux laptop and a Huawei phone on a Vodafone network, but that's outdated now, and Vodafone support didn't think it was useful. Later I experienced similar problems with another Linux laptop in an O2 network. After replacing their router with a used FritzBox (many second-hand 1&1 routers can be reconfigured for any other popular ISP) the problems disappeared at home and I never had any similar problems in any professional workplace.

Travelling around the country in Deutsche Bahn trains and working from my dad's place in an old suburban house connected to an average Telekom network, I remembered my timeouts that became critical when I failed to reach GitHub and my own remote `ssh` server!

## Increasing Ubuntu network timeouts and retries

Checking various sources, I learned that Ubuntu Linux networking did have some special problems, most of which seemed to have disappeared after an upgrade to the latest release at the time of writing. Those posts are usually five to ten years old. But one option still works in Ubuntu 22.04 in 2024: increasing the network timeouts and retries.

We can change the settings ad hoc using the `sysctl` interface. Tweaking `net.ipv4` requires root privileges on my system, so I tried

- `sudo sysctl net.ipv4.tcp_fin_timeout=180` to increase the timeout to 3 minutes (3x the default 60 seconds)
- `sudo sysctl net.ipv4.tcp_synack_retries=8` to increase passive FTP retries above the default 5 times

A quick check before and after the settings looked good: GitHub, GMX (a popular German email provider), and several other servers notorious for latency problems with my Ubuntu machine on a train or with cheap routers, ran into timeouts before tweaking, but I could reach all of them almost immediately when trying again afterwards, at least in Google Chrome. Maybe the problem is worse in combination with Vivaldi, or my browser has cached the outdated network settings. 🤔

To persist these settings, I add the corresponding lines to my `/etc/sysctl.conf` configuration file:

```
# prevent timeouts when communicating with latent routers
# override default 60s timeout:
net.ipv4.tcp_fin_timeout=180

# override default 5 passive ftp retries
net.ipv4.tcp_synack_retries=8
```

That's it! 

I'll see and verify my solution. 👀

 - ❎ using my dad's Telekom router ☎️: maybe less critical than before❓
 - ◻ in a Deutsche Bahn train ("WiFi on ICE" 🧊)
 - ◻ using the default O2 and Vodafone routers 🫧
 - ◻ using public cafés and bars ☕🍹

I still find it hard to tell. Between edge cases like "I can never connect to GitHub" and  "I can always use every part of GitHub without any delay" lies reality and its perceived improvements and placebo effects, unless I start measung and gather actual data which I should also have done before tweaking my network. But here is an intermediate conclusion: I still had issues in the Telekom router net, and I always have occasional issues on a train no matter which machine I use, and GitHub gave me the most and the most critical timeouts when trying to work anywhere outside the big cities.

Related network tuning advice for Ubuntu users:
[Creating a Captive Page to Sign into any Public Network 
(a.k.a. "There is no Internet"](https://dev.to/ingosteinke/creating-a-captive-page-to-sign-into-any-public-network-19a4)

{% post https://dev.to/ingosteinke/creating-a-captive-page-to-sign-into-any-public-network-19a4 %}

## Discussion

Maybe you're a network expert or you had similar latency issues with your Ubuntu machine? What are your experiences and suggestions? Which tools and metrics do you use to measure network quality?