Hosts file in Linux. Linux hosts file Linux hosts file

I want to tell you about a somewhat non-standard way with which you can open sites in a browser using short names. For example, instead of typing “yandex.ru” in your browser, you can simply type one letter “y”. The file /etc/hosts will help us with this.

File /etc/hosts

The /etc/hosts file specifies correspondence between the IP address and the host name (hostname, domain), as well as their aliases (also called synonyms, aliases). When you access an address on the network, for example, http://yandex.ru, to access the site, the system must first convert the site address into its corresponding IP address; for this, the system requests the IP address from the DNS server. If the /etc/hosts file contains a correspondence between yandex.ru and an IP address, then the system will use this particular IP address. And since we can also specify an alias in the /etc/hosts file, through which a specific IP address will be accessible, we can specify, for example, the alias “y” for yandex.ru. Accordingly, when you request “y” in your browser, the system will read the IP address in the /etc/hosts file and open the yandex.ru website. That is, /etc/hosts is a kind of local DNS server.

How to find out the IP address of a site

Now we need to determine the IP addresses of the sites that we want to add to /etc/hosts. It is worth noting that not all sites have a separate dedicated IP address and it is impossible to access them only by IP address. But almost all large sites and portals have their own dedicated IP address. An easy way to find out the IP address of a site is to use the ping command:

Ping site-address.ru

For example, let's do:

ping yandex.ru

The ping process will be displayed on the screen (to interrupt, press Ctrl+C). So, we will get the output of the ping command like this:

PING yandex.ru (87.250.250.11) 56(84) bytes of data. 64 bytes from yandex.ru (87.250.250.11): icmp_seq=1 ttl=57 time=3.57 ms ...

Here you can see that yandex.ru corresponds to the IP address 87.250.250.11. We do the same for other sites.

Editing the /etc/hosts file

You need to edit the /etc/hosts file carefully so as not to spoil anything, as this system file and it is important not to break its syntax. Open the file for editing, to do this run in command line:

Sudo gedit /etc/hosts

The contents of the file look something like this:

127.0.0.1 localhost::1 mycomp localhost6.localdomain6 localhost6 127.0.1.1 mycomp # The following lines are desirable for IPv6 capable hosts::1 localhost ip6-localhost ip6-loopback fe00::0 ip6-localnet ...

The syntax for the /etc/hosts file is very simple:

IP address hostname [aliases, ...]

Let's add new lines to the file for different sites:

74.125.232.19 google.ru g 94.100.191.203 mail.ru m 194.186.36.211 rbc.ru r 87.250.250.11 yandex.ru y

Save and close the file. We have written correspondences between IP addresses, site names and their aliases. Now go to your browser and address bar Just enter “g” and the website google.ru should open. To open mail.ru, enter simply “m”, for rbc.ru - simply “r”, yandex.ru - “y”.

Author Shekin Reading 6 min Published by July 21, 2015

A little-known feature called “ the hosts file” can be used to modify your system depending on your needs. Whether you need to create abbreviations to block websites or something else , all of this can be done using the hosts file.
But how can I make changes to it? Here we will tell you how, and provide some examples, so you can start using the file right now.

What is the hosts file?
If we talk in plain language, the hosts file is a simple text file that can be used on any operating system for translating host names into IP addresses. When you type a host name – for example, facebook.com or website – your system will check the hosts file to get the IP address, which is required for connecting to the appropriate server. But if you open this file on your computer, you will quickly find that there is not stored a directory of all websites on the Internet. There may be just a few lines and nothing more. Your system is always first checks the hosts file, and everything not specified in it, will be found on the DNS servers configured in your network settings (usually a server of your Internet provider).

But it also means that you can use the Hosts file to add addresses that cannot be provided DNS servers (for example, it may be aliases of different locations on your home network that otherwise would be available only if the local network is installed and configured your own DNS server), or to bypass the IP addresses provided by your DNS servers by default.

