LINUX Network basics-general Linux technology-Linux technology and application information. For details, refer to the following section. Teaching Content:
Protocol TCP/IP protocol
Worker network configuration file
Startup of butler service
Teaching objectives:
Remark understand the network services supported by Linux
Familiar with the Service Startup methods in Linux
Measure the test taker's knowledge about Linux Ethernet settings, network operation commands, and Service Startup methods.
Teaching focus:
Ethernet settings
Frequently Used commands of the worker network
How to start the ingress Service
Teaching difficulties:
Elastic super server
I. TCP/IP protocol
1. TCP/IP Reference Mode
(1) Network Interface Layer
In fact, the TCP/IP reference model does not really describe the implementation of this layer. It only requires that an access interface be provided to the upper-layer Internet layer so that IP groups can be transmitted on it. Since this level is not defined, the specific implementation method varies with the network type.
(2) Internet Layer
The Internet layer is the core of the entire TCP/IP protocol group. Its main function is to address and transmit data between networks. The main protocols defined at this layer are shown in Table 8-1.
Table 1-1 Internet Layer Protocol
Protocol description
The IP address provides the packet transmission and Route Selection services between hosts.
Transmission of error and control packets between ICMP Control Host and gateway
ARPARP resolves TCP/IP-based IP addresses into LAN hardware MAC addresses
RARP is mainly used for diskless nodes and resolves the IP addresses of diskless nodes into MAC addresses.
(3). Transport Layer
In the TCP/IP model, the transport layer enables peer entities on the source and target hosts to perform sessions. The Transport Layer defines two protocols with different service quality. That is, the transmission control protocol TCP (transmission control protocol) and user datagram protocol UDP (user datagrams protocol ).
TCP is a connection-oriented and reliable protocol. It sends the byte stream sent by a host to other hosts on the Internet without error. At the sender end, it is responsible for dividing the byte streams transmitted from the upper layer into packet segments and transmitting them to the lower layer. At the receiving end, it is responsible for reorganizing the received packets and then submitting them to the upper layer. The TCP protocol also needs to handle end-to-end traffic control, so that the receiver that receives slowly does not have enough buffer to receive a large amount of data sent by the sender.
UDP is an unreliable and connectionless protocol. It is applicable to scenarios where packets do not need to be sorted or throttled.
(4) Application Layer
The TCP/IP model combines the Session Layer and presentation layer functions in the OSI reference model into the application layer. The Application Layer introduces different application layer protocols for different network applications. common protocols are shown in Table 8-2.
Table 1-2 Application Layer Protocols
Protocol description
FTP is used to transfer files between hosts.
HTTP is used to implement WWW services on the Internet
SMTP is used to implement the email transmission function on the Internet.
DNS is used to convert host names and IP addresses.
SMB is used to share files between Windows and Linux Hosts.
TELNET for remote login
DHCP is used to dynamically allocate IP configuration information.
2. Introduction to TCP/IP subprotocols
(1) Introduction to the internet Layer Protocol
IP protocol
Description: it is mainly responsible for addressing and selecting the route of data packets between hosts, grouping and encapsulation of data packets. The IP protocol does not include the error recovery encoding and is an unreliable protocol. It is the most important protocol of the network.
IP package format:
Route table operation:
# Route (displays the route table information of the current system)
# Route add? Net 192.168.0.0/24 dev eth0 (add a network route)
# Route add? Host 192.168.3.2 dev eth1 (add host route)
# Route add? Host 192.168.1.3 gw 192.168.1.1
# Route add default gw 192.168.0.1 (add default gateway)
# Route del? Host 192.168.3.2. dev eth1 (delete route)
# Route del? Net 192.168.0.0/24 dev eth0
# Route del default gw 192.168.0.1
ICMP protocol
Note: Through the ICMP protocol, the host and router can report errors and exchange related status information. Generally, ICMP messages are automatically sent in the following cases.
• IP datagram cannot access the target.
• IP routers (gateways) cannot forward data packets at the current transmission rate.
• The IP router redirects the sending host to a better route to the destination.
ICMP packet format:
ICMP packet type:
ARP Protocol
Note: ARP resolves IP addresses used by TCP/IP software into MAC addresses used by LAN hardware.
ARP Process
ARP table operations:
# Arp (displays the arp Address Table)
# Arp-s 192.168.3.1 00: 60: 08: 27: ce: b2 (add a record to the arp Address Table)
# Arp-d 192.168.3.1 (delete records in the arp Address Table)
# Arp-f (read the added records from the/etc/ethers file)
(2) Transport Layer Protocol
Protocol TCP
Description: it provides reliable and connection-oriented data transmission services to ensure correct sorting and delivery of segmented data in sequence. Check the integrity of transmitted data by calculating the checksum. Whether the data is successfully sent or not. Confirm the selected data or send the data that has not been received.
TCP datagram format:
Source Port (2 bytes) Destination Port (2 bytes)
Sequence Number (4 bytes) Validation sequence number (4 bytes)
Header Length (4 bits) reserved (6 bits)
URGACKPSHRSTSYNPIN
Window Size (2 bytes) checksum (16 bits)
Emergency pointer (16-bit) option (optional)
Data
Working Process:
Token creates a connection through a three-way handshake.
Producer sends data
Disconnect
UDP protocol:
Note: UDP provides non-connected datagram service, which means that UDP cannot guarantee the transmission and verification of any datagram.
UDP packet format:
Source Port (2 bytes) Destination Port (2 bytes)
Packet Length (2 bytes) checksum (2 bytes)
Data
3. IP address and subnet mask
(1) Definition of IP
• An IP address is a network code. It can be the address of a host (server or client) or a port of a router, that is, the IP address determines a connection in the network.
• All IP addresses are centrally allocated by the Network Information Center (NIC) of the international Organization. Currently, there are three such Network Information centers in the world.
? INTERNIC: Responsible for the United States and other regions
? RIPE-NIC: Europe
? APNIC: Responsible for the Asia Pacific region and headquartered at Tokyo University
(2) ip address Representation
• Binary/decimal representation of vertices
(3) Public and private addresses
• Public IP addresses are unique and managed and allocated by IANA in a unified manner.
• Private IP addresses cannot be directly connected to the Internet, solving the public address shortage problem
(4) Subnet Mask
• Subnet mask Function
? Identifies the network ID and host ID of an IP address.
? Distinguish between local hosts and remote hosts
• Default mask
? Class A address
255.0.0.0
? Class B address
255.255.0.0
? Class C address
255.255.255.0
• Subnet division
? The Network bit is lent to the host bit
? Number of subnets: 2n-2, n is the number of digits the network bits borrow from the host bits
? Number of hosts in each subnet: 2 m-2, and m is the number of remaining hosts after the bid
(4) services and ports
The TCP/UDP port range is 0-65535. Among them, 0-is called a "well-known port", which is reserved for common service programs. 1024-is a dedicated UNIX/Linux service. More than of the ports are dynamic ports. dynamic ports are not pre-allocated and are allocated to processes only when necessary.
Service name default port
Www80 (TCP)
Ftp-control21 (TCP)
Ftp-data20 (TCP)
Smtp25 (TCP)
Telnet23 (TCP)
Dns53 (UDP)
Pop3110 (110)
Ii. Network Configuration File
1./etc/sysconfig/network File
Function: sets the basic network information of a host, including the host name and default gateway.
Content:
① NETWORKING = yes/no: Set whether to enable the network service when the system is started.
② HOSTNAME = www. sina. cm set the Host Name (not the NETBIOS name ).
③ GATEWAY = 192.168.0.1 sets the default GATEWAY.
④ GATEWAYDEV = eth0: Set the gateway interface.
⑤ FORWARD_IPV4 = yes/no: Set whether IP Forwarding is supported in LINUX.
2./etc/sysconfig/network-scripts/ifcfg-ethX (the value of X is 0, 1, 2 ,....... N)
Function: used to configure the initial information of an Ethernet interface card ,.
Content:
① ONBOOT = yes indicates whether to activate the NIC at startup.
② DEVICE = eth0: Set the name of the physical DEVICE.
③ BOOTPROTO = none | static | dhcp | bootp sets the NIC startup protocol.
④ NETMASK = 255.255.255.0 sets the subnet mask.
⑤ BROADCAST = 192.168.3.255 sets the BROADCAST code.
⑥ NETWORK = 192.168.3.0 set the NETWORK number.
7. IPADDR = 192.168.3.2 sets the Host IP address.
Note: How do I bind an Ethernet card to multiple IP addresses?
Instance: Set the eth0 device in the host. its ip address is 192.168.3.1/24. You must bind the ip address 192.168.5.1 to eth0.
① # Cp/etc/sysconfig/network-scripts/ifcfg-eth0
/Etc/sysconfig/network-scrppts/ifcfg-eth0: 0 (the value of x starts from 0)
② # Vi/etc/sysconfigt/network-scrpts/ifcfg-eth0: 0
After modification:
DEVICE = eth0: 0
ONBOOT = YES
BOOTPROTO = NONE
IPADDR = 192.168.5.1
NETMASK = 255.255.255.0
NETWORK = 192.168.5.0
BROADCAST = 192.168.5.255
3./etc/resolv. conf
Function: configuration file of the Domain Name Service client, used to specify the location of the Domain Name Server
Content:
Domainname linux.cn sets the host domain name.
Search linux.cn sets the search list.
Nameserver 192.168.0.254 sets the IP address of the DNS server (up to three ).
4./etc/host. conf
Function: Configure DNS resolution sequence and resolution parameters.
File Options: order bind, hosts/hosts, bind configure Resolution Sequence
Multi on/off: sets whether a host name can correspond to multiple IP addresses in the hosts file.
Whether nospoolf on/off prevents host Spoofing
5./etc/hosts
Function: configure the ing between the host name and IP address. You can use this file for name resolution.
File Format:
IP address host name host alias
192.168.0.1 www.abc.com www
6./etc/hosts. deny and hosts. allow
Function: controls the client address used to access the tcp Service. hosts. allow sets the client address that is allowed to access, and hosts. deny sets the client address that is not allowed to access. If the configuration files of the two files conflict, the hosts. deny prevails.
Format: server_name: hosts-list
Instance: smbd: 192.168.2.0/255.255.255.0
7./etc/services
Function: configure the service port opening. you can disable the port through record lines if you do not need a port.
3. Start the service
1. Definition of daemon
The programs that provide services on the linux system are executed by the backend daemon. These backend daemon listen to the client requests on specific ports and provide corresponding services to the client, we call this backend daemon as a "daemon process" or "service ".
2. Service Running Mode
(1) independent running mode: The init script is responsible for the management of the Independently Running Service. Each Service only listens to the specified port of the service, and the startup script of the service is stored in/etc/rc. d/init. d.
(2) Super Service Running Mode: The Super Service is managed by xinetd. xinetd creates multiple sockets and listens to multiple ports at the same time. The configuration files of the service managed by xinetd are stored in/etc/xinetd. d directory.
3. Service Startup, shutdown, and restart
(1) Start, shut down, and restart an independent service
Manual mode:
① #/Etc/rc. d/init. d/Script Name
Instance:
#/Etc/rc. d/init. d/network restart
② # Service name
Instance:
# Service httpd start
Automatic mode:
① # Ntsysv [-level]
Instance:
# Ntsysv (set the service to be run at the current running level)
# Ntsysv -? Level 5)
② # Chkconfig [-list |-level] [service name ]
Instance:
# Chkconfig? -List (displays the status of each service at each running level)
# Chkconfig? -Level 3 dhcpd on
(2) super server startup, shutdown, and restart
Manual mode:
① #/Etc/rc. d/init. d/xinetd
② # Service xinetd
Automatic mode:
① # Ntsysv [-- level] level
② # Chkconfig [-- list | -- level] level service name
4. xinetd
(1) functions of xinetd
Ingress supports the startup, shutdown, and restart of rpc, tcp, and udp services.
Period-Based Access Control
Tcp_wrapper host access control
The ingress can bind the service to the specified port.
Limit can limit the Log Size
Limit can limit the number of concurrent connections of the client.
(2) Installation of xinetd
# Rpm? Ivh xinetd-2.3.10-6.i386.rpm
Related Files:
/Etc/xinetd. d directory: stores the configuration file of the xinetd managed object
/Etc/rc. d/init. d/xinetd: xinetd Startup Script
/Etc/xinetd. conf: xinetd configuration file
(3) xinetd configuration
Configure xinetd. conf
Function: Specify the default options for services managed by xinetd.
File Content:
Defaults {
Instances = 60 specify the maximum value for the service to accept concurrent client connections
Log_type = syslog authriv specify the logging method
Log_on_sucess = host pid indicates the information registered when the client connection is successful.
Log_on_failure = host record indicates the information registered when the client fails to connect.
}
Includedir/etc/xinetd. d specifies the storage location of the service configuration file managed by xinetd
Configure the service configuration file managed by xinetd
File Format:
Service name {
Option operator Value
Option operator Value
............
............
............
}
Note:
Operator
= Indicates assigning one or more values to the option
+ = Indicates adding one or more values to the option based on the original one.
-= Indicates to reduce one or more values based on the original options.
Option
Socket_type = stream (tcp) | dgram (udp) | seqpacket (reliable ordered datagram)
Define the TCP/IP SOCKET type
Repeated log_type = SYSLOG file name/file name
Set the log type. SYSLOG indicates that SYSLOG is used to record the log to a specified log file or to a specified file.
Login server = path
Set the location of the corresponding program of the daemon process
Protocol = tcp/udp /..
Set the service working protocol. Refer to the/etc/protocols file.
Export port = port number
Set the working port of the service. See the/etc/services file.
Export wait = yes/no
When the service is started, does other xinetd services wait?
Export log_on_sucess = HOST | PID | USERID | EXIT | DURATION
Set the information recorded in the log when logon is successful
HOST indicates the IP address of the client.
USERID indicates the UID of the login user of the Client
PID indicates the PID of the process
EXIT indicates that the registration process is terminated.
DURATION indicates recording session persistence
Export log_on_failure = HOST | USERID | RECORD
Specifies the information to be registered upon failure, such as the local user, remote user, and terminal type.
Login user = user Name
Set the service administrator account
Consumer group = group name
Set the group to which the service administrator belongs
Protocol type = rpc/internal/unlisted
Set service type
Rpc indicates the RPC service
Internal indicates the xinetd built-in Service
Unlisted indicates the services not listed in the/etc/services or/etc/rpc file.
Export access_times = hh: mm-hh: mm
Set access time
Required flags = REUSE | INTERCEPT | NORETRY | IDONLY
Set socket Flag Information
REUSE sets socket reusability
INTERCEPT obtains the datagram for access check
NORETRY indicates that fork failed and no retry
IDONLY indicates that the connection is accepted only when the remote end identifies a remote user.
Only_from = Host IP Address/network number/Host Name
The following methods can be used to set the accessible client:
0.0.0.0 indicates matching the IP addresses of all hosts
0 in x. x. x.0 x. x.0.0 x.0.0.0 contains wildcards, for example, 192.168.3. All IP addresses from 192.168.3.0 to 192.168.3.255
X. x. x {a, B ,......} Host table
IP address/netmask defines the network number to be matched
No_access = Host IP Address/network number/Host Name
Access prohibited host
Instances = Number
Sets the maximum number of concurrent connections for the client.
Optional disable = YES/NO
Set whether to disable the service
Required bind = Host IP Address/Interface Name
To bind a service to a specified interface, you must specify the protocol value and port
Repeated redirect = Host IP [port number]
Server redirection. The protocol value and port must be specified first.
Required per_source = Number
Set the maximum number of concurrent connections for each client
Required banner = File Name
Set the welcome information file displayed during Client Connection
Required banner_success = File Name
When the client connection is set to successful, the content stored in the specified file is displayed.
Export banner_fail = File Name
When the client fails to be connected, it is stored in the specified file.
Repeated cps = numbers
Limit the customer's connection speed. The first number indicates the number of handles connected per second. If the client exceeds this number, the server will temporarily interrupt the connection, the second number indicates how long the client will automatically restore after the connection is temporarily interrupted. The default two numbers are 50, 10.
Instance: Set the telnet service configuration file to meet the following requirements:
Start the telnet service when starting the system
Accept only the 192.168.0.3 client connection-
Ingress binding service on 192.168.0.2 Network Interface
# Vi/etc/xinetd. d/telnet
Service telnet {
Disable = no
Flags = rescue
Socket_type = stream
Wait = no
User = root
Server =/usr/sbin/in. telnetd
Protocol = tcp
Port = 23
Log_on_failure + = USERID
Only_from = 192.168.0.3
Access_times =-
Bind = 192.168.0.2
Per_source = 5
Instances = 5
}
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