Who uses the network in linux. Networking, networking in Unix systems

Modern computer provides the user with many opportunities, without a good half of which he could easily do without. To this day, there is a debate on the net about whether it needs 3D graphics and high-quality sound. However, there is one function, the need for which is not disputed by anyone - this is access to the network.

Free OS connoisseurs argue that Linux is built for the web, like a bird for flight. True, they immediately make an allowance for the fact that only the elite will see the true power of this system, since setting up network interfaces is a difficult task and requires serious knowledge.

It is difficult to argue with this statement, since its comprehensive nature is obvious. Indeed, without having special skills, even stools cannot be put together. Nevertheless, here we are dealing with some exaggeration. Linux is a simple system. The Windows user has to keep much more information in memory in order to ensure comfortable work with it.

So that the last statement does not look unfounded, consider the procedure for setting up a network in Linux system. Moreover, as is customary in the free software world, there is not one way, but several options. And the user himself will choose the one that he likes best.

ifconfig command

As a rule, network adapter drivers are connected during system installation. To verify this, just type ifconfig -a in the console. By the way, this name is not at all a mangled name for the ipconfig command familiar to Windows users. It's just short for Interface Configuration.

In response, the user will receive information about the characteristics of the Ethernet connection and the parameters of the so-called ring interface. The first is designated as eth0 (if there are several network adapters, then each will have its own eth[sequence number] section), and the second as lo.

The same command can be used to activate the interface. Most often it looks like this:

ifconfig [interface name] netmask [netmask] broadcast [broadcast address] up.

However, in practice, all parameters may not be specified. For example, if the netmask and broadcast address are not set explicitly, then the system will use the default values ​​(network address with machine part 255 and mask 255.255.255.0).

The pointopoint option must be used to activate PLIP, SLIP and PPP. In this case, the interfaces will be named like this:

– plip[sequence number starting from zero] — for PLIP;

– slip[sequence number starting from zero] — for SLIP;

– ppp[sequence number starting from zero] — for PPP.

For example, to configure a PLIP interface that connects two computers at addresses [address1] and [address2], type in the console:

ifconfig plip0 [address1] pointopoint [address2].

Disabling an interface is done with the ifconfig [interface designation] down command. Thus, using just one command, you can control a network device. And of course, there is no point in keeping all its options in memory - if you forgot something, then man ifconfig will always come to the rescue.

route command

The route command is responsible for routing. That is, it tells the system to which network computer packets should be sent in order to reach their destination.

This command displays the routing table. In addition, each entry consists of several fields:

– Destination—IP address of the route's destination;

– Gateway — IP address or name of the gateway (if it is not present, then the symbol “*” is used);

– Genmask — route network mask;

– Flags — route type or state indicator (can take the following values: U—active, H—host, C—gateway, D—dynamic, M—modified);

– MSS is the maximum amount of data transmitted at one time;

– Metric—number of hops to the gateway;

– Ref—number of requests to the route at a certain point in time;

Window - the maximum amount of data for the receiving side;

– Use—number of packets transmitted along the route;

– Iface—interface type.

To add an address to the routing table, use the route command with the add option. It should be noted that if the corresponding interface has already been configured using ifconfig, then the system itself can obtain information about it. In this case, there is no point in using specifiers - it is enough to specify the address of the destination. All other data will be redundant, and therefore optional.

Obviously, at least one entry must be made in the routing table in order to work on the network. The default destination is indicated by the default label.

Use the route del -net command to delete a route.

Other commands

If the interface settings are stored in the system, then the ifup and ifdown commands can be used to quickly activate and deactivate, as follows:

– ifup [interface designation] — to enable.

– ifdown [interface designation] — to disable.

To display a list of network connections, routing tables, interface statistics, etc., use netstat command. Among other things, it allows you to display the status of the connection, which is useful when analyzing the system for its security.

For example, LISTEN means that the service is waiting for a connection to another machine, and ESTABLISHED means that it has already been established. If there are no running programs for which this state is normal, then this may be unsafe and indicate an attack on the host.

