Ubuntu Wi-Fi not working? Here's how to fix it. How to enable wifi on a laptop? Connecting to wifi in ubuntu via terminal


Ubuntu is a powerful, free, open-source operating system source code, which is good for beginners who want to explore Linux and seasoned professionals who want a reliable, secure system for projects and the like. However, despite all its advantages, sometimes you may have problems connecting to Wi-Fi networks.

Connection problem

WiFi can be in both hardware and software. Here are some effective solutions if users are facing problem connecting to Wi-Fi networks.


Problem 1: Device not detected


If the wireless device is not detected by Ubuntu (or any distro for that matter), you will need to access a terminal and enter the following command:


sudo lsusb

if you are using the plugin in USB wireless card/key.


sudo lspci
if you have internal wireless card.

If the response from these commands comes back with output similar to the screenshot below, then you are in luck, Ubuntu can find the map. This is usually defined by "Network Controller" or "Ethernet Controller".


In the past, many Linux distributions had difficulty finding a wireless card. Luckily the support has gotten a lot better so this is now a rare occurrence.


Additional commands


You can also use the following command to check whether the machine can see the wireless device, the user may need lshw first install it on your computer.


lshw -C network

The result should resemble something like this:
*-network description:

Wireless interface product:

PRO/Wireless 3945ABG Network Connection vendor:

Intel Corporation


If so and the system finds the wireless card, you can proceed to install the driver/module as shown below.


Problem 2: Driver module is missing


Following successful teams lsusb And lspci, assuming Ubuntu can see the wireless card, you can assume that the firmware is working, it's just that the system has no idea what to do with the card. Where is it
necessary drivers or modules.


Go back to the terminal and enter the following command:


sudo lsmod


You see a list of modules used. To activate your module, enter the following command, where "modulename" is the name of your chipset.


sudo modprobe modulename

For example, if your wireless chipset is "RT2870", it will be as follows.


sudo modprobe rt2800usb

After that run the command lsmod again to check if it is loaded correctly.


sudo nano /etc/modules

The Nano text editor will open. Now add your module name at the bottom and save the file. You will then need to restart your computer and check if the wireless card can now see the network so you can connect normally.

If you get stuck, repeat this process. Luckily, Ubuntu has helpful help pages in its online documentation that you can read as well. Alternatively, you can use the built-in help in the terminal by typing:


man lsusb

man lspci


Problem 3: DNS


It's rare that DNS will be an issue, but it's worth investigating if you're having connectivity issues. In a terminal, enter the following command to evaluate where the DNS is coming from.


nmcli device show wlan1 | grep IP4.DNS

This will show you the address local network in the router. If this doesn't work, you may need to change " wlan1» to what your wireless connection is using. The following command can also be used to capture the notation:


ip address

Once you have this information, the next method is to ping your router's address. If it works, try checking Google's DNS servers


ping 8.8.8.8

As a result of this, you can determine where the DNS problem is. If all devices in your home or office are experiencing page loading errors, change your router's DNS server to Google or open DNS servers. You'll need to check with your router manufacturer on how to do this, but this is usually done from the admin pages most often by logging in to 192.168.0.1 or similar.

If your DNS problem is Ubuntu only, follow these steps using the Network Manager GUI.


  1. Right click on Network Manager.
  2. Change connections.
  3. Select a suitable Wi-Fi connection.
  4. Select IPv4 Settings.
  5. Change the method for DHCP addresses only.
  6. Add 8.8.8.8, 8.8.4.4 to the DNS servers field. Be aware of commas separating IP addresses and do not leave spaces.
  7. Save, then close.

As a final step, restart your computer or restart Network Manager from a terminal.

Perhaps you have already managed to “transplant” all your home devices to wireless Internet. Even if this is so, not all configuration issues can be considered closed. Especially when the decision is made to switch to the free and free operating system Ubuntu. No other OS offers the freedom to customize and manage resources like Linux. This fully applies to its distributions. When using Ubuntu, setting up Wi-Fi is of utmost importance. After all, a rare OS will allow you to use even half of its capabilities without Internet access.

Today, a very common option for using Wi-Fi is when a wire from a modem is connected to the router. And the router already broadcasts the wireless signal where it is needed. And buying new laptop, you probably expect to set everything up according to the “plug and forget” principle. When it comes to Ubuntu, not all devices can provide the functionality you need wireless communication. So how do you set up Wi-Fi if it doesn't work out of the box?

You may have already tried Wi-Fi, but nothing worked. For some unknown reason, the computer does not find any available networks, and the signal is always zero. It’s even worse if the wireless network adapter is not detected. Well, fully tuned new computer- is very rare, so installing all the necessary options is your task. We will look at installing drivers on Broadcom devices. They are quite common. We will explain in detail how to set up Wi-Fi on Ubuntu.