For example, if you ask your browser to open facebook.com the DNS server will return the IP address of Facebook on your PC. But if you suddenly want to block Facebook on your computer, you can add to hosts file entry that points to your computer that all requests for facebook.com need to redirect to some other IP address that is different from the real IP address of Facebook. To block this social network, you can simply register a transfer of requests facebook.com the IP address 127.0.0.1 , which will always return to your system. You can do a lot with this file, and this is just a very simple example – it all depends on your desires and needs.

Warning : keep in mind, hosts this is a system file, edit it only if you know what you’re doing it !

How to edit hosts file
In Linux Mint you can find hosts file in /etc/hosts. Since this is a plain text file, you can just use a plain text editor (whether terminal or graphical). Unfortunately, there is only one graphic tool that provides partial control of the hosts file is the application Domain Blocker for Linux Mint.

This program works by adding entries to your hosts file which redirects your specified domains to 127.0.0.1 – that is on your computer. Anyway, that’s all you can do with Domain Blocker– all other uses of the hosts file require you to manually edit the file with a text editor.

As hosts it is a system file , you’ll need administrative rights to save changes to the file. However, you can edit it using terminal commands such as

sudo nano /etc/hosts

sudo gedit /etc/hosts

You can also replace the nano or gedit on the command to start your favorite text editor . When you're finished editing the file in nano , you can press Ctrl +X and then y to confirm the overwriting of changes.

How to understand the format of the contents of the hosts file?
In the hosts file each record is on its own line. For the purposes of our article you can use a very simple syntax – you type the IP address to which you want to redirect the host name (domain) , then the tab character (TAB) and the actual domain . For example, to block Facebook, you can enter 127.0.0.1-facebook.com where is the Tab key on your keyboard. To make sure it is entered correctly, you can also look at the screenshot and compare it with what is in your file.

Hosts – change and manage the /etc/hosts file

Here is another example of use of this opportunity. For example, if your home network is the computer (for example, its IP address is 192.168.100.1) running a simple website that makes something useful for you. You can enter the following in the hosts file: 192.168.100.1 –myhomeserver. Now, if you open your browser and just type in the address bar http://myhomeserver it will automatically show you the contents of the host 192.168.100.10. It is much easier than to enter the IP address every time.

Potential problems
The only problem that I came across, related to the work of the Chrome browser. Chrome tends to ignore the hosts file, if you don’t do at least one of two possible things:
– to enter http:// in front of each address. For example, if you blocked Facebook via hosts file, Chrome will bypass the lock if you simply enter facebook.com in the address bar. If you enter http://facebook.com in the address bar, Chrome “listen” hosts file and block the website of this social network.
– disable the option “ Use a web service to help resolve navigation errors ” in the Chrome settings, and then you don’t have to type http:// before the address each time

Try it!
Hosts is a small magic file, which offers several useful features. Even if you don’t need any features that it provides (although, perhaps, you think), to see how it works will be very helpful. If you ever get into a situation where you could use the hosts file, you are familiar with them and know how to configure.

What is in your hosts file? Are there any unique cases of such use? Tell us in the comments!

The Domain Name System (DNS) is used to determine which IP belongs to a given domain on the Internet. When any program needs to access a site by its domain name, the operating system sends a request to the DNS server to find out which IP to forward packets to. But this doesn't always happen. For example, when we access the localhost domain, the request is always sent to our local computer.

The reason for everything hosts file. If you've used Windows before, you've probably already heard about this file. There, it was most often used to quickly block access to a resource. But its application is much wider. In this article we will look at how to configure the hosts file in Linux, as well as what capabilities it provides us.

Before we move on to the hosts file itself, we need to understand how to look up an IP address for a domain name in Linux. I said that the operating system immediately sends a request to the DNS server, but this is not entirely true. There is a specific search order according to which it is performed. This order is set in the /etc/nsswitch.conf configuration file

cat /etc/nsswitch.conf

Here we are interested in the hosts line. It lists, in order of priority, the services that are used to find an IP address for a domain name. The files item means using the /etc/hosts file, and dns means the Internet domain name service. If files is located before hosts, this means that first the system will try to find the domain in /etc/hosts, and only then using DNS. By default, this is the case.

Setting up the hosts file in Linux

The file we need is located in the /etc/ directory. To open it, you can use any text editor both on the command line and in graphical interface, you just need to open it with superuser rights. For example, using vim:

sudo vi /etc/hosts

sudo gedit /etc/hosts

The file syntax is quite simple. It contains several lines with domain names and the IP addresses that need to be used for them. Each of them looks like this:

ip_address domain alias

Usually the first line creates a rule to redirect all requests to the localhost domain to the local IP address - 127.0.0.1:

127.0.0.1 localhost

This file also contains redirections for your computer name and IPv6 addresses by default. You can create your own settings for any desired domain. To do this, add a line to the end of the file ..0.0.1:

127.0.0.1 site

Please note that only the domain is indicated here, without the protocol. There is no need to specify the http or https prefix, otherwise nothing will work. But for the www subdomain you need to create a separate entry or write it as an alias. For example:

127.0.0..site

Now, when requesting a domain, the site will open our local IP. To return access to the original resource, just remove the added line. But you can use not only a local address, but also any other one. This is very convenient if you have just registered a domain and the domain zone has not yet been updated, but you already want to work with a new site. Just add the details to /etc/hosts and work as usual.

conclusions

In this short article we looked at how to do DNS setting via Linux hosts file. As you can see, with its help you can block access to unwanted resources, for example, which programs should not have access to, and also use it in your work as a webmaster.

about the author

Founder and administrator of the site, I am fond of open software and operating room Linux system. I currently use Ubuntu as my main OS. In addition to Linux, I am interested in everything related to information technology and modern science.

Good afternoon, dear readers. I am publishing the second part. In the current part the main emphasis is on network implementation in Linux(how to set up a network in Linux, how to diagnose a network in Linux and maintain the network subsystem in Linux).

Configuring TCP/IP in Linux to work on an Ethernet network

To work with network protocols TCP/IP in Linux is enough to have only loopback interface, but if it is necessary to connect hosts with each other, naturally, it is necessary to have a network interface, data transmission channels (for example, twisted pair), perhaps some network equipment. Also, it is necessary to have installed ones (, etc.), usually supplied to. It is also necessary to have a network (for example /etc/hosts) and network support.

Network settings

Let's start understanding Linux network mechanisms with manual network configuration, that is, with the case when IP address network interface static. So, when setting up a network, you need to consider and configure the following parameters:

IP address- as already mentioned in the first part of the article - this is the unique address of the machine, in the format of four decimal numbers separated by dots. Usually, when working in local network, selected from private ranges, for example: 192.168.0.1

Subnet mask- also, 4 decimal numbers that determine which part of the address relates to the network/subnet address, and which part to the host address. A subnet mask is a number that is added (in binary form) with an IP address to determine which subnet the address belongs to. For example, the address 192.168.0.2 with a mask of 255.255.255.0 belongs to the subnet 192.168.0.

Subnet address- determined by the subnet mask. However, there are no subnets for loopback interfaces.

Broadcast address- the address used to send broadcast packets that will be received by all hosts on the subnet. Typically, it is equal to the subnet address with a host value of 255, that is, for the subnet 192.168.0 the broadcast will be 192.168.0.255, similarly, for the subnet 192.168 the broadcast will be 192.168.255.255. There is no broadcast address for loopback interfaces.

Gateway IP address- this is the address of the machine that is the default gateway for communication with the outside world. There can be several gateways if the computer is connected to several networks at the same time. The gateway address is not used on isolated networks (not connected to global network), because these networks have nowhere to send packets outside the network, the same applies to loopback interfaces.

Name server IP address (DNS server)- address of the server that converts host names into IP addresses. Usually provided by the provider.

Network settings files in Linux (configuration files)

To understand how the network works in Linux, I would definitely recommend reading the article "". In general, the entire operation of Linux is based on, which is born when the OS boots and produces its descendants, which in turn do all the necessary work, be it launching bash or a daemon. Yes, and the entire Linux boot is based on, which spells out the entire sequence of launching small utilities with various parameters that are sequentially started/stopped when the system starts/stops. The Linux network subsystem starts in the same way.

