Windows.  Viruses.  Notebooks.  Internet.  office.  Utilities.  Drivers

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

FILE /etc/hosts

The /etc/hosts file specifies the correspondence between the IP address and the host name (hostname, domain), as well as their aliases (also called synonyms, aliases). When you access some address on the network, for example, http://yandex.ru, then in order to access the site, the system first needs to convert the site address into its corresponding IP address, for this the system queries the IP address from the DNS server. If there is a correspondence between yandex.ru and an IP address in the /etc/hosts file, then the system will use this IP address. And since we can also specify an alias in the /etc/hosts file, by which a specific IP address will be available, 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 site. That is /etc/hosts, it's kind of local DNS server.

How to find the IP address of a site

Now we need to define the IP addresses of the sites 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 major 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. Similarly, we perform for other sites.

Editing the /etc/hosts file

Editing the /etc/hosts file must be done 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 content of the file looks 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 registered correspondences between IP addresses, site names and their aliases. Now go to your browser and address bar just enter "g", the site google.ru should open. To open mail.ru, simply enter "m", for rbc.ru - just "r", yandex.ru - "y".

Another name resolution method is to use a local database of hostnames, similar to how it was done in the early days Internet networks. The /etc/hosts file contains a list of hostnames with corresponding IP addresses. Listing 4.3 shows an example /etc/hosts file for a Linux client. It should contain the name of your machine and its IP address, as well as the 127.0.0.1 loopback IP address for service purposes. In addition, if there are any remote hosts that your Linux server periodically connects to, it is also advisable to specify their IP addresses in the /etc/hosts file. Now, each time these hosts are accessed, the Linux server will already have their IP addresses; thus, there is no need to perform DNS queries. In addition, it greatly speeds up the connection establishment.

1 127.0.0.1 localhost 2 192.168.0.1 shadrach.smallorg.org 3 10.0.0.1 mail1.isp.net 4 10.0.0.2 mail2.isp.net 5 10.0.0.3 fred.otherplace.com Listing 4.3. An example /etc/hosts file

The first and second lines are the IP addresses for the local Linux server. Lines 3-5 are the IP addresses for the most frequently requested machines on your network. Due to this, access to them from a Linux-based server is faster than using the DNS system.

localhost name

All Linux computers support localhost . This name always corresponds to the IP address 127.0.0.1 , which is assigned to a special loopback network device. This name and address allows internal processes to communicate with other processes on the same system using network protocols. Many programs are even configured to use the name localhost . Changing this name or its corresponding IP address may affect the operation of these programs.

DNS Translation File

The /etc/host.conf file defines how and how Linux OS names are resolved. Listing 4.4 shows an example /etc/host.conf file.

1 order hosts, bind 2 multi on Listing 4.4. Sample /etc/host.conf file

The first line specifies the order in which hostnames are resolved. This tells the Linux operating system to first look at the /etc/hosts file and look up the host there, and then try to resolve the name using the DNS system (bind) if /etc/hosts fails.

Linux DNS Client Utilities

To help the system administrator, many utilities have been written for Linux to make it easier for DNS to find information about remote hosts and networks. For UNIX systems, the Internet Software Consortium created software package Berkeley Internet Name Domain (BIND), which includes three of the author's most useful and widely used utilities: host , nslookup and dig . These programs are distributed with the software included with most Linux OS distributions. Red Hat and Mandrake Linux provide these programs as RPM packages.

When solving possible problems related to work Email on the Internet, these utilities are quite useful. Often the sender makes mistakes in the recipient's e-mail address, and the letters are not accepted. Naturally, he will be quite sure that he used the correct address, and will lay the blame for the returned messages on you. However, after a little discussion with the DNS, we can draw unambiguous conclusions about the correctness or error of the email address.

host utility

The host program performs the simplest name resolution using DNS. The host command format is as follows:

host [-l] [-v] [-w] [-r] [-d] [-t querytype] [-a] host