Configuration files

The above commands are enough to configure the network. However, these utilities have one significant drawback: the result of their work will be valid for only one session. After the reboot, everything will have to start over. For this reason, it is much more convenient to edit the configuration files once.

Despite the fact that their device is independent of the distribution, they can be located in different places. For example, in Debian, the /etc/init.d/network file is responsible for setting up interfaces and routing, and in Slackware (MOPS, Zenwalk) it is /etc/rc.d/rc.inet1. There is only one universal piece of advice that can be given in this regard: when starting to work with a particular product, be sure to read the technical documentation.

As an example, consider the ASPLinux distribution. The /etc/sysconfig/network-scripts/ directory is used to store network interface settings. Each of them is defined by the ifcfg-[interface designator] file.

This file consists of lines of the form: [parameter]=[value]. The parameters can be the following:

– NAME—arbitrary connection name;

– DEVICE—interface designation;

– IPADDR — interface IP address;

– NETMASK—network mask;

– GATEWAY — gateway IP address;

– ONBOOT — pointer to the need to activate during boot;

– USERCTL—indicates that an ordinary user can activate the interface;

– MTU — MTU value (maximum packet size transmitted through the interface);

– PEERDNS—indicates the need to use the DNS servers obtained when the interface was activated;

– DNS1, DNS2 — IP addresses of primary and secondary DNS servers;

– BOOTPROTO — interface configuration mode indicator (none — using user parameters, boottp or dhcp — using appropriate protocols).

The /etc/host.conf and /etc/resolv.conf files are responsible for configuring DNS. The first one is the usual text file, which specifies the rules for the operation of the subsystem for searching for names and addresses of hosts. Its structure is typical for all objects of this type - each line contains a parameter and its values ​​(there may be several of them).

The order parameter specifies the method for finding the node's IP address. It can take the following values: bind (use DNS server), hosts (use local address database), nis (use NIS server). They must be in the order in which the search will be performed.

The trim parameter is used to describe exceptions. The corresponding line specifies the domain that will be automatically removed from the name.

The reorder parameter can take on/off values. It is responsible for enabling the mode of operation in which local addresses take precedence over all found ones. Spoofalert turns on the mode of writing the results of checking for false names to the system log. And multi allows you to customize the method of processing the local base of nodes. Of course, it is not necessary to specify all parameters. In practice, there are often /etc/host.conf files that consist of two lines.

The /etc/resolv.conf file describes some of the options that are used by the name lookup subsystem. It may consist of the following lines:

– nameserver—addresses of DNS servers;

– domain — name of the local domain to search for addresses in local network;

– search — list of domains to search for addresses.

Obviously, the domain and search parameters cannot be relevant at the same time. If the system detects this contradiction, it will consider only the last entry.

Or can Linux not use a nameserver at all? Theoretically, yes, although in practice the method described below is used only in very small networks, where other methods are not justified.

The way is to use the /etc/hosts file. It is a list of hostnames and their IP addresses, and more than one name can be specified for one address.

Graphical customization tools

Although setting up a network by directly editing configuration files is not a very difficult task, almost all modern distributions offer the user graphical tools designed to solve it. Even Zenwalk, which is not usually considered friendly in the Windows sense of the word, allows you to configure network interfaces without using the command line.

And today we have the right to say that in addition to elementary settings, the user can perform quite complex operations. In particular, a few years ago, the topic of setting up a VPN connection in Linux occupied a prominent place on the technical support forums, and all the proposed methods for solving this problem could not be called simple. But times are changing.

For example, users of the Linux XP Desktop distribution set up a VPN connection using a convenient GUI tool that is even simpler than the similar tool in Windows. Approximately the same is offered to the consumer by ASPLinux, Mandriva and SuSE Linux.

All in all, Linux is truly built for the web. And this can be appreciated not only advanced users but also newbies.

Linux was originally designed for networking, so networking is one of the strengths of Linux.