Each Linux distribution has a slightly different network initialization mechanism, but I think the general picture will be clear after reading. If you look at the start scripts of the network subsystem of any Linux distribution, how to configure the network configuration using configuration files will become more or less clear, for example, in Debian (let’s take this distribution as a basis), a script is responsible for initializing the network /etc/init.d/networking, having looked at which:

Net-server:~#cat /etc/init.d/networking #!/bin/sh -e ### BEGIN INIT INFO # Provides: networking # Required-Start: mountkernfs $local_fs # Required-Stop: $local_fs # Should -Start: ifupdown # Should-Stop: ifupdown # Default-Start: S # Default-Stop: 0 6 # Short-Description: Raise network interfaces. ### END INIT INFO PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" [ -x /sbin/ifup ] || exit 0 . /lib/lsb/init-functions process_options() ( [ -e /etc/network/options ] || return 0 log_warning_msg "/etc/network/options still exists and it will be IGNORED! Read README.Debian of netbase." ) check_network_file_systems() ( [ -e /proc/mounts ] || return 0 if [ -e /etc/iscsi/iscsi.initramfs ]; then log_warning_msg "not deconfiguring network interfaces: iSCSI root is mounted." exit 0 fi exec 9<&0 < /proc/mounts while read DEV MTPT FSTYPE REST; do case $DEV in /dev/nbd*|/dev/nd*|/dev/etherd/e*) log_warning_msg "not deconfiguring network interfaces: network devices still mounted." exit 0 ;; esac case $FSTYPE in nfs|nfs4|smbfs|ncp|ncpfs|cifs|coda|ocfs2|gfs|pvfs|pvfs2|fuse.httpfs|fuse.curlftpfs) log_warning_msg "not deconfiguring network interfaces: network file systems still mounted." exit 0 ;; esac done exec 0<&9 9<&- } check_network_swap() { [ -e /proc/swaps ] || return 0 exec 9<&0 < /proc/swaps while read DEV MTPT FSTYPE REST; do case $DEV in /dev/nbd*|/dev/nd*|/dev/etherd/e*) log_warning_msg "not deconfiguring network interfaces: network swap still mounted." exit 0 ;; esac done exec 0<&9 9<&- } case "$1" in start) process_options log_action_begin_msg "Configuring network interfaces" if ifup -a; then log_action_end_msg $? else log_action_end_msg $? fi ;; stop) check_network_file_systems check_network_swap log_action_begin_msg "Deconfiguring network interfaces" if ifdown -a --exclude=lo; then log_action_end_msg $? else log_action_end_msg $? fi ;; force-reload|restart) process_options log_warning_msg "Running $0 $1 is deprecated because it may not enable again some interfaces" log_action_begin_msg "Reconfiguring network interfaces" ifdown -a --exclude=lo || true if ifup -a --exclude=lo; then log_action_end_msg $? else log_action_end_msg $? fi ;; *) echo "Usage: /etc/init.d/networking {start|stop}" exit 1 ;; esac exit 0

You can find several functions that check for the presence of mounted network file systems ( check_network_file_systems(), check_network_swap()), as well as checking the existence of some still unclear config /etc/network/options ( function process_options()), and at the very bottom, the design case "$1" in and in accordance with the entered parameter (start/stop/force-reload|restart or any other) performs certain actions. Of these same " certain actions", using the start argument as an example, you can see that the function is launched first process_options, then the phrase is sent to the log Configuring network interfaces, and the command is run ifup -a. If you look at man ifup , you can see that this command reads the config from a file /etc/network/interfaces and according to the key -a launches all interfaces that have the parameter auto.

The ifup and ifdown commands may be used to configure (or, respectively, deconfigure) network interfaces based on interface definitions in the file /etc/network/interfaces.

-a, --all
If given to ifup, affect all interfaces marked auto. Interfaces are brought up in the order in which they are defined in /etc/network/interfaces. If given to ifdown, affect all defined interfaces. Interfaces are brought down in the order in which they are currently listed in the state file. Only interfaces defined in /etc/network/interfaces will be brought down.

ip-server:~# cat /etc/network/interfaces # 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 # The primary network interface allow-hotplug eth0 iface eth0 inet dhcp allow-hotplug eth2 iface eth2 inet static address 192.168.1.1 netmask 255.255.255.0 gateway 192.168.1.254 broadcast 192.168.1.255