"$sudolspci | grep Network".


"$lspci -nn -d 14e4:".

  • After this, you need to check the cards supported by the driver and the data received by the command. If there are no matches, you need to select another driver.
  • You also need to find out about the firmware that will be required for the driver to work properly. This can be done in the driver documentation.

IMPORTANT. On the website https://wireless.wiki.kernel.org/en/users/drivers you will find the drivers themselves, descriptions, firmware, as well as step by step instructions by use.

  • Before you launch required driver, you need to disable the launch of some equipment modules - to avoid conflicts in operation:

"$ sudo modprobe -r module name." Here the name is written without any characters, separated by a space.

  • To prevent the disabled from loading again, do this:

"$ vi /etc/modprobe.d/blacklist-bcm.conf
blacklist module name
blacklist module name
blacklist module name"

  • Run the driver using the command:

"$ sudo modprobebrcmsmac."

We looked at the first stage of how to set up Wi-Fi on Ubuntu. Next, let's try in practice to connect to a wireless network using a terminal.

Connection setup

Of course, you can use the GUI to configure Wi-Fi in Ubuntu Server. However, there are often cases when this method is not applicable. In addition, using the console, you will receive very informative data about the networks that you can work with. The setup principles are the same across all Linux distributions, so you can: necessary actions in any OS based on Li.0nix. For example, we are using a WPA connection. Using WEP on this moment is not justified, since the security level of such a network connection is too weak.


"$sudo iwlist scan."

This query in the console will allow you to see the available networks and their characteristics. Find the ESSID parameter. It denotes the name assigned to the network and will be used to work with it.


"$wpa_passphrase(network name)>wpa.conf."

The network name is filled in separated by a space, without other characters.

  • Enter the password to access the network in the console. It will be automatically saved in the configuration file.

You can now fully use the graphical interface to use Wi-Fi in Ubuntu.

Creating an access point

Now we will look at how to create a Wi-Fi access point in Ubuntu. As you know, an access point is an “extension” of an already existing wireless network, or a base for creating a completely new network. Wi-Fi setup Ubuntu Server in this role is best done in a graphical interface.

  1. First of all, you need to disconnect your computer from all networks to which it is currently connected.
  2. Connect your computer to the wired network for which you will create an access point. The Taskbar should show that the PC has a wired connection.
  3. Call up menu network connections by clicking the right mouse button. Click Edit Connection. After that, add a new connection.
  4. Select “Wi-Fi” from the list and click the “Create” button.
  5. Start setting up your new connection. To do this, enter all the current parameters that may be useful. This:
  • Hotspot mode.
  • Connection name and
  • Data encryption mode. It is advisable to select WPA2 or WPA.
  1. Save your current settings. After you set up Wi-Fi, you need to turn it on. Select "Connect to a hidden network." After that, find the network that you recently created in the list and create a connection to it.
  2. Now you can use the access point as convenient as possible!

In conclusion

We learned how to do several useful techniques. We learned in detail how to set up Wi-Fi on Ubuntu, and also diagnosed network faults. If you still have questions, or any problems are not resolved, you can always contact us in the comments, leave your opinion or ask something from visitors to our site. Go for it!

If you are the owner of any mobile device governed by OS Linux, then you will first have to think about completing task number one - setting up a connection with a wireless point Wifi access. Default, standard tools For Linux desktops reliable and easy to use. For example, Wifi Radar, Network Manager, and many other programs of this class. Of course, it is assumed that you are using environments like Gnome or KDE, which have very rich functionality and choice.

But what if you have something different and rarer - an E17, Fluxbox, ION, or even a bare console? In this case you should use classic way settings - command line.

Let's look at two cases of setting up a connection with a wireless access point:

  • graphical application Wicd (for example);
  • console utilities.

Introduction

It is assumed that you have a wireless network device (adapter) that runs under Linux. If you suddenly find that your device is not working, you can suggest, as one of the options for beginners, to install latest version distribution Ubuntu and install proprietary drivers for your wireless card. The proposed case is the simplest and most effective, compared to attempts to make the adapter work through the ndiswrapper driver.
It also assumes that you have two parameters available to connect to the wireless point: SSID and identification key. Without them (especially without the second one, since the first one can still be easily recognized) you will not be able to establish a connection.

Wicd

Wicd is a graphical application written in Python. Flexible and easy-to-use program offering great functionality. Wicd is easy to install and easy to use. It only takes a few minutes to get acquainted with the program. It is also worth noting that Wicd, in addition to the graphical interface, also has a console version of “execution”, which is not inferior in functionality.

Command line

Let's now see how to configure wifi-connection via command line. By the way, this method is universal, since it uses utilities that are standard for all distributions Linux. Moreover, all GUI applications are based on these utilities. Figuratively speaking, if we “remove” the GUI “roof” from any graphical application, then under it we will see the modest and inconspicuous workers of the console: ifconfig, wireless-tools, wpa_supplicant, ping, nmap and many others.

