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.
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 ".
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
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:
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.
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:
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;
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:
-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.
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.
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.
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.