By default, the host command attempts to obtain an IP address for the name specified as host using the DNS server defined in the /etc/resolv.conf file. If server is specified on the command line, then by default the host command will use it as the DNS server. By adding additional options on the command line, you can modify how the host command works. All these parameters are listed in Table. 4.5.

Table 4.5. host command parameters
Parameter Description
-l Shows full information about the domain
-v Uses verbose format when outputting results
-w Causes the host command to wait for a response
-r Turns off recursion mode
-d Turns on debug mode
-t querytype Specifies the type of request
-a Restores all records in DNS

The -l option can be used to search for information about all hosts in a domain. Very often, the -t option is used with it to filter information by type (for example, -t MX returns only the MX records for the domain). Unfortunately, the -l option is currently difficult to use for security reasons, as most DNS servers refuse to provide information about hosts from their databases. If the information is being requested from a remote or busy DNS server (or over a slow connection), the -w option can be used. With its help, the host program forcibly waits for a response to a request. The default timeout is about a minute.

One of the more useful options is -r . It instructs the DNS server to return only the information contained in its local database. In this case, the DNS server does not look for information from other DNS servers.

This is quite handy in determining if your DNS server is caching DNS responses correctly. First, try the -r option. If there is no information about the host name, then no response will be received from the local DNS server. Then issue the command without the -r option. A normal response should be received here as the local DNS server is allowed to receive data from others DNS servers. Next, try the host command again with the -r option. Now the information obtained should exactly match the data obtained as a result of the previous attempt. This means that the DNS server this time got information from the cache that was related to the previous attempt. If no information is received, then the local DNS server did not cache the previous response. Then you should notice a significant slowdown in getting a response to a request, since it is done over the network, and not taken from the cache.

By default, the host command will try to output its output in a human-readable format. For example, as shown in Listing 4.5. If the -v option is given, then the output looks like the original DNS records. This can be useful when debugging the DNS system.

1 $host www.linux.org 2 www.linux.org has address 198.182.196.56 3 www.linux.org mail is handled (pri=2O) by router.invlogic.com 4 www.linux.org mail is handled (pri =30) by border-ai.invlogic.com 5 www.linux.org mail is handled (pri=10) by mail.linux.org 6 $ Listing 4.5. host command example

Line 1 shows the basic format of the host command - just add the name of the host you want information about. Lines 2-5 are the output of the command. Line 2 shows that the DNS server was able to resolve the given hostname into its IP address. Next, lines 3-5 show three computers that can receive e-mail for a given host, according to the MX records. Note that the host command even shows the weights (or priorities) for each mail server. If the mail was sent to the user of the specified host, then the server with priority 10 (mail.linux.org) will take care of its delivery first. If the host command is not executed, then you can send a query through another DNS server by specifying its address after the host address on the command line. This is quite effective if you think the local DNS server is not behaving quite right.

Question. How can I add a user to a group in Linux?

Answer. You can use the useradd or usermod commands to add a user to a group. The useradd command creates a new user or updates the information of an existing one. The usermod command modifies an existing user. All user and group information is stored in the /etc/passwd, /etc/shadow and /etc/group files.

useradd example - Adding a new user to a secondary group

Use the useradd command to add a new user to an existing group. If the group does not exist, create it. Syntax:

useradd -G (group-name ) username

Let's create a vivek user and add it to the developers group. Log in as root and make sure the developers group exists:

# grep developers /etc/group

Developers:x:1124:

If the group does not exist, use the groupadd command to create new group developers:

# groupadd developers

Then add the vivek user to the developers group:

# useradd -G developers vivek

Set a password for the vivek user:

Make sure the user is added to the developers group:

#id vivek Output:

Uid=1122(vivek) gid=1125(vivek) groups=1125(vivek),1124(developers)

The -G option allows you to add a group to the user. Groups can be listed separated by commas. For example, let's add user jerry to groups

admins, ftp, www, and developers by typing:

# useradd -G admins,ftp,www,developers jerry

useradd example - Adding a new user to the main group

To add the user tony to the developers group, use the following command:

# useradd -g developers tony

uid=1123(tony) gid=1124(developers) groups=1124(developers)

The -g option allows you to add the user to the main group. The group must exist.

usermod example - Add an existing user to an existing group

Add the existing user tony to the ftp secondary group:

# usermod -a -G ftp tony

Change the primary group for the existing user tony to www:

# usermod -g www tony

guard

For the second tower, I ordered an essay on the Studinform website. It's a shame, of course, but there is absolutely no time to do it yourself. The order was completed very quickly and efficiently. I recommend!

For my car now I think what tires to put. I thought a lot about studded tires. According to reviews, as far as I read, the difference between the braking distance of the best studded tires and best models without spikes was 10 meters! Something to think about...

Version of host.

Description

In the syntax listed below, name is the domain name that is to be looked up. The name can also be a dotted-decimal IPv4 address or a colon-delimited IPv6 address, in which case host will by default perform a reverse lookup for that address. The server is an optional argument that is either the name or IP address of the name server that host should query instead of the server or servers listed in /etc/resolv.conf.

Syntax

host [-aCdlnrsTwv] [-c class][-N ndots][-R number][-t type][-W wait][-m flag] [-4] [-6] {name} [server]

Options

The -a (all) option is equivalent to setting the -v option and asking host to make a query of type ANY.

When the -C option is used, host will attempt to display the SOA records for zone name from all the listed authoritative name servers for that zone. The list of name servers is defined by the NS records that are found for the zone.

-c class

The -c option instructions host to make a DNS query of class class. This can be used to lookup Hesiod or Chaosnet class resource records. The default class is IN(Internet).

Verbose output is generated by host when the -d or -v option is used. The two options are equivalent. They have been provided for backward compatibility. In previous versions, the -d option switched on debugging traces and -v enabled verbose output.

List mode is selected by the -l option. This makes host perform a zone transfer for zone name. Transfer the zone printing out the NS, PTR, and address records (A/AAAA). If combined with -a all records will be printed.

The -i option specifies that reverse lookups of IPv6 addresses should use the IP6.INT domain as defined in RFC1886. The default is to use IP6.ARPA.

-N ndots

The -N option sets the number of dots that have to be in name for it to be considered absolute. The default value is that defined using the ndots statement in /etc/resolv.conf, or 1 if no ndots statement is present. Names with fewer dots are interpreted as relative names and will be searched for in the domains listed in the search or domain directive in /etc/resolv.conf.

-R number

The -s option tells host not to send the query to the next nameserver if any server responds with a SERVFAIL response, which is the reverse of normal stub resolver behavior.

-m flag

The -m can be used to set the memory usage debugging flags record, usage and trace.

Examples

host 204.228.150.3

This command performs a reverse lookup on the IP address 204.228.150.3 , which results in the output:

3.150.228.204.in-addr.arpa domain name pointer www.site.

related commands

dig— DNS lookup utility.
nslookup- Query a name server for information about a remote host.
ping- Send ICMP ECHO_REQUEST packets to network hosts.

This article will tell you about the host command. The host utility is designed to query DNS servers.

[Alexey Vyskubov]

This article will tell you about the host command.

Examples of work are given in operating rooms Linux systems 2.2.17 (Debian unstable, "woody") and FreeBSD 4.2.

The host utility is designed to query DNS servers.
By default, it simply finds the IP address that matches the given hostname, for example:

$ host www.site

Www.site A 195.5.132.10

$ host www.site

Www.site has address 195.5.132.10

As you can see, in the case Linux utility gives a type A DNS record, and FreeBSD simply reports the host address using English language. Note that the Linux-supplied DNS record is unsuitable for direct insertion into the DNS server database because the hostname does not end with a dot; putting a dot after the hostname when calling host doesn't help either.
Also, the IN between the hostname and A is missing. If you need to get a record that can be directly put into the DNS base, on Linux you can use the -Z option:

$ host -Z slashdot.org

Slashdot.org. 3600 IN A 64.28.67.48

FreeBSD does not have this feature.

A similar situation occurs when the specified name is an alias --- Linux prints a line with the word CNAME, while FreeBSD uses the construct "xxx.yyy.zzz is a nickname for aaa.bbb.ccc" :

$ host admin1.piter-press.ru

admin1.piter-press.ru CNAME ns.piter-press.ru

Ns.piter-press.ru A 195.239.142.33

$ host admin1.piter-press.ru.

Admin1.piter-press.ru is a nickname for ns.piter-press.ru

Ns.piter-press.ru has address 195.239.142.33

It should be noted that after the hostname in the host command, the name of the server you want to poll can be specified. If the server name is not specified (as in our examples), then one of the DNS servers for the given zone is polled.

If host receives as input not a host name, but an IP address, then the reverse conversion is made --- to FQDN.

$ host 195.239.142.33

Name: ns.piter-press.ru

Address: 195.239.142.33

$ host 195.239.142.33

33.142.239.195.IN-ADDR.ARPA domain name pointer ns.piter-press.ru

This time, in the case of Linux, plain text information is given (although, it would seem, why not display a DNS record like PTR?). FreeBSD is more logical --- IP address converted to its corresponding hostname in the IN-ADDR.ARPA zone, for which information is displayed --- again, using English.

Local domain substitution

Another important difference between the Linux and FreeBSD versions of host is that if the host name does not end with a dot, FreeBSD tries to substitute the local domain for it, which Linux does not do (possibly a bug, since the man page says otherwise). ):

$ hostname -d

$ nslookup woe.spb.ru

Server: frei.home

Address: 192.168.1.5

Name: woe.spb.ru

Address: 193.125.200.14

$ host woe

Woe does not exist (Authoritative answer)

As we can see, spb.ru is a local domain, the host woe.spb.ru exists, but the host woe command does not produce the desired result. It should be noted that the presence of the search spb.ru (or domain spb.ru) line in the /etc/resolv.conf file would solve the problem. Under FreeBSD host behaves differently:

$ host alv

Alv.home has address 192.168.1.1

$ host alv.

host not found

The local domain was substituted only in the first case because the name did not end with a dot. The search and/or domain lines in resolv.conf are optional.

Details: -v option

A useful option is -v (verbose). In both Linux and FreeBSD, its effect is almost the same: additional information about the zone is displayed.

$ host -v www.spb.ru

Query about www.spb.ru for record types A

Trying www.spb.ru ...

Query done, 1 answer, status: no error

www.spb.ru 2134 IN A 195.190.101.3

authority information:

Www.spb.ru 48235 IN NS ns.nevalink.ru

Www.spb.ru 48235 IN NS ns1.gldn.net

Www.spb.ru 48235 IN NS ns2.gldn.net

Additional information:

Ns.nevalink.ru 54275 IN A 195.190.100.28

ns1.gldn.net 10978 IN A 194.67.2.108

ns2.gldn.net 10972 IN A 195.218.218.8

$ host -v www.spb.ru.

Rcode = 0 (Success), ancount=1

The following answer is not authoritative:

The following answer is not verified as authentic by the server:

www.spb.ru 2053 IN A 195.190.101.3

For authoritative answers, see:

Www.spb.ru 48154 IN NS ns.nevalink.ru

Www.spb.ru 48154 IN NS ns1.gldn.net

Www.spb.ru 48154 IN NS ns2.gldn.net

Additional information:

Ns.nevalink.ru 51480 IN A 195.190.100.28

ns1.gldn.net 10348 IN A 194.67.2.108

ns2.gldn.net 10342 IN A 195.218.218.8

