Linux Network Basics

Source: Internet
Author: User
Tags echo 7 domain name server
Linux Network basics-Linux Enterprise Application-Linux server application information. For details, refer to the following section. 1. Statement

2. Introduction to network-related configuration files

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/hosts

127.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 | more

Tcpmux 1/tcp # TCP port service multiplexer
Echo 7/tcp
Echo 7/udp
Discard 9/tcp sink null
Discard 9/udp sink null
Listen at 11/tcp users
Daytime 13/tcp
Daytime 13/udp
Netstat 15/tcp
Qotd 17/tcp quote
Msp 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 interpretation 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: compat
Group: compat
Shadow: compat

Hosts: files dns
Networks: files

Protocols: db files
Services: db files
Ethers: db files
Rpc: db files

Netgroup: 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 IP address of the DNS server
Domain # define a local domain name
Search # define the domain name search list
Sortlist # Sort the returned domain names

Below is an example:

# Cat/etc/resolv. conf
Domain mydebian.com
Nameserver 192.168.1.1 // a maximum of 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 activates the interface. If an address is declared for the interface, this option is implicitly declared.
Down
This option disables the interface driver.

Netmask addr
Set 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
Add an IPv6 address to the interface.
Del addr/prefixlen
Deletes an IPv6 address for the interface.
Hw class address
If the interface driver supports this function, 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 FIG: 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 loopback address in Linux, used to simulate network behavior,
* HWaddr: The hardware address of the NIC, that is, the MAC address.
* Inet addr: IP address of the NIC
* Bcast: broadcast address (broadcast );
* Mask: Subnet Mask;
* MTU: the abbreviation of the Maximum transmission Unit (Maximum Trasmission Unit), which indicates the Maximum number of packets that can be transmitted by this network interface. Setting errors of this value may cause network faults.
* RX: reception of data from the network startup till now
* TX: Data Transmission status from network startup to now
* Collisions: network signal conflict;

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
Ifconfig eth0 up

4. Network Services

5. Test the 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 stops sending (and receiving) an echo response group with a count value.
-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 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 that the TTL value is 255 by default.

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 bytes ed, 0% packet loss, time 3003 ms
Rtt min/avg/max/mdev = 103.513/116.329/126.598/9.856 MS
Tony @ tonybox :~ $

5.2 route

The Route 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 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: a large amount of information will be generated, including all the parameters of the routing table.
Add: 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 ppp0
192.168.1.0*255.255.255.0 U 0 0 0 eth0
Default * 0.0.0.0 U 0 0 ppp0

Route add-net 127.0.0.0
Add A common loop record, which uses the mask 255.0.0.0 (from the target address, it can be determined to be A class A network) and is associated with the device "lo.

Route add-net 192.168.1.0 netmask 255.255.255.0 dev eth0
Add a route entry pointing to network 192.56.76.x to the route table through "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
This is a fuzzy command. Record it to let people know how to do it. This command sets routes for all Class D addresses (for multicast) 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 an invalid computer name resolution address.
-H maximum_hops
Specify the maximum number of jumps to the target.
-Jcomputer-list
Loose Source Route in computer-list.
-W timeout
Wait for the number of milliseconds specified by timeout for each response.
Host
The 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

Confirm that your Nic is detected
Enter your ADSL account
Enter your ADSL account password
General option: whether to modify the default route: yes
Retrieve DNS: yes
Automatic Connection during boot: yes
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 # manually disconnect

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.