Linux supports popular network protocols such as TCP/IP and SMB (NetBIOS) and has advanced tools for monitoring and filtering network traffic. Linux provides services such as FTP, web server, Windows file and print server. Linux even provides the ability to centrally manage services, Virtual Private Networking (VPN), and remote procedure calls.

Linux can work with any network hardware for which it has a driver. Linux drivers are either built into the kernel or compiled as loadable modules. Many common network cards supported by the Linux kernel by default. When choosing network equipment, you should use devices listed in the "Hardware Compatibility List". Use the most latest versions Linux distributions.


As a rule, if you are using compatible network equipment, your card will be automatically recognized during system installation. You can check the network hardware detected by the system using the ifconfig command. By default, ifconfig shows you active network devices. To see all network devices, add the -a switch:

Leave your comment!

Before starting setup network connection in Linux, you need to start by looking at what network settings are currently in use. To do this, you need to use the command ifconfig. In information mode, it is available without ROOT rights, although for its full use it is better to obtain superuser privileges by entering the command sudo ifconfig. The result of its work will be a list of network connections available in the system and their parameters.

In different versions of Linux, the name of the network interface can be an abbreviation for Ethernet - eth0, eth1, eth2, etc.

On the interface lo - short for loopback - that is, a local loop with the address 127.0.0.1 .
For example, consider the Eth0 interface.
In line inet addr displays the current IP address of the computer on the local network connected to this network card. In the example it is: 192.168.1.144
Bcast- This is a broadcast address on the network, the so-called Broadcast (Broadcast).
Mask is the netmask.
HWaddr- this is the hardware address of the network card, it is also the MAC address used at the data link layer.

We learned information about current connections, now let's look at setting up a local network in Linux. You can do this in three ways:
1 - Through the graphical shell
2 - via command ifconfig or tool network manager
3 - through the configuration files of the Netork or Networking network service.

In my opinion, the last method is the most convenient and reliable, and therefore the correct one. To set up a network in Linux, you need to open the file containing the interface config. It all depends on what Linux distribution used.

Option 1: On Debian-based distributions (Ubuntu, Kubuntu, etc.)

File with network connection parameters:

/etc/network/interfaces

In order to change into linux settings network, you need to file it with as root any text editor. For example, via nano:

sudo nano /etc/network/interfaces

To automatically obtain addresses from a DHCP server, write the following:

Allow-hotplug eth0 iface eth0 inet dhcp

If the address needs to be registered statically, then specify the following:

Allow-hotplug eth0 iface eth0 inet static address 192.168.1.2 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255 gateway 192.168.1.1 dns-nameservers 192.168.1.1

This config considers an example of a normal home network, where the computer address will be 192.168.1.2, the address of the gateway and DNS server (their functions are usually performed by a wifi router) - .

Option 2. RedHat-based distributions (Fedora, OpenSuse, CentOS)

Linux network settings file:

/etc/sysconfig/network-scripts/ifcfg-eth0

We open it in the same way through nano or vim:

Vim /etc/sysconfig/network-scripts/ifcfg-eth0

If automatically receiving settings from a DHCP server:

DEVICE=eth0 BOOTPROTO=dhcp HWADDR=00-1C-1B-11-F6-07 ONBOOT=yes

Static IP address:

DEVICE=eth0 HWADDR=00-1C-1B-11-F6-07 IPADDR=192.168.1.2 NETMASK=255.255.255.0 BROADCAST=192.168.1.255 GATEWAY=192.168.1.1 ONBOOT=yes

The IP addresses of the DNS servers in this case are written in the file

/etc/resolv.conf

Here is an example for public DNS servers from Google:

Nameserver 8.8.8.8 nameserver 8.8.4.4

Network setup in Linux is complete. It remains only to restart the network with the command:

Service network restart

Actually everything.

As a postscript, I'll tell you how to turn the network on and off in Linux. This is done through the same ifconfig command. Disable eth0 network card:

sudo ifconfig eth0 down

Enable the network card in Linux back:

sudo ifconfig eth0 up