In this config the lines allow-hotplug And auto- these are synonyms and interfaces will be raised on command ifup -a. This, in fact, is the entire chain of operation of the network subsystem. Similarly, in other distributions: in RedHat and SUSE the network is launched by a script /etc/init.d/network. Having examined it, you can similarly find where the network configuration lies.

/etc/hosts

This file stores a list IP addresses And hostnames corresponding to them (addresses).The file format is no different from the master file:

Ip-server:~# cat /etc/hosts # ip host.in.domain host 127.0.0.1 localhost 127.0.1.1 ip-server.domain.local ip-server 192.168.1.1 ip-server.domain.local ip-server

Historically, this file was used instead of the DNS service. Currently, the file can also be used instead of the DNS service, but only on the condition that the number of machines in your network is measured in units, and not in tens or hundreds, because in this case, you will have to monitor the correctness of this file on each machine.

/etc/hostname

This file contains NetBIOS hostname:

Ip-server:~# cat /etc/hostname ip-server

This file stores the names and addresses of local and other networks. Example:

Ip-server:~# cat /etc/networks default 0.0.0.0 loopback 127.0.0.0 link-local 169.254.0.0 home-network 192.168.1.0

When using this file, networks can be managed by name. For example, do not add a route route add 192.168.1.12 , A route add.

/etc/nsswitch.conf

File defines hostname lookup order/network, the following lines are responsible for this setting:

For hosts: hosts: files dns For networks: networks: files

Parameter files specifies to use the specified files (/etc/hosts And /etc/networks respectively), parameter dns specifies to use the service dns.

/etc/host.conf

The file specifies name resolution parameters for the resolver

Ip-server:~# cat /etc/host.conf multi on

This file tells the resolv library to return all valid host addresses that appear in the /etc/hosts file, and not just the first one.

/etc/resolv.conf

This file defines the parameters of the mechanism for converting network names to IP addresses. In simple terms, defines DNS settings. Example:

Ip-server:~# cat /etc/resolv.conf nameserver 10.0.0.4 nameserver 10.0.0.1 search domain.local

First 2 lines indicate DNS servers. The third line specifies the search domains. If, when resolving a name, the name is not an FQDN name, then this domain will be substituted as an “end”. For example, when executing the ping host command, the pinged address is converted to host.domain.local. The remaining parameters can be read in man resolv.conf. Very often, Linux uses dynamic generation of this file, using the so-called. programs /sbin/resolvconf. This program is an intermediary between services that dynamically provide name servers (for example DHCP client) and services that use name server data. To use a dynamically generated file /etc/resolv.conf, you need to make this file a symbolic link to /etc/resolvconf/run/resolv.conf. In some distributions the path may be different; this will definitely be written in man resolveconf.

Network configuration

After reviewing the main configuration files, you can look at . The command has already been mentioned above ifup, ifdown, but these tools are not entirely universal; for example, RH distributions do not have these commands by default. In addition, new distributions have introduced a new high-level network management tool - which belongs to the iproute package. I will dedicate it to him (the iproute package). And in the current post I will not consider it. The commands described below belong to .

