Vim/network/ssh

Source: Internet
Author: User
Tags line web domain name server ftp client nslookup

First, editor--vimThe VI Editor is the most basic text editor on Linux and Unix, working in character mode. Because no graphical interface is required, VI is a highly efficient text editor. Although there are many graphical interface editors available on Linux, the functions of VI in System and server management are unmatched by the graphical editors. Vim is a reinforced version of VI, which is easier to use than VI. Almost all of the VI commands can be used on vim.1. Vim Three modesGeneral mode: You cannot edit the contents of a document directly, but you can accept instructions to process the contents of the document or implement a function. Edit mode: You can edit the document Content Command mode: You can accept visible instructions to implement a function2. General ModeWhen the VIM editor has just opened a file, it enters the general mode. Some commonly used operations are as follows: H,j,k,l left and right; the command executes a number before the execution, the implementation of the Ctrl+f page backward; ctrl+b forward; 0 back to the beginning of the line $ go to the end of the row GG to the first line of the file, the command executes a number of times before the execution of G to the end of the file; Implements multiple executions W moves the cursor backward through the word (jumping at the beginning of the word); the command executes several times before the execution of a number, which implements E to move the cursor backward by the word (beating at the ending); the command executes a number before the execution of the order B moves the cursor forward by the word (jumping at the beginning of the word) Jump to file head m jump to the middle of the file L jump to the end of the file to make the current line at the top of the screen, (top) ZZ to make the current line on the screen, ZB the current line at the bottom of the screen, (bottom) dd Delete a row, add a p, paste; Execute the DG multiple times. Removes all data from the current line to the last row of the cursor DGG delete all data from the current line to the first row d$ delete the character of the cursor to the end of the line D0 delete the character of the cursor to the beginning of the line to delete a word that is located in the back of the cursor and enter the edit state dw,de Delete the word at the cursor backward yy copy rows; The command executes a number before execution p/p paste the line to the current line after/before the AYY adds the copied row to buffer A, VI provides the buffer function, can be used to present the data bufferap will be placed in buffer a data paste. B3yy three rows of data into buffer B. B3P will present buffer b data paste yw, ye, YB, y$, y0 in-line copy R to modify the character R to replace the character at the cursor until you press ESC u undo the Last action U undo the operation of the whole row Ctrl + R Redo v Visual state, you can select the specified area by the cursor in the (whole row) Ctrl + V function Ibid. (Whole block)3. Edit ModeThe command characters from general mode to edit mode are: I,i,a,a,s,s,o,o from edit mode to general mode. Press ESC4. Command mode4.1, enter the command mode, press ': ': Set NU Display line number: Set Nonu suppress line number: Set autoindent auto-alignment, cancellation method as in the first example: Set all print all options: Set display different from system default settings parameter: Set Noic lookup is ignore case: Set list display tab (^I) and end-of-line symbols: Set ts=8 tab is equivalent to 8 spaces: Set Hlsearch sets the highlight lookup, cancellation method such as the first example: syntax on open according to program-related syntax to display different colors, close the method itself4.2. Replacement function: 1, $s/aa/bb the first AA of the first line to the last row is replaced with a BB, ' 1,$ ' can also use '% ' instead, you can also use the number to specify the line: 1, $s/aa/bb/g the first line to the last row of all AA replaced by bb:1, $s/aa/bb/gc Confirm all; L confirm current and exit: 1, $s/aa\/cc/g space remember to use ' \ ' escape4.3. Search function: G/text1/s/text2/text3 finds the row that contains the Text1, replaces the command represented by Text3 with the Text2:g/text/command on all lines that contain text: V/text/command Commands represented by running command on all lines that do not contain text: = = = 240gg = = 240G quickly position the cursor on 240 rows/admin Search Admin keyword4.4. split Screen function: split/etc/passwd A horizontal screen to open a file/etc/passwd:vsplit/etc/passwd more separate a vertical screen open file/etc/passwdctrl + WW switchable window4.5. Exit EditQ Exit q! Forced exit W Save Wq first save after launch equivalent to xwq! Forcibly Save and exit4.6. More versatilein (, [, {}, enter% above to jump to the corresponding other parenthesis. Represents an arbitrary character ^ with what begins $ with what ends:%s/./u/implementation: The first letter of each line in the document is replaced by a u#vim/etc/vimrcset tabstop=4--tab key Four set shiftwidth=4--SHIFT + > Also for four 4.7, configure vim# Vim/etc/vimrcset nobackup---Save the set tabstop=4 before saving--used to press the TAB key when set softtabstop=4--To delete set Expandtab--Put tab Key converted to n SPACEBAR, quantity n=abstopset autoindent--Auto indent set shiftwidth=4--set Fileencoding=utf8 when user indents alignment--determines encoding set when writing document fileencodings=utf8,gbk,gb18030,big5,gb2312--For reading documents when encoding recognition set hidden--multi-document editing, do not need to save, directly between the documents switch set confirm--Prompt to savesecond, the Simple network configuration1. NetworkManager ServiceNetworkManager Introduction: NetworkManager A background service that is connected by a management system network and reports its status through D-bus, and a client program that allows users to manage network connections. Pros: Simplify the work of network connections so that the desktop itself and other applications can perceive the network. But it's not necessary for us, and it's not necessary; we, as professionals, have to manage our own networks. The service adds a certain amount of trouble to us instead. So # service NetworkManager Stop--Turn off services # Chkconfig--level NetworkManager off--boot not from boot 2, network entry Linux operating system, NIC default name is eth?# ifconf Ig-a--Find all network cards on your computer # LSPCI | Grep-i ETH--View all network cards connected by the current system # Mii-tool eth0--Check if the network card eth0 is connected to the net # ifconfig--Output all currently in Use Network card # ifconfig eth0--View information for the specified NIC # Ifcon Fig eth0 172.16.1.144 netmask 255.255.255.0--Temporarily set IP and mask # Service Network Restart--once the network is restarted, the network we temporarily set will fail on the three elements of the Internet: IP, GATEWAY,DNS3, permanently set network card via config file # vim/etc/sysconfig/network-scripts/ifcfg-eth0--This configuration will not take effect immediatelyDevice=eth0--Device nameOnboot=yes---When the network service starts, yes is the active state, no means disablehwaddr=14:da:e9:eb:a9:61--strongly recommended not to delete, and to ensure correct MAC addressbootproto=static--dhcp Dynamic acquisition of IP, none depending on the other options to determine whether dynamic or static, static refers to the manually specified IPNm_controlled=no--If the NetworkManager service is enabled, the NIC configuration file is not used NetworkManager managementipaddr=172.16.2.10--Manually set the IP address yourselfnetmask=255.255.0.0--Subnet maskgateway=172.16.2.1-If the network card is active, add a gateway to the system, optional. Generally not recommended to write here# Service Network Restart--this is a way to make the above configuration take effect immediately, and one is to restart the system 4, gateway settingsfunction: Allows direct communication between different networks. A gateway is often an interface on a router# Route-n--View the routing table. The table that determines how the packet should be sent out # route add default GW 10.172.16.1--Temporary Add Gateway # route del default GW 10.172.16.1--Delete default gateway # route Del-net 16 9.254.0.0 netmask 255.255.0.0 Dev eth1-delete normal routing table data # Vim/etc/sysconfig/network-Permanently add a default gateway.Networking=yes-whether to enable networking (No:service network start without any response)hostname=www.upl.com--Set host namegateway=172.16.1.1--Set default gateway5, set the hostname operating system in the course of operation, you can give it a name, through the name of the communication. In the last configuration, the FQDN is permanently configured (fully canonical hostname), which is generally used. As a split symbol. Into the www.baidu.com--Host header. Domain # hostname# uname-n--View hostname # hostname node7.upl.com--command to temporarily set or change hostname # vim/etc/hosts--the previous default two lines don't Modify, do not delete. We strongly recommend that you bind your host name to your own master IP.127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4:: 1 localhost localhost.localdomain localhost6 localhost6.localdomain6172.16.2.7 node7.upl.com# ping node7.upl.com-Ping yourself by your host name 6, specify the role of DNS domain name: The domain name is resolved to IP. # vim/etc/resolv.conf--Specify DNS domain name server nameserver 114.114.114.114Note: Always remember to close the NetworkManager service. Otherwise, the configuration will be cleared when you restart the network7, one card configuration multiple ip# ifconfig eth0:1 10.1.1.244 netmask 255.255.255.0--Temporary configuration # vim/etc/sysconfig/network-scripts/ifcfg-eth0:1 --Permanent configuration of sub-interfacesdevice=eth0:1Onboot=yesbootproto=staticipaddr=10.1.1.7netmask=255.255.0.08, network card Switch control # ifconfig eth0 down--temporarily shut down the network card # ifconfig eth0 up--when on, will not read the configuration file # Ifdown eth0--Completely shut down the network card # ifup eth0--open, will read each network configuration file 9, Network Fault Troubleshooting # Mii-tool-it is possible to connect a valid cable, but still do not see the link OK, you can first determine the network card configuration file is correct, and Onboot=yes, and then restart the Network Service (service network restart) # ping 127.0.0.1-means that the system can support TCP/IP communication. Cause: The related drive is damaged or not. The firewall iptables intercepted. # ping Gateway does not work; Reason: There is a problem with the gateway, or IP conflict resolution: Ping the other IP in the same network segment; Other computers ping the Gateway # ping External network (IP or domain name) Ping the extranet IP. Communication is not a problem, the gateway is set correctly, it is possible that the gateway is unable to ping the network domain. If the IP of the corresponding domain name cannot be returned, the domain name resolution fails, because there is a problem with DNS settings. # Ping Error Network unreachable (unreachable):--generally not set the correct gateway Unknow host xxxx:--Set DNS invalid 10, understand dns# nslookup www.baidu.com# dig www. baidu.com# host Www.baidu.com11, Telnet # ssh [email protected]--Telnet must be connected to the network # SSH-Y [email protected]-- Telnet and allow the graphics software on the remote machine to run. Symbols-y/-x12, netstat are used to display various network-related information, such as network connections, routing tables, Interface states (Interface Statistics), masquerade connections, multicast members (multicast memberships), and so on. # NETSTAT-TUPN-T, can display TCP; U, can display UDP; p, display PID; N, displays the # Netstat-tupna---a parameter as the number of ports, lists all network-related information, displays only stat established# NETSTAT-TUPNL---l parameter, and does not list stat as ESTablished  third, network development1, one virtual multiple IP address # VIM/ETC/SYSCONFIG/NETWORK-SCRIPTS/IFCFG-ETH1-RANGE0ipaddr_start=192.168.133.110--The virtual IP start valueipaddr_end=192.168.133.120--Virtual IP end valuenetmask=255.255.255.0--Subnet maskclonenum_start=110--refers to eth1: The number starting value after# Service Network restart# IFCONFIG2, routing Management # route add default GW 172.16.1.1--Adding a default route is actually adding a gateway # route add-net 10.1.3.0/ Dev eth0-Add Direct Connect route (to device) # route add-net 10.1.2.0/24 GW 10.1.1.2--Add route to specified network # route add-host 10.1.3.1 GW 10.1.1.3--add Route to the specified host to delete the above route, the format is basically the same. Simply change ' add ' to ' del ' to 3, IP address classification reference (not to be remembered): A begins with 0 (binary code) 0.0.0.1-127.255.255.255 default subnet mask: 255.0.0.0B starts with 10 (binary code) 128.0.0.0-191 .255.255.255 Default Subnet mask: 255.255.0.0C starts with 110 (binary code) 192.0.0.0-223.255.255.255 default subnet mask: 255.255.255.0D starts with 1110 (binary code) Multicast 224.0.0.0-239.255.255.255e starts with 1111 (binary code) 240.0.0.0-247.255.255.2554, remembers three private network IP segment Class A: 10.0.0.0-10.255.255.255B class: 172.16.0.0-172.31.255.255C class: 192.168.0.0-192.168.255.2555, Special network address 0.0.0.0--representing all the addresses of the world 127.0.0.1-127.255.255.255-- Local loopback address to test if native TCP/IP is normal. Some cluster software will also use the loopback address (the LVS cluster's Dr Direct routing architecture uses the loopback address) 6, view network card tool # Ethtool eth07, common network management commands, and Common Client tool ARP-- Managing the correspondence between the physical address and IP address of the network card ping--testing the connectivity of the network Nmap--port scan Tool Traceroute--route tracking tool LFTP--FTP client elinks--command line web browser wget--  Command-Line download tool (-C, continue unfinished Task)Nslookup--Query domain name DIG--query domain name   third, SSHSecure link mode, can be used for remote login, transfer files, create encrypted tunnels, etc.;1, remote login: # SSH [email protected]/ipaddress---Remote command line # ssh-x/y [email protected]/ipaddress--Remote GUI # SSH [email& NBSP;PROTECTED] 2, remote transfer file # SCP/ETC/PASSWD [email protected]:/etc/--locally uploaded to remote machine # SCP [email protected]:/ etc/passwd/etc/--Remote upload to local, add-r parameter, can transfer folder  3, other # echo something | SSH [email protected] "Cat >/somewhere/file"--a string that echoes out of the native, cat comes out on the remote machine, and redirects the input to the remote machine's/tmp/file file # echo Geo rge | SSH [email protected] "cat"--run the cat command on the remote machine, and the output of the command is displayed locally # echo George | SSH [email protected] "passwd--stdin guo"----on the local machine to change the remote computer's account Guo password to george. 4, configure SSH certificate login mode 4.1, Server # cd/root/. ssh# rm-rf *# ssh-keygen-t rsa-b 4096--Create a set of keys, you can return all the way, there are special requirements can be self-pondering # ls--Generate a private key, a public key Id_rsa id_rsa.pub# cat id_rsa.pub > Authorized_keys--Import the public key content into the file authorized_keys# SCP Id_rsa [email protected]:/root/--Tell the private key to the client 4.2, client # Cat ID that needs to be connected. _rsa >> ssh/id_rsa# ssh [email protected]-you can log on to the server directly on the client. no password 4.3, wrong # ssh [email protected]--If the following error occurs, the public key can not be used to logThe server still asks for the login password Agent admitted failure to sign using the key.[email protected] ' s password:Workaround:# unset Ssh_auth_sock--delete variable ssh_auth_sock# ssh-add ~/.ssh/id_rsa--Add the private key you just created with the Ssh-add command

Vim/network/ssh

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.