To complete our task you will need the following utilities:

  • ifconfig: completely controls the work of any network adapter your computer (whether wired or wireless);
  • iwlist: displays a list of wireless access points available for connection (within range);
  • iwconfig: wireless management and configuration utility network devices(adapters);
  • dhclient(or its taxes): automatically obtains an IP address from the dhcp server wireless point;
  • wpa_supplicant: utility for setting up encrypted connections.

Before you start setting up wifi-connection, it would be logical to check the presence of all these utilities in the system (although almost all of them are included in the standard set Linux-distributions). Let's, nevertheless, make sure that we have them by running very simple commands (see man which):

  • which ifconfig
  • which iwlist
  • which iwconfig
  • which dhclient
  • which wpa_supplicant

When you run each of these commands, you will see the path where they are located in file system. If you suddenly don’t see it, you’ll have to install the missing ones. The simplest and most recommended is the package manager of that distribution Linux which you are using. As an alternative, you can offer installation from sources, but this path requires sufficient experience from the user.

Let's look at an example of connecting to a wifi point with WEP encryption

  1. The first thing we will do is look at what network adapters we have on our computer:
# ifconfig -a

The output will contain the names and detailed description all network interfaces that the utility was able to detect ifconfig. If the desired one was not found, then the reason is only one thing - there are no drivers for it and support for this interface is not enabled in the Linux kernel.

  1. Launch the wireless network adapter:
# ifconfig wlan0 up
  • wlan0- standard in most Linux-system name wifi-cards;
  • up- the option tells the ifconfig command to launch (“raise”) the network device.
  1. Now we need to scan the air around us for available hot-spots:
# iwlist wlan0 scan
  • wlan0- name of the wireless adapter;
  • scan- the iwlist command is launched in scanning mode.

The result of the work iwlist there will be a detailed report, from which at this stage we are only interested in one line: ESSID: "Some_Name". The value of the ESSID parameter ("Some_Name") is the name of the wireless access point. Now we know which one specifically wifi-point we will connect.

  1. Making the connection:
# iwconfig wlan0 essid Some_Name key Wireless_Key
  • wlan0- network adapter on which the connection is configured;
  • essid- set the name of the access point to which we connect;
  • key- indicate the encryption key used by this access point to transfer data.

Comment:

Team iwconfig By default, it uses HEX data for the encryption key. If you want to specify the key in plain text (ASCII), you need to use the s option.
For example, like this:

# iwconfig wlan0 essid Some_Name key s:Wireless_Key

The connection has been established.

  1. The last step is to get the IP address from the wifi hotspot’s dhcp server:
# dhclient wlan0

Naturally, performing the above steps every time is tedious. We can simplify the connection setup process by writing a connection script in which we combine all these commands into one:

#! /bin/bash ifconfig wlan0 up iwconfig wlan0 essid Some_Name key s:Wireless_Key sleep 10 dhclient wlan0

Here we have added another sleep command with a parameter of 10 seconds. It is recommended to do this before obtaining an IP address to ensure the reliability of the connection.
Save this file under some name (for example, wireless_up) and make it executed by the command:

# chmod u+x wireless_up

Move wireless_up to /usr/local/bin to make it globally visible to the entire system. Now you just need to dial in command line:

# wireless_up

and the connection will be established.

Let's consider a more complex case - connecting to an access point using WPA encryption

Connections with such encryption are supported only by the utility wpa_supplicant, so we need it. Also, again, we assume that we know the encryption key (password) for this access point.

  1. We generate a password based on this key using the utility wpa_passphrase, which is included in the package wpa_supplicant. The fact is that the password that we will use further must be in the form of a hexadecimal number:
# wpa_passphrase ssid password

The utility will display the generated psk line, which we will insert into the wpa_supplicant.conf configuration file:

# sudo nano -w /etc/wpa_supplicant.conf Network=( ssid=SSID psk=PSK )

This is a very simplified configuration file, but it will work. You may need to add another line to the head of this file:

Ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=wheel

to provide the necessary access rights.
2. “Raise” the wlan0 interface:

# ifconfig wlan0 up

  1. We indicate which point we want to connect to:
# iwconfig wlan0 essid ssid
  1. Run the wpa_supplicant utility to establish a connection:
# wpa_supplicant -B -Dwext -i wlan0 -c /etc/wpa_supplicant.conf
  • -B- run the command wpa_supplicant in the background;
  • -Dwext- we tell the utility wpa_supplicant use wext driver for interface wlan0;
  • -i- set a custom network interface (wlan0 in our case);
  • -With- specify the path to the wpa_supplicant.conf configuration file.
  1. We check that the connection is established:
# iwconfig wlan0