So, to be sure that the command works on any Linux distribution, you need to use two main old commands. This , and arp. The first team (responsible for setting up network interfaces(ip, mask, gateway), second () - routing setup, third (arp) - arp table management. I would like to note that executing these commands without disabling the standard SystemV startup script of the network subsystem will make changes only until the first reboot/restart of the network service, because if you think about it, you can understand that the script /etc/init.d/networking the next time it starts, it will re-read the above configs and apply the old settings. Accordingly, the way out for permanently setting the settings is either to enter the ifconfig command with the appropriate parameters in , or to manually correct the corresponding configs of the network interfaces.

Also, if the command is executed ifconfig with missing parameters(for example, only an IP address), then the rest are added automatically (for example, a broadcast address is added by default with a host address ending in 255 and the default subnet mask is 255.255.255.0).

Routing for existing interfaces in modern kernels it is always raised automatically by the kernel. Or rather, direct routes to the network according to the IP settings and the subnet into which the raised interface looks are formed automatically, by the kernel. The gateway field for such entries indicates the address of the output interface or *. In older versions of the kernel (I can’t tell you the kernel number from which routes began to rise automatically), it was necessary to add the route manually.

If there is a need to organize your routes, then you need to use . With this command you can add and remove routes, but again, this will only help until you restart /etc/init.d/networking (or another script responsible for the network in your distribution). In order for routes to be added automatically, you must, in the same way as with the ifconfig command, add commands for adding routes to rc.local, or manually correct the corresponding network interface configs (for example, in Deb - /etc/network/options).

By what rules routes to networks are formed, I'm in

Linux network diagnostics

There are a large number of network diagnostic tools in Linux, often very similar to utilities from Microsoft. I will look at 3 main network diagnostic utilities, without which it will be difficult to identify problems.

I think that this utility is familiar to almost everyone. This utility works by sending so-called ICMP packets to the remote server, which will be specified in the command parameters, the server returns the sent commands, and pingcounts the time required for the sent packet to reach the server and return. For example:

# ping ya.ru PING ya.ru (87.250.251.3) 56(84) bytes of data. 64 bytes from www.yandex.ru (87.250.251.3): icmp_seq=1 ttl=57 time=42.7 ms 64 bytes from www.yandex.ru (87.250.251.3): icmp_seq=2 ttl=57 time=43.2 ms 64 bytes from www.yandex.ru (87.250.251.3): icmp_seq=3 ttl=57 time=42.5 ms 64 bytes from www.yandex.ru (87.250.251.3): icmp_seq=4 ttl=57 time=42.5 ms 64 bytes from www .yandex.ru (87.250.251.3): icmp_seq=5 ttl=57 time=41.9 ms ^C --- ya.ru ping statistics --- 5 packets transmitted, 5 received, 0% packet loss, time 4012ms rtt min/ avg/max/mdev = 41.922/42.588/43.255/0.500 ms

As can be seen from the above example, ping gives us a bunch of useful information. First of all, we found out that we can establish a connection with the host ya.ru(sometimes they say that “the ya.ru host is available to us”). Secondly, we see that DNS is working correctly, because the “pinged” name was correctly converted to an IP address (PING ya.ru (87.250.251.3)). Further, in field icmp_seq= numbering of sent packets is indicated. Each sent packet is sequentially assigned a number, and if there are “dips” in this numbering, this will tell us that the connection with the “pinged” is unstable, and may also mean that the server to which the packets are sent is overloaded. By value time= we see, how long did the package travel to 87.250.251.3 and back. You can stop the ping utility by pressing Ctrl+C.

Also, ping utility It is interesting because it can allow you to see exactly where the problems occurred. Let's say ping utility displays a message network not reachable (network not available), or other similar message. This most likely indicates that your system is configured incorrectly. In this case, you can send packets to the provider’s IP address to understand where the problem occurs (between the local PC or “further”). If you are connected to the Internet through a router, you can send packets via its IP. Accordingly, if the problem appears already at this stage, this indicates incorrect configuration of the local system, or damage to the cable; if the router is recalled, but the provider’s server is not, then the problem is in the provider’s communication channel, etc. Finally, if the name to IP conversion fails, then you can check the IP connection; if the responses come correctly, then you can guess that the problem is in the DNS.

It should be noted that this utility is not always a reliable diagnostic tool. The remote server can block responses to ICMP requests.

traceroute

In simple terms, the command is called route tracing. As the name suggests, this utility will show which route the packets took to reach the host. traceroute utility somewhat similar to ping, but displays more interesting information. Example:

# traceroute ya.ru traceroute to ya.ru (213.180.204.3), 30 hops max, 60 byte packets 1 243-083-free.kubtelecom.ru (213.132.83.243) 6.408 ms 6.306 ms 6.193 ms 2 065-064-free .kubtelecom.ru (213.132.64.65) 2.761 ms 5.787 ms 5.777 ms 3 lgw.kubtelecom.ru (213.132.75.54) 5.713 ms 5.701 ms 5.636 ms 4 KubTelecom-lgw.Krasnodar.gldn.net (1 94.186.6.177) 81.430 ms 81.581 ms 81.687 ms 5 cat26.Moscow.gldn.net (194.186.10.118) 47.789 ms 47.888 ms 48.011 ms 6 213.33.201.230 (213.33.201.230) 43.322 ms 41.783 ms 41. 106 ms 7 carmine-red-vlan602.yandex.net (87.250. 242.206) 41.199 ms 42.578 ms 42.610 ms 8 www.yandex.ru (213.180.204.3) 43.185 ms 42.126 ms 42.679 ms

As you can see, you can trace the route from the provider’s router 243-083-free.kubtelecom.ru (213.132.83.243) (South of Russia) to the end host at www.yandex.ru (213.180.204.3) in Moscow.

dig

This utility sends queries to DNS servers and returns information about the specified domain. Example:

# dig @ns.kuban.ru roboti.ru ;<<>> DiG 9.3.6-P1<<>> @ns.kuban.ru roboti.ru ; (1 server found) ;; global options: printcmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 64412 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 0 ;; QUESTION SECTION: ;roboti.ru. IN A ;; ANSWER SECTION: roboti.ru. 448 IN A 72.52.4.90 ;; AUTHORITY SECTION: roboti.ru. 345448 IN NS ns1.sedoparking.com. roboti.ru. 345448 IN NS ns2.sedoparking.com. ;; Query time: 102 msec ;; SERVER: 62.183.1.244#53(62.183.1.244) ;; WHEN: Thu Feb 17 19:44:59 2011 ;; MSG SIZE rcvd: 94

dig command sent a request DNS server - ns.kuban.ru (@ns.kuban.ru- this parameter is not necessary to specify, in this case the source of information about DNS will be the server from your system settings) about the domain name roboti.ru. As a result, I received a response, in which we can see in the section ANSWER SECTION information about domain IP addresses, in the section AUTHORITY SECTION information about the so-called authoritative DNS servers. The third line from the bottom tells us which server provided the response.

Other diagnostic utilities

ping, dig and other diagnostic utilities with parameters can be found in the post.

Connecting a new network card

Connecting and launching a new network card comes down to a few steps:

1. Physical connection of the card

3. View the output of whether the system has detected a new network card:

Let's see the conclusion BEFORE connecting a new card:

Server:~# dmesg | grep eth [ 4.720550] e1000: eth0: e1000_probe: Intel(R) PRO/1000 Network Connection [ 5.130191] e1000: eth1: e1000_probe: Intel(R) PRO/1000 Network Connection [ 15.285527] e1000: eth2: e1000_watchdog: NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX [ 15.681056] e1000: eth0: e1000_watchdog: NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX

The output shows that the system has 2 network cards eth1 and eth2. We connect the third one and look at the output:

Server:~# dmesg | grep eth [ 4.720513] e1000: eth0: e1000_probe: Intel(R) PRO/1000 Network Connection [ 5.132029] e1000: eth1: e1000_probe: Intel(R) PRO/1000 Network Connection [ 5.534684] e1000: eth2: e1000_probe: Intel(R ) Pro/1000 Network Connection [39.274875] udev: Renamed Network Interface Eth2 to Eth3 [39.287661] UDEV: Renamed Network IntH1_RENAME_REN TO ETH2 [45.670744] ETH2 [45.670744] 1000: ETH2: E1000_WatchDOG: Nic Link Is up 1000 MBPS Full Duplex, Flow Control: RX [ 46.237232] e1000: eth0: e1000_watchdog: NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX [ 96.977468] e1000: eth3: e1000_watchdog: NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX

IN dmesg we see that a new network has appeared - eth3, which is actually eth2, but renamed by the udev device manager to eth3, and eth2 is actually a renamed eth1 (we will talk about udev in a separate post). The appearance of our new network in dmesg tells us that the network card supported core and correct decided. All that's left is to set up the new interface in /etc/network/interfaces(Debian) because this map was not initialized by the startup script /etc/init.d/network. ifconfig sees this map:

Server:~# ifconfig eth3 eth3 Link encap:Ethernet HWaddr 08:00:27:5f:34:ad inet6 addr: fe80::a00:27ff:fe5f:34ad/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric: 1 RX packets:311847 errors:0 dropped:0 overruns:0 frame:0 TX packets:126 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:104670651 (99.8 MiB) TX bytes: 16184 (15.8 KiB)

but again - it does not configure. How to configure the network card was discussed above.

Summary

I think that's all for today. When I started writing this article, I thought that I would fit into one post, but it turned out to be huge. Therefore, it was decided to split the article into two. In total, I tried to present, not a step-by-step procedure for setting up a network, but to outline the principle and explain the understanding of how the network starts and works in Linux. I really hope that I succeeded. I will be glad to see your comments and additions. Over time, I will add to the article.

How to Modify and Manage the Hosts File in Linux A little-known feature called the hosts file can be used to modify your system depending on your needs. Whether you need to create shortcuts, block websites, or anything else, you can do it all using the hosts file. But how do you make changes to it? Here we will tell you how and give you some usage examples so that you can start using the file right away. What is a hosts file? In simple terms, a hosts file is a simple text file that is used in any operating system for translation hostnames to IP addresses. When you type the hostname - e.g. facebook.com or myubuntu.ru- your system will check the hosts file to obtain the IP address that is required to connect to the corresponding server. But if you open this file on your computer, you will quickly discover that it does not contain a directory of all Internet sites. There may be just a couple of lines and nothing more. Your system will always check the hosts file first, and anything not set there will be found on the DNS servers configured in your network settings (usually those of your ISP). But this also means that you can use the Hosts file to add addresses to it that cannot be provided by DNS servers (for example, these could be aliases for various locations on your home network, which would otherwise only be available if you have installed and configured own DNS server), or to bypass the IP addresses provided by your default DNS servers. For example, if you ask your browser to open facebook.com, DNS servers will return Facebook's IP address to your computer. But if you suddenly want to block Facebook on your computer, you can add an entry to the hosts file that will indicate to your computer that all requests for facebook.com needs to be redirected to some other IP address that is different from the real Facebook IP address. To block this social network, you can simply register requests to be translated to facebook.com to IP address 127.0.0.1, which will always return to your system. You can do a lot of things with this file, and this is just a very simple example - it all depends on your desires and needs. How to edit the hosts file On Linux operating systems, you can find the hosts file in /etc/hosts. Since this is a regular text file, you can just use a regular text editor (whether terminal or graphical). Unfortunately, there is only one graphical tool that provides partial hosts file management - the Domain Blocker application from Linux Mint. This program works by adding entries to your hosts file that redirect the domains you specify to 127.0.0.1- that is, on your computer. Anyway, that's all you can do with Domain Blocker - all other uses of the hosts file require you to manually edit the file using a text editor. Since hosts is a system file, you will need administrative rights to save changes to this file. However, you can edit it using a terminal command such as sudo nano /etc/hosts or gksu gedit /etc/hosts. You need to use a terminal so that you can run the required application with administrative rights this way. You can also replace nano or gedit with the command to launch your favorite text editor. When you are done editing the file in nano, you can press Ctrl+X and then y to confirm overwriting the changes. How do you understand the format of the contents of a hosts file? In a hosts file, each entry is on its own line. For the purposes of this article, you can use a very simple syntax - you type the IP address to which you want to forward the hostname (domain), then a tab character and the domain itself. For example, to block Facebook you can enter 127.0.0.1facebook.com, where is pressing the Tab key on your keyboard. To make sure the input is correct, you can also look at the screenshot and compare it with what is in your file. Let's give another example of using this feature. For example, if you have a computer on your home network (let's say its IP address 192.168.1.10), which runs a simple website that does something useful for you. You can enter the following in the hosts file: 192.168.1.10homeserver. Now if you open your browser and simply type http://homeserver into the address bar, it will automatically show you the contents of the host 192.168.1.10. It's much easier than typing in the IP address every time. Potential Issues The only issue I've come across is with the Chrome browser. It tends to ignore the hosts file unless you do at least one of two possible things: enter http:// before each address. For example, if you have Facebook blocked via the hosts file, Chrome will bypass the block if you simply enter