Completely stop all network interfaces.

Service network stop

/etc/init.d/network stop

Turn everything back on:

Service network start

/etc/init.d/network restart

To systematize information on setting up a network in Linux OS, it was decided to write this note. Here, in an accessible form, the process of setting up a network interface is described using the Ubuntu OS as an example. Also, this guide will help you "raise" the local network on any other Linux distribution.

To view the current network settings and the status of network interfaces in Linux OS, there is a command:

Sample output:

eth0 Link encap:Ethernet Hwaddr 00:11:5b:91:25:3e

inet addr:192.168.1.18 bcast:192.168.255.255 Mask:255.255.0.0
inet6 addr: fe80::211:5bff:fe91:253e/64 Range:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:648009 errors:0 dropped:0 overruns:0 frame:0
TX packets:1075413 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:70177943 (70.1 MB) TX bytes:1536487024 (1.5 GB)
Aborted:19 Base address:0xd000

lo Link encap:Loopback

inet addr:127.0.0.1Mask:255.0.0.0
inet6 addr: ::1/128 Range:Node
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:106 errors:0 dropped:0 overruns:0 frame:0
TX packets:106 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:13776 (13.7 KB) TX bytes:13776 (13.7 KB)

To view absolutely all network interfaces, run the command with the key -a:

# sudo ifconfig -a

From the above example, you can see that the computer uses two network interfaces: eth0 And lo.

Interface lo is a local loop that has an IP address of 127.0.0.1 and is intended for network access to its own computer. Further, this interface will not be considered, since it does not require additional configuration for effective operation.

Interface eth0 is an Ethernet network card that has network parameters: IP address - 192.168.1.18 , netmask - 255.255.0.0 and MAC address - 00:11:5b:91:25:3e. Meaning RUNNING indicates that the network interface eth0 is currently up.

To view the connection type, speed and parameters supported by the eth0 network interface, type the command:

# sudo ethtool eth0

Conclusion:

Supported ports: [ TP MII ]
Supported link modes:10baseT/Half 10baseT/Full

100baseT/Half 100baseT/Full

Supports auto negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full

100baseT/Half 100baseT/Full

Advertised auto-negotiation: Yes
Speed: 100Mb/s
Duplex: Full
Port: MII
PHYAD: 1
Transceiver: internal
Auto negotiation: on
Supports Wake-on: pg
Wake-on: d
Current message level: 0x000000c5 (197)
Link detected: yes

From the output, you can see that the eth0 network interface is running at 100Mbps with Full Duplex enabled. Full duplex differs from half duplex (Half Duplex) in that the first provides data transfer in both directions at the same time, and the second transfers incoming and outgoing data alternately.

2. How to stop/start or restart the network interface?

To stop the network interface eth0, there is a command:

# sudo ifconfig eth0 down

The command is easy to remember, since after the name of the command itself comes the name of the interface and after the action to be performed on it (down or up).

To resume network interface eth0:

# sudo ifconfig eth0 up

To restart all network interfaces of the OS, enter the command:

# sudo /etc/init.d/networking restart

This line runs the networking bash script, which restarts the system's network interfaces.

Similarly, by analogy, all interfaces are stopped:

# sudo /etc/init.d/networking stop

And running them:

# sudo /etc/init.d/networking start

3. How to change network settings?

There are two ways to change network settings in Linux OS:
  1. use commands to assign network interface parameters;
  2. edit the configuration file containing the parameters of network interfaces.