On the output we will see detailed information on the specified interface wlan0.

  1. We get the local IP address:
# dhclient wlan0

7. We simplify the process by creating an entry along the path /etc/network/interfaces that looks like this:

Auto wlan0 iface wlan0 inet dhcp pre-up wpa_supplicant -Bw -Dwext -i wlan0 -c /etc/wpa_supplicant.conf post-down killall -q wpa_supplicant

Conclusion

Depending on the distribution Linux, there are many ways to configure wifi- connections. It is thanks to this diversity that you can set up a connection in almost any Linux-system.

The main thing is that you wireless adapter supported in Linux at the driver level. But this already depends mainly on operating system developers.

WITH Wi-Fi support adapters in Ubuntu are observed certain problems. It’s good if you can choose a known compatible model when purchasing, but more often you have to use the equipment that you have. In this case, you will have to install the adapter yourself. Today we will look at just such a case.

Looking ahead, let's say that there is nothing complicated about connecting unsupported Wi-Fi adapters. Despite the fact that a number of actions we perform can be performed using a graphical interface, we will work exclusively in the console, which will allow us to use the recommendations in this article for both desktop and server versions of Ubuntu.

For example, consider connecting an inexpensive USB adapter in Ubuntu 12.04 LTS TP-Link TL-WN725N.

Let's go to the home directory and download the repository archive, having previously elevated the rights to superuser:

Sudo-s
cd ~
wget "https://github.com/lwfinger/rtl8188eu/archive/master.zip"

Let's unpack the archive (if necessary, install unzip).

Unzip master.zip

As you can see from the command output, the contents of the archive were unpacked into the directory rtl8188eu-master, go to it and build the module:

Cd rtl8188eu-master
make

After building the module, it should appear in the directory file 8188eu.ko, this is the required kernel module. Now install it with the command:

Make install

All that remains is to enable our module by running the command:

Modprobe 8188eu

or simply disconnect and reconnect the adapter. On a desktop system, you will immediately see a message about the ability to connect to a wireless network.

Or run the command in the console:

Ifconfig

In the output you will see the wireless interface appear wlan0.

As you can see, there is nothing complicated. However, you should remember that the module is built and installed under the current version of the kernel, and when updating it, you will need to build and install the module again. If this is not possible, then you should hold Shift When loading, select and load the kernel version for which the module is built.

This guide explains how to connect your computer to the network using configuration files and console utilities. The main goal is to talk about in various ways connecting to the Internet without using a GUI (graphical interface). The guide does not cover topics such as setting up network filters or, for example, your own Wi-Fi access points. It is assumed that there is a certain method of connecting to the Internet provided by the provider, to use which you must follow the steps below.

The guide provides examples of editing configuration files using text editors"nano" and "gedit". Please note that the first editor is launched in the terminal and can be used either when running Ubuntu with or without a GUI, while "gedit" can only be used when the GUI is enabled.

System requirements

Any system installation option is suitable to reproduce the actions described in the manual. A graphical user interface is not required. All actions must be performed in the console. It is understood that commands starting with the $ symbol must be executed as a user, and those starting with # must be executed as a superuser (root).

Before you begin, make sure that:

    Various network filters(for example iptables), and their configuration utilities (for example, Firestarter) are disabled/correctly configured and do not interfere with the network.

    You have all the necessary parameters for connecting on your network (for example, IP address, subnet mask and default gateway for a connection using a static IP).

    Network devices that filter by MAC address are correctly configured and “know” your network interface.

    The driver of your network device is installed correctly, the cable (for a wired connection) is working properly and connected.

For settings, you will definitely need the name of your network adapter. You can find it out from the command output:

$ sudo lshw -C network

It allows you to view connected network devices.

Example command output:

Ubuntu@ubuntu:~$ sudo lshw -C network *-network description: Ethernet interface # Device type product: L2 100 Mbit Ethernet Adapter # Adapter name vendor: Attansic Technology Corp. # Device manufacturer physical id: 0 bus info: pci@0000:03:00.0 logical name: eth0 # Network interface name version: a0 serial: 00:00:00:00:00:00 # Physical address of the device (mac address) size: 100MB/s capacity: 100MB/s width: 64 bits clock: 33MHz capabilities: pm msi pciexpress vpd bus_master cap_list ethernet physical tp 10bt 10bt-fd 100bt 100bt-fd autonegotiation configuration: autonegotiation=on broadcast=yes driver=atl2 # Used driver driverversion=2.2.3 # Driver version duplex=full firmware=L2 ip=192.168.0.5 latency=0 link=yes # Availability of link module=atl2 multicast=yes port=twisted pair speed=100MB/s # Current connection speed.

Pay attention to the line:

Logical name: eth0

eth0 is the desired name of the network interface.