The numeric field that appeared in the host response needs some explanation. By calling host several times, you can see that its value is constantly decreasing, which is not surprising, since this field contains TTL --- time life of the record in the zone.

Under Linux, you can use the -vv option to display information about the process of obtaining DNS records.

Selecting Record Types: Options -a and -t

Two more important options for the host command are -a and -t . The -a option means -t ANY on Linux and -v -t any on FreeBSD, so let's look at the meaning of the -t option.

This parameter is used to set the type of DNS records you are interested in. Supported record types are A, NS, MD, MF, CNAME, SOA, MB, MG, MR, NULL, WKS, PTR, HINFO, INFO, MX, UINFO, UID, GID, UNSPEC. Please note that in linux type entries can be specified in any case, but in FreeBSD only in lowercase letters (a, ns, cname, etc.). If the -t option is not specified, then by default Linux searches for records of type A, if the -l option is specified (see below), then the types A, NS, PTR. FreeBSD searches for records of types A and MX if the -t option is not specified, and if the -l option is specified, it also searches for PTR and NS records. The Linux version of host also supports the MAILB entry type, which means any type from MB, MR, MG, or MINFO. Instead of specifying the -t MAILB option, you can specify the -m option; in this case, records of types MR and MG will also be recursively expanded to MB. Zone Listing: -l Option You can list an entire zone by using the host command with the -l option. Use the -a and -t options to specify the post types you are interested in. Keep in mind that the zone listing is generated by an AXFR request to transfer the zone and extract the desired information from the information received. This means that the -l option creates additional load on the network and DNS servers, so you should use it as little as possible. In addition, many system administrators configure their DNS servers in such a way that they don't give the zone to "just anyone" by refusing to process an AXFR request (while the FreeBSD version of host won't even bother to clearly explain to you what happened):

$ host -l slashdot.org

Slashdot.org AXFR record query refused by ns2.andover.net

Slashdot.org AXFR record query refused by ns3.andover.net

Slashdot.org AXFR record query refused by ns1.andover.net

No nameservers for slashdot.org responded

$ host -l slashdot.org

Server failed: Query refused

Under Linux, you can create a complete copy of the zone suitable for bind feeding with host -Z -a -l (and write it to a file by adding -f filename).

Other options

As you know, DNS is a recursive system. If the DNS server does not find the information requested from it, it initiates a recursive query to the "upstream" server.
The host command has an option to prevent this: the -r option disables recursive queries: only the default DNS server is queried. This option works almost the same under Linux and FreeBSD, but the output of the command when the entry is not found is slightly different:

$ host -r www.spb.ru

Www.spb.ru A record currently not present

$ host -r www.spb.ru

As you can see, FreeBSD just doesn't output anything.

The host command, in principle, can be used not only on the Internet. The -c option allows us to specify the class of entries we are interested in. Record classes IN, CHAOS, HS, HESIOD are supported (IN is used by default). Under Linux, the INTERNET, CS, CSNET, CH classes are also supported. You can use the ANY keyword to specify all classes (under Linux, you can also use the * symbol, just remember to escape it from the shell).

To display debug information, use the -d option (under Linux, it can be duplicated --- -dd --- to increase the amount of debug information).

The FreeBSD version of host uses the -s switch to work with DNSSEC (the Linux version does not work with DNSSEC, the -s switch is used to specify the DNS server timeout in seconds).

Zone listing: additional features Linux versions

The options described in this section are specific to the Linux version of host.

Recursive Listings: The -L Option The -L option specifies the level of recursion when listing a zone. For example, the command:

$ host -l -a -L 1 some.zone

This will list the some.zone zone, as well as all its delegated zones.
Increasing the level of recursion increases the depth of browsing for delegated zones. Everything said about the undesirability of using the -l option is even more important when using the -L -l combination.

Statistics: -S option Specifying the -S option when getting a zone listing displays statistical information about the number of records found various types, the number of hosts of various types, the number of delegated zones, etc.:

$ host -l -a -S freshmeat.net

freshmeat.net. SOA freshmeat.net. dns-admin.freshmeat.net.



Using specific DNS servers: -p and -P options

The -p option tells you to use only the primary DNS server when getting the zone listing. The name of the primary DNS server is determined using the SOA record of the zone in question.
The -P option allows you to specify a list of preferred domains (separated by commas). The DNS server that has the highest number of name component matches with one of the specified domains will be used. The use of these options can be seen in the following example:

$ host -vv -p -l peter.com

Trying server 195.239.142.33 (ns.piter.com) ...

$ host -vv -P hellix.piter.com -l piter.com

Finding nameservers for piter.com ...

Query done, 2 answers, status: no error

The following answer is not authoritative:

Piter.com 3308 IN NS ns.piter.com

Piter.com 3308 IN NS hellix.piter.com

Additional information:

Ns.piter.com 85293 IN A 195.239.142.33

Hellix.piter.com 3308 IN A 193.125.199.13

Found 1 address for ns.piter.com

Found 1 address for hellix.piter.com

Trying server 193.125.199.13 (hellix.piter.com) ...

Skip Zones: Option -N

The -N option allows you to specify a list of zones (separated by commas) about which information is not required. It is usually used in conjunction with the -L option.

Linux: extended syntax By specifying the -x option, you can use the so-called extended syntax for the host command, passing it multiple hostnames instead of one. Since each name in this case is treated as a hostname to be retrieved, the -X option is used to specify the DNS server to be queried. If the -X option is specified, then -x is implied.

The extended syntax allows you to run host without hostnames at all, passing them later to standard input programs. One line can contain multiple hostnames, but if a # or ; character appears on the line, the remainder of the line is ignored.

Linux: special modes

One of the special modes supported by the host utility is the zone transfer mode, enabled by the -l option. The Linux version of the utility has several other special modes, all but one of which are variations of the -l mode.

Zone Transfer Mode Variations

The -C option is similar to the -l option, but it invokes various checks on the zone, such as checking whether each of the DNS servers listed in the NS records for the zone is indeed capable of giving an authoritative answer to a zone query. Other validation checks for the zone are also performed.

The -H option is also the same as the -l option, causing a zone transfer, although it does not display information about the entries. Instead, the number of A-records in the zone is counted. Special care is taken (see man 1 host) to take into account only "real" hosts. The combination of -H -S options allows you to get detailed zone statistics:

$ host -H -S freshmeat.net

Found 34 A records within freshmeat.net

Found 4 NS records within freshmeat.net

Found 9 CNAME records within freshmeat.net

Found 2 SOA records within freshmeat.net

Found 4 MX records within freshmeat.net

Found 32 hosts within freshmeat.net

Found 9 duplicate hosts within freshmeat.net

Found 12 extrazone hosts within freshmeat.net

Found 1 gateway host within freshmeat.net

Found 0 delegated zones within freshmeat.net

The -G , -D , -E options display the names of gateway hosts (gateway), duplicate hosts, and extrazone hosts, respectively. In this case, a gateway is a host with more than one IP address, a duplicate host is a host with exactly one IP address, which also corresponds to several names (possibly from different zones --- this may mean an error in the zone). An out-of-zone host for some.zone is a host of the form host.something.some.zone, where something.some.zone is not a delegated zone.

Address Check Mode

The last mode of the Linux version of the host utility that we haven't analyzed is the address checking mode, initiated by the -A option. In this case, the following actions are performed:

* If a host name was specified as an argument, then its address is determined, by which the host name is determined, and checked for a match with the original name.

* If an IP address was given as an argument, then the corresponding hostname is determined, and then it is checked whether the source IP address is included in the list of IP addresses for the found hostname.

* If the option is specified together with the -l option, then the described actions are performed for each A-record in the zone.

Alexey Vyskubov,

If you notice an error, select a piece of text and press Ctrl + Enter
SHARE: