How to speed up your internet connection on Linux
The speed of your internet connection is something that is affected by a lot of different elements, most of which are out of your reach and/or jurisdiction. That said, there isn't a way to transform a slow internet connection into a lighting-speed one if your provider is just not giving you enough bandwidth, no matter what you do. This post is only aiming to provide generic advice on how to make things a little bit better if possible, and if applicable to each case.
Sometimes browsing websites seems to be somewhat “clunky” with images not loading correctly, large latency values between your computer and the DNS resolving server, and online cache issues. This may be a sign that your internet provider's DNS are not up to the task, so you may have to change to an alternative option. The two most popular DNS server alternatives are the Google Public DNS and the OpenDNS, but there are a lot more free to use alternatives as well.
Here's how to change to the Google Public DNS on Ubuntu-based distributions. Open your network settings and hop onto the “Advanced Settings”. This will open up a new window where you will find the “IPv4 and IPv6 Settings” tabs. Navigate to both and change the “Method” from Automatic (DHCP) to Automatic (DHCP) Addresses only. Then insert “18.104.22.168” on the DNS servers box of the IPv4 tab, and “2001:4860:4860::8888” on the IPv6 tab. Now, click the “Save” button and you're done.
To test whether your new DNS settings are working properly or not, insert any fixed IP address that points to a website and see if it gets correctly resolved. Insert “22.214.171.124” on your browser address bar and if it gets resolved to ubuntu.com, then you have done things right. You may always revert to your default DNS by leaving the DNS servers box blank and setting the method back to “Automatic (DHCP)”. You can also benchmark your new DNS by using the namebench open source DNS benchmarking utility, and see how much faster your internet browsing really got. It is worth noting that changing your DNS also improves your privacy, security, and may potentially open up access to geoblocked content.
Firewall and Security
It is often the case that aggressive firewalls cause bottlenecks to your regular browsing and downloading. If you don't really need them, change their settings to allow more traffic to pass back and forth without proactive checking, or completely disable them. You can open a terminal and give “sudo iptables -L” to determine what is you Linux kernel-level firewall settings. For higher-level firewalls, you will need to check your router settings and the specific software tools you are using for this purpose.
If you're using Fedora or CentOS, chances are SELinux will be enabled by default. This otherwise magnificent piece of software could possibly cause increased latencies so you may want to disable it. To do so, open the /etc/sysconfig/selinux configuration file as root and find the line that contains “SELINUX=enforcing” and change it to “SELINUX=disabled” and save the file. Hopefully, things will get somewhat faster by doing this, but you should consider the required security level in your system before disabling SELINUX. A median solution would be the “SELINUX=permissive” option that keeps the security module active, but limited to the printing of warning messages.
MTU stands for Maximum Transmission Unit and it is basically a parameter that determines the maximum size of data packets that are allowed to be transferred from the network to your system. If the MTU value is too small, then you are crippling your speed by dealing with large number of packages, and if it is too large, you are letting the data transmission occupy significant portions of your bandwidth for larger periods of time, essentially causing lag. So, there is a golden ratio as in everything really and if you want to squeeze the maximum performance out of your internet connection, you can determine and set your MTU to an optimal value.
Open a new terminal session and start ping tests to see what the optimal MTU value is. Use the following command:
ping -M do -s 1472 howtoforge.com
Start with 1472 and drop 10 by 10 until you find the highest value that is indicating 0% packet loss, using “Ctrl+C” to cancel each ping.
After you have determined the optimal MTU value, go to /etc/network/interfaces:
And add a line “mtu 1462” (or whatever value you found as the best) and save the file. Note that you need to open the configuration file as the system administrator or else you won't be able to save your changes. Hopefully, this will speed things up a bit without causing network data package errors.
If all of the above has failed to deliver anything truly noteworthy, you may want to resort to the browser settings as a final attempt to give your internet browsing a small boost to the better. Firefox and Chrome/Chromium have started to tentatively use a simpler and faster caching method that may speed up your regular browsing a little bit. To enable them do the following:
On Chrome, insert the following on the address bar and press enter:
Then locate the “Simple Cache for HTTP” and choose the enable option.
On Firefox, insert the following on the address bar and press enter:
Then search for browser.cache.use_new_backend and double click it to open a new config window. Change the “0” value to “1” and press “OK” and you're done.
Finally, you can use the Opera browser that offers an up to date Linux version. Opera features a “Turbo mode” that when enabled activates a server-side compression of images on a rate to up to 80%, essentially letting you browse more comfortably on slower internet connections.