The name eth0 will be further used to configure this particular network card. Where eth indicates that the Ethernet interface is used, and 0 is the device number. If you have several network devices installed, then, accordingly, they will be given names: eth0, eth1, eth2, etc.

After the implementation of SystemD (since Ubuntu 15.04), network interfaces may have other names (not ethX). This was done so that the names of network devices do not change when new adapters are connected to the machine (in Lately, some USB modems act as a network adapter). As a result, eth0 can be called for example enp0s4 or eno1, or even enx78e7d1ea46da. This is the name of the network adapter that should be used in setting up the network.

You can read more about the naming of network interfaces in SystemD (English).

This renaming can be disabled by adding /etc/default/grub, to a string with a variable GRUB_CMDLINE_LINUX_DEFAULT line net.ifnames=0. After this you need to do sudo update-grub

Setting up a wired network

Setting IP address, default gateway, subnet mask

/etc/network/interfaces, for example like this:

And add to it:
For static IP:

Iface eth0 inet static address 192.168.0.1 netmask 255.255.255.0 gateway 192.168.0.254 dns-nameservers 192.168.0.254 8.8.8.8 auto eth0

    Iface eth0 inet static - indicates that the interface (iface eth0) is in the IPv4 (inet) address range with a static ip (static);

    Address 192.168.0.1 - indicates that the IP address (address) of our network card is 192.168.0.1;

    Netmask 255.255.255.0 - indicates that our subnet mask (netmask) is 255.255.255.0;

    Gateway 192.168.0.254 - default gateway address 192.168.0.254;

    Dns-nameservers 192.168.0.254 8.8.8.8 - DNS server addresses (we’ll talk about the bottom ones later)

    Auto eth0 - indicates to the system that the eth0 interface should be enabled automatically when the system boots with the above parameters.

eth0- the name of your interface being connected. The list of interfaces can be viewed by typing:

$ip addr

As a result, the file /etc/network/interfaces should look something like this:
(for one wired connection with static IP)

# This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). # The loopback network interface auto lo iface lo inet loopback # My wired network. iface eth0 inet static address 192.168.0.1 netmask 255.255.255.0 gateway 192.168.0.254 dns-nameservers 192.168.0.254 8.8.8.8 auto eth0

Save the file and close the editor. IN in this example(nano editor) - press Ctrl + X , then Y , make sure the "Write File Name" is /etc/network/interfaces and press Enter .

More details about file syntax /etc/network/interfaces can be read in the documentation.

Example configuration for dynamic IP:

Iface eth0 inet dhcp auto eth0

Temporarily setting the IP address and subnet mask

If you need to set test settings, do:

$ sudo ip addr add 192.168.0.1/24 dev eth0

Where 192.168.0.1 is our IP address, /24 is the number of bits in the prefix part of the address (corresponding to the subnet mask 255.255.255.0).
eth0- plug-in network interface.

These settings will disappear after a system reboot and will not affect the file /etc/network/interfaces

DNS Settings

The resolvconf utility, which works in tandem with a small DNS caching server dnsmasq, is responsible for the DNS configuration. resolvconf allows you to do DNS settings based on data from different subsystems.
One of the consequences of this useful innovation (the transition to this scheme occurred in Ubuntu starting with version 12.04) is that now the /etc/resolv.conf file is generated automatically, and not individually by each program that wants to change it (sometimes overwriting changes made earlier ). Automatic generation of /etc/resolv.conf means that manual changes made to it will be lost.
The automatically generated /etc/resolv.conf contains a link to the DNS server on the local interface (127.0.1.1), and there (on port 53) sits the dnsmasq service, which is responsible for resolving symbolic names into IP addresses. It should be noted that this port (53) is open in LISTEN mode, but since Since this is a local interface, this port is not accessible from the external network.
DNS information for static interfaces must now be entered in /etc/network/interfaces in the dns-nameservers, dns-search and dns-domain parameters (which correspond to the nameserver, search and domain parameters in /etc/resolv.conf)

Please note that in /etc/resolv.conf, when recording several servers, several nameserver keys are used, and in /etc/network/interfaces all DNS server addresses were written in one line after the dns-nameservers key, separated by spaces.

As a result, the description of the static interface in /etc/network/interfaces should look something like this:

Iface eth0 inet static address 192.168.0.1 netmask 255.255.255.0 gateway 192.168.0.254 dns-nameservers 8.8.8.8 192.168.0.254 auto eth0

Ubuntu up to version 12.04

In older versions of ubuntu, when there is a need to specify static addresses DNS servers (if they are not provided automatically) run:

$ sudo gedit /etc/resolv.conf

and enter the DNS server addresses there (separate records for each server):

Nameserver 192.168.0.100 nameserver 192.168.0.200

Where 192.168.0.100 and 192.168.0.200 are the DNS server addresses. If you need to add more addresses, each address must start with new line and from the phrase nameserver

Setting up ppp connections

The daemon is responsible for creating point-to-point connections in Ubuntu. pppd, more detailed information about which is available in the documentation. Within this manual examples of creating will be considered PPPoE connections via a DSL modem, PPTP connections (VPN connections) and DIAL-UP connections via a regular modem.

PPPoE connection

To standard installing Ubuntu includes a utility for setting up PPPoE connections – pppoeconf, to launch it, type:

$ sudo pppoeconf

A “pseudographic” window will appear in the terminal. The utility will search for network devices and display them on the screen, then it will search for a modem on these devices. If at this stage pppoeconf gives a negative result, check the correct connection and power supply of the modem. The next step is choosing “popular options” - in most cases you should agree. Next, the utility will ask for your login and then a password. Now - choosing a method for specifying DNS servers. Again, in most cases you should agree to receive DNS server addresses automatically. Next, you will be asked to limit the MSS size to 1452 bytes - as a rule, you should agree. The next question is whether to establish a connection automatically when the computer boots. The last question from the utility is whether to establish a connection now. pppoeconf by default creates the name dsl-provider for the connection. You can manage the connection using the commands:

$ sudo pon dsl-provider # To connect or $ sudo poff dsl-provider # To disconnect

If in your case the options provided by the utility pppoeconf is not enough - consult the pppd or pppoeconf documentation.

Note: when setting up a connection using pppoeconf Some settings are written to /etc/network/interfaces, as a result of which Network Manager can no longer manage the network. Exit: either use only NM, or only console + configs. You can return control of Network Manager as follows. Bring /etc/network/interfaces to the following form (it is not necessary to delete the excess, just comment it out):

# This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). # The loopback network interface auto lo iface lo inet loopback

Restart the network:

Reboot or restart Network Manager:

$ sudo /etc/init.d/NetworkManager restart

PPTP connection

To make a VPN connection using pppd you will need to install the package pptp-linux, which can be found at installation disk Ubuntu. Next, create (as root) in the folder /etc/ppp/peers file with the name of your provider and edit it, for example like this:

$ sudo nano /etc/ppp/peers/my-provider

And add connection options there, for example:

Persist # If the connection is broken, reconnect again. maxfail 0 # Maximum number of failed connection attempts. 0 - infinite. mtu 1476 # Value MTU name (login) # Your login. #nodefaultroute # Do not be the default gateway defaultroute # Be the default gateway replacedefaultroute # Replace the default gateway if it was remotename (vpn) # The name of the remote server (for us), can be anything. pty "pptp (server_address) --nolaunchpppd" # Command to launch pptp. # Server address - can be either an IP address or domain name, for example vpn.foo.bar

(login) (vpn) (password)

After the system reboots, you will be able to manage the connection using the commands:

The process of setting up a VPN connection can be greatly simplified by a script assistant.

Setting up DIAL-UP connection

To configure a modem connection, you can use the built-in configurator pppd - pppconfig or special utility wvdial .

Using pppconfig

Setup process using pppconfig looks a lot like a utility pppoeconfig, You will be asked one by one questions about the connection parameters, and will be asked to enter your phone number, login and password, as well as the connection name. You should run pppconfig with superuser rights. For example like this:

$sudo pppconfig

You can manage the connection like this:

$ sudo pon my-provider # To connect or $ sudo poff my-provider # To disconnect

Where my-provider is the name you assigned to the connection during setup.

Using wvdial

In some cases (for example, when connecting using mobile phone), more convenient to use wvdial. To do this, you need to install it first. For example like this:

$ sudo apt-get install wvdial

Included in the package wvdial includes an automatic configuration utility - wvdialconf .

$sudo wvdialconf

The output will be something like this:

Ubuntu@ubuntu:~$ sudo wvdialconf password for ubuntu: Editing `/etc/wvdial.conf". Scanning your serial ports for a modem. Modem Port Scan<*1>: S0 S1 S2 S3 WvModem<*1>: Cannot get information for serial port. ttyACM0<*1>: ATQ0 V1 E1 -- ​​OK ttyACM0<*1>: ATQ0 V1 E1 Z -- OK ttyACM0<*1>: ATQ0 V1 E1 S0=0 -- OK ttyACM0<*1>: ATQ0 V1 E1 S0=0 &C1 -- OK ttyACM0<*1>: ATQ0 V1 E1 S0=0 &C1 &D2 -- OK ttyACM0<*1>: ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0 -- OK ttyACM0<*1>: Modem Identifier: ATI -- Manufacturer: QUALCOMM INCORPORATED ttyACM0<*1>: Speed ​​4800: AT -- OK ttyACM0<*1>: Speed ​​9600: AT -- OK ttyACM0<*1>: Speed ​​19200: AT -- OK ttyACM0<*1>: Speed ​​38400: AT -- OK ttyACM0<*1>: Speed ​​57600: AT -- OK ttyACM0<*1>: Speed ​​115200: AT -- OK ttyACM0<*1>: Speed ​​230400: AT -- OK ttyACM0<*1>: Speed ​​460800: AT -- OK ttyACM0<*1>: Max speed is 460800; that should be safe. ttyACM0<*1>: ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0 -- OK Found an USB modem on /dev/ttyACM0. Modem configuration written to /etc/wvdial.conf. ttyACM0 : Speed ​​460800; init "ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0"

Now all that remains is to edit the file /etc/wvdial.conf and add your phone number, login and password to it.

$ sudo nano /etc/wvdial.conf

Init1 = ATZ Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0 Modem Type = USB Modem ISDN = 0 Idle Seconds = 0 New PPPD = yes Dial Attempts = 0 Phone = #777 Modem = /dev/ttyACM0 Username = mobile Password = internet Baud = 460800 Idle Seconds = 0 # Time connection downtime, # after which you will need to break it. Value 0 - never. Dial Attempts = 0 # Number of dial attempts. 0 - infinite. Dial Command = ATDP # Dial command (P - pulse, T - tone). Makes sense for pulse dialing on older PBXs.

The /etc/wvdial.conf file is divided into sections, the separators of which are the section names themselves, preceded by the word Dialer, in square brackets. If you execute the command without parameters, then the settings listed in the Defaults section will be used. Otherwise, the commands specified in the additional sections will be additionally executed.

Now that everything is configured, the connection can be established by typing:

$sudo wvdial

If you need to start wvdial with pulse dialing, you can do this with the command

$ sudo wvdial pulse

You can terminate the connection by interrupting the execution of the wvdial command, i.e. in the same terminal you need to press Ctrl + C.

Automatic connection

Edit the configuration file /etc/network/interfaces, for example like this:

$ sudo nano /etc/network/interfaces

And add to it:
For pppoe, pptp, and modem connection without using wvdial :

Iface ppp0 inet ppp provider my-provider auto ppp0

Where my-provider- the name of your connection.
Using wvdial:

Iface ppp0 inet wvdial provider wvdial auto ppp0

Now on restart network services the connection will be automatically established.

Manual routing setup

If you do not receive the default gateway address from the server you are connecting to, or for any other reason you need to specify routes manually, you can create your own script in /etc/ppp/ip-up.d/, or according to the recommendation of the official documentation, create /etc/ppp/ip-up.local for example like this:

$ sudo nano /etc/ppp/ip-up.local

$ sudo nano /etc/ppp/ip-up.d/routing

with the following code:

#! /bin/sh # route del default route add default ppp0 # Ppp connection name. # here are the necessary routes, for example: route add -net 192.168.0.0 netmask 255.255.255.0 gw 192.168.0.1 dev eth0

$ sudo chmod ug+x /etc/ppp/ip-up.local

$ sudo chmod ug+x /etc/ppp/ip-up.d/routing

Now routes will be automatically connected when a ppp connection is established.

Setting MTU and TTL

MTU (Maximum Transfer Unit) - the parameter determines the value of the maximum transfer unit. This is the maximum number of octets (bytes) that the interface is capable of supporting in a single transmit/receive operation. For Ethernet this default value is 1500 ( maximum size Ethernet packet).

TTL (Time To Live) - lifetime of an IP packet in seconds. Needed to avoid overloading the network with packets. Typically, each router through which the packet passed reduces the TTL by one. If TTL=0, the packet is removed from the system. Initially TTL=128 (for Windows) and TTL=64 (for Ubuntu). For DNS records, TTL determines how long the data is up to date when caching requests.

To change the MTU value, edit the configuration file /etc/network/interfaces, for example like this:

Auto eth0 iface eth0 inet static address 192.168.1.5 netmask 255.255.255.0 mtu 600

To change the TTL value, type:

$ sudo su then # echo "128" > /proc/sys/net/ipv4/ip_default_ttl

The TTL value changes only with administrator rights, to log out of the administrator account, enter exit

WiFi setup

Setting up Wi-Fi using wpa-supplicant and /etc/network/interfaces

This chapter will talk about setting up a connection to an existing Wi-Fi networks using WPA2, the most secure encryption and authentication standard available today. Additionally, examples of settings for less secure connections are provided.

If you can influence the settings of the access point, for example, if it is your home Wi-Fi router- try to configure authorization using WPA2, because it is the most secure authentication protocol in wireless networks Nowadays.

Notes

Problem solving

Wi-Fi/Ethernet connection with access point/router cannot be established

Symptoms: The network usually initially works fine, for a long or short time, and then suddenly disappears and does not appear after a reboot. This problem may not be permanent. The network starts working “by itself” and then disappears again. When restarting the network adapter this way:

Sudo ifdown wlan0 sudo ifup wlan0

similar text will be displayed in the console

Listening on LPF/wlan0/00-02-2A-E1-E0-6C Sending on LPF/wlan0/00-02-2A-E1-E0-6C Sending on Socket/fallback DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 8 DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 8 DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 15 No DHCPOFFERS received. No working leases in persistent database - sleeping.

Cause of the problem maybe that motherboard It is not completely de-energized when the computer is turned off. In this case, some peripheral equipment is probably not de-energized, incl. may not be de-energized usb ports. If you are using, for example, a Wi-Fi USB adapter, then you can notice the LED on the adapter is lit (if it is equipped with one). The problem probably occurs because the network equipment does not work entirely correctly in this mode.

A simple solution The problem is to turn off the computer and unplug the power cord from the outlet, then plug in the power cord and turn on the computer.

Difficult decision The problem is setting the BIOS parameters to completely de-energize network equipment when turning off the computer.

Sometimes the Wi-Fi connection to the access point/router drops completely

Symptoms: the network initially works, and then after rebooting the access point/router it suddenly disappears, and does not appear either after a reboot or after dancing with a tambourine. In this case, the wireless adapter does not see the access point point-blank (although it may be standing next to the computer), but it perfectly sees all neighboring networks. Then, after the ~tenth~ reboot of the router, the network reappears by itself.

Cause of the problem It may be that some routers arbitrarily select the working channel number, ignoring the channel number selected in the router settings. If the channel number for the wireless interface is listed in the /etc/network/interfaces file, then this is likely the problem. Channel number 6 is indicated in the file something like this:

Auto wlan0 ... wireless-channel 6

A simple solution The problem is to comment out this parameter so that the adapter is not limited to only this channel, and restart the network

Auto wlan0 ... #wireless-channel 6

Difficult decision The problem is to register the bug on the website of the router manufacturer (firmware for it) and update the router firmware after (if) it is fixed.

Restarting the network

Now that all the necessary steps have been completed, you can restart the network and check the connection. For this:

$ sudo /etc/init.d/networking restart

Now, when you run the ip addr command, the eth0 connection with the configured parameters should be displayed. If the connection is visible, but the parameters are not the same as those specified in the /etc/network/interfaces file, or any other errors occur, double-check this file for inaccuracies or typos and try restarting the network again.

Network FAQ

How to log into my computer from outside (via the Internet)?

First, you need to find out what IP address your provider gives you - gray or white (not to be confused with static/dynamic). If it's gray, then nothing will work. If white, then two options are possible:

    There is no router or it is operating in bridge mode. In this case, a white IP address is assigned to the computer itself. We enter the address - we get to the computer, everything is simple.

    The white address is assigned to the router. Accordingly, this address takes us to the router, and not to the computer. To get to the computer, you need to forward ports on the router (see below).

I think my network is too slow!

Measure the network speed between two computers using iperf. You can use this instruction. It suggests compiling the program from source, but you can simply install it from the repository. If iperf shows a value slightly lower than expected, then everything is fine with the network, the problem may be in the hardware (hard drive/processor cannot provide high speed), in the transfer method (for example, scp and ftp are very slow), in the settings ( speed can be limited, for example, by settings FTP servers) or something else. If iperf showed a value that is several times less than desired, then yes, there is a problem with the network. It’s worth checking whether the card is working in the required mode (for example, using ethtool), checking for “errors” in the ifconfig output, and testing the connection speed to a third computer.

How can I find out what programs are listening on ports on my computer?

To view a list of open ports and the names of programs listening to them, use the command:

Sudo netstat -nlpA inet,inet6

To display information about specific port you can use grep. For example, for 80 port:

Sudo netstat -nlpA inet,inet6 | grep:80

It is not always clear from the netstat output which program is being referred to (for example, 2671/python), ps will tell you more about the process:

PS aux | grep 2671

How to assign two IP addresses to one network card?

For example, the interface eth0 need to add address 192.168.1.1 . Briefly, until the network is restarted:

Sudo ip addr add 192.168.1.1/24 dev eth0

Forever - add the following to /etc/network/interfaces:

#fix line auto auto eth0 eth0:1 # add alias iface eth0:1 inet static address 192.168.1.1 netmask 255.255.255.0

How to forward a port?

For example, you need to forward port 8081. Let's call the address to which the client accesses external_ip, and the address to which it should go is internal_ip.

Iptables -t nat -A PREROUTING -p tcp -d external_ir --dport 8081 -j DNAT --to-destination internal_ir:8081 iptables -t nat -A POSTROUTING -p tcp --dst internal_ir --dport 8081 -j SNAT - -to-source external_ir

And you definitely need something like

Iptables -t filter -A FORWARD -m conntrack --ctstate DNAT -j ACCEPT