Linux Network Basics

Source: Internet
Author: User
Tags domain name server
Network-related configuration file introduction 2.1/etc/hosts

Contains a list of known hosts (in the local network. If the system IP address is not dynamically obtained, you can use it. For simple host name resolution (Dot-based representation), before requesting a DNS or NIS network name server,/etc/hosts. conf usually tells the DNS program to check the domain name first.

 

File Format: IP address host name alias $ CAT/etc/hosts127.0.0.1 localhost. localdomain localhost

 

2.2/etc/service.ap-southeast-1.maxcompute.aliyun-inc.com/api

The Internet service file to convert the network service name to the port number/protocol. It is read by inetd, telnet, tcpdump, and some other programs. Each row in the file corresponds to a service. It consists of four fields separated by tabs or spaces, service name, port used, protocol name, And alias respectively ".

 

File Format: service port/port type alias $ CAT/etc/services | moretcpmux 1/tcp # TCP port service multiplexerecho 7/tcpecho 7/udpdiscard 9/tcp sink nulldiscard 9/udp sink nullsystat 11/ TCP usersdaytime 13/tcpdaytime 13/udpnetstat 15/tcpqotd 17/tcp quotemsp 18/tcp # Message send Protocol

 

2.3/etc/hostname

The host name configuration file, which has only one line and records the Host Name of the local machine.

File Format:

 

Host Name $ CAT/etc/hostname tonybox

 

2.4/etc/host. conf

When both DNS domain name resolution and/etc/hosts host table mechanism exist in the system, the/etc/host. conf determines the host name interpretation order. Example:

 

Order hosts, bind # name explanation order multi on # Allow the host to have multiple IP addresses nospoof on # Disable IP Address Spoofing

 

Order is the keyword. It is defined to first interpret the name in the host table of the local host. If it cannot be interpreted, search for the BIND name server (DNS ).

2.5/etc/nsswitch. conf

Name Service Switch configuration file. It controls database search, including recognized hosts, users, and groups. In addition, this file defines the database to be searched, for example, this row:

 

hosts: files dns

 

Specifies that the host database comes from two places, files (/etc/hosts file) and DNS, and files on the local machine are preferred over DNS.

 

$ cat /etc/nsswitch.conf passwd:         compatgroup:          compatshadow:         compathosts:          files dnsnetworks:       filesprotocols:      db filesservices:       db filesethers:         db filesrpc:            db filesnetgroup:       nis

 

2.6/etc/resolv. conf

This file is a DNS domain name resolution configuration file. Its format is very simple. Each line starts with a keyword, followed by configuration parameters. Resolv. conf has four keywords:

 

Nameserver # define the DNS server IP address domain # define the local domain name search # define the domain name search list sortlist # Sort the returned domain names

 

Below is an example:

 

# Cat/etc/resolv. confdomain mydebian. comnameserver 192.168.1.1 // up to three Domain Name Server addresses

 

2.7/etc/Network/interfaces

In the network interface parameter configuration file, the following is a configuration example. There are two network interfaces, in which eth0 assigns a static IP address and eth1 dynamically obtains the IP Address:

        # 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        auto eth0        iface eth0 inet static                address 192.168.1.254                network 192.168.1.0                netmask 255.255.255.0                broadcast 192.168.1.255                gateway 192.168.1.1        auto eth1        iface eth1 inet dhcp

 

If you modify this file, you need to restart the network to make it take effect:

        # /etc/init.d/networking restart

 

3. Basic network configuration commands and scripts 3.1 etherconf

Debian provides a software package named etherconf for configuring network information, including host name, IP address, DHCP, DNS, gateway, netmask... by default, this software package is not installed. You need to manually install it:

 

        # aptitude install etherconf

 

Run after installation:

 

        $dpkg-reconfigure etherconf

 

Configure.

The software modifies the following configuration files:

 

        /etc/resolv.conf        /etc/network/interfaces        /etc/hosts        /etc/hostname

 

The method to reuse this configuration file is:

 

        # dpkg-reconfigure etherconf

 

3.2/etc/init. d/networking

The initialization script when the system starts. When the system starts at a certain level, it initializes all configured network interfaces.

3.3 ifconfig

The network interface used to configure the resident kernel. It is used to set network interfaces when the boot is successful. After that, it is used only when debugging and system adjustment are required.

 

Command Format: ifconfig [interface] ifconfig interface [aftype] Options | address...

 

If no parameter is provided, ifconfig displays the status of the current valid interface. If a single interface is given as a parameter, it only displays the status of the interface given; if a-a parameter is given, it displays the status of all interfaces, including those disabled interfaces. Otherwise, an interface is configured.

 

Option interface name. It is usually the name of the driver device followed by the unit number, for example, the first Ethernet interface eth0. Up this option to activate the interface. If an address is declared for the interface, this option is implicitly declared. Turn off the interface driver. Netmask ADDR sets the IP network mask for the interface. The default value is generally A, B, or C-type network mask (introduced by the IP address of the interface), but it can also be set to another value. Add ADDR/prefixlen to add an IPv6 address to the interface. Del ADDR/prefixlen deletes an IPv6 address for the interface. If the HW Class address is supported by the interface driver, set the hardware address of the interface. This option must be followed by printable ASCII characters equivalent to the hardware type name and hardware address. Currently Supported Hardware types include ether (Ethernet), ax25 (ampr ax.25), ARCNET, and netrom (ampr net/ROM)

Use the ifconfig command to view Network Information:

 

 

ifconfig        eth0      Link encap:Ethernet  HWaddr 00:15:58:3E:F2:6B                    inet addr:192.168.1.254  Bcast:192.168.1.255  Mask:255.255.255.0                  inet6 addr: fe80::215:58ff:fe3e:f26b/64 Scope:Link                  UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1                  RX packets:29458 errors:0 dropped:0 overruns:0 frame:0                  TX packets:23690 errors:0 dropped:0 overruns:0 carrier:0                  collisions:0 txqueuelen:1000                   RX bytes:10945195 (10.4 MiB)  TX bytes:2935004 (2.7 MiB)                  Interrupt:169 Base address:0xe200         eth0:0    Link encap:Ethernet  HWaddr 00:15:58:3E:F2:6B                    inet addr:192.168.1.244  Bcast:192.168.1.255  Mask:255.255.255.0                  UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1                  Interrupt:169 Base address:0xe200         lo        Link encap:Local Loopback                    inet addr:127.0.0.1  Mask:255.0.0.0                  inet6 addr: ::1/128 Scope:Host                  UP LOOPBACK RUNNING  MTU:16436  Metric:1                  RX packets:354 errors:0 dropped:0 overruns:0 frame:0                  TX packets:354 errors:0 dropped:0 overruns:0 carrier:0                  collisions:0 txqueuelen:0                   RX bytes:45062 (44.0 KiB)  TX bytes:45062 (44.0 KiB)        ppp0      Link encap:Point-to-Point Protocol                    inet addr:18.18.18.13  P-t-P:18.18.18.1  Mask:255.255.255.255                  UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1396  Metric:1                  RX packets:9631 errors:0 dropped:0 overruns:0 frame:0                  TX packets:9189 errors:0 dropped:0 overruns:0 carrier:0                  collisions:0 txqueuelen:3                   RX bytes:8460352 (8.0 MiB)  TX bytes:913898 (892.4 KiB)

 

The first format of ifconfig (or the ifconfig command without any parameters) can be used to view the network configuration of the current system.

 

* Eth0: indicates the NIC Code * lo: The network loop address in Linux. It is used to simulate network behavior. * hwaddr: The hardware address of the NIC, that is, the MAC address * Inet ADDR: nic IP Address * bcast: broadcast address (broadcast); * mask: Subnet Mask; * MTU: Maximum trasmission Unit ), indicates the maximum number of packets that can be transmitted for this network interface. Setting Errors for this value may cause network faults. * RX: reception of data from the start to the present of the Network * TX: transmission of data from the start to the present of the Network * Collisions: Conflict of network signals;

 

Activate a network device

 

        ifconfig eth0 up

 

Change network device information

 

        #ifconfig eth0 192.168.1.112 netmask 255.255.255.0

 

Disable network devices

 

        ifconfig eth0 down

 

Modify the MAC address of an Eni

 

        ifconfig eth0 down        ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx        ifconfig eth0 up

 

4. Network Service related 5. Test network 5.1 Ping

Send an ICMP Echo Request (echo_request) group program to the network host to send an ICMP echo response using the forced echo request data report of the ICMP protocol. Echo the request datagram (''pings IP address and ICMP header, it is followed by a ''time value keyword ''and then a byte of any length is used to keep the group length as an integer multiple of 16. The following are program options:

 

Ping [-c count] [-I wait] [-P pattern] [-s packetsize] [-T TTL] destination-C count in sending (and receiving) the operation is stopped after the echo response group with a Count value exists. -I wait waits for the number of seconds for each group to be sent. The default value is one second for each group. This option and-F option cannot be used at the same time. -P pattern can be used to specify a maximum of 16 filling bytes to keep the group length as an integer multiple of 16. This option is useful when diagnosing data-related problems on the network. For example, ''- pff'' will fill the data zone with all the sent groups. -S packetsize specifies the number of bytes of data to be sent. The default value is 56, which is a 64-byte ICMP datagram after an 8-byte ICMP header is added. -T ttl indicates the TTL value of the survival value. The default value is 255.

 

 

        tony@tonybox:~$ ping www.linuxsir.org -c 4        PING www.linuxsir.org (218.61.34.138) 56(84) bytes of data.        64 bytes from 218.61.34.138: icmp_seq=1 ttl=52 time=103 ms        64 bytes from 218.61.34.138: icmp_seq=2 ttl=52 time=125 ms        64 bytes from 218.61.34.138: icmp_seq=3 ttl=52 time=126 ms        64 bytes from 218.61.34.138: icmp_seq=4 ttl=52 time=110 ms        --- www.linuxsir.org ping statistics ---        4 packets transmitted, 4 received, 0% packet loss, time 3003ms        rtt min/avg/max/mdev = 103.513/116.329/126.598/9.856 ms        tony@tonybox:~$ 

 

5.2 route

The route program operates on the kernel's IP route table. It is mainly used to specify the host or network to set static routes for interfaces configured with ifconfig (8.

When the Add or del option is used, route modifies the route table. If these options are not available, route displays the content of the current route table.

 

# Route [-nee] # route add [-net |-host] target host or network [netmask] [GW | Dev] # route del [-net |-host] Target Host or the network [netmask] [GW | Dev]-N: the address is displayed as a numeric address instead of an interpreted host name. This is very useful for detecting the cause of your failure in the route to the Domain Name Server. -Ee: Add a route DEL: delete a route-Net: the target of the route is the network. -Host: the target of the route is the host. Netmask: Specify the network mask for the added route! GW: uses a gateway to Route packets.

 

Note:

The specified gateway must be reachable first. That is to say, a static route must be specified in advance for the gateway. If you specify the gateway address for one of the local interfaces, the gateway address is used to determine how the Group on this interface will be routed. This is compatible with the BSD style. Dev: force the route to be associated with the specified device; otherwise, the kernel will attempt to detect the corresponding device (by checking the existing route and device declaration in the environment where the route entry to be added is located ). You do not need to use it on most normal networks.

 

# Route view local route information tonybox: /etc/Network/run # route kernel IP routing table destination gateway genmask flags metric ref use iface 18.18.18.1*255.255.255.255 uh 0 0 0 0 ppp0 192.168.1.0*255.255.255.0 u 0 0 0 eth0 default * 0.0.0.0 u 0 0 0 ppp0

 

 

Route add-net 127.0.0.0 adds a common loop record, which uses the mask 255.0.0.0 (which can be determined from the target address as a Class A network) and is associated with the device "Lo. route add-net 192.168.1.0 netmask route 255.255.0 Dev eth0 Add a route entry pointing to network 192.56.76.x to the route table "eth0. The Class C subnet mask modifier is not mandatory because 192. * is a class c ip address. The keyword "Dev" can be omitted here ". Route add default GW 192.168.1.1 Add a default route (use it if it cannot match other routes ). All packages using this route will be transmitted through the gateway 192.168.1.1. Route add 224.0.0.0 netmask 240.0.0.0 Dev eth0 is a fuzzy command. Record it to let people know how to do it. this command sets all routes for Class D addresses (for multicast) to run through "eth0. This is the correct configuration line for the kernel with multicast.

 

5.3 Traceroute

 

        traceroute [ -dFIlnrvx ] [ -f first_ttl ] [ -g gateway ]                       [ -i iface ] [ -m max_ttl ] [ -p port ]                       [ -q nqueries ] [ -s src_addr ] [ -t tos ]                       [ -w waittime ] [ -z pausemsecs ]                       host [ packetlen ]

 

With traceroute, we can know the path from your computer to the host on the other end of the Internet. Of course, the path for each packet to arrive at the same destination from a certain source may be different, however, most of the time the routes are the same. In Unix systems, we call traceroute, Which is tracert in MS windows. Traceroute sends a small packet to the target device until it returns, to measure how long it takes. Traceroute of each device in a path must be tested three times. The output results contain the time (MS) of each test, the name of the device (if any), and its IP address.

 

-D specifies the address not to be resolved by the computer name. -H maximum_hops specifies the maximum number of jumps to the target. -Jcomputer-list indicates Loose Source Route in computer-list. -W Timeout: the number of milliseconds specified by timeout for each response. Host Name of the target computer.

 

 

        # traceroute www.linuxsir.org        traceroute to www.linuxsir.org (218.61.34.138), 30 hops max, 40 byte packets

 

6. Configure ADSL for Internet access

First, you must have an Internet account and password, and a network card is correctly connected to ADSL moden.

6.1 install the pppoe package

 

        $ sudo install pppoe pppoeconf

 

6.2 and then configure

 

Check that your network adapter has entered your ADSL account and entered your ADSL account password. General options: Modify default route: Yes Get DNS: Yes automatic connection during boot: yes whether to establish a connection immediately: Yes

 

After completing these steps, the connection will be ready for use.

6.3 manual control

 

$ Sudo Pon DSL-provider # manual connection $ sudo poff DSL-provider # manual disconnection

 

6.4 FAQ

Q: The dial is successful but cannot communicate with the Internet.

A: run the route command to check the local route and check whether the default route is correct.

Q: The domain name cannot be resolved.

A: Check the/etc/resolv. conf file to see if DNS is obtained correctly.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.