You can set up the network using one of the above methods. These two methods are completely interchangeable. Who is more accustomed to

  1. Network setup using commands.

    To configure the network interface without getting into the jungle of the configuration file, you need to use special commands.

    To set the primary IP address and netmask for the eth0 interface:

    # sudo ifconfig eth0 192.168.0.1 netmask 255.255.255.0

    To assign an additional IP address to the eth0 interface:

    # sudo ifconfig eth0:0 10.10.0.1 netmask 255.255.255.0

  2. Network setup by editing the configuration file.

    Let's edit the configuration file /etc/network/interfaces. To display the contents of the config, type the command:

    # sudo nano /etc/network/interfaces

    If the local network to which we are connecting implies manual setting IP addresses, the contents of the configuration file should look something like this:

    iface lo inet loopback

    auto eth0
    iface eth0 inet static
    address 192.168.1.18
    netmask 255.255.0.0
    gateway 192.168.1.253

    We leave the first lines as they are, since they additional setting not required.

    Line auto eth0 says that the eth0 network interface should start when the OS boots.

    Second line iface eth0 inet static says that the IP address of the eth0 network interface is set manually.

    Line address 192.168.1.18 says that the eth0 network interface is assigned the IP address 192.168.1.18 (this network address is taken as an example and can be any other in its place).

    Line netmask 255.255.0.0 says the netmask is 255.255.0.0.

    Last line gateway 192.168.1.253 indicates that the network gateway is a computer with an IP address of 192.168.1.253. This line may be absent, since its presence in the configuration file depends on the settings of the local network to which the configured computer is connected.

    If the connected local network uses automatic distribution of network settings by a DHCP server, then the configuration file /etc/network/interfaces should be rendered as:

    iface lo inet loopback

    auto eth0
    iface eth0 inet dhcp

4. Additional network settings: DNS servers, MAC addresses and network interface speed.

Setting up a DNS server.

Also, in many cases, for the correct operation of the local network on the computer being configured, you will need to enter the IP address of the DNS server used.

To do this, open the configuration file with the command:

# sudo nano /etc/resolv.conf

Conclusion:

# Generated by NetworkManager
nameserver 192.168.1.253

Line nameserver 192.168.1.253 says that the computer with the IP address 192.168.1.253 is used as the DNS server.

Change the MAC address of the network card.

To temporarily change the MAC address of the eth0 network card, you need to use the command:

# sudo ifconfig eth0 hw ether 00:01:02:03:04:05

The last number is the new MAC address.

To change the MAC address permanently, you need in the configuration file /etc/network/interfaces add a line with a new MAC address to the network interface settings:

iface eth0 inet dhcp

pre-up ifconfig eth0 hw ether 00:01:02:03:04:05

Change the speed of the network interface.

To strictly set the network card speed:

# sudo ethtool -s eth0 speed 100 duplex full autoneg off

# Force network interface speed to 100Mbit and Full Duplex mode and disable auto-detection

# sudo ethtool -s eth0 speed 10 duplex half autoneg off

# Force network interface speed to 10Mbit and Half Duplex mode and disable auto-detection

Random 7 articles:

Comments

  1. Sergo
    1 November, 23:27

    thanks a lot for the article! in Linux recently, it helped a lot, can you tell me if there are two network dns-servers in the computer, one has a network dns-server 192.168.0.9, and the other has 192.168.1.9, for example, it will be correct to write
    nameserver 192.168.0.9
    nameserver 192.168.1.9
    Setevukha to whom what dns will understand?
    And is it possible to assign a name to a network card in Linux, for example, eth0 is loc, and eth1 is prov?

  2. [email protected]
    November 2, 00:07

    1. DNS can specify both, but network masks should be specified as 255.255.255.0. Then they will go to their DNS `am.

    2. I don't know about network names. I think you can, it's Linux!!

  3. Sergo
    November 2, 03:44

    turn off the interface
    ifconfig eth0 down
    give a command
    ifrename -i eth0 -n new_name (e.g. local)
    ifconfig local up
    then in your Linux it will probably be necessary to change some eth0 to local in the /etc/network/interfaces file, I just have an alt, and this file does not exist at all, I have /etc/net/ifaces/folders_with_interfaces, and now I need the eth0 folder rename to local, and then
    service network restart :)

  4. [email protected]
    November 2, 08:45

    Will need to add to the article, thanks))

  5. gpns
    14 May, 17:36

    I think it's worth correcting the line: sudo ifconfig eth0:0 10.10.0.1 netmask 255.255.255.0
    alias cannot have /24 mask (255.255.255.0), this is not an error, because in any case, the eth0:0 interface will be assigned the mask /32 (255.255.255.255)
    In your case it would be: sudo ifconfig eth0:0 10.10.0.1/32

  6. [email protected]
    16 May, 12:02

    gps: I think it's worth correcting the line: sudo ifconfig eth0:0 10.10.0.1 netmask 255.255.255.0 in any case, the eth0:0 interface will be given the mask /32 (255.255.255.255) In your case it will be: sudo ifconfig eth0:0 10.10.0.1/32

    Damn, you turned my whole mind upside down. You will have to redo the network interface settings on the computer, which have been working for almost 2 years.
    Why then the team ifconfig the mask that I set is shown?

  7. HydruS
    13 September, 23:32

    Plain language! Clear and understandable! Thanks a lot!
    P.S. Only in command entry listings would it be nice to make a font where 0 is visually different from O.

  8. [email protected]
    14 September, 18:34

    HydroS: P.S. Only in command entry listings would it be nice to make a font where 0 is visually different from O.

    Thanks, I'll take it into account. Although there seems to be a difference, to the point)

  9. andrey
    18 September, 23:50

    thanks for your site. I like! everything is intelligible and understandable
    I have a question for you. if possible, please tell me how to set up the network so that the LAN and DSL connection work at the same time.
    I can't figure out how to do this???

  10. [email protected]
    20 September, 07:18

    andrey: thanks for your site. I like! Everything is intelligible and understandable, I have a question for you. if possible, please tell me how to set up the network so that the LAN and DSL connection work at the same time.

    To be honest, I have not come across DSL connections for a long time. Tell me more:
    1. What is the local network? Behind the modem or on another network?

  11. andrey
    20 September, 18:38

    the most common connection is the city network
    computer connected via network card
    Internet access is connected via a DSL connection

  12. [email protected]
    21 September, 17:22

    andrey: the most common connection is a city network the computer is connected via a network card Internet access is connected via a DSL connection

    In my opinion, you need to configure the modem itself. Look to the side Dual PPPOE
    I did something similar on the D-Link DIR -320 router, but not once on the modem.

  13. andrey
    21 September, 18:22

    Thank you!!! I will look for!

  14. Serpent22
    November 3, 06:21

    To the words about DSL through a local network: I took a lot of steam, rummaged through a bunch of mana (I have Debian Lenny) and in order to save other people from the same rake, I’ll say that pppoeconf does not help everyone, for example, the Internet appeared for a couple of seconds and miraculously disappeared . Configs, logs did not help. But after two weeks and a pile of torn hair, I came across a simple ifconfig ppp0 mtu 1372 command. I hope this helps someone. I spoke out, it became easier)))

  15. Nick
    7 December, 09:17

    Good afternoon, in my etc folder there is neither a network folder nor a net folder, it costs centos 5.7, tell me what to do

  16. Marina
    27 December, 21:12

    Hello, this problem happened. The computer is connected to the Internet through a router .. The problem is that some sites do not open - it writes a dns conversion error .. What needs to be done. for everything to work properly? Thank you in advance!!

  17. papick
    30 July, 17:05

    Artem: 2 network cards. on one screw network with the domain. in the second, an adsl modem with a PPPoE connection is plugged in. how to make it possible to work on the network and on the internet ?!

    for example, write routing rules on the machine in such a way that packets destined for the local network are sent to etn0, and all the rest to etn1
    but this topic is beyond the scope of this article.

  18. Compomer
    29 August, 03:01

    Quite a good article. Thanks a lot

  19. valera
    21 January, 07:20

    I’ve only been on linux for 3 months, but I’ve already tried 17 pieces, but no one wants to connect dsl \ immediately breaks the LAN \ left zorin and put ALT - I work like homework, but for the Piggy network \ 7 - demolished like everyone else \.if- If I had a network on ALT, then until the end of my life ... I've only mastered the computer for 7 years - it's already old.

mob_info